diff --git a/example/index.ts b/example/index.ts index 6184763..cbf9c8c 100644 --- a/example/index.ts +++ b/example/index.ts @@ -14,7 +14,7 @@ import "../styles.css" uri:"https://wasac.github.io/mapbox-stylefiles/unvt/style.json" } ]; - const defaultStyle = styles[1]; + const defaultStyle = styles[0]; const map = new mapboxgl.Map({ container: 'map', diff --git a/lib/index.ts b/lib/index.ts index d5247a5..1d01089 100644 --- a/lib/index.ts +++ b/lib/index.ts @@ -88,10 +88,13 @@ export class MapboxStyleSwitcherControl implements IControl srcElement.classList.add("active"); }); if (style.title === this.defaultStyleFromUrl){ - styleElement.classList.add("active"); - this.map!.setStyle(style.uri); + const elms = this.mapStyleContainer!.getElementsByClassName("active"); + if (elms.length === 0){ + styleElement.classList.add("active"); + this.map!.setStyle(style.uri); + } } - if (style.title === this.defaultStyle) + if (!this.defaultStyleFromUrl && style.title === this.defaultStyle) { const elms = this.mapStyleContainer!.getElementsByClassName("active"); if (elms.length === 0){ diff --git a/package.json b/package.json index a5a82f6..d00ea9e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@watergis/mapbox-gl-style-switcher", - "version": "1.0.10", + "version": "1.0.11", "description": "Mapbox GL JS Style Switcher", "main": "dist/index.js", "types": "dist/index.d.ts",