Skip to content

Commit 834259d

Browse files
committed
Add StacLayer to layercontrol, other minor fixes #503
1 parent d391e8d commit 834259d

File tree

2 files changed

+27
-19
lines changed

2 files changed

+27
-19
lines changed

src/components/Map.vue

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
<l-map class="map" v-if="show" :class="stac.type" @ready="init" :options="mapOptions">
44
<l-control-fullscreen :key="`fullscreen${ix}`" :options="fullscreenOptions" />
55
<l-control-zoom :key="`zoom${ix}`" v-bind="zoomControlTexts" position="topleft" />
6-
<l-control-layers v-if="showLayerControl" position="bottomleft" ref="layerControl" />
6+
<l-control-layers position="bottomleft" ref="layerControl" />
77
<component
88
v-for="basemap of basemaps" :is="basemap.is" :key="basemap.key"
99
ref="basemaps" layerType="base" v-bind="basemap"
1010
/>
11-
<l-tile-layer v-for="xyz of xyzLinks" ref="overlays" :key="xyz.url" layerType="overlay" v-bind="xyz" />
12-
<LWMSTileLayer v-for="wms of wmsLinks" ref="overlays" :key="wms.url" layerType="overlay" v-bind="wms" />
11+
<l-tile-layer v-for="xyz of xyzLinks" ref="xyzOverlays" :key="xyz.url" layerType="overlay" v-bind="xyz" />
12+
<LWMSTileLayer v-for="wms of wmsLinks" ref="wmsOverlays" :key="wms.url" layerType="overlay" v-bind="wms" />
1313
<l-geo-json v-if="geojson" ref="geojson" :geojson="geojson" :options="{onEachFeature: showPopup}" :optionsStyle="{color: secondaryColor, weight: secondaryWeight}" />
1414
</l-map>
1515
<b-popover
@@ -137,9 +137,6 @@ export default {
137137
return map;
138138
}).filter(map => Utils.isObject(map));
139139
},
140-
showLayerControl() {
141-
return this.xyzLinks.length > 0 || this.wmsLinks.length > 0 || this.basemaps.length > 1;
142-
},
143140
xyzLinks() {
144141
const links = this.getWebMapLinks('xyz');
145142
return links.map(link => ({
@@ -163,13 +160,14 @@ export default {
163160
styles = link['wms:styles'][i];
164161
}
165162
const name = [link.title, layers].filter(x => Boolean(x)).join(' - ');
163+
const transparent = Utils.hasText(link['wms:transparent']) ? link['wms:transparent'].toLowerCase() === "true" : true;
166164
const props = {
167165
baseUrl: link.href,
168166
name,
169167
attribution: link.attribution || this.stac.getMetadata('attribution'),
170168
version: '1.3.0',
171169
layers,
172-
transparent: String(link['wms:transparent'] || false),
170+
transparent,
173171
styles
174172
};
175173
if (typeof link['type'] === 'string' && link['type'].startsWith('image/')) {
@@ -192,9 +190,6 @@ export default {
192190
if (newVal) {
193191
this.$nextTick(() => this.geojsonToFront());
194192
}
195-
},
196-
showLayerControl() {
197-
this.updateLayerControl();
198193
}
199194
},
200195
created() {
@@ -243,13 +238,16 @@ export default {
243238
return links;
244239
},
245240
updateLayerControl() {
246-
if (this.showLayerControl) {
247-
const basemaps = Array.isArray(this.$refs.basemaps) ? this.$refs.basemaps : [];
248-
const xyzOverlays = Array.isArray(this.$refs.xyzOverlays) ? this.$refs.xyzOverlays : [];
249-
const wmsOverlays = Array.isArray(this.$refs.wmsOverlays) ? this.$refs.wmsOverlays : [];
250-
const layers = basemaps.concat(xyzOverlays).concat(wmsOverlays);
251-
layers.forEach(layer => this.$refs.layerControl.addLayer(layer));
252-
}
241+
const basemaps = Array.isArray(this.$refs.basemaps) ? this.$refs.basemaps : [];
242+
basemaps.forEach(layer => this.$refs.layerControl.mapObject.addBaseLayer(layer, layer.name));
243+
244+
const xyzOverlays = Array.isArray(this.$refs.xyzOverlays) ? this.$refs.xyzOverlays : [];
245+
const wmsOverlays = Array.isArray(this.$refs.wmsOverlays) ? this.$refs.wmsOverlays : [];
246+
const geojsonOverlays = Array.isArray(this.$refs.geojson) ? this.$refs.geojson : [];
247+
xyzOverlays
248+
.concat(wmsOverlays)
249+
.concat(geojsonOverlays)
250+
.forEach(layer => this.$refs.layerControl.mapObject.addOverlay(layer, layer.name));
253251
},
254252
viewChanged(event) {
255253
if (this.popover) {
@@ -262,6 +260,7 @@ export default {
262260
let hadLayer = false;
263261
if (this.stacLayer) {
264262
this.map.removeLayer(this.stacLayer);
263+
this.$refs.layerControl.mapObject.removeLayer(this.stacLayer);
265264
this.stacLayer = null;
266265
hadLayer = true;
267266
}
@@ -275,6 +274,8 @@ export default {
275274
return;
276275
}
277276
277+
let isLinkOrAsset = this.stacLayerData && ('href' in this.stacLayerData);
278+
278279
let getDefaultOptions = (customOptions = {}) => Object.assign({
279280
baseUrl: this.stac.getAbsoluteUrl(),
280281
resolution: this.geoTiffResolution,
@@ -284,8 +285,10 @@ export default {
284285
displayGeoTiffByDefault: this.displayGeoTiffByDefault
285286
}, customOptions);
286287
287-
let options = getDefaultOptions();
288-
if (this.stacLayerData && 'href' in this.stacLayerData) {
288+
let options = getDefaultOptions({
289+
displayOverview: !isLinkOrAsset
290+
});
291+
if (isLinkOrAsset) {
289292
if (this.stac.isItem()) {
290293
options.bbox = this.stac?.bbox;
291294
}
@@ -326,6 +329,8 @@ export default {
326329
this.addMapClickEvent(this.stacLayer);
327330
this.stacLayer.on("fallback", event => this.$emit('dataChanged', event.stac));
328331
this.stacLayer.addTo(this.map);
332+
const title = this.stac.type === 'Feature' ? `stacItem` : `stac${this.stac.type}`;
333+
this.$refs.layerControl.mapObject.addOverlay(this.stacLayer, this.$tc(title));
329334
if (!this.fitBoundsOnce || !hadLayer) {
330335
this.fitBounds(this.stacLayer, this.selectBounds);
331336
}
@@ -342,6 +347,7 @@ export default {
342347
this.itemPreviewsLayer = await stacLayer(this.stacLayerData, itemPreviewOptions);
343348
this.addMapClickEvent(this.itemPreviewsLayer);
344349
this.itemPreviewsLayer.addTo(this.map);
350+
this.$refs.layerControl.mapObject.addOverlay(this.itemPreviewsLayer, this.$tc('stacItem', this.stacLayerData.features.length));
345351
this.itemPreviewsLayer.bringToFront();
346352
if (!this.stacLayer) {
347353
this.fitBounds(this.itemPreviewsLayer);
@@ -392,6 +398,7 @@ export default {
392398
})
393399
.then(layer => {
394400
layer.addTo(this.map);
401+
this.$refs.layerControl.mapObject.addOverlay(layer, layer.name || link.title);
395402
// Bring GeoJSON to front to allow opening the popups
396403
this.geojsonToFront();
397404
})

src/components/ShowAssetMixin.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ export default {
4040
this.tab = 0;
4141
this.selectedAsset = asset;
4242
this.selectedAssetKey = id;
43+
this.shownAssetsOnMap = [this.selectedAssetKey];
4344
}
4445
if (this.$refs.tabs) {
4546
Utils.scrollTo(this.$refs.tabs.$el);

0 commit comments

Comments
 (0)