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() {
if(this.markerSet.hidden) {
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 {
icon: string;
label: string;
showLabel: boolean;
isHtml?: boolean;
}
@ -40,7 +39,6 @@ export class DynmapIcon extends DivIcon {
icon: 'default',
label: '',
iconSize: [16, 16],
showLabel: false,
isHtml: false,
className: '',
};
@ -72,10 +70,6 @@ export class DynmapIcon extends DivIcon {
this._image.height = size.y;
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}`);
if (this.options.isHtml) {
@ -99,11 +93,6 @@ export class DynmapIcon extends DivIcon {
}
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) {
this._image!.src = `${window.config.url.markers}_markers_/${options.icon}.png`;
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._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._vectorPane.style.zIndex = (400 + this.options.priority).toString();
@ -106,6 +108,30 @@ export default class DynmapLayerGroup extends LayerGroup {
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) {
if(!this._map) {
return;

View File

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

View File

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