diff --git a/assets/js/theme.js b/assets/js/theme.js index 30dd35947..cb011cd18 100644 --- a/assets/js/theme.js +++ b/assets/js/theme.js @@ -669,7 +669,7 @@ class FixIt { this._mapboxArr = this._mapboxArr || []; } this.util.forEach(document.querySelectorAll('.mapbox:empty'), ($mapbox) => { - const { lng, lat, zoom, lightStyle, darkStyle, marked, navigation, geolocate, scale, fullscreen } = JSON.parse($mapbox.dataset.options); + const { lng, lat, zoom, lightStyle, darkStyle, marked, markers, navigation, geolocate, scale, fullscreen } = JSON.parse($mapbox.dataset.options); const mapbox = new mapboxgl.Map({ container: $mapbox, center: [lng, lat], @@ -681,6 +681,17 @@ class FixIt { if (marked) { new mapboxgl.Marker().setLngLat([lng, lat]).addTo(mapbox); } + const markerArray = typeof markers === 'string' ? JSON.parse(markers) : markers; + if (Array.isArray(markerArray) && markerArray.length > 0) { + markerArray.forEach(marker => { + const { lng: markerLng, lat: markerLat, description } = marker; + const popup = new mapboxgl.Popup({ offset: 25 }).setText(description); + new mapboxgl.Marker() + .setLngLat([markerLng, markerLat]) + .setPopup(popup) + .addTo(mapbox); + }); + } if (navigation) { mapbox.addControl(new mapboxgl.NavigationControl(), 'bottom-right'); } diff --git a/layouts/shortcodes/mapbox.html b/layouts/shortcodes/mapbox.html index 5fbf0bbfa..47c2dd5e5 100644 --- a/layouts/shortcodes/mapbox.html +++ b/layouts/shortcodes/mapbox.html @@ -4,6 +4,7 @@ {{- $lat := cond .IsNamedParams (.Get "lat") (.Get 1) -}} {{- $zoom := cond .IsNamedParams (.Get "zoom") (.Get 2) | default 10 -}} {{- $marked := cond .IsNamedParams (.Get "marked") (.Get 3) | ne false -}} +{{- $markers := cond .IsNamedParams (.Get "markers") (.Get 6) | default "[]" -}} {{- $lightStyle := $mapbox.lightStyle -}} {{- $darkStyle := $mapbox.darkStyle -}} {{- $navigation := $mapbox.navigation -}} @@ -26,8 +27,9 @@ {{- $lightStyle = .Get 4 | default $lightStyle -}} {{- $darkStyle = .Get 5 | default $darkStyle -}} {{- end -}} + {{- $darkStyle = $darkStyle | default $lightStyle -}} -{{- $options := dict "lng" $lng "lat" $lat "zoom" $zoom "marked" $marked "lightStyle" $lightStyle "darkStyle" $darkStyle "geolocate" $geolocate "navigation" $navigation "scale" $scale "fullscreen" $fullscreen -}} +{{- $options := dict "lng" $lng "lat" $lat "zoom" $zoom "marked" $marked "markers" $markers "lightStyle" $lightStyle "darkStyle" $darkStyle "geolocate" $geolocate "navigation" $navigation "scale" $scale "fullscreen" $fullscreen -}} {{- $attrs := printf `style="width: %v; height: %v;"` $width $height -}}