Y-SLD/assets/plugins/leaflet/print-master/dist/leaflet.print.js

5 lines
13 KiB
JavaScript
Raw Normal View History

2024-03-01 11:23:55 +00:00
/*
Leaflet.print, implements the Mapfish print protocol allowing a Leaflet map to be printed using either the Mapfish or GeoServer print module.
(c) 2013, Adam Ratcliffe, GeoSmart Maps Limited
*/
!function(t,i){L.print=L.print||{},L.print.Provider=L.Class.extend({includes:L.Mixin.Events,statics:{MAX_RESOLUTION:156543.03390625,MAX_EXTENT:[-20037508.34,-20037508.34,20037508.34,20037508.34],SRS:"EPSG:3857",INCHES_PER_METER:39.3701,DPI:72,UNITS:"m"},options:{autoLoad:!1,autoOpen:!0,outputFormat:"pdf",outputFilename:"leaflet-map",method:"POST",rotation:0,customParams:{},legends:!1},initialize:function(t){if(L.version<="0.5.1")throw"Leaflet.print requires Leaflet 0.6.0+. Download latest from https://github.com/Leaflet/Leaflet/";var i;t=L.setOptions(this,t),t.map&&this.setMap(t.map),t.capabilities?this._capabilities=t.capabilities:this.options.autoLoad&&this.loadCapabilities(),t.listeners&&(t.listeners.context&&(i=t.listeners.context,delete t.listeners.context),this.addEventListener(t.listeners,i))},loadCapabilities:function(){if(this.options.url){var t;t=this.options.url+"/info.json",this.options.proxy&&(t=this.options.proxy+t),$.ajax({type:"GET",dataType:"json",url:t,success:L.Util.bind(this.onCapabilitiesLoad,this)})}},print:function(i){if(i=L.extend(L.extend({},this.options),i),!i.layout||!i.dpi)throw"Must provide a layout name and dpi value to print";this.fire("beforeprint",{provider:this,map:this._map});var e,o=JSON.stringify(L.extend({units:L.print.Provider.UNITS,srs:L.print.Provider.SRS,layout:i.layout,dpi:i.dpi,outputFormat:i.outputFormat,outputFilename:i.outputFilename,layers:this._encodeLayers(this._map),pages:[{center:this._projectCoords(L.print.Provider.SRS,this._map.getCenter()),scale:this._getScale(),rotation:i.rotation}]},this.options.customParams,i.customParams,this._makeLegends(this._map)));"GET"===i.method?(e=this._capabilities.printURL+"?spec="+encodeURIComponent(o),i.proxy&&(e=i.proxy+encodeURIComponent(e)),t.open(e),this.fire("print",{provider:this,map:this._map})):(e=this._capabilities.createURL,i.proxy&&(e=i.proxy+e),this._xhr&&this._xhr.abort(),this._xhr=$.ajax({type:"POST",contentType:"application/json; charset=UTF-8",processData:!1,dataType:"json",url:e,data:o,success:L.Util.bind(this.onPrintSuccess,this),error:L.Util.bind(this.onPrintError,this)}))},getCapabilities:function(){return this._capabilities},setMap:function(t){this._map=t},setDpi:function(t){var i=this.options.dpi;i!==t&&(this.options.dpi=t,this.fire("dpichange",{provider:this,dpi:t}))},setLayout:function(t){var i=this.options.layout;i!==t&&(this.options.layout=t,this.fire("layoutchange",{provider:this,layout:t}))},setRotation:function(t){var i=this.options.rotation;i!==this.options.rotation&&(this.options.rotation=t,this.fire("rotationchange",{provider:this,rotation:t}))},_getLayers:function(t){var i,e,o,n=[],s=[],r=[],a=[];for(o in t._layers)if(t._layers.hasOwnProperty(o)){if(!t._layers.hasOwnProperty(o))continue;var l=t._layers[o];l instanceof L.TileLayer.WMS||l instanceof L.TileLayer?r.push(l):l instanceof L.ImageOverlay?a.push(l):l instanceof L.Marker?n.push(l):l instanceof L.Path&&l.toGeoJSON&&s.push(l)}n.sort(function(t,i){return t._icon.style.zIndex-i._icon.style.zIndex});var c;for(c=1;c<n.length;c++)n[c]._icon.style.zIndex<=n[c-1]._icon.style.zIndex&&(n[c]._icon.style.zIndex=n[c-1].icons.style.zIndex+1);for(r.sort(function(t,i){return t._container.style.zIndex-i._container.style.zIndex}),c=1;c<r.length;c++)r[c]._container.style.zIndex<=r[c-1]._container.style.zIndex&&(r[c]._container.style.zIndex=r[c-1]._container.style.zIndex+1);return i=[].slice.call(this,t._panes.overlayPane.childNodes),a.sort(function(t,e){return i.indexOf(t._image)-i.indexOf(e._image)}),t._pathRoot&&(e=[].slice.call(this,t._pathRoot.childNodes),s.sort(function(t,i){return e.indexOf(t._container)-e.indexOf(i._container)})),r.concat(s).concat(a).concat(n)},_getScale:function(){for(var t,i,e=this._map,o=e.getBounds(),n=1e3*L.print.Provider.INCHES_PER_METER,s=this._capabilities.scales,r=o.getSouthWest(),a=o.getNorthEast(),l=(r.lat+a.lat)/2,c=L.latLng(l,r.lng),p=L.latLng(l,a.lng),h=c.distanceTo(p),u=e.getSize().x,d=h/u/1e3,f=(d||1e-6)*n*L.print.Provider.DPI,_=Number.POSITIVE_INFINITY,y=s.length;y--;)t=Math.abs(f-s[y].value),_>t&&(_=t,i=parseInt(s[y].value