--- a/src/pyams_gis/resources/js/pyams_gis.js Fri Jan 26 15:56:21 2018 +0100
+++ b/src/pyams_gis/resources/js/pyams_gis.js Fri Jan 26 15:57:57 2018 +0100
@@ -50,52 +50,53 @@
if (first_load) {
L = globals.L;
L.Control.Layers.prototype._addItem = PyAMS_GIS._layersControlAddItem;
- MyAMS.getCSS('/--static--/pyams_gis/css/leaflet-1.0.3' + MyAMS.devext + '.css',
- 'leaflet');
}
- MyAMS.ajax.post('get-map-configuration.json', {}, function(config) {
- var data = map.data();
- 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
- };
- settings = $.extend({}, settings, options);
- map.trigger('map.init', [map, settings, config]);
- var leafmap = L.map(map.attr('id'), settings);
- if (config.layers) {
- for (var index = 0; index < config.layers.length; index++) {
- var layerConfig = config.layers[index];
- map.trigger('map.layer.init', [map, layerConfig]);
- PyAMS_GIS.getLayer(layerConfig).addTo(leafmap);
+ MyAMS.getCSS('/--static--/pyams_gis/css/leaflet-1.0.3' + MyAMS.devext + '.css',
+ 'leaflet', function() {
+ MyAMS.ajax.post('get-map-configuration.json', {}, function(config) {
+ var data = map.data();
+ 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
+ };
+ settings = $.extend({}, settings, options);
+ map.trigger('map.init', [map, settings, config]);
+ var leafmap = L.map(map.attr('id'), settings);
+ if (config.layers) {
+ for (var index = 0; index < config.layers.length; index++) {
+ var layerConfig = config.layers[index];
+ map.trigger('map.layer.init', [map, layerConfig]);
+ PyAMS_GIS.getLayer(layerConfig).addTo(leafmap);
+ }
+ } else {
+ L.tileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
+ maxZoom: 19,
+ id: 'osm',
+ attribution: '© <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>'
+ }).addTo(leafmap);
}
- } else {
- L.tileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
- maxZoom: 19,
- id: 'osm',
- attribution: '© <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>'
- }).addTo(leafmap);
- }
- if (config.zoomControl && (data.mapLeafletHideZoomControl !== true)) {
- L.control.scale().addTo(leafmap);
- }
- if (config.bounds) {
- leafmap.fitBounds(config.bounds);
- }
- map.data('leafmap', leafmap);
- map.data('leafmap.config', config);
- map.trigger('map.finishing', [map, leafmap]);
- if (callback) {
- callback(leafmap, config);
- }
- map.trigger('map.finished', [map, leafmap]);
+ if (config.zoomControl && (data.mapLeafletHideZoomControl !== true)) {
+ L.control.scale().addTo(leafmap);
+ }
+ if (config.bounds) {
+ leafmap.fitBounds(config.bounds);
+ }
+ map.data('leafmap', leafmap);
+ map.data('leafmap.config', config);
+ map.trigger('map.finishing', [map, leafmap]);
+ if (callback) {
+ callback(leafmap, config);
+ }
+ map.trigger('map.finished', [map, leafmap]);
+ });
});
});
},
@@ -203,8 +204,8 @@
longitude: parseFloat(longitude.val()),
latitude: parseFloat(latitude.val())
},
- from_projection: projection.val() || PyAMS_GIS.WGS_SRID,
- to_projection: PyAMS_GIS.WGS_SRID
+ from_srid: projection.val() || PyAMS_GIS.WGS_SRID,
+ to_srid: PyAMS_GIS.WGS_SRID
};
PyAMS_GIS.callJSON('transformPoint', params, function(result) {
if (!result.error) {
@@ -240,14 +241,15 @@
longitude: latlng.lng,
latitude: latlng.lat
},
- from_projection: PyAMS_GIS.WGS_SRID,
- to_projection: projection.val()
+ from_srid: PyAMS_GIS.WGS_SRID,
+ to_srid: projection.val()
};
PyAMS_GIS.callJSON('transformPoint', params, function(result) {
if (!result.error) {
var point = result.result.point;
$('input[name="' + fieldname + '.widgets.longitude"]').val(point.longitude);
$('input[name="' + fieldname + '.widgets.latitude"]').val(point.latitude);
+ $(map).trigger('marker.changed', [map, point]);
}
});
},
@@ -268,8 +270,8 @@
longitude: parseFloat(longitude.val()),
latitude: parseFloat(latitude.val())
},
- from_projection: projection.val(),
- to_projection: 4326
+ from_srid: projection.val(),
+ to_srid: PyAMS_GIS.WGS_SRID
};
PyAMS_GIS.callJSON('transformPoint', params, function (result) {
if (!result.error) {
@@ -300,8 +302,8 @@
longitude: parseFloat(longitude.val()),
latitude: parseFloat(latitude.val())
},
- from_projection: previous,
- to_projection: current
+ from_srid: previous,
+ to_srid: current
};
PyAMS_GIS.callJSON('transformPoint', params, function (result) {
if (!result.error) {
@@ -320,6 +322,33 @@
clear: function(event) {
var fieldset = $(this).parents('fieldset:first');
$('input', fieldset).val(null);
+ },
+
+ moveMarkerTo: function(map, position, srid) {
+ // Update fields
+ var fieldname = map.data('map-leaflet-fieldname');
+ $('input[name="' + fieldname + '.widgets.longitude"]').val(position.lon);
+ $('input[name="' + fieldname + '.widgets.latitude"]').val(position.lat);
+ // Get map coordinates
+ var params = {
+ point: {
+ longitude: position.lon,
+ latitude: position.lat
+ },
+ 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);
+ }
+ });
}
},
@@ -377,8 +406,8 @@
x2: parseFloat(x2.val()),
y2: parseFloat(y2.val())
},
- from_projection: projection.val(),
- to_projection: PyAMS_GIS.WGS_SRID
+ from_srid: projection.val(),
+ to_srid: PyAMS_GIS.WGS_SRID
};
PyAMS_GIS.callJSON('transformArea', params, function(result) {
if (!result.error) {
@@ -423,8 +452,8 @@
x2: area.getEast(),
y2: area.getNorth()
},
- from_projection: PyAMS_GIS.WGS_SRID,
- to_projection: projection
+ from_srid: PyAMS_GIS.WGS_SRID,
+ to_srid: projection
};
PyAMS_GIS.callJSON('transformArea', params, function(result) {
if (!result.error) {
@@ -459,8 +488,8 @@
x2: parseFloat(x2.val()),
y2: parseFloat(y2.val())
},
- from_projection: projection.val(),
- to_projection: 4326
+ from_srid: projection.val(),
+ to_srid: 4326
};
PyAMS_GIS.callJSON('transformArea', params, function (result) {
if (!result.error) {
@@ -495,8 +524,8 @@
x2: parseFloat(x2.val()),
y2: parseFloat(y2.val())
},
- from_projection: previous,
- to_projection: current
+ from_srid: previous,
+ to_srid: current
};
PyAMS_GIS.callJSON('transformArea', params, function (result) {
if (!result.error) {
--- a/src/pyams_gis/resources/js/pyams_gis.min.js Fri Jan 26 15:56:21 2018 +0100
+++ b/src/pyams_gis/resources/js/pyams_gis.min.js Fri Jan 26 15:57:57 2018 +0100
@@ -1,1 +1,1 @@
-(function(c,b){var d=b.MyAMS;var a;var e={RPC_ENDPOINT:"/api/gis/json",WGS_SRID:4326,_layersControlAddItem:function(m){var l=c("<div></div>").addClass("inline-group"),i=c("<label></label>").addClass(m.overlay?"checkbox":"radio"),g,j=c("<i></i>"),h,k=this._map.hasLayer(m.layer);if(m.overlay){g=document.createElement("input");g.type="checkbox";g.className="leaflet-control-layers-selector";g.defaultChecked=k}else{g=this._createRadioElement("leaflet-base-layers",k)}g.layerId=a.stamp(m.layer);c(g).addClass(m.overlay?"checkbox":"radio");a.DomEvent.on(g,"click",this._onInputClick,this);h=c("<span></span>").text(" "+m.name);i.append(g);i.append(j);i.append(h);l.append(i);var f=m.overlay?this._overlaysList:this._baseLayersList;c(f).append(l);return l},init:function(g,f,i){var h=g;d.ajax.check(b.L,"/--static--/pyams_gis/js/leaflet-1.0.3"+d.devext+".js",function(j){if(j){a=b.L;a.Control.Layers.prototype._addItem=e._layersControlAddItem;d.getCSS("/--static--/pyams_gis/css/leaflet-1.0.3"+d.devext+".css","leaflet")}d.ajax.post("get-map-configuration.json",{},function(m){var p=h.data();var n={preferCanvas:p.mapLeafletPreferCanvas||false,attributionControl:p.mapLeafletAttributionControl===undefined?m.attributionControl:p.mapLeafletAttributionControl,zoomControl:p.mapLeafletZoomControl===undefined?m.zoomControl:p.mapLeafletZoomControl,crs:p.mapLeafletCrs||d.getObject(m.crs)||b.L.CRS.EPSG3857,center:p.mapLeafletCenter||m.center,zoom:p.mapLeafletZoom||m.zoom};n=c.extend({},n,f);h.trigger("map.init",[h,n,m]);var o=a.map(h.attr("id"),n);if(m.layers){for(var l=0;l<m.layers.length;l++){var k=m.layers[l];h.trigger("map.layer.init",[h,k]);e.getLayer(k).addTo(o)}}else{a.tileLayer("http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png",{maxZoom:19,id:"osm",attribution:'© <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>'}).addTo(o)}if(m.zoomControl&&(p.mapLeafletHideZoomControl!==true)){a.control.scale().addTo(o)}if(m.bounds){o.fitBounds(m.bounds)}h.data("leafmap",o);h.data("leafmap.config",m);h.trigger("map.finishing",[h,o]);if(i){i(o,m)}h.trigger("map.finished",[h,o])})})},getLayer:function(i){var g=d.getObject(i.factory);if(g!==undefined){delete i.factory;var f=[];if(i.dependsOn){for(var h in i.dependsOn){if(!i.dependsOn.hasOwnProperty(h)){continue}if(d.getObject(h)===undefined){f.push(d.getScript(i.dependsOn[h]))}}delete i.dependsOn}if(f.length>0){c.when.apply(c,f)}return g(i)}},factory:{TileLayer:function(g){var f=g.url;delete g.url;return a.tileLayer(f,g)},WMS:function(g){var f=g.url;delete g.url;return a.tileLayer.wms(f,g)},Geoportal:{WMS:function(f){d.getCSS("/--static--/pyams_gis/css/leaflet-gp-3.0.2"+d.devext+".css","geoportal");return a.geoportalLayer.WMS(f)}},ESRI:{Feature:function(f){return a.esri.featureLayer(f)}},Google:function(g){var h=g.apiKey;delete g.apiKey;if(d.getObject("window.google.maps")===undefined){var f=d.getScript("https://maps.googleapis.com/maps/api/js?key="+h);c.when.apply(c,[f])}return a.gridLayer.googleMutant(g)}},callJSON:function(h,f,g){d.ajax.check(c.jsonRPC,d.baseURL+"ext/jquery-jsonrpc"+d.devext+".js",function(){c.jsonRPC.withOptions({endPoint:e.RPC_ENDPOINT,cache:false},function(){c.jsonRPC.request(h,{id:new Date().getTime(),params:f,success:g,error:d.error.show})})})},position:{init:function(){var f=c(".map",c(this));if(f.data("leafmap")===undefined){f.css("height",c(window).height()-200);e.init(f,{},function(o,h){var j=f.data();var p=a.icon({iconUrl:"/--static--/pyams_gis/img/marker-icon.png",iconSize:[25,41],iconAnchor:[13,40]});var k=a.marker();k.setIcon(p);var m=j.mapLeafletFieldname;var g=c('input[name="'+m+'.widgets.longitude"]');var n=c('input[name="'+m+'.widgets.latitude"]');if(g.val()&&n.val()){var l=c('select[name="'+m+'.widgets.projection:list"]');var i={point:{longitude:parseFloat(g.val()),latitude:parseFloat(n.val())},from_projection:l.val()||e.WGS_SRID,to_projection:e.WGS_SRID};e.callJSON("transformPoint",i,function(r){if(!r.error){var q=r.result.point;k.setLatLng({lon:q.longitude,lat:q.latitude});k.addTo(o);o.setView(k.getLatLng(),h.zoom||13)}})}else{k.setLatLng([-90,0]);k.addTo(o)}f.data("marker",k);o.on("click",e.position.onClick)})}},onClick:function(i){var k=i.target.getContainer();var j=c(k).data();var g=j.marker;var m=i.latlng;g.setLatLng(m);var h=j.mapLeafletFieldname;var f=c('select[name="'+h+'.widgets.projection:list"]');var l={point:{longitude:m.lng,latitude:m.lat},from_projection:e.WGS_SRID,to_projection:f.val()};e.callJSON("transformPoint",l,function(o){if(!o.error){var n=o.result.point;c('input[name="'+h+'.widgets.longitude"]').val(n.longitude);c('input[name="'+h+'.widgets.latitude"]').val(n.latitude)}})},changedCoordinate:function(){var h=c(this);var j=c(".map",h.parents("fieldset:first"));if(!j.data("marker")){return}var g=j.data("map-leaflet-fieldname");var i=c('input[name="'+g+'.widgets.longitude"]');var l=c('input[name="'+g+'.widgets.latitude"]');if(i.val()&&l.val()){var f=c('select[name="'+g+'.widgets.projection:list"]');var k={point:{longitude:parseFloat(i.val()),latitude:parseFloat(l.val())},from_projection:f.val(),to_projection:4326};e.callJSON("transformPoint",k,function(n){if(!n.error){var m=n.result.point;var o=j.data("marker");o.setLatLng({lon:m.longitude,lat:m.latitude})}})}},changedProjection:function(h){var n=c(this);var g=c(".map",n.parents("fieldset:first"));var k=g.data("map-leaflet-fieldname");var f=c('input[name="'+k+'.widgets.longitude"]');var m=c('input[name="'+k+'.widgets.latitude"]');if(h.removed){var j=h.removed.id;var l=h.added.id;if(j!==l){if(f.val()&&m.val()){var i={point:{longitude:parseFloat(f.val()),latitude:parseFloat(m.val())},from_projection:j,to_projection:l};e.callJSON("transformPoint",i,function(p){if(!p.error){var o=p.result.point;f.val(o.longitude);m.val(o.latitude)}})}}}else{e.position.changedCoordinate.apply(f)}},clear:function(g){var f=c(this).parents("fieldset:first");c("input",f).val(null)}},area:{init:function(){var f=c(".map",c(this));if(f.data("leafmap")===undefined){f.css("height",c(window).height()-200);e.init(f,{},function(g){a.Draw=a.Draw||{};a.Edit=a.Edit||{};d.ajax.check([a.Draw,a.Draw.Event,a.Map.TouchExtend,a.Edit.SimpleShape],["/--static--/pyams_gis/js/leaflet.Draw"+d.devext+".js","/--static--/pyams_gis/js/leaflet.Draw.Event"+d.devext+".js","/--static--/pyams_gis/js/TouchEvents"+d.devext+".js","/--static--/pyams_gis/js/Edit.SimpleShape"+d.devext+".js"],function(){d.ajax.check(a.Edit.Rectangle,"/--static--/pyams_gis/js/Edit.Rectangle"+d.devext+".js",function(){function h(w,v){var u=new a.FeatureGroup();q=a.rectangle([w,v]);u.addLayer(q);g.addLayer(u);g.fitBounds(q.getBounds());q.editing.enable();f.data("area",q);g.on(a.Draw.Event.EDITMOVE,e.area.changedArea);g.on(a.Draw.Event.EDITRESIZE,e.area.changedArea);g.on(a.Draw.Event.EDITVERTEX,e.area.changedArea)}var m=f.data();var o=m.mapLeafletFieldname;var j=c('input[name="'+o+'.widgets.x1"]');var r=c('input[name="'+o+'.widgets.y1"]');var i=c('input[name="'+o+'.widgets.x2"]');var p=c('input[name="'+o+'.widgets.y2"]');var t,s,q;if(j.val()&&r.val()&&i.val()&&p.val()){var n=c('select[name="'+o+'.widgets.projection:list"]');var l={area:{x1:parseFloat(j.val()),y1:parseFloat(r.val()),x2:parseFloat(i.val()),y2:parseFloat(p.val())},from_projection:n.val(),to_projection:e.WGS_SRID};e.callJSON("transformArea",l,function(u){if(!u.error){var v=u.result.area;t=a.latLng({lon:v.x1,lat:v.y1});s=a.latLng({lon:v.x2,lat:v.y2});h(t,s)}})}else{var k=f.data("leafmap.config");if(k.bounds){t=a.latLng(k.bounds[0]);s=a.latLng(k.bounds[1])}else{t=a.latLng({lon:-168,lat:-56.37});s=a.latLng({lon:191.25,lat:83.72})}h(t,s)}})})})}},last_event:null,changedArea:function(f){e.area.last_event=f;setTimeout(function(){if(f===e.area.last_event){var k=f.target.getContainer();var j=c(k).data();var i=j.area.getBounds();var h=j.mapLeafletFieldname;var g=c('select[name="'+h+'.widgets.projection:list"]').val();var l={area:{x1:i.getWest(),y1:i.getSouth(),x2:i.getEast(),y2:i.getNorth()},from_projection:e.WGS_SRID,to_projection:g};e.callJSON("transformArea",l,function(m){if(!m.error){var n=m.result.area;c('input[name="'+h+'.widgets.x1"]').val(n.x1);c('input[name="'+h+'.widgets.y1"]').val(n.y1);c('input[name="'+h+'.widgets.x2"]').val(n.x2);c('input[name="'+h+'.widgets.y2"]').val(n.y2)}})}},100)},changedCoordinate:function(){var n=c(this);var f=c(".map",n.parents("fieldset:first"));if(!f.data("area")){return}var j=f.data("map-leaflet-fieldname");var h=c('input[name="'+j+'.widgets.x1"]');var m=c('input[name="'+j+'.widgets.y1"]');var g=c('input[name="'+j+'.widgets.x2"]');var l=c('input[name="'+j+'.widgets.y2"]');if(h.val()&&m.val()&&g.val()&&l.val()){var k=c('select[name="'+j+'.widgets.projection:list"]');var i={area:{x1:parseFloat(h.val()),y1:parseFloat(m.val()),x2:parseFloat(g.val()),y2:parseFloat(l.val())},from_projection:k.val(),to_projection:4326};e.callJSON("transformArea",i,function(o){if(!o.error){var q=o.result.area;var p=f.data("area");p.editing.disable();p.setBounds([a.latLng({lon:q.x1,lat:q.y1}),a.latLng({lon:q.x2,lat:q.y2})]);p.editing.enable()}})}},changedProjection:function(g){var p=c(this);var f=c(".map",p.parents("fieldset:first"));var l=f.data("map-leaflet-fieldname");var i=c('input[name="'+l+'.widgets.x1"]');var o=c('input[name="'+l+'.widgets.y1"]');var h=c('input[name="'+l+'.widgets.x2"]');var n=c('input[name="'+l+'.widgets.y2"]');if(g.removed){var k=g.removed.id;var m=g.added.id;if(k!==m){if(i.val()&&o.val()&&h.val()&&n.val()){var j={area:{x1:parseFloat(i.val()),y1:parseFloat(o.val()),x2:parseFloat(h.val()),y2:parseFloat(n.val())},from_projection:k,to_projection:m};e.callJSON("transformArea",j,function(q){if(!q.error){var r=q.result.area;i.val(r.x1);o.val(r.y1);h.val(r.x2);n.val(r.y2)}})}}}else{e.area.changedCoordinate.apply(i)}},clear:function(g){var f=c(this).parents("fieldset:first");c("input",f).val(null)}}};b.PyAMS_GIS=e})(jQuery,this);
\ No newline at end of file
+!function(a,e){"use strict";var t,n=e.MyAMS,i={RPC_ENDPOINT:"/api/gis/json",WGS_SRID:4326,_layersControlAddItem:function(e){var n,i,r=a("<div></div>").addClass("inline-group"),l=a("<label></label>").addClass(e.overlay?"checkbox":"radio"),o=a("<i></i>"),s=this._map.hasLayer(e.layer);e.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(e.layer),a(n).addClass(e.overlay?"checkbox":"radio"),t.DomEvent.on(n,"click",this._onInputClick,this),i=a("<span></span>").text(" "+e.name),l.append(n),l.append(o),l.append(i),r.append(l);var d=e.overlay?this._overlaysList:this._baseLayersList;return a(d).append(r),r},init:function(r,l,o){var s=r;n.ajax.check(e.L,"/--static--/pyams_gis/js/leaflet-1.0.3"+n.devext+".js",function(r){r&&((t=e.L).Control.Layers.prototype._addItem=i._layersControlAddItem),n.getCSS("/--static--/pyams_gis/css/leaflet-1.0.3"+n.devext+".css","leaflet",function(){n.ajax.post("get-map-configuration.json",{},function(r){var d=s.data(),p={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||n.getObject(r.crs)||e.L.CRS.EPSG3857,center:d.mapLeafletCenter||r.center,zoom:d.mapLeafletZoom||r.zoom};p=a.extend({},p,l),s.trigger("map.init",[s,p,r]);var c=t.map(s.attr("id"),p);if(r.layers)for(var u=0;u<r.layers.length;u++){var m=r.layers[u];s.trigger("map.layer.init",[s,m]),i.getLayer(m).addTo(c)}else t.tileLayer("http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png",{maxZoom:19,id:"osm",attribution:'© <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>'}).addTo(c);r.zoomControl&&!0!==d.mapLeafletHideZoomControl&&t.control.scale().addTo(c),r.bounds&&c.fitBounds(r.bounds),s.data("leafmap",c),s.data("leafmap.config",r),s.trigger("map.finishing",[s,c]),o&&o(c,r),s.trigger("map.finished",[s,c])})})})},getLayer:function(e){var t=n.getObject(e.factory);if(void 0!==t){delete e.factory;var i=[];if(e.dependsOn){for(var r in e.dependsOn)e.dependsOn.hasOwnProperty(r)&&void 0===n.getObject(r)&&i.push(n.getScript(e.dependsOn[r]));delete e.dependsOn}return i.length>0&&a.when.apply(a,i),t(e)}},factory:{TileLayer:function(a){var e=a.url;return delete a.url,t.tileLayer(e,a)},WMS:function(a){var e=a.url;return delete a.url,t.tileLayer.wms(e,a)},Geoportal:{WMS:function(a){return n.getCSS("/--static--/pyams_gis/css/leaflet-gp-3.0.2"+n.devext+".css","geoportal"),t.geoportalLayer.WMS(a)}},ESRI:{Feature:function(a){return t.esri.featureLayer(a)}},Google:function(e){var i=e.apiKey;if(delete e.apiKey,void 0===n.getObject("window.google.maps")){var r=n.getScript("https://maps.googleapis.com/maps/api/js?key="+i);a.when.apply(a,[r])}return t.gridLayer.googleMutant(e)}},callJSON:function(e,t,r){n.ajax.check(a.jsonRPC,n.baseURL+"ext/jquery-jsonrpc"+n.devext+".js",function(){a.jsonRPC.withOptions({endPoint:i.RPC_ENDPOINT,cache:!1},function(){a.jsonRPC.request(e,{id:(new Date).getTime(),params:t,success:r,error:n.error.show})})})},position:{init:function(){var e=a(".map",a(this));void 0===e.data("leafmap")&&(e.css("height",a(window).height()-200),i.init(e,{},function(n,r){var l=e.data(),o=t.icon({iconUrl:"/--static--/pyams_gis/img/marker-icon.png",iconSize:[25,41],iconAnchor:[13,40]}),s=t.marker();s.setIcon(o);var d=l.mapLeafletFieldname,p=a('input[name="'+d+'.widgets.longitude"]'),c=a('input[name="'+d+'.widgets.latitude"]');if(p.val()&&c.val()){var u=a('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(a){if(!a.error){var e=a.result.point;s.setLatLng({lon:e.longitude,lat:e.latitude}),s.addTo(n),n.setView(s.getLatLng(),r.zoom||13)}})}else s.setLatLng([-90,0]),s.addTo(n);e.data("marker",s),n.on("click",i.position.onClick)}))},onClick:function(e){var t=e.target.getContainer(),n=a(t).data(),r=n.marker,l=e.latlng;r.setLatLng(l);var o=n.mapLeafletFieldname,s=a('select[name="'+o+'.widgets.projection:list"]'),d={point:{longitude:l.lng,latitude:l.lat},from_srid:i.WGS_SRID,to_srid:s.val()};i.callJSON("transformPoint",d,function(e){if(!e.error){var n=e.result.point;a('input[name="'+o+'.widgets.longitude"]').val(n.longitude),a('input[name="'+o+'.widgets.latitude"]').val(n.latitude),a(t).trigger("marker.changed",[t,n])}})},changedCoordinate:function(){var e=a(this),t=a(".map",e.parents("fieldset:first"));if(t.data("marker")){var n=t.data("map-leaflet-fieldname"),r=a('input[name="'+n+'.widgets.longitude"]'),l=a('input[name="'+n+'.widgets.latitude"]');if(r.val()&&l.val()){var o=a('select[name="'+n+'.widgets.projection:list"]'),s={point:{longitude:parseFloat(r.val()),latitude:parseFloat(l.val())},from_srid:o.val(),to_srid:i.WGS_SRID};i.callJSON("transformPoint",s,function(a){if(!a.error){var e=a.result.point;t.data("marker").setLatLng({lon:e.longitude,lat:e.latitude})}})}}},changedProjection:function(e){var t=a(this),n=a(".map",t.parents("fieldset:first")).data("map-leaflet-fieldname"),r=a('input[name="'+n+'.widgets.longitude"]'),l=a('input[name="'+n+'.widgets.latitude"]');if(e.removed){var o=e.removed.id,s=e.added.id;if(o!==s&&r.val()&&l.val()){var d={point:{longitude:parseFloat(r.val()),latitude:parseFloat(l.val())},from_srid:o,to_srid:s};i.callJSON("transformPoint",d,function(a){if(!a.error){var e=a.result.point;r.val(e.longitude),l.val(e.latitude)}})}}else i.position.changedCoordinate.apply(r)},clear:function(e){var t=a(this).parents("fieldset:first");a("input",t).val(null)},moveMarkerTo:function(e,t,n){var r=e.data("map-leaflet-fieldname");a('input[name="'+r+'.widgets.longitude"]').val(t.lon),a('input[name="'+r+'.widgets.latitude"]').val(t.lat);var l={point:{longitude:t.lon,latitude:t.lat},from_srid:n,to_srid:4326};i.callJSON("transformPoint",l,function(a){if(!a.error){var n=a.result.point;e.data("marker").setLatLng({lon:n.longitude,lat:n.latitude}),e.data("leafmap").setView(t)}})}},area:{init:function(){var e=a(".map",a(this));void 0===e.data("leafmap")&&(e.css("height",a(window).height()-200),i.init(e,{},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/leaflet.Draw"+n.devext+".js","/--static--/pyams_gis/js/leaflet.Draw.Event"+n.devext+".js","/--static--/pyams_gis/js/TouchEvents"+n.devext+".js","/--static--/pyams_gis/js/Edit.SimpleShape"+n.devext+".js"],function(){n.ajax.check(t.Edit.Rectangle,"/--static--/pyams_gis/js/Edit.Rectangle"+n.devext+".js",function(){function n(a,n){var l=new t.FeatureGroup;s=t.rectangle([a,n]),l.addLayer(s),r.addLayer(l),r.fitBounds(s.getBounds()),s.editing.enable(),e.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 l,o,s,d=e.data().mapLeafletFieldname,p=a('input[name="'+d+'.widgets.x1"]'),c=a('input[name="'+d+'.widgets.y1"]'),u=a('input[name="'+d+'.widgets.x2"]'),m=a('input[name="'+d+'.widgets.y2"]');if(p.val()&&c.val()&&u.val()&&m.val()){var g=a('select[name="'+d+'.widgets.projection:list"]'),v={area:{x1:parseFloat(p.val()),y1:parseFloat(c.val()),x2:parseFloat(u.val()),y2:parseFloat(m.val())},from_srid:g.val(),to_srid:i.WGS_SRID};i.callJSON("transformArea",v,function(a){if(!a.error){var e=a.result.area;l=t.latLng({lon:e.x1,lat:e.y1}),o=t.latLng({lon:e.x2,lat:e.y2}),n(l,o)}})}else{var f=e.data("leafmap.config");f.bounds?(l=t.latLng(f.bounds[0]),o=t.latLng(f.bounds[1])):(l=t.latLng({lon:-168,lat:-56.37}),o=t.latLng({lon:191.25,lat:83.72})),n(l,o)}})})}))},last_event:null,changedArea:function(e){i.area.last_event=e,setTimeout(function(){if(e===i.area.last_event){var t=e.target.getContainer(),n=a(t).data(),r=n.area.getBounds(),l=n.mapLeafletFieldname,o=a('select[name="'+l+'.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:o};i.callJSON("transformArea",s,function(e){if(!e.error){var t=e.result.area;a('input[name="'+l+'.widgets.x1"]').val(t.x1),a('input[name="'+l+'.widgets.y1"]').val(t.y1),a('input[name="'+l+'.widgets.x2"]').val(t.x2),a('input[name="'+l+'.widgets.y2"]').val(t.y2)}})}},100)},changedCoordinate:function(){var e=a(this),n=a(".map",e.parents("fieldset:first"));if(n.data("area")){var r=n.data("map-leaflet-fieldname"),l=a('input[name="'+r+'.widgets.x1"]'),o=a('input[name="'+r+'.widgets.y1"]'),s=a('input[name="'+r+'.widgets.x2"]'),d=a('input[name="'+r+'.widgets.y2"]');if(l.val()&&o.val()&&s.val()&&d.val()){var p=a('select[name="'+r+'.widgets.projection:list"]'),c={area:{x1:parseFloat(l.val()),y1:parseFloat(o.val()),x2:parseFloat(s.val()),y2:parseFloat(d.val())},from_srid:p.val(),to_srid:4326};i.callJSON("transformArea",c,function(a){if(!a.error){var e=a.result.area,i=n.data("area");i.editing.disable(),i.setBounds([t.latLng({lon:e.x1,lat:e.y1}),t.latLng({lon:e.x2,lat:e.y2})]),i.editing.enable()}})}}},changedProjection:function(e){var t=a(this),n=a(".map",t.parents("fieldset:first")).data("map-leaflet-fieldname"),r=a('input[name="'+n+'.widgets.x1"]'),l=a('input[name="'+n+'.widgets.y1"]'),o=a('input[name="'+n+'.widgets.x2"]'),s=a('input[name="'+n+'.widgets.y2"]');if(e.removed){var d=e.removed.id,p=e.added.id;if(d!==p&&r.val()&&l.val()&&o.val()&&s.val()){var c={area:{x1:parseFloat(r.val()),y1:parseFloat(l.val()),x2:parseFloat(o.val()),y2:parseFloat(s.val())},from_srid:d,to_srid:p};i.callJSON("transformArea",c,function(a){if(!a.error){var e=a.result.area;r.val(e.x1),l.val(e.y1),o.val(e.x2),s.val(e.y2)}})}}else i.area.changedCoordinate.apply(r)},clear:function(e){var t=a(this).parents("fieldset:first");a("input",t).val(null)}}};e.PyAMS_GIS=i}(jQuery,this);