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
Update or-map-widget.ts (#931)
NinaBianca59c6dc2fa3c8
diff --git a/ui/component/or-dashboard-builder/src/or-dashboard-settingspanel.ts b/ui/component/or-dashboard-builder/src/or-dashboard-settingspanel.tsindex e0668c9a4..05221227d 100644--- a/ui/component/or-dashboard-builder/src/or-dashboard-settingspanel.ts+++ b/ui/component/or-dashboard-builder/src/or-dashboard-settingspanel.ts@@ -601,10 +601,9 @@ export class OrDashboardSettingsPanel extends LitElement {}}"></or-mwc-input></div>-<div style="padding: 0 10px 12px 10px;"><div class="switchMwcInputContainer">- <span>${i18next.t('showLabels')}</span>+ <span>${i18next.t('dashboard.showLabels')}</span><or-mwc-input .type="${InputType.SWITCH}" style="width: 70px;".value="${config.showLabels}"@or-mwc-input-changed="${(event: CustomEvent) => {@@ -614,7 +613,7 @@ export class OrDashboardSettingsPanel extends LitElement {></or-mwc-input></div><div class="switchMwcInputContainer">- <span>${i18next.t('showUnits')}</span>+ <span>${i18next.t('dashboard.showUnits')}</span><or-mwc-input .type="${InputType.SWITCH}" style="width: 70px;".value="${config.showUnits}".disabled="${!config.showLabels}"diff --git a/ui/component/or-dashboard-builder/src/widgets/or-map-widget.ts b/ui/component/or-dashboard-builder/src/widgets/or-map-widget.tsindex 18524e46f..2adbf66e7 100644--- a/ui/component/or-dashboard-builder/src/widgets/or-map-widget.ts+++ b/ui/component/or-dashboard-builder/src/widgets/or-map-widget.ts@@ -7,7 +7,6 @@ import {WellknownMetaItems,GeoJSONPoint,AssetDescriptor,- WellknownValueTypes} from "@openremote/model";import {InputType, OrInputChangedEvent} from "@openremote/or-mwc-components/or-mwc-input";import {i18next} from "@openremote/or-translate";@@ -28,10 +27,8 @@ import {RangeAttributeMarkerColours,AttributeMarkerColoursRange,MapMarkerColours,- OrMapLongPressEvent,- ViewSettings,} from "@openremote/or-map";-import {LngLat, LngLatBounds, LngLatBoundsLike} from "maplibre-gl";+import {LngLat} from "maplibre-gl";export interface MapWidgetConfig extends OrWidgetConfig {// General values@@ -123,11 +120,10 @@ export class OrMapWidgetContent extends LitElement {/* ---------- */render() {- const config = JSON.parse(JSON.stringify(this.widget!.widgetConfig)) as MapWidgetConfig;this.markers = {};return html`- <or-map id="miniMap" class="or-map" .zoom="${config.zoom ? config.zoom! : undefined}"- .center="${config.center ? config.center! : undefined}"+ <or-map id="miniMap" class="or-map" .zoom="${this.widget?.widgetConfig?.zoom}"+ .center="${this.widget?.widgetConfig?.center}"style="height: 100%">${(this.assets) ?this.assets.filter((asset: Asset) => {@@ -193,6 +189,9 @@ export class OrMapWidgetContent extends LitElement {if (config.assetType && config.attributeName) {let assets: Asset[] = [];await manager.rest.api.AssetResource.queryAssets({+ realm: {+ name: this.realm+ },select: {attributes: [config.attributeName, 'location']},@@ -220,7 +219,7 @@ class OrMapWidgetSettings extends LitElement {private assetTypes: string[] = [];// Default values- private expandedPanels: string[] = [i18next.t('map')];+ private expandedPanels: string[] = [i18next.t('configuration.mapSettings'), i18next.t('attributes'), i18next.t('thresholds')];static get styles() {@@ -230,18 +229,17 @@ class OrMapWidgetSettings extends LitElement {// UI Renderingrender() {const config = JSON.parse(JSON.stringify(this.widget!.widgetConfig)) as MapWidgetConfig; // duplicate to edit, to prevent parent updates. Please trigger updateConfig()- const CoordinatesRegexPattern = "^[ ]*(?:Lat: )?(-?\\d+\\.?\\d*)[, ]+(?:Lng: )?(-?\\d+\\.?\\d*)[ ]*$";return html`<div>- ${this.generateExpandableHeader(i18next.t('map'))}+ ${this.generateExpandableHeader(i18next.t('configuration.mapSettings'))}</div><div>- ${this.expandedPanels.includes(i18next.t('map')) ? html`+ ${this.expandedPanels.includes(i18next.t('configuration.mapSettings')) ? html`<div style="padding: 12px 24px 48px 24px; display: flex; flex-direction: column; gap: 16px;"><div><or-mwc-input .type="${InputType.NUMBER}" style="width: 100%;"- .value="${config.zoom}" label="${i18next.t('zoom')}"+ .value="${this.widget?.widgetConfig?.zoom}" label="${i18next.t('dashboard.zoom')}"@or-mwc-input-changed="${(event: OrInputChangedEvent) => {config.zoom = event.detail.value;this.updateConfig(this.widget!, config);@@ -250,16 +248,15 @@ class OrMapWidgetSettings extends LitElement {</div><div style="display: flex; gap: 8px;"><or-mwc-input .type="${InputType.TEXT}" style="width: 100%;"- .value="${config.center ? 'Lat: ' + (Object.values(config.center))[1] + ', Lng: ' + (Object.values(config.center))[0] : undefined}"- label="${i18next.t('center')}"- .pattern="${CoordinatesRegexPattern}"+ .value="${this.widget?.widgetConfig?.center ? (Object.values(this.widget.widgetConfig.center))[0] + ', ' + (Object.values(this.widget.widgetConfig.center))[1] : undefined}"+ label="${i18next.t('dashboard.center')}"@or-mwc-input-changed="${(event: OrInputChangedEvent) => {if (event.detail.value) {- const lngLatArr = (event.detail.value as string).replace('Lat:', '').replace('Lng:', '').split(/[, ]/).filter(v => !!v);+ const lngLatArr = (event.detail.value as string).split(/[, ]/).filter(v => !!v);if (lngLatArr.length === 2) {var value = new LngLat(- Number.parseFloat(lngLatArr[1]),- Number.parseFloat(lngLatArr[0])+ Number.parseFloat(lngLatArr[0]),+ Number.parseFloat(lngLatArr[1]));config.center = value as LngLatLike;this.updateConfig(this.widget!, config);@@ -274,10 +271,10 @@ class OrMapWidgetSettings extends LitElement {` : null}</div><div>- ${this.generateExpandableHeader(i18next.t('display'))}+ ${this.generateExpandableHeader(i18next.t('attributes'))}</div><div>- ${this.expandedPanels.includes(i18next.t('display')) ? html`+ ${this.expandedPanels.includes(i18next.t('attributes')) ? html`<or-dashboard-settingspanel .type="${SettingsPanelType.ASSETTYPES}".widgetConfig="${this.widget?.widgetConfig}"@updated="${(event: CustomEvent) => {@@ -304,6 +301,16 @@ class OrMapWidgetSettings extends LitElement {`}+ updated(changedProperties: Map<string, any>){+ if(!this.widget?.widgetConfig?.zoom && !this.widget?.widgetConfig?.center){+ manager.rest.api.MapResource.getSettings().then((response) => {+ this.widget!.widgetConfig.zoom = response.data.options.default.zoom;+ this.widget!.widgetConfig.center = response.data.options.default.center;+ this.updateConfig(this.widget!, this.widget!.widgetConfig);+ })+ }+ }+updateConfig(widget: DashboardWidget, config: OrWidgetConfig | any, force: boolean = false) {const oldWidget = JSON.parse(JSON.stringify(widget)) as DashboardWidget;widget.widgetConfig = config;