Handle maps without markers
authorThierry Florac <tflorac@ulthar.net>
Wed, 03 Feb 2021 18:54:30 +0100
changeset 84 e85d04d8a62e
parent 83 8ee2396eecd1
child 85 e1ecb82594cc
Handle maps without markers
src/pyams_gis/locales/fr/LC_MESSAGES/pyams_gis.mo
src/pyams_gis/locales/fr/LC_MESSAGES/pyams_gis.po
src/pyams_gis/resources/js/pyams_gis.js
src/pyams_gis/resources/js/pyams_gis.min.js
Binary file src/pyams_gis/locales/fr/LC_MESSAGES/pyams_gis.mo has changed
--- a/src/pyams_gis/locales/fr/LC_MESSAGES/pyams_gis.po	Wed Feb 03 17:36:05 2021 +0100
+++ b/src/pyams_gis/locales/fr/LC_MESSAGES/pyams_gis.po	Wed Feb 03 18:54:30 2021 +0100
@@ -261,7 +261,7 @@
 
 #: src/pyams_gis/interfaces/configuration.py:35
 msgid "List of available layers displayed into this map"
-msgstr "Liste des couches dispopnibles à intégrer dans cette carte"
+msgstr "Liste des couches disponibles à intégrer dans cette carte"
 
 #: src/pyams_gis/interfaces/configuration.py:39
 msgid "Adjust bounds to markers layer"
--- a/src/pyams_gis/resources/js/pyams_gis.js	Wed Feb 03 17:36:05 2021 +0100
+++ b/src/pyams_gis/resources/js/pyams_gis.js	Wed Feb 03 18:54:30 2021 +0100
@@ -285,73 +285,75 @@
 							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
+						if (markers) {
+							// 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
 								});
-							}
-						});
-
-						// 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);
+								if (markerConfig.href) {
+									marker.addEventListener('click', clickMarker);
+								}
+								icons[markerConfig.id] = marker;
+								// bind tooltip with title content
+								var label;
+								if (markerConfig.img) {
+									label = '<div>' +
+										'<div class="marker__label p-2"> ' + markerConfig.label + '</div>' +
+										'<div class="text-center">' +
+										'<img src="' + markerConfig.img.src + '" width="' + markerConfig.img.w + '" height="' + markerConfig.img.h + '" alt="" />' +
+										'</div>' +
+										'</div>';
+								} 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]);
 							}
-							icons[markerConfig.id] = marker;
-							// bind tooltip with title content
-							var label;
-							if (markerConfig.img) {
-								label = '<div>' +
-									'<div class="marker__label p-2"> ' + markerConfig.label + '</div>' +
-										'<div class="text-center">' +
-											'<img src="' + markerConfig.img.src + '" width="' + markerConfig.img.w + '" height="' + markerConfig.img.h + '" alt="" />' +
-										'</div>' +
-									'</div>';
-							} else {
-								label = markerConfig.label;
-							}
-							if (label) {
-								var className = markers.tooltipClass || 'map-tooltip';
-								if (markerConfig.img) {
-									className += ' p-0';
+							leafmap.addLayer(markersClusterCustom);
+							if (config.adjust === 'auto') {
+								leafmap.fitBounds(markersClusterCustom.getBounds());
+								if (markers.markers.length === 1) {
+									leafmap.setZoom(config.zoom);
 								}
-								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);
 							}
 						}
 					});
