# HG changeset patch # User Thierry Florac # Date 1616155910 -3600 # Node ID 53d13af906a18442493a5f0f6ff99dc6ab1eb46b # Parent 5dc59cc687ac2fd6407d4ef90b6f01572cc66054 Added check before updating map position on selected marker diff -r 5dc59cc687ac -r 53d13af906a1 src/pyams_gis/resources/js/pyams_gis.js --- a/src/pyams_gis/resources/js/pyams_gis.js Fri Feb 05 13:56:29 2021 +0100 +++ b/src/pyams_gis/resources/js/pyams_gis.js Fri Mar 19 13:11:50 2021 +0100 @@ -541,17 +541,19 @@ from_srid: srid, to_srid: 4326 }; - PyAMS_GIS.callJSON('transformPoint', params, function(result) { - if (!result.error) { - var point = result.result.point; - var marker = map.data('marker'); - marker.setLatLng({ - lon: point.longitude, - lat: point.latitude - }); - map.data('leafmap').setView(position); - } - }); + var marker = map.data('marker'); + if (marker) { + PyAMS_GIS.callJSON('transformPoint', params, function(result) { + if (!result.error) { + var point = result.result.point; + marker.setLatLng({ + lon: point.longitude, + lat: point.latitude + }); + map.data('leafmap').setView(position); + } + }); + } } }, diff -r 5dc59cc687ac -r 53d13af906a1 src/pyams_gis/resources/js/pyams_gis.min.js --- a/src/pyams_gis/resources/js/pyams_gis.min.js Fri Feb 05 13:56:29 2021 +0100 +++ b/src/pyams_gis/resources/js/pyams_gis.min.js Fri Mar 19 13:11:50 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};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("
").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);