♻️ Refactor: refactor mapbox shortcode data store way (#420)

This commit is contained in:
Cell
2024-04-22 10:11:05 +08:00
parent bae1678c59
commit fd13ca782b
3 changed files with 6 additions and 5 deletions
+2 -2
View File
@@ -608,7 +608,7 @@ class FixIt {
mapboxgl.setRTLTextPlugin(this.config.mapbox.RTLTextPlugin);
this._mapboxArr = this._mapboxArr || [];
this.util.forEach(document.getElementsByClassName('mapbox'), ($mapbox) => {
const { lng, lat, zoom, lightStyle, darkStyle, marked, navigation, geolocate, scale, fullscreen } = this.data[$mapbox.id];
const { lng, lat, zoom, lightStyle, darkStyle, marked, navigation, geolocate, scale, fullscreen } = JSON.parse($mapbox.dataset.options);
const mapbox = new mapboxgl.Map({
container: $mapbox,
center: [lng, lat],
@@ -647,7 +647,7 @@ class FixIt {
this._mapboxOnSwitchTheme = this._mapboxOnSwitchTheme || (() => {
this.util.forEach(this._mapboxArr, (mapbox) => {
const $mapbox = mapbox.getContainer();
const { lightStyle, darkStyle } = this.data[$mapbox.id];
const { lightStyle, darkStyle } = JSON.parse($mapbox.dataset.options);
mapbox.setStyle(this.isDark ? darkStyle : lightStyle);
mapbox.addControl(new MapboxLanguage());
});
+4 -2
View File
@@ -28,5 +28,7 @@
{{- 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 -}}
{{- $id := dict "Content" $options "Scratch" .Page.Scratch | partial "function/id.html" -}}
<div class="mapbox" id="{{ $id }}" style="width: {{ $width }}; height: {{ $height }};"></div>
{{- $attrs := printf `style="width: %v; height: %v;"` $width $height -}}
<div class="mapbox" data-options="{{ $options | jsonify }}" {{ $attrs | safeHTMLAttr }}></div>
{{- /* EOF */ -}}
-1
View File
@@ -47,4 +47,3 @@
{{- else -}}
<meting-js server="{{ .Get 0 }}" type="{{ .Get 1 }}" id="{{ .Get 2 }}" theme="{{ $theme }}"></meting-js>
{{- end -}}
{{- /* EOF */ -}}