Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/geolocation layerswitch bug #1914

Merged
merged 2 commits into from
Nov 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions src/mapper/src/constants/baseLayers.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,33 @@
export const osmStyle = {
id: 'OSM Raster',
version: 8,
name: 'OpenStreetMap',
sources: {
osm: {
type: 'raster',
tiles: [
'https://a.tile.openstreetmap.org/{z}/{x}/{y}.png',
'https://b.tile.openstreetmap.org/{z}/{x}/{y}.png',
'https://c.tile.openstreetmap.org/{z}/{x}/{y}.png',
],
minzoom: 0,
maxzoom: 19,
attribution:
'Β© <a target="_blank" rel="noopener" href="https://openstreetmap.org/copyright">OpenStreetMap contributors</a>',
},
},
layers: [
{
id: 'osm',
type: 'raster',
source: 'osm',
layout: {
visibility: 'visible',
},
},
],
};

let stamenStyle = {
id: 'Stamen Raster',
version: 8,
Expand Down
8 changes: 6 additions & 2 deletions src/mapper/src/lib/components/map/layer-switcher.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -144,14 +144,18 @@ map = new Map({
if (reAddSources?.length > 0) {
for (const reAddSource of reAddSources) {
for (const [id, source] of Object.entries(reAddSource)) {
map?.addSource(id, source);
if (!map?.getStyle().sources[id]) {
map?.addSource(id, source);
}
}
}
}
// reapply user defined layers
if (reAddLayers?.length > 0) {
for (const layer of reAddLayers) {
map?.addLayer(layer);
if (!map?.getStyle().layers.find((layerx) => layerx?.id === layer.id)) {
map?.addLayer(layer);
}
}
}
}
Expand Down
32 changes: 1 addition & 31 deletions src/mapper/src/lib/components/map/main.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
import { getProjectSetupStepStore } from '$store/common.svelte.ts';
// import { entityFeatcolStore, selectedEntityId } from '$store/entities';
import { projectSetupStep as projectSetupStepEnum } from '$constants/enums.ts';
import { baseLayers } from '$constants/baseLayers.ts';
import { baseLayers, osmStyle } from '$constants/baseLayers.ts';

type bboxType = [number, number, number, number];

Expand Down Expand Up @@ -78,36 +78,6 @@
}
}
});

const osmStyle = {
id: 'OSM Raster',
version: 8,
name: 'OpenStreetMap',
sources: {
osm: {
type: 'raster',
tiles: [
'https://a.tile.openstreetmap.org/{z}/{x}/{y}.png',
'https://b.tile.openstreetmap.org/{z}/{x}/{y}.png',
'https://c.tile.openstreetmap.org/{z}/{x}/{y}.png',
],
minzoom: 0,
maxzoom: 19,
attribution:
'Β© <a target="_blank" rel="noopener" href="https://openstreetmap.org/copyright">OpenStreetMap contributors</a>',
},
},
layers: [
{
id: 'osm',
type: 'raster',
source: 'osm',
layout: {
visibility: 'visible',
},
},
],
};
</script>

<!-- Note here we still use Svelte 4 on:click until svelte-maplibre migrates -->
Expand Down