# HG changeset patch # User Thierry Florac # Date 1612182498 -3600 # Node ID c038be68256704e8f3129a850ac02c955f52440a # Parent 808bd0bc9d864e0f7c1a592d47080441c6c84621 Handle pages with multiple maps diff -r 808bd0bc9d86 -r c038be682567 src/pyams_gis/resources/js/pyams_gis.js --- a/src/pyams_gis/resources/js/pyams_gis.js Mon Feb 01 13:27:46 2021 +0100 +++ b/src/pyams_gis/resources/js/pyams_gis.js Mon Feb 01 13:28:18 2021 +0100 @@ -42,8 +42,7 @@ return group; }, - init: function(context, options, callback) { - var map = context; + init: function(context, options, callback, globalCallback) { MyAMS.ajax.check([ globals.L ], [ @@ -60,20 +59,26 @@ } $.when.apply($, required).then(function() { - function createMap(config) { - var settings = { - preferCanvas: data.mapLeafletPreferCanvas || false, - attributionControl: data.mapLeafletAttributionControl === undefined ? - config.attributionControl : - data.mapLeafletAttributionControl, - zoomControl: data.mapLeafletZoomControl === undefined ? - config.zoomControl : - data.mapLeafletZoomControl, - crs: data.mapLeafletCrs || MyAMS.getObject(config.crs) || globals.L.CRS.EPSG3857, - center: data.mapLeafletCenter || config.center, - zoom: data.mapLeafletZoom || config.zoom, - gestureHandling: true - }; + function createMap(map, config) { + var data = map.data(), + settings = { + preferCanvas: data.mapLeafletPreferCanvas || false, + attributionControl: data.mapLeafletAttributionControl === undefined ? + config.attributionControl : + data.mapLeafletAttributionControl, + zoomControl: data.mapLeafletZoomControl === undefined ? + config.zoomControl : + data.mapLeafletZoomControl, + crs: data.mapLeafletCrs || MyAMS.getObject(config.crs) || globals.L.CRS.EPSG3857, + center: data.mapLeafletCenter || config.center, + zoom: data.mapLeafletZoom || config.zoom, + gestureHandling: data.mapLeafletWheelZoom === undefined ? + !config.scrollWheelZoom : + data.mapLeafletWheelZoom, + keyboard: data.mapLeafletKeyboard === undefined ? + config.keyboard && !L.Browser.mobile : + data.amsLeafletKeyboard + }; settings = $.extend({}, settings, options); map.trigger('map.init', [map, settings, config]); var leafmap = L.map(map.attr('id'), settings); @@ -114,14 +119,24 @@ }); } - var data = map.data(), - config = data.mapConfiguration; - if (config) { - createMap(config); - } else { - MyAMS.ajax.post(data.mapConfigurationUrl || 'get-map-configuration.json', {}, function(config) { - createMap(config); + var maps = $.map(context, function(elt) { + return new Promise(function(resolve, reject) { + var map = $(elt), + data = map.data(), + config = data.mapConfiguration; + if (config) { + createMap(map, config); + resolve(); + } else { + MyAMS.ajax.post(data.mapConfigurationUrl || 'get-map-configuration.json', {}, function(config) { + createMap(map, config); + resolve(); + }); + } }); + }); + if (globalCallback) { + $.when.apply($, maps).then(globalCallback); } }); } @@ -223,7 +238,7 @@ */ markers: { - init: function(leafmap, markers, config) { + init: function(maps) { MyAMS.ajax.check([ L.MarkerClusterGroup @@ -251,76 +266,84 @@ this.closeTooltip(); } - // create custom icon - var markerIcon = L.icon({ - iconUrl: markers.icon.url, - iconSize: markers.icon.size, - iconAnchor: markers.icon.anchor - }); - // customize cluster icon - var markersClusterCustom = new L.MarkerClusterGroup({ - iconCreateFunction: function(cluster) { - return L.divIcon({ - html: cluster.getChildCount(), - className: markers.clusterClass || 'map-cluster', - iconSize: null + maps.each(function(idx, elt) { + + var map = $(elt), + data = map.data(), + leafmap = map.data('leafmap'), + config = map.data('leafmap.config'), + markers = data.mapMarkers; + + // create custom icon + var markerIcon = L.icon({ + iconUrl: markers.icon.url, + iconSize: markers.icon.size, + iconAnchor: markers.icon.anchor + }); + // customize cluster icon + var markersClusterCustom = new L.MarkerClusterGroup({ + iconCreateFunction: function(cluster) { + return L.divIcon({ + html: cluster.getChildCount(), + className: markers.clusterClass || 'map-cluster', + iconSize: null + }); + } + }); + + // object to save markers + var icons = {}; + + // create markers + for (var i = 0; i < markers.markers.length; i++) { + var markerConfig = markers.markers[i]; + var latLng = new L.LatLng(markerConfig.point.y, markerConfig.point.x); + var marker = new L.Marker(latLng, { + icon: markerIcon, + clickURL: markerConfig.href, + markerId: markerConfig.id, + alt: markerConfig.id }); + if (markerConfig.href) { + marker.addEventListener('click', clickMarker); + } + icons[markerConfig.id] = marker; + // bind tooltip with title content + var label; + if (markerConfig.img) { + label = '
' + + '
' + markerConfig.label + '
' + + '
' + + '' + + '
' + + '
'; + } else { + label = markerConfig.label; + } + if (label) { + var className = markers.tooltipClass || 'map-tooltip'; + if (markerConfig.img) { + className += ' p-0'; + } + icons[markerConfig.id].bindTooltip(label, { + direction: 'top', + offset: [0, -markerIcon.options.iconSize[1]], + opacity: 1, + className: className + }); + icons[markerConfig.id].addEventListener('mouseover', hoverMarker); + icons[markerConfig.id].addEventListener('mouseout', leaveMarker); + } + markersClusterCustom.addLayer(icons[markerConfig.id]); + } + leafmap.addLayer(markersClusterCustom); + if (config.adjust === 'auto') { + leafmap.fitBounds(markersClusterCustom.getBounds()); + if (markers.markers.length === 1) { + leafmap.setZoom(config.zoom); + } } }); - - // object to save markers - var icons = {}; - - // create markers - for (var i = 0; i < markers.markers.length; i++) { - var markerConfig = markers.markers[i]; - var latLng = new L.LatLng(markerConfig.point.y, markerConfig.point.x); - var marker = new L.Marker(latLng, { - icon: markerIcon, - clickURL: markerConfig.href, - markerId: markerConfig.id, - alt: markerConfig.id - }); - if (markerConfig.href) { - marker.addEventListener('click', clickMarker); - } - icons[markerConfig.id] = marker; - // bind tooltip with title content - var label; - if (markerConfig.img) { - label = '
' + - '
' + markerConfig.label + '
' + - '
' + - '' + - '
' + - '
'; - } else { - label = markerConfig.label; - } - if (label) { - var className = markers.tooltipClass || 'map-tooltip'; - if (markerConfig.img) { - className += ' p-0'; - } - icons[markerConfig.id].bindTooltip(label, { - direction: 'top', - offset: [0, -markerIcon.options.iconSize[1]], - opacity: 1, - className: className - }); - icons[markerConfig.id].addEventListener('mouseover', hoverMarker); - icons[markerConfig.id].addEventListener('mouseout', leaveMarker); - } - markersClusterCustom.addLayer(icons[markerConfig.id]); - } - leafmap.addLayer(markersClusterCustom); - if (config.adjust === 'auto') { - leafmap.fitBounds(markersClusterCustom.getBounds()); - if (markers.markers.length === 1) { - debugger - leafmap.setZoom(config.zoom); - } - } }); } }, diff -r 808bd0bc9d86 -r c038be682567 src/pyams_gis/resources/js/pyams_gis.min.js --- a/src/pyams_gis/resources/js/pyams_gis.min.js Mon Feb 01 13:27:46 2021 +0100 +++ b/src/pyams_gis/resources/js/pyams_gis.min.js Mon Feb 01 13:28:18 2021 +0100 @@ -1,1 +1,1 @@ -!function(e,a){"use strict";var t,i=a.MyAMS,n={RPC_ENDPOINT:"/api/gis/json",WGS_SRID:4326,_layersControlAddItem:function(a){var i,n,r=e("
").addClass("inline-group"),o=e("").addClass(a.overlay?"checkbox":"radio"),l=e(""),s=this._map.hasLayer(a.layer);a.overlay?((i=document.createElement("input")).type="checkbox",i.className="leaflet-control-layers-selector",i.defaultChecked=s):i=this._createRadioElement("leaflet-base-layers",s),i.layerId=t.stamp(a.layer),e(i).addClass(a.overlay?"checkbox":"radio"),t.DomEvent.on(i,"click",this._onInputClick,this),n=e("").text(" "+a.name),o.append(i),o.append(l),o.append(n),r.append(o);var d=a.overlay?this._overlaysList:this._baseLayersList;return e(d).append(r),r},init:function(r,o,l){var s=r;i.ajax.check([a.L],["/--static--/pyams_gis/js/leaflet-1.7.1"+i.devext+".js"],(function(r){var d=[];r&&((t=a.L).Control.Layers.prototype._addItem=n._layersControlAddItem,d.push(i.getScript("/--static--/pyams_gis/js/leaflet-gesture-handling-1.2.1"+i.devext+".js")),i.getCSS("/--static--/pyams_gis/css/leaflet-1.7.1"+i.devext+".css","leaflet"),i.getCSS("/--static--/pyams_gis/css/leaflet-gesture-handling-1.2.1"+i.devext+".css","leaflet-gesture-handling")),e.when.apply(e,d).then((function(){function r(r){var c={preferCanvas:d.mapLeafletPreferCanvas||!1,attributionControl:void 0===d.mapLeafletAttributionControl?r.attributionControl:d.mapLeafletAttributionControl,zoomControl:void 0===d.mapLeafletZoomControl?r.zoomControl:d.mapLeafletZoomControl,crs:d.mapLeafletCrs||i.getObject(r.crs)||a.L.CRS.EPSG3857,center:d.mapLeafletCenter||r.center,zoom:d.mapLeafletZoom||r.zoom,gestureHandling:!0};c=e.extend({},c,o),s.trigger("map.init",[s,c,r]);var p=t.map(s.attr("id"),c),u=[];if(r.layers)for(var m=0;mOpenStreetMap contributors'}));e.when.apply(e,u).then((function(...e){for(var a=0;a0&&e.when.apply(e,o),r(a,t,n)}},factory:{GeoJSON:function(a,i,n){var r=n.url;delete n.url;var o=t.geoJSON(null,n);return a.on("map.finished",(function(a,t,i,l){e.get(r,(function(e){o.addData(e.geometry,{style:n.style}),l.fitLayer===n.name&&i.fitBounds(o.getBounds())}))})),o},TileLayer:function(e,a,i){var n=i.url;return delete i.url,t.tileLayer(n,i)},WMS:function(e,a,i){var n=i.url;return delete i.url,t.tileLayer.wms(n,i)},Geoportal:{WMS:function(e,a,n){return i.getCSS("/--static--/pyams_gis/css/leaflet-gp-3.0.2"+i.devext+".css","geoportal"),t.geoportalLayer.WMS(n)}},ESRI:{Feature:function(e,a,i){return t.esri.featureLayer(i)}},Google:function(a,n,r){var o=r.apiKey;if(delete r.apiKey,void 0===i.getObject("window.google.maps")){var l=i.getScript("https://maps.googleapis.com/maps/api/js?key="+o);e.when.apply(e,[l])}return t.gridLayer.googleMutant(r)}},callJSON:function(a,t,r){i.ajax.check(e.jsonRPC,i.baseURL+"ext/jquery-jsonrpc"+i.devext+".js",(function(){e.jsonRPC.withOptions({endPoint:n.RPC_ENDPOINT,cache:!1},(function(){e.jsonRPC.request(a,{id:(new Date).getTime(),params:t,success:r,error:i.error.show})}))}))},markers:{init:function(e,a,n){i.ajax.check([t.MarkerClusterGroup],["/--static--/pyams_gis/js/leaflet-markercluster-1.4.1"+i.devext+".js"],(function(r){r&&(i.getCSS("/--static--/pyams_gis/css/leaflet-markercluster-1.4.1"+i.devext+".css","leaflet-markercluster"),i.getCSS("/--static--/pyams_gis/css/leaflet-markercluster-default-1.4.1"+i.devext+".css","leaflet-markercluster-default"));for(var o=function(e){window.location.href=this.options.clickURL},l=function(e){this.openTooltip()},s=function(e){this.closeTooltip()},d=t.icon({iconUrl:a.icon.url,iconSize:a.icon.size,iconAnchor:a.icon.anchor}),c=new t.MarkerClusterGroup({iconCreateFunction:function(e){return t.divIcon({html:e.getChildCount(),className:a.clusterClass||"map-cluster",iconSize:null})}}),p={},u=0;u
'+g.label+'
':g.label){var y=a.tooltipClass||"map-tooltip";g.img&&(y+=" p-0"),p[g.id].bindTooltip(m,{direction:"top",offset:[0,-d.options.iconSize[1]],opacity:1,className:y}),p[g.id].addEventListener("mouseover",l),p[g.id].addEventListener("mouseout",s)}c.addLayer(p[g.id])}e.addLayer(c),"auto"===n.adjust&&(e.fitBounds(c.getBounds()),1===a.markers.length&&e.setZoom(n.zoom))}))}},position:{init:function(){var a=e(".map",e(this));void 0===a.data("leafmap")&&(a.css("height",e(window).height()-200),n.init(a,{},(function(i,r){var o=a.data(),l=t.icon({iconUrl:"/--static--/pyams_gis/img/marker-icon.png",iconSize:[25,41],iconAnchor:[12,39]}),s=t.marker();s.setIcon(l);var d=o.mapLeafletFieldname,c=e('input[name="'+d+'.widgets.longitude"]'),p=e('input[name="'+d+'.widgets.latitude"]');if(c.val()&&p.val()){var u=e('select[name="'+d+'.widgets.projection:list"]'),m={point:{longitude:parseFloat(c.val()),latitude:parseFloat(p.val())},from_srid:u.val()||n.WGS_SRID,to_srid:n.WGS_SRID};n.callJSON("transformPoint",m,(function(e){if(!e.error){var a=e.result.point;s.setLatLng({lon:a.longitude,lat:a.latitude}),s.addTo(i),i.setView(s.getLatLng(),r.zoom||13)}}))}else s.setLatLng([-90,0]),s.addTo(i);a.data("marker",s),i.on("click",n.position.onClick)})))},onClick:function(a){var t=a.target.getContainer(),i=e(t).data(),r=i.marker,o=a.latlng;r.setLatLng(o);var l=i.mapLeafletFieldname,s=e('select[name="'+l+'.widgets.projection:list"]'),d={point:{longitude:o.lng,latitude:o.lat},from_srid:n.WGS_SRID,to_srid:s.val()};n.callJSON("transformPoint",d,(function(a){if(!a.error){var i=a.result.point;e('input[name="'+l+'.widgets.longitude"]').val(i.longitude),e('input[name="'+l+'.widgets.latitude"]').val(i.latitude),e(t).trigger("marker.changed",[t,i])}}))},changedCoordinate:function(){var a=e(this),t=e(".map",a.parents("fieldset:first"));if(t.data("marker")){var i=t.data("map-leaflet-fieldname"),r=e('input[name="'+i+'.widgets.longitude"]'),o=e('input[name="'+i+'.widgets.latitude"]');if(r.val()&&o.val()){var l=e('select[name="'+i+'.widgets.projection:list"]'),s={point:{longitude:parseFloat(r.val()),latitude:parseFloat(o.val())},from_srid:l.val(),to_srid:n.WGS_SRID};n.callJSON("transformPoint",s,(function(e){if(!e.error){var a=e.result.point;t.data("marker").setLatLng({lon:a.longitude,lat:a.latitude})}}))}}},changedProjection:function(a){var t=e(this),i=e(".map",t.parents("fieldset:first")).data("map-leaflet-fieldname"),r=e('input[name="'+i+'.widgets.longitude"]'),o=e('input[name="'+i+'.widgets.latitude"]');if(a.removed){var l=a.removed.id,s=a.added.id;if(l!==s&&r.val()&&o.val()){var d={point:{longitude:parseFloat(r.val()),latitude:parseFloat(o.val())},from_srid:l,to_srid:s};n.callJSON("transformPoint",d,(function(e){if(!e.error){var a=e.result.point;r.val(a.longitude),o.val(a.latitude)}}))}}else n.position.changedCoordinate.apply(r)},clear:function(a){var t=e(this).parents("fieldset:first");e("input",t).val(null);var i=e(".map",t),n=i.data("marker");if(n){n.setLatLng([-90,0]);var r=i.data("leafmap"),o=i.data("leafmap.config");if(o.bounds)r.fitBounds(o.bounds);else{var l=i.data();r.setView(l.mapLeafletCenter||o.center,o.zoom||13)}}i.trigger("marker.cleared.position",[i])},moveMarkerTo:function(a,t,i){var r=a.data("map-leaflet-fieldname");e('input[name="'+r+'.widgets.longitude"]').val(t.lon),e('input[name="'+r+'.widgets.latitude"]').val(t.lat);var o={point:{longitude:t.lon,latitude:t.lat},from_srid:i,to_srid:4326};n.callJSON("transformPoint",o,(function(e){if(!e.error){var i=e.result.point;a.data("marker").setLatLng({lon:i.longitude,lat:i.latitude}),a.data("leafmap").setView(t)}}))}},area:{init:function(){var a=e(".map",e(this));void 0===a.data("leafmap")&&(a.css("height",e(window).height()-200),n.init(a,{},(function(r){t.Draw=t.Draw||{},t.Edit=t.Edit||{},i.ajax.check([t.Draw,t.Draw.Event,t.Map.TouchExtend,t.Edit.SimpleShape],["/--static--/pyams_gis/js/Draw/Leaflet.draw"+i.devext+".js","/--static--/pyams_gis/js/Draw/Leaflet.Draw.Event"+i.devext+".js","/--static--/pyams_gis/js/Draw/ext/TouchEvents"+i.devext+".js","/--static--/pyams_gis/js/Draw/edit/handler/Edit.SimpleShape"+i.devext+".js"],(function(){i.ajax.check(t.Edit.Rectangle,"/--static--/pyams_gis/js/Draw/edit/handler/Edit.Rectangle"+i.devext+".js",(function(){function i(e,i){var o=new t.FeatureGroup;s=t.rectangle([e,i]),o.addLayer(s),r.addLayer(o),r.fitBounds(s.getBounds()),s.editing.enable(),a.data("area",s),r.on(t.Draw.Event.EDITMOVE,n.area.changedArea),r.on(t.Draw.Event.EDITRESIZE,n.area.changedArea),r.on(t.Draw.Event.EDITVERTEX,n.area.changedArea)}var o,l,s,d=a.data().mapLeafletFieldname,c=e('input[name="'+d+'.widgets.x1"]'),p=e('input[name="'+d+'.widgets.y1"]'),u=e('input[name="'+d+'.widgets.x2"]'),m=e('input[name="'+d+'.widgets.y2"]');if(c.val()&&p.val()&&u.val()&&m.val()){var g=e('select[name="'+d+'.widgets.projection:list"]'),f={area:{x1:parseFloat(c.val()),y1:parseFloat(p.val()),x2:parseFloat(u.val()),y2:parseFloat(m.val())},from_srid:g.val(),to_srid:n.WGS_SRID};n.callJSON("transformArea",f,(function(e){if(!e.error){var a=e.result.area;o=t.latLng({lon:a.x1,lat:a.y1}),l=t.latLng({lon:a.x2,lat:a.y2}),i(o,l)}}))}else{var v=a.data("leafmap.config");v.bounds?(o=t.latLng(v.bounds[0]),l=t.latLng(v.bounds[1])):(o=t.latLng({lon:-168,lat:-56.37}),l=t.latLng({lon:191.25,lat:83.72})),i(o,l)}}))}))})))},last_event:null,changedArea:function(a){n.area.last_event=a,setTimeout((function(){if(a===n.area.last_event){var t=a.target.getContainer(),i=e(t).data(),r=i.area.getBounds(),o=i.mapLeafletFieldname,l=e('select[name="'+o+'.widgets.projection:list"]').val(),s={area:{x1:r.getWest(),y1:r.getSouth(),x2:r.getEast(),y2:r.getNorth()},from_srid:n.WGS_SRID,to_srid:l};n.callJSON("transformArea",s,(function(a){if(!a.error){var t=a.result.area;e('input[name="'+o+'.widgets.x1"]').val(t.x1),e('input[name="'+o+'.widgets.y1"]').val(t.y1),e('input[name="'+o+'.widgets.x2"]').val(t.x2),e('input[name="'+o+'.widgets.y2"]').val(t.y2)}}))}}),100)},changedCoordinate:function(){var a=e(this),i=e(".map",a.parents("fieldset:first"));if(i.data("area")){var r=i.data("map-leaflet-fieldname"),o=e('input[name="'+r+'.widgets.x1"]'),l=e('input[name="'+r+'.widgets.y1"]'),s=e('input[name="'+r+'.widgets.x2"]'),d=e('input[name="'+r+'.widgets.y2"]');if(o.val()&&l.val()&&s.val()&&d.val()){var c=e('select[name="'+r+'.widgets.projection:list"]'),p={area:{x1:parseFloat(o.val()),y1:parseFloat(l.val()),x2:parseFloat(s.val()),y2:parseFloat(d.val())},from_srid:c.val(),to_srid:4326};n.callJSON("transformArea",p,(function(e){if(!e.error){var a=e.result.area,n=i.data("area");n.editing.disable(),n.setBounds([t.latLng({lon:a.x1,lat:a.y1}),t.latLng({lon:a.x2,lat:a.y2})]),n.editing.enable()}}))}}},changedProjection:function(a){var t=e(this),i=e(".map",t.parents("fieldset:first")).data("map-leaflet-fieldname"),r=e('input[name="'+i+'.widgets.x1"]'),o=e('input[name="'+i+'.widgets.y1"]'),l=e('input[name="'+i+'.widgets.x2"]'),s=e('input[name="'+i+'.widgets.y2"]');if(a.removed){var d=a.removed.id,c=a.added.id;if(d!==c&&r.val()&&o.val()&&l.val()&&s.val()){var p={area:{x1:parseFloat(r.val()),y1:parseFloat(o.val()),x2:parseFloat(l.val()),y2:parseFloat(s.val())},from_srid:d,to_srid:c};n.callJSON("transformArea",p,(function(e){if(!e.error){var a=e.result.area;r.val(a.x1),o.val(a.y1),l.val(a.x2),s.val(a.y2)}}))}}else n.area.changedCoordinate.apply(r)},clear:function(a){var t=e(this).parents("fieldset:first");e("input",t).val(null);var i=e(".map",t);i.trigger("marker.cleared.area",[i])}}};a.PyAMS_GIS=n}(jQuery,this); +!function(e,a){"use strict";var t,i=a.MyAMS,n={RPC_ENDPOINT:"/api/gis/json",WGS_SRID:4326,_layersControlAddItem:function(a){var i,n,r=e("
").addClass("inline-group"),o=e("").addClass(a.overlay?"checkbox":"radio"),l=e(""),s=this._map.hasLayer(a.layer);a.overlay?((i=document.createElement("input")).type="checkbox",i.className="leaflet-control-layers-selector",i.defaultChecked=s):i=this._createRadioElement("leaflet-base-layers",s),i.layerId=t.stamp(a.layer),e(i).addClass(a.overlay?"checkbox":"radio"),t.DomEvent.on(i,"click",this._onInputClick,this),n=e("").text(" "+a.name),o.append(i),o.append(l),o.append(n),r.append(o);var d=a.overlay?this._overlaysList:this._baseLayersList;return e(d).append(r),r},init:function(r,o,l,s){i.ajax.check([a.L],["/--static--/pyams_gis/js/leaflet-1.7.1"+i.devext+".js"],(function(d){var c=[];d&&((t=a.L).Control.Layers.prototype._addItem=n._layersControlAddItem,c.push(i.getScript("/--static--/pyams_gis/js/leaflet-gesture-handling-1.2.1"+i.devext+".js")),i.getCSS("/--static--/pyams_gis/css/leaflet-1.7.1"+i.devext+".css","leaflet"),i.getCSS("/--static--/pyams_gis/css/leaflet-gesture-handling-1.2.1"+i.devext+".css","leaflet-gesture-handling")),e.when.apply(e,c).then((function(){function d(r,s){var d=r.data(),c={preferCanvas:d.mapLeafletPreferCanvas||!1,attributionControl:void 0===d.mapLeafletAttributionControl?s.attributionControl:d.mapLeafletAttributionControl,zoomControl:void 0===d.mapLeafletZoomControl?s.zoomControl:d.mapLeafletZoomControl,crs:d.mapLeafletCrs||i.getObject(s.crs)||a.L.CRS.EPSG3857,center:d.mapLeafletCenter||s.center,zoom:d.mapLeafletZoom||s.zoom,gestureHandling:void 0===d.mapLeafletWheelZoom?!s.scrollWheelZoom:d.mapLeafletWheelZoom,keyboard:void 0===d.mapLeafletKeyboard?s.keyboard&&!t.Browser.mobile:d.amsLeafletKeyboard};c=e.extend({},c,o),r.trigger("map.init",[r,c,s]);var p=t.map(r.attr("id"),c),u=[];if(s.layers)for(var m=0;mOpenStreetMap contributors'}));e.when.apply(e,u).then((function(...e){for(var a=0;a0&&e.when.apply(e,o),r(a,t,n)}},factory:{GeoJSON:function(a,i,n){var r=n.url;delete n.url;var o=t.geoJSON(null,n);return a.on("map.finished",(function(a,t,i,l){e.get(r,(function(e){o.addData(e.geometry,{style:n.style}),l.fitLayer===n.name&&i.fitBounds(o.getBounds())}))})),o},TileLayer:function(e,a,i){var n=i.url;return delete i.url,t.tileLayer(n,i)},WMS:function(e,a,i){var n=i.url;return delete i.url,t.tileLayer.wms(n,i)},Geoportal:{WMS:function(e,a,n){return i.getCSS("/--static--/pyams_gis/css/leaflet-gp-3.0.2"+i.devext+".css","geoportal"),t.geoportalLayer.WMS(n)}},ESRI:{Feature:function(e,a,i){return t.esri.featureLayer(i)}},Google:function(a,n,r){var o=r.apiKey;if(delete r.apiKey,void 0===i.getObject("window.google.maps")){var l=i.getScript("https://maps.googleapis.com/maps/api/js?key="+o);e.when.apply(e,[l])}return t.gridLayer.googleMutant(r)}},callJSON:function(a,t,r){i.ajax.check(e.jsonRPC,i.baseURL+"ext/jquery-jsonrpc"+i.devext+".js",(function(){e.jsonRPC.withOptions({endPoint:n.RPC_ENDPOINT,cache:!1},(function(){e.jsonRPC.request(a,{id:(new Date).getTime(),params:t,success:r,error:i.error.show})}))}))},markers:{init:function(a){i.ajax.check([t.MarkerClusterGroup],["/--static--/pyams_gis/js/leaflet-markercluster-1.4.1"+i.devext+".js"],(function(n){n&&(i.getCSS("/--static--/pyams_gis/css/leaflet-markercluster-1.4.1"+i.devext+".css","leaflet-markercluster"),i.getCSS("/--static--/pyams_gis/css/leaflet-markercluster-default-1.4.1"+i.devext+".css","leaflet-markercluster-default"));var r=function(e){window.location.href=this.options.clickURL},o=function(e){this.openTooltip()},l=function(e){this.closeTooltip()};a.each((function(a,i){for(var n=e(i),s=n.data(),d=n.data("leafmap"),c=n.data("leafmap.config"),p=s.mapMarkers,u=t.icon({iconUrl:p.icon.url,iconSize:p.icon.size,iconAnchor:p.icon.anchor}),m=new t.MarkerClusterGroup({iconCreateFunction:function(e){return t.divIcon({html:e.getChildCount(),className:p.clusterClass||"map-cluster",iconSize:null})}}),f={},g=0;g
'+h.label+'
':h.label){var L=p.tooltipClass||"map-tooltip";h.img&&(L+=" p-0"),f[h.id].bindTooltip(v,{direction:"top",offset:[0,-u.options.iconSize[1]],opacity:1,className:L}),f[h.id].addEventListener("mouseover",o),f[h.id].addEventListener("mouseout",l)}m.addLayer(f[h.id])}d.addLayer(m),"auto"===c.adjust&&(d.fitBounds(m.getBounds()),1===p.markers.length&&d.setZoom(c.zoom))}))}))}},position:{init:function(){var a=e(".map",e(this));void 0===a.data("leafmap")&&(a.css("height",e(window).height()-200),n.init(a,{},(function(i,r){var o=a.data(),l=t.icon({iconUrl:"/--static--/pyams_gis/img/marker-icon.png",iconSize:[25,41],iconAnchor:[12,39]}),s=t.marker();s.setIcon(l);var d=o.mapLeafletFieldname,c=e('input[name="'+d+'.widgets.longitude"]'),p=e('input[name="'+d+'.widgets.latitude"]');if(c.val()&&p.val()){var u=e('select[name="'+d+'.widgets.projection:list"]'),m={point:{longitude:parseFloat(c.val()),latitude:parseFloat(p.val())},from_srid:u.val()||n.WGS_SRID,to_srid:n.WGS_SRID};n.callJSON("transformPoint",m,(function(e){if(!e.error){var a=e.result.point;s.setLatLng({lon:a.longitude,lat:a.latitude}),s.addTo(i),i.setView(s.getLatLng(),r.zoom||13)}}))}else s.setLatLng([-90,0]),s.addTo(i);a.data("marker",s),i.on("click",n.position.onClick)})))},onClick:function(a){var t=a.target.getContainer(),i=e(t).data(),r=i.marker,o=a.latlng;r.setLatLng(o);var l=i.mapLeafletFieldname,s=e('select[name="'+l+'.widgets.projection:list"]'),d={point:{longitude:o.lng,latitude:o.lat},from_srid:n.WGS_SRID,to_srid:s.val()};n.callJSON("transformPoint",d,(function(a){if(!a.error){var i=a.result.point;e('input[name="'+l+'.widgets.longitude"]').val(i.longitude),e('input[name="'+l+'.widgets.latitude"]').val(i.latitude),e(t).trigger("marker.changed",[t,i])}}))},changedCoordinate:function(){var a=e(this),t=e(".map",a.parents("fieldset:first"));if(t.data("marker")){var i=t.data("map-leaflet-fieldname"),r=e('input[name="'+i+'.widgets.longitude"]'),o=e('input[name="'+i+'.widgets.latitude"]');if(r.val()&&o.val()){var l=e('select[name="'+i+'.widgets.projection:list"]'),s={point:{longitude:parseFloat(r.val()),latitude:parseFloat(o.val())},from_srid:l.val(),to_srid:n.WGS_SRID};n.callJSON("transformPoint",s,(function(e){if(!e.error){var a=e.result.point;t.data("marker").setLatLng({lon:a.longitude,lat:a.latitude})}}))}}},changedProjection:function(a){var t=e(this),i=e(".map",t.parents("fieldset:first")).data("map-leaflet-fieldname"),r=e('input[name="'+i+'.widgets.longitude"]'),o=e('input[name="'+i+'.widgets.latitude"]');if(a.removed){var l=a.removed.id,s=a.added.id;if(l!==s&&r.val()&&o.val()){var d={point:{longitude:parseFloat(r.val()),latitude:parseFloat(o.val())},from_srid:l,to_srid:s};n.callJSON("transformPoint",d,(function(e){if(!e.error){var a=e.result.point;r.val(a.longitude),o.val(a.latitude)}}))}}else n.position.changedCoordinate.apply(r)},clear:function(a){var t=e(this).parents("fieldset:first");e("input",t).val(null);var i=e(".map",t),n=i.data("marker");if(n){n.setLatLng([-90,0]);var r=i.data("leafmap"),o=i.data("leafmap.config");if(o.bounds)r.fitBounds(o.bounds);else{var l=i.data();r.setView(l.mapLeafletCenter||o.center,o.zoom||13)}}i.trigger("marker.cleared.position",[i])},moveMarkerTo:function(a,t,i){var r=a.data("map-leaflet-fieldname");e('input[name="'+r+'.widgets.longitude"]').val(t.lon),e('input[name="'+r+'.widgets.latitude"]').val(t.lat);var o={point:{longitude:t.lon,latitude:t.lat},from_srid:i,to_srid:4326};n.callJSON("transformPoint",o,(function(e){if(!e.error){var i=e.result.point;a.data("marker").setLatLng({lon:i.longitude,lat:i.latitude}),a.data("leafmap").setView(t)}}))}},area:{init:function(){var a=e(".map",e(this));void 0===a.data("leafmap")&&(a.css("height",e(window).height()-200),n.init(a,{},(function(r){t.Draw=t.Draw||{},t.Edit=t.Edit||{},i.ajax.check([t.Draw,t.Draw.Event,t.Map.TouchExtend,t.Edit.SimpleShape],["/--static--/pyams_gis/js/Draw/Leaflet.draw"+i.devext+".js","/--static--/pyams_gis/js/Draw/Leaflet.Draw.Event"+i.devext+".js","/--static--/pyams_gis/js/Draw/ext/TouchEvents"+i.devext+".js","/--static--/pyams_gis/js/Draw/edit/handler/Edit.SimpleShape"+i.devext+".js"],(function(){i.ajax.check(t.Edit.Rectangle,"/--static--/pyams_gis/js/Draw/edit/handler/Edit.Rectangle"+i.devext+".js",(function(){function i(e,i){var o=new t.FeatureGroup;s=t.rectangle([e,i]),o.addLayer(s),r.addLayer(o),r.fitBounds(s.getBounds()),s.editing.enable(),a.data("area",s),r.on(t.Draw.Event.EDITMOVE,n.area.changedArea),r.on(t.Draw.Event.EDITRESIZE,n.area.changedArea),r.on(t.Draw.Event.EDITVERTEX,n.area.changedArea)}var o,l,s,d=a.data().mapLeafletFieldname,c=e('input[name="'+d+'.widgets.x1"]'),p=e('input[name="'+d+'.widgets.y1"]'),u=e('input[name="'+d+'.widgets.x2"]'),m=e('input[name="'+d+'.widgets.y2"]');if(c.val()&&p.val()&&u.val()&&m.val()){var f=e('select[name="'+d+'.widgets.projection:list"]'),g={area:{x1:parseFloat(c.val()),y1:parseFloat(p.val()),x2:parseFloat(u.val()),y2:parseFloat(m.val())},from_srid:f.val(),to_srid:n.WGS_SRID};n.callJSON("transformArea",g,(function(e){if(!e.error){var a=e.result.area;o=t.latLng({lon:a.x1,lat:a.y1}),l=t.latLng({lon:a.x2,lat:a.y2}),i(o,l)}}))}else{var v=a.data("leafmap.config");v.bounds?(o=t.latLng(v.bounds[0]),l=t.latLng(v.bounds[1])):(o=t.latLng({lon:-168,lat:-56.37}),l=t.latLng({lon:191.25,lat:83.72})),i(o,l)}}))}))})))},last_event:null,changedArea:function(a){n.area.last_event=a,setTimeout((function(){if(a===n.area.last_event){var t=a.target.getContainer(),i=e(t).data(),r=i.area.getBounds(),o=i.mapLeafletFieldname,l=e('select[name="'+o+'.widgets.projection:list"]').val(),s={area:{x1:r.getWest(),y1:r.getSouth(),x2:r.getEast(),y2:r.getNorth()},from_srid:n.WGS_SRID,to_srid:l};n.callJSON("transformArea",s,(function(a){if(!a.error){var t=a.result.area;e('input[name="'+o+'.widgets.x1"]').val(t.x1),e('input[name="'+o+'.widgets.y1"]').val(t.y1),e('input[name="'+o+'.widgets.x2"]').val(t.x2),e('input[name="'+o+'.widgets.y2"]').val(t.y2)}}))}}),100)},changedCoordinate:function(){var a=e(this),i=e(".map",a.parents("fieldset:first"));if(i.data("area")){var r=i.data("map-leaflet-fieldname"),o=e('input[name="'+r+'.widgets.x1"]'),l=e('input[name="'+r+'.widgets.y1"]'),s=e('input[name="'+r+'.widgets.x2"]'),d=e('input[name="'+r+'.widgets.y2"]');if(o.val()&&l.val()&&s.val()&&d.val()){var c=e('select[name="'+r+'.widgets.projection:list"]'),p={area:{x1:parseFloat(o.val()),y1:parseFloat(l.val()),x2:parseFloat(s.val()),y2:parseFloat(d.val())},from_srid:c.val(),to_srid:4326};n.callJSON("transformArea",p,(function(e){if(!e.error){var a=e.result.area,n=i.data("area");n.editing.disable(),n.setBounds([t.latLng({lon:a.x1,lat:a.y1}),t.latLng({lon:a.x2,lat:a.y2})]),n.editing.enable()}}))}}},changedProjection:function(a){var t=e(this),i=e(".map",t.parents("fieldset:first")).data("map-leaflet-fieldname"),r=e('input[name="'+i+'.widgets.x1"]'),o=e('input[name="'+i+'.widgets.y1"]'),l=e('input[name="'+i+'.widgets.x2"]'),s=e('input[name="'+i+'.widgets.y2"]');if(a.removed){var d=a.removed.id,c=a.added.id;if(d!==c&&r.val()&&o.val()&&l.val()&&s.val()){var p={area:{x1:parseFloat(r.val()),y1:parseFloat(o.val()),x2:parseFloat(l.val()),y2:parseFloat(s.val())},from_srid:d,to_srid:c};n.callJSON("transformArea",p,(function(e){if(!e.error){var a=e.result.area;r.val(a.x1),o.val(a.y1),l.val(a.x2),s.val(a.y2)}}))}}else n.area.changedCoordinate.apply(r)},clear:function(a){var t=e(this).parents("fieldset:first");e("input",t).val(null);var i=e(".map",t);i.trigger("marker.cleared.area",[i])}}};a.PyAMS_GIS=n}(jQuery,this);