Groupement de calques: premier jet - Attention, ne fonctionne qu'avec Leaflet >= 3
authorLudovic CHEVALIER <l.chevalier@lespetitsdebrouillards-ra.org>
Mon, 5 Dec 2011 18:56:44 +0000 (19:56 +0100)
committerLudovic CHEVALIER <l.chevalier@lespetitsdebrouillards-ra.org>
Mon, 5 Dec 2011 18:56:44 +0000 (19:56 +0100)
contenu/page-carte_de_sites.html

index 5609079..538a276 100644 (file)
@@ -1,18 +1,9 @@
+<div id="map" style="width: 540px; height: 400px">
 <script src="#CONFIG{adresse_site}/lib/CloudMade-Leaflet-404b097/dist/leaflet.js"></script>
 
-<div id="map" style="width: 540px; height: 400px">
 <script>
-       var map = new L.Map('map');
-       
-       var cloudmadeUrl = 'http://{s}.tile.cloudmade.com/BC9A493B41014CAABB98F0471D759707/997/256/{z}/{x}/{y}.png',
-               cloudmadeAttribution = 'Map data &copy; 2011 OpenStreetMap contributors, Imagery &copy; 2011 CloudMade',
-               cloudmade = new L.TileLayer(cloudmadeUrl, {maxZoom: 18, attribution: cloudmadeAttribution});
-       
-       map.setView(new L.LatLng(46.8, 2.52), 5).addLayer(cloudmade);
-  
-               
-       
 <BOUCLE_ateliers_types(MOTS){type = Ateliers}{par num titre}>
+               var group_#ID_MOT = new L.LayerGroup();
                <BOUCLE_sites(SITES){id_mot}>
                                <BOUCLE_coord(GIS){id_syndic}>
                                                var WorkshopIcon = L.Icon.extend({
                                                });
                                                siteIcon = new WorkshopIcon()
                                                var markerAtelier = new L.Marker(new L.LatLng(#LAT, #LON), {icon: siteIcon});
-                                               map.addLayer(markerAtelier);
                                                markerAtelier.bindPopup("<span style='float: left; width: 45px;'> <img src='#CONFIG{adresse_site}/IMG/#LOGO_SYNDIC**' alt='' style='width: 45px;' width='45'></span><a href='#URL_SITE'>#NOM_SITE</a><br/>#_sites:DESCRIPTIF<span class='spip_documents spip_documents_right' style='float: right; width: 100px;'> <img src='#CONFIG{adresse_site}/IMG/#LOGO_SYNDIC_SURVOL**' alt='' style='width: 100px;' width='100'></span>#ADRESSE<br/> #CODE_POSTAL #VILLE<br/><br/><em>Statut: [(#_ateliers_types:TITRE|supprimer_numero)]</em>");
+                                               group_#ID_MOT.addLayer(markerAtelier)
                                </BOUCLE_coord>
                </BOUCLE_sites>
 </BOUCLE_ateliers_types>
 
-                       
+       var cloudmadeAttribution = 'Map data &copy; 2011 OpenStreetMap contributors, Imagery &copy; 2011 CloudMade',
+               cloudmadeOptions = {maxZoom: 18, attribution: cloudmadeAttribution},    
+               cloudmadeUrl = 'http://{s}.tile.cloudmade.com/BC9A493B41014CAABB98F0471D759707/{styleId}/256/{z}/{x}/{y}.png';
+               
+       var minimal = new L.TileLayer(cloudmadeUrl, cloudmadeOptions, {styleId: 22677}),
+               midnightCommander = new L.TileLayer(cloudmadeUrl, cloudmadeOptions, {styleId: 999}),
+               motorways = new L.TileLayer(cloudmadeUrl, cloudmadeOptions, {styleId: 46561});
+
+<B_map>
+       var map = new L.Map('map', {center: new L.LatLng(46.8, 2.52), zoom: 5, layers: [<BOUCLE_map(MOTS){type = Ateliers}>     group_#ID_MOT,</BOUCLE_map>     minimal, midnightCommander, motorways]});
+</B_map>
+
+       var baseMaps = {
+                               "Minimal": minimal,
+                               "Night View": midnightCommander
+                       };
+
+<B_groups>
+       var overlayMaps = {     
+               <BOUCLE_groups(MOTS){type = Ateliers}{par num titre}>
+                       "[(#TITRE|supprimer_numero)]": group_#ID_MOT,</BOUCLE_groups>
+                       "Motorways": motorways
+       };
+</B_groups>
+
+
+       layersControl = new L.Control.Layers(baseMaps, overlayMaps);
+        
+       map.addControl(layersControl);
+
        map.on('click', onMapClick);
        
        var popup = new L.Popup();
 
-             function onMapClick(e) {
-                     var latlngStr = '(' + e.latlng.lat.toFixed(3) + ', ' + e.latlng.lng.toFixed(3) + ')';
+       function onMapClick(e) {
+               var latlngStr = '(' + e.latlng.lat.toFixed(3) + ', ' + e.latlng.lng.toFixed(3) + ')';
+               popup.setLatLng(e.latlng);
+               popup.setContent("You clicked the map at " + latlngStr);
+               map.openPopup(popup);
+       }
 
-                     popup.setLatLng(e.latlng);
-                     popup.setContent("You clicked the map at " + latlngStr);
-                     map.openPopup(popup);
-       }                               
-       
 </script>
 </div>
 
-
-
 <h2 class='h2 spip'>Legende</h2>
 <BOUCLE_legende(MOTS){type = Ateliers}{par num titre}>
        <p>#LOGO_MOT [(#TITRE|supprimer_numero)]</p>
 </BOUCLE_legende>
 
-
-
 <h2 class='h2 spip'>Ateliers</h2>
 <BOUCLE_liste_pays(GIS){par pays}{fusion pays}>
        <h3 class='h3 spip'>#PAYS</h3>
@@ -66,4 +81,3 @@
                                </BOUCLE_liste_ateliers>
                </BOUCLE_liste_region>
 </BOUCLE_liste_pays>   
-