mirror of
https://github.com/hugo-fixit/FixIt.git
synced 2026-09-03 12:12:39 +00:00
✨ Feat: more markers can be added to mapbox (#506)
* feat: ✨ More markers can be added to mapbox * 🐛 Fix: move mapbox param `markers` to **seventh** positional parameter --------- Co-authored-by: Cell <1024@lruihao.cn>
This commit is contained in:
+12
-1
@@ -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');
|
||||
}
|
||||
|
||||
@@ -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 -}}
|
||||
<div class="mapbox" data-options="{{ $options | jsonify }}" {{ $attrs | safeHTMLAttr }}></div>
|
||||
|
||||
Reference in New Issue
Block a user