Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html>
- <head>
- <title>Leaflet Layers Control Example</title>
- <meta charset="utf-8" />
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet-0.6.4/leaflet.css"/>
- <!--[if lte IE 8]><link rel="stylesheet" href="../dist/leaflet.ie.css" /><![endif]-->
- </head>
- <body>
- <div id="map" style="width: 600px; height: 400px"></div>
- <script src="export-geojson.js" type="text/javascript"></script>
- <script src="http://cdn.leafletjs.com/leaflet-0.6.4/leaflet.js"></script>
- <script src="/home/cristian/Scrivania/leaflet/leaflet-plugins/layer/tile/Bing.js" type="text/javascript"></script>
- <script src="http://maps.google.com/maps/api/js?v=3.2&sensor=false"></script>
- <script src="/home/cristian/Scrivania/leaflet/leaflet-plugins/layer/tile/Google.js" type="text/javascript"></script>
- <script>
- // parking icon from Open SVG Map Icons
- // by L. Delucchi
- // https://github.com/lucadelu/Open-SVG-Map-Icons
- var parkingIcon = L.icon({
- iconUrl: 'parking_32x32.png',
- iconSize: [16, 16],
- iconAnchor: [0, 0],
- popupAnchor: [0, -14]
- });
- cloudmadeUrl = 'http://{s}.tile.cloudmade.com/{key}/{styleId}/256/{z}/{x}/{y}.png'
- cloudmadeAttribution = 'Map data © 2013 OpenStreetMap contributors, Imagery © 2012 CloudMade';
- cloudmadeKey = '74f3f6ca3f714d4ab3aab495f7d9e6e9'
- var minimal = L.tileLayer(cloudmadeUrl, {
- styleId: 22677,
- attribution: cloudmadeAttribution,
- key: cloudmadeKey}),
- midnight = L.tileLayer(cloudmadeUrl, {
- styleId: 999,
- attribution: cloudmadeAttribution,
- key: cloudmadeKey}),
- motorways = L.tileLayer(cloudmadeUrl, {
- styleId: 46561,
- attribution: cloudmadeAttribution,
- key: cloudmadeKey});
- var map = L.map('map', {
- center: new L.LatLng(45.70, 9.64),
- zoom: 13,
- layers: [minimal]
- });
- var ggl = new L.Google();
- var bingAttribution = "Map data © 2013 OpenStreetMap contributors, Imagery © 2013 Microsoft Corporation, Bing, © 2010 GeoEye, © 2010 TerraItaly, © 2010 Blom"
- var bingKey = 'AggYzpIFoBJd3Zx671A-O6V8RWue5cyuDgCNoQRnzFU3bedB5tSfpegsq1RB7kbD'
- var bing = new L.BingLayer(bingKey, {
- attribution: bingAttribution,
- });
- var baseMaps = {
- "Minimal": minimal,
- "Bing": bing,
- "Google": ggl
- };
- function onEachFeature(feature, layer) {
- var popupContent = "<b>Parcheggio pubblico</b><br />"
- if (feature.properties.name) {
- popupContent += "Nome: " + feature.properties.name + " ciao!"
- }
- if(feature.geometry.type=="Polygon") {
- var x = 0;
- var y = 0;
- var numcoord = feature.geometry.coordinates[0].length;
- for(var c=0; c<numcoord; c++) {
- y += feature.geometry.coordinates[0][c][0]/numcoord;
- x += feature.geometry.coordinates[0][c][1]/numcoord;
- }
- // alert("here: " + x + "," + y)
- if(x!=0 && y!=0) {
- return L.marker([x, y], {icon: parkingIcon}).addTo(map)
- .bindPopup(popupContent);
- }
- }
- layer.bindPopup(popupContent);
- }
- L.geoJson(parkings, {
- pointToLayer: function (feature, latlng) {
- return L.marker(latlng, {icon: parkingIcon});
- },
- onEachFeature: onEachFeature
- }).addTo(map);
- L.control.layers(baseMaps).addTo(map);
- </script>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement