Handle showLabels config setting

This commit is contained in:
James Lyne 2020-12-18 23:01:32 +00:00
parent 0eea500098
commit 7b1afa1c20
5 changed files with 45 additions and 14 deletions

View File

@ -69,6 +69,24 @@ export default defineComponent({
} }
}, },
watch: {
markerSet: {
handler(newValue) {
if(newValue && this.layerGroup) {
console.log('Updating layer group');
this.layerGroup.update({
id: this.markerSet.id,
minZoom: this.markerSet.minZoom,
maxZoom: this.markerSet.maxZoom,
showLabels: this.markerSet.showLabels || useStore().state.components.markers.showLabels,
priority: this.markerSet.priority,
});
}
},
deep: true,
}
},
mounted() { mounted() {
if(this.markerSet.hidden) { if(this.markerSet.hidden) {
this.leaflet.getLayerManager().addHiddenLayer(this.layerGroup, this.markerSet.label, 1); this.leaflet.getLayerManager().addHiddenLayer(this.layerGroup, this.markerSet.label, 1);

View File

@ -22,7 +22,6 @@ import {DivIconOptions, PointExpression, Icon, DivIcon, DomUtil, point} from 'le
export interface DynmapIconOptions extends DivIconOptions { export interface DynmapIconOptions extends DivIconOptions {
icon: string; icon: string;
label: string; label: string;
showLabel: boolean;
isHtml?: boolean; isHtml?: boolean;
} }
@ -40,7 +39,6 @@ export class DynmapIcon extends DivIcon {
icon: 'default', icon: 'default',
label: '', label: '',
iconSize: [16, 16], iconSize: [16, 16],
showLabel: false,
isHtml: false, isHtml: false,
className: '', className: '',
}; };
@ -72,10 +70,6 @@ export class DynmapIcon extends DivIcon {
this._image.height = size.y; this._image.height = size.y;
this._image.src = url; this._image.src = url;
if(this.options.showLabel) {
this._label.classList.add('marker__label--show');
}
this._label.classList.add(/*'markerName_' + set.id,*/ `marker__label--${sizeClass}`); this._label.classList.add(/*'markerName_' + set.id,*/ `marker__label--${sizeClass}`);
if (this.options.isHtml) { if (this.options.isHtml) {
@ -99,11 +93,6 @@ export class DynmapIcon extends DivIcon {
} }
update(options: DynmapIconOptions) { update(options: DynmapIconOptions) {
if(options.showLabel !== this.options.showLabel) {
this._label!.classList.toggle('marker__label--show', this.options.showLabel);
this.options.showLabel = options.showLabel;
}
if(options.icon !== this.options.icon) { if(options.icon !== this.options.icon) {
this._image!.src = `${window.config.url.markers}_markers_/${options.icon}.png`; this._image!.src = `${window.config.url.markers}_markers_/${options.icon}.png`;
this.options.icon = options.icon; this.options.icon = options.icon;

View File

@ -50,6 +50,8 @@ export default class DynmapLayerGroup extends LayerGroup {
this._markerPane = map.createPane(`${this.options.id}-markers`); this._markerPane = map.createPane(`${this.options.id}-markers`);
this._vectorPane = map.createPane(`${this.options.id}-vectors`); this._vectorPane = map.createPane(`${this.options.id}-vectors`);
this._markerPane.classList.toggle('leaflet-pane--show-labels', this.options.showLabels);
this._markerPane.style.zIndex = (401 + this.options.priority).toString(); this._markerPane.style.zIndex = (401 + this.options.priority).toString();
this._vectorPane.style.zIndex = (400 + this.options.priority).toString(); this._vectorPane.style.zIndex = (400 + this.options.priority).toString();
@ -106,6 +108,30 @@ export default class DynmapLayerGroup extends LayerGroup {
return super.addLayer(layer); return super.addLayer(layer);
} }
update(options: DynmapLayerGroupOptions) {
this.options.showLabels = options.showLabels;
if(this._markerPane) {
this._markerPane.classList.toggle('leaflet-pane--show-labels', options.showLabels);
}
if(options.minZoom !== this.options.minZoom || options.maxZoom !== this.options.maxZoom) {
this.options.minZoom = options.minZoom;
this.options.maxZoom = options.maxZoom;
this._updateLayerVisibility();
}
if(options.priority !== this.options.priority) {
this.options.priority = options.priority;
if(this._markerPane) {
this._markerPane.style.zIndex = (401 + this.options.priority).toString();
this._vectorPane!.style.zIndex = (400 + this.options.priority).toString();
}
}
}
_updateLayerVisibility(onAdd?: boolean) { _updateLayerVisibility(onAdd?: boolean) {
if(!this._map) { if(!this._map) {
return; return;

View File

@ -338,7 +338,7 @@ button {
text-overflow: ellipsis; text-overflow: ellipsis;
overflow: hidden; overflow: hidden;
&.marker__label--show { @at-root .leaflet-pane--show-labels .marker__label {
display: block; display: block;
} }
} }

View File

@ -29,7 +29,6 @@ export const createMarker = (options: DynmapMarker, projection: DynmapProjection
icon: options.icon, icon: options.icon,
label: options.label, label: options.label,
iconSize: options.dimensions, iconSize: options.dimensions,
showLabel: false,
isHtml: options.isHTML, isHtml: options.isHTML,
}), }),
maxZoom: options.maxZoom, maxZoom: options.maxZoom,
@ -57,7 +56,6 @@ export const updateMarker = (marker: Marker | undefined, options: DynmapMarker,
icon: options.icon, icon: options.icon,
label: options.label, label: options.label,
iconSize: options.dimensions, iconSize: options.dimensions,
showLabel: false,
isHtml: options.isHTML, isHtml: options.isHTML,
}); });
} }