Skip to content

Commit

Permalink
Merge pull request #7 from oliverheilig/master
Browse files Browse the repository at this point in the history
Fix VirtualLayere
  • Loading branch information
oliverheilig authored Apr 21, 2024
2 parents 90b69c3 + 548a28c commit dd99548
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 18 deletions.
19 changes: 6 additions & 13 deletions SharpMap.Web/VirtualLayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
* L.VirtualLayer
*/
L.VirtualLayer = L.Layer.extend({
includes: L.Mixin.Events,
options: {
attribution: '',
minZoom: 0,
Expand All @@ -24,11 +23,6 @@ L.VirtualLayer = L.Layer.extend({
L.setOptions(this, options);
},

addTo: function (map) {
map.addLayer(this);
return this;
},

onAdd: function (map) {
this._map = map;
this.hostLayer.virtualLayers[this.name] = true;
Expand Down Expand Up @@ -56,19 +50,18 @@ L.VirtualLayer = L.Layer.extend({
if (this.hostLayer.virtualLayers[key])
visibileLayers.push(key);

map.removeLayer(this.hostLayer);

if (this.hostLayer.wmsParams)
this.hostLayer.wmsParams.layers = visibileLayers.join(',');
else {
this.hostLayer._url = this.hostLayer._url.substring(0, this.hostLayer._url.indexOf("&layers="));
this.hostLayer._url = this.hostLayer._url + '&layers=' + visibileLayers.join(',');
var url = this.hostLayer._url = this.hostLayer._url.substring(0, this.hostLayer._url.indexOf("&layers="));
url = this.hostLayer._url + '&layers=' + visibileLayers.join(',');
this.hostLayer.setUrl(url);
}

if (visibileLayers.length == 0)
map.removeLayer(this.hostLayer);
else {
if (visibileLayers.length > 0)
map.addLayer(this.hostLayer);
this.hostLayer.redraw();
}

return this;
}
Expand Down
7 changes: 3 additions & 4 deletions SharpMap.Web/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@

<body>
<div id="map" />
<script src="https://unpkg.com/[email protected]/dist/jquery.min.js"></script>
<script src="https://unpkg.com/[email protected]/dist/jquery.min.js"></script>
<script src="https://unpkg.com/[email protected]/dist/leaflet.js"></script>
<script src="https://unpkg.com/[email protected]/dist/NonTiledLayer.js"></script>
Expand Down Expand Up @@ -68,12 +67,12 @@

// add dymamic tile layer
var myTileLayerUrl = 'SharpMapTilesHandler.ashx?x={x}&y={y}&z={z}&layers=',
sharpMapTileLayer = new L.TileLayer(myTileLayerUrl, {
sharpMapTileLayer = L.tileLayer(myTileLayerUrl, {
maxZoom: 19, minZoom: 0, zIndex: 100
});

// add dynamic overlay layer
var sharpMapOverlayLayer = new L.NonTiledLayer.WMS('SharpMapOverlayHandler.ashx', {
var sharpMapOverlayLayer = L.nonTiledLayer.wms('SharpMapOverlayHandler.ashx', {
zIndex: 1,
minZoom: 0, maxZoom: 19,
opacity: 1.0,
Expand Down Expand Up @@ -186,7 +185,7 @@
subdomains: '1234'
});

var foreground = new L.NonTiledLayer.WMS(url + '?xtok=' + token, {
var foreground = L.nonTiledLayer.wms(url + '?xtok=' + token, {
zIndex: 0,
minZoom: 0, maxZoom:19,
opacity: 1.0,
Expand Down
2 changes: 1 addition & 1 deletion SharpMap.Web/token.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
// this is a time-limited demo token.
// You need your own xServer-internet token for your application!
var token = 'CD71BDAA-681B-4438-B8A8-6DE9DE7F11C2';
var token = '1D00DA08-6381-4E1E-8913-0243D445D6E0';

0 comments on commit dd99548

Please sign in to comment.