mappe per georeferenziazione
Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.

1 riga
7.1 KiB

2 anni fa
(function(factory){if(typeof define==="function"&&define.amd){define(["leaflet"],factory)}else if(typeof module!=="undefined"){module.exports=factory(require("leaflet"))}else{if(typeof this.L==="undefined")throw"Leaflet must be loaded first!";this.L.WMS=this.L.wms=factory(this.L)}})(function(L){var wms={};if(!("keys"in Object)){Object.keys=function(obj){var result=[];for(var i in obj){if(obj.hasOwnProperty(i)){result.push(i)}}return result}}wms.Source=L.Layer.extend({options:{untiled:true,identify:true},initialize:function(url,options){L.setOptions(this,options);if(this.options.tiled){this.options.untiled=false}this._url=url;this._subLayers={};this._overlay=this.createOverlay(this.options.untiled)},createOverlay:function(untiled){var overlayOptions={};for(var opt in this.options){if(opt!="untiled"&&opt!="identify"){overlayOptions[opt]=this.options[opt]}}if(untiled){return wms.overlay(this._url,overlayOptions)}else{return wms.tileLayer(this._url,overlayOptions)}},onAdd:function(){this.refreshOverlay()},getEvents:function(){if(this.options.identify){return{click:this.identify}}else{return{}}},setOpacity:function(opacity){this.options.opacity=opacity;if(this._overlay){this._overlay.setOpacity(opacity)}},bringToBack:function(){this.options.isBack=true;if(this._overlay){this._overlay.bringToBack()}},bringToFront:function(){this.options.isBack=false;if(this._overlay){this._overlay.bringToFront()}},getLayer:function(name){return wms.layer(this,name)},addSubLayer:function(name){this._subLayers[name]=true;this.refreshOverlay()},removeSubLayer:function(name){delete this._subLayers[name];this.refreshOverlay()},refreshOverlay:function(){var subLayers=Object.keys(this._subLayers).join(",");if(!this._map){return}if(!subLayers){this._overlay.remove()}else{this._overlay.setParams({layers:subLayers});this._overlay.addTo(this._map)}},identify:function(evt){var layers=this.getIdentifyLayers();if(!layers.length){return}this.getFeatureInfo(evt.containerPoint,evt.latlng,layers,this.showFeatureInfo)},getFeatureInfo:function(point,latlng,layers,callback){var params=this.getFeatureInfoParams(point,layers),url=this._url+L.Util.getParamString(params,this._url);this.showWaiting();this.ajax(url,done);function done(result){this.hideWaiting();var text=this.parseFeatureInfo(result,url);callback.call(this,latlng,text)}},ajax:function(url,callback){ajax.call(this,url,callback)},getIdentifyLayers:function(){if(this.options.identifyLayers)return this.options.identifyLayers;return Object.keys(this._subLayers)},getFeatureInfoParams:function(point,layers){var wmsParams,overlay;if(this.options.untiled){wmsParams=this._overlay.wmsParams}else{overlay=this.createOverlay(true);overlay.updateWmsParams(this._map);wmsParams=overlay.wmsParams;wmsParams.layers=layers.join(",")}var infoParams={request:"GetFeatureInfo",query_layers:layers.join(","),X:Math.round(point.x),Y:Math.round(point.y)};return L.extend({},wmsParams,infoParams)},parseFeatureInfo:function(result,url){if(result=="error"){result="<iframe src='"+url+"' style='border:none'>"}return result},showFeatureInfo:function(latlng,info){if(!this._map){return}this._map.openPopup(info,latlng)},showWaiting:function(){if(!this._map)return;this._map._container.style.cursor="progress"},hideWaiting:function(){if(!this._map)return;this._map._container.style.cursor="default"}});wms.source=function(url,options){return new wms.Source(url,options)};wms.Layer=L.Layer.extend({initialize:function(source,layerName,options){L.setOptions(this,options);if(!source.addSubLayer){source=wms.getSourceForUrl(source,options)}this._source=source;this._name=layerName},onAdd:function(){if(!this._source._map)this._source.addTo(this._map);this._source.addSubLayer(this._name)},onRemove:function(){this._source.removeSubLayer(this._name)},setOpacity:function(opacity){this._source.setOpacity(opacity)},bringToBack:function(){this._source.bringToBack()},bringToFront:function(){this._source.bringToFront()}});wms.layer=function(source,options){return new wms.Layer(source,options)};var sources={};wms.getSourceForUrl=function(url,options){if(!sources[ur