[PLUGINS] ~gis v4.41.1 --> v4.43.1
[lhc/web/www.git] / www / plugins / gis / modeles / carte_gis_preview.html
index ed83889..165f625 100755 (executable)
 #SET{autocenter,''}\r
 <script type="text/javascript">\r
 /*<![CDATA[*/\r
-(function($){\r
-       var init_map_preview = function() {\r
-               var map_preview;\r
-               var map_preview_container = 'map_preview';\r
-               var marker;\r
-               \r
-               map_preview = new L.Map(map_preview_container);\r
-               \r
-               map_preview.attributionControl.setPrefix('');\r
-\r
-               var base_layer = [(#ENV{layer_defaut}|=={none}|?{"'none'",[new (#EVAL{$GLOBALS\['gis_layers'\]}|table_valeur{[(#ENV{layer_defaut,[(#REM|gis_layer_defaut)]})]/layer})]})];\r
-               if(base_layer != 'none'){\r
-                       map_preview.addLayer(base_layer);\r
+var jQgisloader;\r
+(function (){\r
+       if (typeof jQuery.ajax == "undefined"){ jQuery(init_gis); } else { init_gis(); }\r
+       function init_gis(){\r
+               // Charger le javascript de GIS une seule fois si plusieurs carte\r
+               if (typeof jQgisloader=="undefined"){\r
+                       jQgisloader = jQuery.ajax({url: '[(#PRODUIRE{fond=javascript/gis.js})]', dataType: 'script', cache: true});\r
                }\r
-               \r
-               map_preview.setView(new L.LatLng([(#LAT)],[(#LON)]),[(#ZOOM|sinon{#CONFIG{gis/zoom,0}})]);\r
-
-               [(#REM) On ajoute les points ou le point unique suivant les params ]\r
-               <B_points>\r
-               var data = {\r
-                       "type": "FeatureCollection",\r
-                       "features": [\r
-               <BOUCLE_points(GIS){id_objet}{objet}{","}>\r
-                               {"type": "Feature",\r
-                                       "geometry": {"type": "Point", "coordinates": [#LON, #LAT]},\r
-                                       "id":"#ID_GIS",\r
-                                       "properties": {\r
-                                               "title":[(#TITRE|supprimer_numero|json_encode)],\r
-                                               "description":[(#DESCRIPTIF|json_encode)][\r
-                                               (#LOGO_GIS|gis_icon_properties)]\r
-                                       }\r
-                               }\r
-               </BOUCLE_points>\r
-                       ]\r
-               };\r
-               [(#TOTAL_BOUCLE|>{1}|oui) #SET{autocenter,oui} ]\r
-               </B_points>\r
-               <BOUCLE_point(GIS){id_gis}>\r
-               var data = {\r
-                       "type": "FeatureCollection",\r
-                       "features": [\r
-                               {"type": "Feature",\r
-                                       "geometry": {"type": "Point", "coordinates": [#LON, #LAT]},\r
-                                       "id":"#ID_GIS",\r
-                                       "properties": {\r
-                                               "title":[(#TITRE|supprimer_numero|json_encode)],\r
-                                               "description":[(#DESCRIPTIF|json_encode)][\r
-                                               (#LOGO_GIS|gis_icon_properties)]\r
-                                       }\r
-                               }]\r
-               };\r
-               </BOUCLE_point>\r
-               <//B_points>\r
-               if (data) {\r
-                       var geojson = new L.geoJson('', {\r
-                               onEachFeature: function (feature, layer) {\r
-                                       if (feature.properties && feature.properties.icon){\r
-                                               layer.setIcon(new L.Icon({\r
-                                                       iconUrl: feature.properties.icon,\r
-                                                       iconSize: new L.Point( feature.properties.icon_size\[0\], feature.properties.icon_size\[1\] ),\r
-                                                       iconAnchor: new L.Point( feature.properties.icon_anchor\[0\], feature.properties.icon_anchor\[1\] ),\r
-                                                       popupAnchor: new L.Point( feature.properties.popup_anchor\[0\], feature.properties.popup_anchor\[1\] )\r
-                                               }));\r
-                                       }\r
-                                       if (feature.properties && feature.properties.title){\r
-                                               var popupContent = '<strong>' + feature.properties.title + '</strong>';\r
-                                               if (feature.properties.description)\r
-                                                       popupContent = popupContent + feature.properties.description;\r
-                                               layer.bindPopup(popupContent);\r
-                                       }\r
+               // et initialiser la carte (des que js GIS charge et des que DOM ready)\r
+               jQgisloader.done(function(){\r
+                       jQuery(function(){\r
+                               var map_preview;\r
+                               var map_preview_container = 'map_preview';\r
+                               var marker;\r
+                               \r
+                               map_preview = new L.Map(map_preview_container);\r
+                               \r
+                               map_preview.attributionControl.setPrefix('');\r
+\r
+                               var base_layer = [(#ENV{layer_defaut}|=={none}|?{"'none'",[new (#EVAL{$GLOBALS\['gis_layers'\]}|table_valeur{[(#ENV{layer_defaut,[(#REM|gis_layer_defaut)]})]/layer})]})];\r
+                               if(base_layer != 'none'){\r
+                                       map_preview.addLayer(base_layer);\r
                                }\r
-                       }).addTo(map_preview);\r
-                       geojson.addData(data);\r
-                       [(#GET{autocenter}|oui)\r
-                       if(data.features.length > 1)\r
-                               map_preview.fitBounds(geojson.getBounds());]\r
-               }\r
-               [(#REM) On ajoute les KML attachés à l'objet ]\r
-               <BOUCLE_kml(DOCUMENTS){tous}{objet}{id_objet}{extension=kml}>\r
-               map_preview.addLayer(new L.KML('[(#URL_DOCUMENT|url_absolue)]', {async: true}));\r
-               </BOUCLE_kml>\r
-               [(#REM) On ajoute les GPX attachés à l'objet ]\r
-               <BOUCLE_gpx(DOCUMENTS){tous}{objet}{id_objet}{extension=gpx}>\r
-               map_preview.addLayer(new L.GPX('[(#URL_DOCUMENT|url_absolue)]', {async: true}));\r
-               </BOUCLE_gpx>\r
-       }\r
+                               \r
+                               map_preview.setView(new L.LatLng([(#LAT)],[(#LON)]),[(#ZOOM|sinon{#CONFIG{gis/zoom,0}})]);\r
 \r
-       $(function(){\r
-               jQuery.getScript('[(#PRODUIRE{fond=javascript/gis.js}|compacte)]',function(){\r
-                       init_map_preview();\r
+                               [(#REM) On ajoute les points ou le point unique suivant les params ]\r
+                               <B_points>\r
+                               var data = {\r
+                                       "type": "FeatureCollection",\r
+                                       "features": [\r
+                               <BOUCLE_points(GIS){id_objet}{objet}{","}>\r
+                                               {"type": "Feature",\r
+                                                       "geometry": {"type": "Point", "coordinates": [#LON, #LAT]},\r
+                                                       "id":"#ID_GIS",\r
+                                                       "properties": {\r
+                                                               "title":[(#TITRE|supprimer_numero|json_encode)],\r
+                                                               "description":[(#DESCRIPTIF|json_encode)][\r
+                                                               (#LOGO_GIS|gis_icon_properties)]\r
+                                                       }\r
+                                               }\r
+                               </BOUCLE_points>\r
+                                       ]\r
+                               };\r
+                               [(#TOTAL_BOUCLE|>{1}|oui) #SET{autocenter,oui} ]\r
+                               </B_points>\r
+                               <BOUCLE_point(GIS){id_gis}>\r
+                               var data = {\r
+                                       "type": "FeatureCollection",\r
+                                       "features": [\r
+                                               {"type": "Feature",\r
+                                                       "geometry": {"type": "Point", "coordinates": [#LON, #LAT]},\r
+                                                       "id":"#ID_GIS",\r
+                                                       "properties": {\r
+                                                               "title":[(#TITRE|supprimer_numero|json_encode)],\r
+                                                               "description":[(#DESCRIPTIF|json_encode)][\r
+                                                               (#LOGO_GIS|gis_icon_properties)]\r
+                                                       }\r
+                                               }]\r
+                               };\r
+                               </BOUCLE_point>\r
+                               <//B_points>\r
+                               if (data) {\r
+                                       var geojson = new L.geoJson('', {\r
+                                               onEachFeature: function (feature, layer) {\r
+                                                       if (feature.properties && feature.properties.icon){\r
+                                                               layer.setIcon(new L.Icon({\r
+                                                                       iconUrl: feature.properties.icon,\r
+                                                                       iconSize: new L.Point( feature.properties.icon_size\[0\], feature.properties.icon_size\[1\] ),\r
+                                                                       iconAnchor: new L.Point( feature.properties.icon_anchor\[0\], feature.properties.icon_anchor\[1\] ),\r
+                                                                       popupAnchor: new L.Point( feature.properties.popup_anchor\[0\], feature.properties.popup_anchor\[1\] )\r
+                                                               }));\r
+                                                       }\r
+                                                       if (feature.properties && feature.properties.title){\r
+                                                               var popupContent = '<strong>' + feature.properties.title + '</strong>';\r
+                                                               if (feature.properties.description)\r
+                                                                       popupContent = popupContent + feature.properties.description;\r
+                                                               layer.bindPopup(popupContent);\r
+                                                       }\r
+                                               }\r
+                                       }).addTo(map_preview);\r
+                                       geojson.addData(data);\r
+                                       [(#GET{autocenter}|oui)\r
+                                       if(data.features.length > 1)\r
+                                               map_preview.fitBounds(geojson.getBounds());]\r
+                               }\r
+                               [(#REM) On ajoute les KML attachés à l'objet ]\r
+                               <BOUCLE_kml(DOCUMENTS){tous}{objet}{id_objet}{extension=kml}>\r
+                               map_preview.addLayer(new L.KML('[(#URL_DOCUMENT|url_absolue)]', {async: true}));\r
+                               </BOUCLE_kml>\r
+                               [(#REM) On ajoute les GPX attachés à l'objet ]\r
+                               <BOUCLE_gpx(DOCUMENTS){tous}{objet}{id_objet}{extension=gpx}>\r
+                               map_preview.addLayer(new L.GPX('[(#URL_DOCUMENT|url_absolue)]', {async: true}));\r
+                               </BOUCLE_gpx>\r
+                       });\r
                });\r
-               //onAjaxLoad(init_map_preview(true));\r
-       });\r
-\r
-})(jQuery);\r
+       }\r
+})()\r
 /*]]>*/\r
 </script>\r
 </BOUCLE_gis>\r