Y-SLD/assets/playkit/js/map-preview.js

1 line
2.0 KiB
JavaScript

L.TileLayer.BetterWMS=L.TileLayer.WMS.extend({onAdd:function(t){L.TileLayer.WMS.prototype.onAdd.call(this,t),t.on("click",this.getFeatureInfo,this)},onRemove:function(t){L.TileLayer.WMS.prototype.onRemove.call(this,t),t.off("click",this.getFeatureInfo,this)},getFeatureInfo:function(t){var e=this.getFeatureInfoUrl(t.latlng),a=L.Util.bind(this.showGetFeatureInfo,this);$.ajax({url:e,success:function(e,r,s){var o="string"==typeof e?null:e;a(o,t.latlng,e)},error:function(t,e,r){a(r)}})},getFeatureInfoUrl:function(t){var e=this._map.latLngToContainerPoint(t,this._map.getZoom()),a=this._map.getSize(),r={request:"GetFeatureInfo",service:"WMS",srs:"EPSG:4326",styles:this.wmsParams.styles,transparent:this.wmsParams.transparent,version:this.wmsParams.version,format:this.wmsParams.format,bbox:this._map.getBounds().toBBoxString(),height:a.y,width:a.x,layers:this.wmsParams.layers,query_layers:this.wmsParams.layers,info_format:"text/html"};return r["1.3.0"===r.version?"i":"x"]=e.x,r["1.3.0"===r.version?"j":"y"]=e.y,this._url+L.Util.getParamString(r,this._url,!0)},showGetFeatureInfo:function(t,e,a){t||jQuery(a).find("tr").length<2||(a=a.toLowerCase(),jQuery(a).filter("table").addClass("table"),L.popup({maxWidth:"auto"}).setLatLng(e).setContent(a).openOn(this._map))}}),L.tileLayer.myWms=function(t,e){return new L.TileLayer.BetterWMS(t,e)},jQuery(document).ready(function(){var t=L.map("mapid",{zoom:8,crs:L.CRS.EPSG4326});t.setView([parseFloat(lat1),parseFloat(lng1)],8),isGoogle()?currentBaseMap=L.tileLayer("https://{s}.google.com/vt/lyrs=s&x={x}&y={y}&z={z}",{maxZoom:20,subdomains:["mt0","mt1","mt2","mt3"]}).addTo(t):currentBaseMap=L.tileLayer(baseLayers.mymap[layername]._url,{maxZoom:18,attribution:baseLayers.mymap[layername].options.attribution,id:baseLayers.mymap[layername].options.id}).addTo(t);var e=L.tileLayer.myWms(url,{format:"image/png",layers:layerName,format:"image/png",transparent:!0});e.addTo(t);var a=new L.LatLngBounds([parseFloat(lat1),parseFloat(lng1)],[parseFloat(lat2),parseFloat(lng2)]);t.fitBounds(a),t.options.minZoom=t.getZoom(),t.setMaxBounds(a)});