L.TileLayer.BetterWMS = L.TileLayer.WMS.extend({ onAdd: function (map) { // Triggered when the layer is added to a map. // Register a click listener, then do all the upstream WMS things L.TileLayer.WMS.prototype.onAdd.call(this, map); map.on('click', this.getFeatureInfo, this); }, onRemove: function (map) { // Triggered when the layer is removed from a map. // Unregister a click listener, then do all the upstream WMS things L.TileLayer.WMS.prototype.onRemove.call(this, map); map.off('click', this.getFeatureInfo, this); }, getFeatureInfo: function (evt) { // Make an AJAX request to the server and hope for the best var url = this.getFeatureInfoUrl(evt.latlng), showResults = L.Util.bind(this.showGetFeatureInfo, this); $.ajax({ url: url, success: function (data, status, xhr) { var err = typeof data === 'string' ? null : data; showResults(err, evt.latlng, data); }, error: function (xhr, status, error) { showResults(error); } }); }, getFeatureInfoUrl: function (latlng) { // Construct a GetFeatureInfo request URL given a point var point = this._map.latLngToContainerPoint(latlng, this._map.getZoom()), size = this._map.getSize(), params = { 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: size.y, width: size.x, layers: this.wmsParams.layers, query_layers: this.wmsParams.layers, info_format: 'text/html' }; params[params.version === '1.3.0' ? 'i' : 'x'] = point.x; params[params.version === '1.3.0' ? 'j' : 'y'] = point.y; return this._url + L.Util.getParamString(params, this._url, true); }, showGetFeatureInfo: function (err, latlng, content) { if (err) { console.log(err); return; } // do nothing if there's an error if (jQuery(content).find("tr").length < 2) { return; } content = content.toLowerCase(); //var content = content.replace('/g', "/gi, "") // .replace(//gi, "") // .replace(/<\/tbody/gi, "<\/div") //); // }); //$('.leaflet-popup-content-wrapper').find('table').addClass("table"); // each(function (){ // $(this).replaceWith( $(this).html() // .replace(//gi, "") // .replace(//gi, "") // .replace(/<\/tbody/gi, "<\/div") // ); // }); } }); L.tileLayer.myWms = function (url, options) { return new L.TileLayer.BetterWMS(url, options); }; jQuery(document).ready(function () { var mymap = L.map('mapid', { zoom: 8, crs: L.CRS.EPSG4326 }); mymap.setView([parseFloat(lat1), parseFloat(lng1)], 8); if (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(mymap); } else { currentBaseMap = L.tileLayer(baseLayers['mymap'][layername]._url, { maxZoom: 18, attribution: baseLayers['mymap'][layername].options.attribution, id: baseLayers['mymap'][layername].options.id }).addTo(mymap); } var states = L.tileLayer.myWms(url, { format: 'image/png', layers: layerName, format: 'image/png', transparent: true, //crs: L.CRS.EPSG4326 }); states.addTo(mymap); var bounds = new L.LatLngBounds([parseFloat(lat1), parseFloat(lng1)], [parseFloat(lat2), parseFloat(lng2)]); mymap.fitBounds(bounds); mymap.options.minZoom = mymap.getZoom(); mymap.setMaxBounds(bounds); //var l = L.latLng(lat, lng); //console.log(states.getFeatureInfoUrl(l)); }) //# sourceMappingURL=map-preview.js.map