--- a/src/pyams_gis/resources/js/pyams_gis.min.js	Wed Feb 03 17:36:05 2021 +0100
+++ b/src/pyams_gis/resources/js/pyams_gis.min.js	Wed Feb 03 18:54:30 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("<div></div>").addClass("inline-group"),o=e("<label></label>").addClass(a.overlay?"checkbox":"radio"),l=e("<i></i>"),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("<span></span>").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 p=[];d&&((t=a.L).Control.Layers.prototype._addItem=n._layersControlAddItem,p.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,p).then((function(){function d(r,s){var d=r.data(),p={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};p=e.extend({},p,o),r.trigger("map.init",[r,p,s]);var c=t.map(r.attr("id"),p),u=[];if(s.layers)for(var m=0;m<s.layers.length;m++){var f=s.layers[m];r.trigger("map.layer.init",[r,f]),u.push(n.getLayer(r,c,f))}else u.push(t.tileLayer("http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png",{maxZoom:19,id:"osm",attribution:'&copy; <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'}));e.when.apply(e,u).then((function(...e){for(var a=0;a<e.length;a++)e[a].addTo(c);s.zoomControl&&!0!==d.mapLeafletHideZoomControl&&t.control.scale().addTo(c),s.center?c.setView(new t.LatLng(s.center.lat,s.center.lon),s.zoom||13):s.bounds&&c.fitBounds(s.bounds),r.data("leafmap",c),r.data("leafmap.config",s),r.trigger("map.finishing",[r,c,s]),l&&l(c,s),r.trigger("map.finished",[r,c,s])}))}var p=e.map(r,(function(a){return new Promise((function(t,n){var r=e(a),o=r.data(),l=o.mapConfiguration;l?(d(r,l),t()):i.ajax.post(o.mapConfigurationUrl||"get-map-configuration.json",{},(function(e){d(r,e),t()}))}))}));s&&e.when.apply(e,p).then(s)}))}))},getLayer:function(a,t,n){var r=i.getObject(n.factory);if(void 0!==r){delete n.factory;var o=[];if(n.dependsOn){for(var l in n.dependsOn)n.dependsOn.hasOwnProperty(l)&&void 0===i.getObject(l)&&o.push(i.getScript(n.dependsOn[l]));delete n.dependsOn}return o.length>0&&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(a){var t=this.getIcon(),i=this.getTooltip();a.containerPoint.y<e(this.getPane()).parents(".map").height()/2?(i.options.direction="bottom",i.options.offset=[0,0]):(i.options.direction="top",i.options.offset=[0,-t.options.iconSize[1]]),this.openTooltip()},l=function(e){this.closeTooltip()};a.each((function(a,i){for(var n=e(i),s=n.data(),d=n.data("leafmap"),p=n.data("leafmap.config"),c=s.mapMarkers,u=t.icon({iconUrl:c.icon.url,iconSize:c.icon.size,iconAnchor:c.icon.anchor}),m=new t.MarkerClusterGroup({iconCreateFunction:function(e){return t.divIcon({html:e.getChildCount(),className:c.clusterClass||"map-cluster",iconSize:null})}}),f={},g=0;g<c.markers.length;g++){var v,h=c.markers[g],y=new t.LatLng(h.point.y,h.point.x),w=new t.Marker(y,{icon:u,clickURL:h.href,markerId:h.id,alt:h.id});if(h.href&&w.addEventListener("click",r),f[h.id]=w,v=h.img?'<div><div class="marker__label p-2"> '+h.label+'</div><div class="text-center"><img src="'+h.img.src+'" width="'+h.img.w+'" height="'+h.img.h+'" alt="" /></div></div>':h.label){var L=c.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"===p.adjust&&(d.fitBounds(m.getBounds()),1===c.markers.length&&d.setZoom(p.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,p=e('input[name="'+d+'.widgets.longitude"]'),c=e('input[name="'+d+'.widgets.latitude"]');if(p.val()&&c.val()){var u=e('select[name="'+d+'.widgets.projection:list"]'),m={point:{longitude:parseFloat(p.val()),latitude:parseFloat(c.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,p=e('input[name="'+d+'.widgets.x1"]'),c=e('input[name="'+d+'.widgets.y1"]'),u=e('input[name="'+d+'.widgets.x2"]'),m=e('input[name="'+d+'.widgets.y2"]');if(p.val()&&c.val()&&u.val()&&m.val()){var f=e('select[name="'+d+'.widgets.projection:list"]'),g={area:{x1:parseFloat(p.val()),y1:parseFloat(c.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 p=e('select[name="'+r+'.widgets.projection:list"]'),c={area:{x1:parseFloat(o.val()),y1:parseFloat(l.val()),x2:parseFloat(s.val()),y2:parseFloat(d.val())},from_srid:p.val(),to_srid:4326};n.callJSON("transformArea",c,(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,p=a.added.id;if(d!==p&&r.val()&&o.val()&&l.val()&&s.val()){var c={area:{x1:parseFloat(r.val()),y1:parseFloat(o.val()),x2:parseFloat(l.val()),y2:parseFloat(s.val())},from_srid:d,to_srid:p};n.callJSON("transformArea",c,(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("<div></div>").addClass("inline-group"),o=e("<label></label>").addClass(a.overlay?"checkbox":"radio"),l=e("<i></i>"),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("<span></span>").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 p=[];d&&((t=a.L).Control.Layers.prototype._addItem=n._layersControlAddItem,p.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,p).then((function(){function d(r,s){var d=r.data(),p={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};p=e.extend({},p,o),r.trigger("map.init",[r,p,s]);var c=t.map(r.attr("id"),p),u=[];if(s.layers)for(var m=0;m<s.layers.length;m++){var f=s.layers[m];r.trigger("map.layer.init",[r,f]),u.push(n.getLayer(r,c,f))}else u.push(t.tileLayer("http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png",{maxZoom:19,id:"osm",attribution:'&copy; <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'}));e.when.apply(e,u).then((function(...e){for(var a=0;a<e.length;a++)e[a].addTo(c);s.zoomControl&&!0!==d.mapLeafletHideZoomControl&&t.control.scale().addTo(c),s.center?c.setView(new t.LatLng(s.center.lat,s.center.lon),s.zoom||13):s.bounds&&c.fitBounds(s.bounds),r.data("leafmap",c),r.data("leafmap.config",s),r.trigger("map.finishing",[r,c,s]),l&&l(c,s),r.trigger("map.finished",[r,c,s])}))}var p=e.map(r,(function(a){return new Promise((function(t,n){var r=e(a),o=r.data(),l=o.mapConfiguration;l?(d(r,l),t()):i.ajax.post(o.mapConfigurationUrl||"get-map-configuration.json",{},(function(e){d(r,e),t()}))}))}));s&&e.when.apply(e,p).then(s)}))}))},getLayer:function(a,t,n){var r=i.getObject(n.factory);if(void 0!==r){delete n.factory;var o=[];if(n.dependsOn){for(var l in n.dependsOn)n.dependsOn.hasOwnProperty(l)&&void 0===i.getObject(l)&&o.push(i.getScript(n.dependsOn[l]));delete n.dependsOn}return o.length>0&&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(a){var t=this.getIcon(),i=this.getTooltip();a.containerPoint.y<e(this.getPane()).parents(".map").height()/2?(i.options.direction="bottom",i.options.offset=[0,0]):(i.options.direction="top",i.options.offset=[0,-t.options.iconSize[1]]),this.openTooltip()},l=function(e){this.closeTooltip()};a.each((function(a,i){var n=e(i),s=n.data(),d=n.data("leafmap"),p=n.data("leafmap.config"),c=s.mapMarkers;if(c){for(var u=t.icon({iconUrl:c.icon.url,iconSize:c.icon.size,iconAnchor:c.icon.anchor}),m=new t.MarkerClusterGroup({iconCreateFunction:function(e){return t.divIcon({html:e.getChildCount(),className:c.clusterClass||"map-cluster",iconSize:null})}}),f={},g=0;g<c.markers.length;g++){var v,h=c.markers[g],y=new t.LatLng(h.point.y,h.point.x),w=new t.Marker(y,{icon:u,clickURL:h.href,markerId:h.id,alt:h.id});if(h.href&&w.addEventListener("click",r),f[h.id]=w,v=h.img?'<div><div class="marker__label p-2"> '+h.label+'</div><div class="text-center"><img src="'+h.img.src+'" width="'+h.img.w+'" height="'+h.img.h+'" alt="" /></div></div>':h.label){var L=c.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"===p.adjust&&(d.fitBounds(m.getBounds()),1===c.markers.length&&d.setZoom(p.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,p=e('input[name="'+d+'.widgets.longitude"]'),c=e('input[name="'+d+'.widgets.latitude"]');if(p.val()&&c.val()){var u=e('select[name="'+d+'.widgets.projection:list"]'),m={point:{longitude:parseFloat(p.val()),latitude:parseFloat(c.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,p=e('input[name="'+d+'.widgets.x1"]'),c=e('input[name="'+d+'.widgets.y1"]'),u=e('input[name="'+d+'.widgets.x2"]'),m=e('input[name="'+d+'.widgets.y2"]');if(p.val()&&c.val()&&u.val()&&m.val()){var f=e('select[name="'+d+'.widgets.projection:list"]'),g={area:{x1:parseFloat(p.val()),y1:parseFloat(c.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 p=e('select[name="'+r+'.widgets.projection:list"]'),c={area:{x1:parseFloat(o.val()),y1:parseFloat(l.val()),x2:parseFloat(s.val()),y2:parseFloat(d.val())},from_srid:p.val(),to_srid:4326};n.callJSON("transformArea",c,(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,p=a.added.id;if(d!==p&&r.val()&&o.val()&&l.val()&&s.val()){var c={area:{x1:parseFloat(r.val()),y1:parseFloat(o.val()),x2:parseFloat(l.val()),y2:parseFloat(s.val())},from_srid:d,to_srid:p};n.callJSON("transformArea",c,(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);