Fix marker labels disappearing when toggling a showLabels: true layer twice
This commit is contained in:
parent
552b289bb9
commit
2d485ac4e5
@ -117,6 +117,16 @@ export class GenericIcon extends DivIcon {
|
|||||||
this._labelCreated = true;
|
this._labelCreated = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
removeLabel() {
|
||||||
|
if(!this._container || !this._labelCreated) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this._label!.remove();
|
||||||
|
this._label = undefined;
|
||||||
|
this._labelCreated = false;
|
||||||
|
}
|
||||||
|
|
||||||
update(options: GenericIconOptions) {
|
update(options: GenericIconOptions) {
|
||||||
if(this._image && options.icon !== this.options.icon) {
|
if(this._image && options.icon !== this.options.icon) {
|
||||||
this._image!.src = useStore().state.currentMapProvider!.getMarkerIconUrl(this.options.icon);
|
this._image!.src = useStore().state.currentMapProvider!.getMarkerIconUrl(this.options.icon);
|
||||||
|
@ -108,15 +108,17 @@ export default class LiveAtlasLayerGroup extends LayerGroup {
|
|||||||
|
|
||||||
update(options: LiveAtlasLayerGroupOptions) {
|
update(options: LiveAtlasLayerGroupOptions) {
|
||||||
if(this.options.showLabels !== options.showLabels) {
|
if(this.options.showLabels !== options.showLabels) {
|
||||||
//Create labels if they are now always visible
|
this.eachLayer((layer) => {
|
||||||
//TODO: This will be slow when many markers exist. Is it worth doing?
|
//Create labels if they are now always visible
|
||||||
if(options.showLabels) {
|
//TODO: This will be slow when many markers exist. Is it worth doing?
|
||||||
this.eachLayer((layer) => {
|
if(layer instanceof GenericMarker) {
|
||||||
if(layer instanceof GenericMarker) {
|
if(options.showLabels) {
|
||||||
(layer as GenericMarker).createLabel();
|
(layer as GenericMarker).createLabel();
|
||||||
|
} else {
|
||||||
|
(layer as GenericMarker).removeLabel();
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
}
|
});
|
||||||
|
|
||||||
this.options.showLabels = options.showLabels;
|
this.options.showLabels = options.showLabels;
|
||||||
}
|
}
|
||||||
|
@ -14,7 +14,7 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import {MarkerOptions, Marker, Util, LatLngExpression, Icon} from 'leaflet';
|
import {MarkerOptions, Marker, LatLngExpression, Icon, Map} from 'leaflet';
|
||||||
import {LiveAtlasMarker} from "@/index";
|
import {LiveAtlasMarker} from "@/index";
|
||||||
import {GenericIcon} from "@/leaflet/icon/GenericIcon";
|
import {GenericIcon} from "@/leaflet/icon/GenericIcon";
|
||||||
|
|
||||||
@ -53,4 +53,16 @@ export class GenericMarker extends Marker {
|
|||||||
createLabel(): void {
|
createLabel(): void {
|
||||||
this.options.icon.createLabel();
|
this.options.icon.createLabel();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
removeLabel(): void {
|
||||||
|
this.options.icon.createLabel();
|
||||||
|
}
|
||||||
|
|
||||||
|
onRemove(map: Map): this {
|
||||||
|
this.options.icon.removeLabel();
|
||||||
|
|
||||||
|
super.onRemove(map);
|
||||||
|
|
||||||
|
return this;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user