# HG changeset patch # User Thierry Florac # Date 1616421434 -3600 # Node ID 6c9dec257d60ba6d5cc02ee28ca4d92498133436 # Parent 53d13af906a18442493a5f0f6ff99dc6ab1eb46b Replace Leaflet tooltips by popups to use autopan feature diff -r 53d13af906a1 -r 6c9dec257d60 src/pyams_gis/resources/js/pyams_gis.js --- a/src/pyams_gis/resources/js/pyams_gis.js Fri Mar 19 13:11:50 2021 +0100 +++ b/src/pyams_gis/resources/js/pyams_gis.js Mon Mar 22 14:57:14 2021 +0100 @@ -253,29 +253,18 @@ 'leaflet-markercluster-default'); } + // show tooltip + var hoverMarker = function(e) { + this.openPopup(); + } + // hide tooltip + var leaveMarker = function(e) { + this.closePopup(); + } // click marker var clickMarker = function(e) { window.location.href = this.options.clickURL; } - // show tooltip - var hoverMarker = function(e) { - var icon = this.getIcon(), - tooltip = this.getTooltip(), - position = e.containerPoint.y, - height = $(this.getPane()).parents('.map').height(); - if (position < height / 2) { - tooltip.options.direction = 'bottom'; - tooltip.options.offset = [0, 0] - } else { - tooltip.options.direction = 'top'; - tooltip.options.offset = [0, -icon.options.iconSize[1]] - } - this.openTooltip(); - } - // hide tooltip - var leaveMarker = function(e) { - this.closeTooltip(); - } maps.each(function(idx, elt) { @@ -316,6 +305,13 @@ markerId: markerConfig.id, alt: markerConfig.id }); + var popup = new L.popup({ + offset: new L.Point(0, -markers.icon.size[1]), + closeButton: false, + autoPan: true + }); + marker.addEventListener('mouseover', hoverMarker); + marker.addEventListener('mouseout', leaveMarker); if (markerConfig.href) { marker.addEventListener('click', clickMarker); } @@ -337,16 +333,18 @@ if (markerConfig.img) { className += ' p-0'; } - icons[markerConfig.id].bindTooltip(label, { + marker.bindPopup(label, { direction: 'top', offset: [0, -markerIcon.options.iconSize[1]], opacity: 1, - className: className + className: className, + closeButton: false, + autoPan: true }); - icons[markerConfig.id].addEventListener('mouseover', hoverMarker); - icons[markerConfig.id].addEventListener('mouseout', leaveMarker); + marker.addEventListener('mouseover', hoverMarker); + marker.addEventListener('mouseout', leaveMarker); } - markersClusterCustom.addLayer(icons[markerConfig.id]); + markersClusterCustom.addLayer(marker); } leafmap.addLayer(markersClusterCustom); if (config.adjust === 'auto') { diff -r 53d13af906a1 -r 6c9dec257d60 src/pyams_gis/resources/js/pyams_gis.min.js --- a/src/pyams_gis/resources/js/pyams_gis.min.js Fri Mar 19 13:11:50 2021 +0100 +++ b/src/pyams_gis/resources/js/pyams_gis.min.js Mon Mar 22 14:57:14 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,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;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(a){var t=this.getIcon(),i=this.getTooltip();a.containerPoint.y
'+h.label+'
':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},l=a.data("marker");l&&n.callJSON("transformPoint",o,(function(e){if(!e.error){var i=e.result.point;l.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,n=a.MyAMS,i={RPC_ENDPOINT:"/api/gis/json",WGS_SRID:4326,_layersControlAddItem:function(a){var n,i,r=e("
").addClass("inline-group"),o=e("").addClass(a.overlay?"checkbox":"radio"),l=e(""),s=this._map.hasLayer(a.layer);a.overlay?((n=document.createElement("input")).type="checkbox",n.className="leaflet-control-layers-selector",n.defaultChecked=s):n=this._createRadioElement("leaflet-base-layers",s),n.layerId=t.stamp(a.layer),e(n).addClass(a.overlay?"checkbox":"radio"),t.DomEvent.on(n,"click",this._onInputClick,this),i=e("").text(" "+a.name),o.append(n),o.append(l),o.append(i),r.append(o);var d=a.overlay?this._overlaysList:this._baseLayersList;return e(d).append(r),r},init:function(r,o,l,s){n.ajax.check([a.L],["/--static--/pyams_gis/js/leaflet-1.7.1"+n.devext+".js"],(function(d){var p=[];d&&((t=a.L).Control.Layers.prototype._addItem=i._layersControlAddItem,p.push(n.getScript("/--static--/pyams_gis/js/leaflet-gesture-handling-1.2.1"+n.devext+".js")),n.getCSS("/--static--/pyams_gis/css/leaflet-1.7.1"+n.devext+".css","leaflet"),n.getCSS("/--static--/pyams_gis/css/leaflet-gesture-handling-1.2.1"+n.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||n.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;mOpenStreetMap contributors'}));e.when.apply(e,u).then((function(...e){for(var a=0;a0&&e.when.apply(e,o),r(a,t,i)}},factory:{GeoJSON:function(a,n,i){var r=i.url;delete i.url;var o=t.geoJSON(null,i);return a.on("map.finished",(function(a,t,n,l){e.get(r,(function(e){o.addData(e.geometry,{style:i.style}),l.fitLayer===i.name&&n.fitBounds(o.getBounds())}))})),o},TileLayer:function(e,a,n){var i=n.url;return delete n.url,t.tileLayer(i,n)},WMS:function(e,a,n){var i=n.url;return delete n.url,t.tileLayer.wms(i,n)},Geoportal:{WMS:function(e,a,i){return n.getCSS("/--static--/pyams_gis/css/leaflet-gp-3.0.2"+n.devext+".css","geoportal"),t.geoportalLayer.WMS(i)}},ESRI:{Feature:function(e,a,n){return t.esri.featureLayer(n)}},Google:function(a,i,r){var o=r.apiKey;if(delete r.apiKey,void 0===n.getObject("window.google.maps")){var l=n.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){n.ajax.check(e.jsonRPC,n.baseURL+"ext/jquery-jsonrpc"+n.devext+".js",(function(){e.jsonRPC.withOptions({endPoint:i.RPC_ENDPOINT,cache:!1},(function(){e.jsonRPC.request(a,{id:(new Date).getTime(),params:t,success:r,error:n.error.show})}))}))},markers:{init:function(a){n.ajax.check([t.MarkerClusterGroup],["/--static--/pyams_gis/js/leaflet-markercluster-1.4.1"+n.devext+".js"],(function(i){i&&(n.getCSS("/--static--/pyams_gis/css/leaflet-markercluster-1.4.1"+n.devext+".css","leaflet-markercluster"),n.getCSS("/--static--/pyams_gis/css/leaflet-markercluster-default-1.4.1"+n.devext+".css","leaflet-markercluster-default"));var r=function(e){this.openPopup()},o=function(e){this.closePopup()},l=function(e){window.location.href=this.options.clickURL};a.each((function(a,n){var i=e(n),s=i.data(),d=i.data("leafmap"),p=i.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
'+h.label+'
':h.label){var L=c.tooltipClass||"map-tooltip";h.img&&(L+=" p-0"),w.bindPopup(v,{direction:"top",offset:[0,-u.options.iconSize[1]],opacity:1,className:L,closeButton:!1,autoPan:!0}),w.addEventListener("mouseover",r),w.addEventListener("mouseout",o)}m.addLayer(w)}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),i.init(a,{},(function(n,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()||i.WGS_SRID,to_srid:i.WGS_SRID};i.callJSON("transformPoint",m,(function(e){if(!e.error){var a=e.result.point;s.setLatLng({lon:a.longitude,lat:a.latitude}),s.addTo(n),n.setView(s.getLatLng(),r.zoom||13)}}))}else s.setLatLng([-90,0]),s.addTo(n);a.data("marker",s),n.on("click",i.position.onClick)})))},onClick:function(a){var t=a.target.getContainer(),n=e(t).data(),r=n.marker,o=a.latlng;r.setLatLng(o);var l=n.mapLeafletFieldname,s=e('select[name="'+l+'.widgets.projection:list"]'),d={point:{longitude:o.lng,latitude:o.lat},from_srid:i.WGS_SRID,to_srid:s.val()};i.callJSON("transformPoint",d,(function(a){if(!a.error){var n=a.result.point;e('input[name="'+l+'.widgets.longitude"]').val(n.longitude),e('input[name="'+l+'.widgets.latitude"]').val(n.latitude),e(t).trigger("marker.changed",[t,n])}}))},changedCoordinate:function(){var a=e(this),t=e(".map",a.parents("fieldset:first"));if(t.data("marker")){var n=t.data("map-leaflet-fieldname"),r=e('input[name="'+n+'.widgets.longitude"]'),o=e('input[name="'+n+'.widgets.latitude"]');if(r.val()&&o.val()){var l=e('select[name="'+n+'.widgets.projection:list"]'),s={point:{longitude:parseFloat(r.val()),latitude:parseFloat(o.val())},from_srid:l.val(),to_srid:i.WGS_SRID};i.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),n=e(".map",t.parents("fieldset:first")).data("map-leaflet-fieldname"),r=e('input[name="'+n+'.widgets.longitude"]'),o=e('input[name="'+n+'.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};i.callJSON("transformPoint",d,(function(e){if(!e.error){var a=e.result.point;r.val(a.longitude),o.val(a.latitude)}}))}}else i.position.changedCoordinate.apply(r)},clear:function(a){var t=e(this).parents("fieldset:first");e("input",t).val(null);var n=e(".map",t),i=n.data("marker");if(i){i.setLatLng([-90,0]);var r=n.data("leafmap"),o=n.data("leafmap.config");if(o.bounds)r.fitBounds(o.bounds);else{var l=n.data();r.setView(l.mapLeafletCenter||o.center,o.zoom||13)}}n.trigger("marker.cleared.position",[n])},moveMarkerTo:function(a,t,n){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:n,to_srid:4326},l=a.data("marker");l&&i.callJSON("transformPoint",o,(function(e){if(!e.error){var n=e.result.point;l.setLatLng({lon:n.longitude,lat:n.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),i.init(a,{},(function(r){t.Draw=t.Draw||{},t.Edit=t.Edit||{},n.ajax.check([t.Draw,t.Draw.Event,t.Map.TouchExtend,t.Edit.SimpleShape],["/--static--/pyams_gis/js/Draw/Leaflet.draw"+n.devext+".js","/--static--/pyams_gis/js/Draw/Leaflet.Draw.Event"+n.devext+".js","/--static--/pyams_gis/js/Draw/ext/TouchEvents"+n.devext+".js","/--static--/pyams_gis/js/Draw/edit/handler/Edit.SimpleShape"+n.devext+".js"],(function(){n.ajax.check(t.Edit.Rectangle,"/--static--/pyams_gis/js/Draw/edit/handler/Edit.Rectangle"+n.devext+".js",(function(){function n(e,n){var o=new t.FeatureGroup;s=t.rectangle([e,n]),o.addLayer(s),r.addLayer(o),r.fitBounds(s.getBounds()),s.editing.enable(),a.data("area",s),r.on(t.Draw.Event.EDITMOVE,i.area.changedArea),r.on(t.Draw.Event.EDITRESIZE,i.area.changedArea),r.on(t.Draw.Event.EDITVERTEX,i.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:i.WGS_SRID};i.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}),n(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})),n(o,l)}}))}))})))},last_event:null,changedArea:function(a){i.area.last_event=a,setTimeout((function(){if(a===i.area.last_event){var t=a.target.getContainer(),n=e(t).data(),r=n.area.getBounds(),o=n.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:i.WGS_SRID,to_srid:l};i.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),n=e(".map",a.parents("fieldset:first"));if(n.data("area")){var r=n.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};i.callJSON("transformArea",c,(function(e){if(!e.error){var a=e.result.area,i=n.data("area");i.editing.disable(),i.setBounds([t.latLng({lon:a.x1,lat:a.y1}),t.latLng({lon:a.x2,lat:a.y2})]),i.editing.enable()}}))}}},changedProjection:function(a){var t=e(this),n=e(".map",t.parents("fieldset:first")).data("map-leaflet-fieldname"),r=e('input[name="'+n+'.widgets.x1"]'),o=e('input[name="'+n+'.widgets.y1"]'),l=e('input[name="'+n+'.widgets.x2"]'),s=e('input[name="'+n+'.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};i.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 i.area.changedCoordinate.apply(r)},clear:function(a){var t=e(this).parents("fieldset:first");e("input",t).val(null);var n=e(".map",t);n.trigger("marker.cleared.area",[n])}}};a.PyAMS_GIS=i}(jQuery,this);