100% open-source IoT Platform - Integrate your devices, add intelligence, build custom apps
Java asset-managementbuildingdashboarddataplatformdevice-managementedge-computingenergyenergy-managementenergy-monitorfleet-managementfleet-telematicsiotiot-applicationiot-platformmodbusmqttmqtt-brokerota-updaterules-enginesmartcity
Fix degraded map performance after re-rendering map markers several times (#2614)
Koen29cce9419a5c
diff --git a/ui/component/or-map/src/index.ts b/ui/component/or-map/src/index.tsindex c4df26eef..d4c0e18e9 100644--- a/ui/component/or-map/src/index.ts+++ b/ui/component/or-map/src/index.ts@@ -488,6 +488,10 @@ export class OrMap extends LitElement {}}+ public _removeMarker(marker: OrMapMarker) {+ this._map?.removeMarker(marker);+ }+protected _onMarkerChangedEvent(evt: OrMapMarkerChangedEvent) {if (this._map) {this._map.onMarkerChanged(evt.detail.marker, evt.detail.property);diff --git a/ui/component/or-map/src/markers/or-map-marker.ts b/ui/component/or-map/src/markers/or-map-marker.tsindex 594b146c5..50ff449a9 100644--- a/ui/component/or-map/src/markers/or-map-marker.ts+++ b/ui/component/or-map/src/markers/or-map-marker.ts@@ -191,6 +191,8 @@ export class OrMapMarker extends LitElement {@query("slot")protected _slot?: HTMLSlotElement;+ protected _map?: OrMap;+public get markerContainer(): HTMLDivElement | undefined {if (this._actualMarkerElement) {return this._actualMarkerElement.firstElementChild as HTMLDivElement;@@ -374,6 +376,11 @@ export class OrMapMarker extends LitElement {const container = this.parentElement.shadowRoot?.querySelector("#map");const styles = (this.constructor as any).styles;+ let styleElem = container?.querySelector("style");+ if (!styleElem) {+ styleElem = document.createElement("style");+ }+let stylesArr: CSSResult[] = [];if (container && styles) {if (!Array.isArray(styles)) {@@ -383,7 +390,6 @@ export class OrMapMarker extends LitElement {}stylesArr.forEach((styleItem) => {- const styleElem = document.createElement("style");styleElem.textContent = String(styleItem);if (container.children.length > 0) {container.insertBefore(styleElem, container.children[0]);@@ -405,11 +411,12 @@ export class OrMapMarker extends LitElement {connectedCallback(): void {super.connectedCallback();this._applyMapMarkerStyles();+ this._map = this.parentElement as OrMap;}disconnectedCallback(): void {super.disconnectedCallback();// Safely cleanup markers once removed from the DOM- this._actualMarkerElement?.parentElement?.removeChild(this._actualMarkerElement);+ this._map?._removeMarker(this);}}