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
UI updates: or-map updated to use standard color palette (or-map-marker-asset asset property renamed to assetId and asset property can now be used to load in an existing asset to minimise network requests)
Rich Turner1e36c1a0493f
diff --git a/ui/component/or-map/src/index.ts b/ui/component/or-map/src/index.tsindex fa2d74646..64851ea38 100644--- a/ui/component/or-map/src/index.ts+++ b/ui/component/or-map/src/index.ts@@ -1,11 +1,10 @@import openremote, {EventCallback, OREvent} from "@openremote/core";import {FlattenedNodesObserver} from "@polymer/polymer/lib/utils/flattened-nodes-observer.js";-import {css, customElement, html, LitElement, property, query, PropertyValues, CSSResult} from "lit-element";+import {CSSResult, customElement, html, LitElement, property, PropertyValues, query} from "lit-element";import {LngLat, LngLatBoundsLike, LngLatLike} from "mapbox-gl";import {MapWidget} from "./mapwidget";-import {- OrMapMarker, OrMapMarkerClickedEvent, OrMapMarkerChangedEvent, MarkerStyle-} from "./markers/or-map-marker";+import {style} from "./style";+import {OrMapMarker, OrMapMarkerChangedEvent} from "./markers/or-map-marker";import {getLngLat} from "./util";export enum Type {@@ -68,32 +67,7 @@ declare global {@customElement("or-map")export class OrMap extends LitElement {- public static styles = [- MarkerStyle,- css`- :host {- display: block;- overflow: hidden;- }-- #map {- position: relative;- width: 100%;- height: 100%;- }-- slot {- display: none;- }-- :host([hidden]) {- display: none;- }-- .leaflet-marker-icon, .mapboxgl-marker {- pointer-events: none !important;- }- `];+ public static styles = style;@property({type: String})public type: Type = Type.VECTOR;@@ -274,3 +248,6 @@ export class OrMap extends LitElement {`;}}++export * from "./markers/or-map-marker";+export * from "./markers/or-map-marker-asset";\ No newline at end of filediff --git a/ui/component/or-map/src/mapwidget.ts b/ui/component/or-map/src/mapwidget.tsindex 7772f9131..f27e401f6 100644--- a/ui/component/or-map/src/mapwidget.ts+++ b/ui/component/or-map/src/mapwidget.ts@@ -142,6 +142,9 @@ export class MapWidget {if (this._center) {options.center = getLatLng(this._center);}+ if (this._zoom) {+ options.zoom = this._zoom + 1;+ }}this._mapJs = L.mapbox.map(this._mapContainer, settings, options);@@ -198,6 +201,9 @@ export class MapWidget {if (this._center) {options.center = this._center;}+ if (this._zoom) {+ options.zoom = this._zoom;+ }this._mapGl = new map.Map(options);diff --git a/ui/component/or-map/src/markers/or-map-marker-asset.ts b/ui/component/or-map/src/markers/or-map-marker-asset.tsindex 873756534..adb7aeb3d 100644--- a/ui/component/or-map/src/markers/or-map-marker-asset.ts+++ b/ui/component/or-map/src/markers/or-map-marker-asset.ts@@ -1,14 +1,18 @@import {customElement, property, PropertyValues} from "lit-element";import {OrMapMarker} from "./or-map-marker";-import {AttributeEvent, Attribute, AttributeType, GeoJSONPoint, AssetType, AssetEvent, AssetEventCause} from "@openremote/model";+import {AttributeEvent, AttributeType, GeoJSONPoint, AssetType, AssetEvent, AssetEventCause, Asset} from "@openremote/model";import {subscribe} from "@openremote/core/dist/asset-mixin";import openremote, {AssetModelUtil} from "@openremote/core";+import {Util} from "@openremote/core";@customElement("or-map-marker-asset")export class OrMapMarkerAsset extends subscribe(openremote)(OrMapMarker) {@property({type: String, reflect: true, attribute: true})- public asset?: string;+ public assetId?: string;++ @property({type: Object, attribute: true})+ public asset?: Asset;public assetTypeAsIcon: boolean = true;@@ -17,63 +21,94 @@ export class OrMapMarkerAsset extends subscribe(openremote)(OrMapMarker) {this.visible = false;}+ protected markerColor?: string;+protected set type(type: string | undefined) {if (!type) {this.visible = false;return;}+ const descriptor = AssetModelUtil.getAssetDescriptor(type);+if (this.assetTypeAsIcon) {- const descriptor = AssetModelUtil.getAssetDescriptor(type);const icon = descriptor ? descriptor.icon : AssetType.THING.icon;this.icon = icon;}++ if (descriptor && descriptor.color) {+ this.markerColor = descriptor.color;+ this.updateColor(this.markerContainer);+ }this.visible = true;}protected shouldUpdate(_changedProperties: PropertyValues): boolean {- if (_changedProperties.has("asset")) {+ if (_changedProperties.has("assetId")) {this.lat = undefined;this.lng = undefined;this.type = undefined;- this.assetIds = this.asset && this.asset.length > 0 ? [this.asset] : undefined;+ this.assetIds = this.assetId && this.assetId.length > 0 ? [this.assetId] : undefined;if (Object.keys(_changedProperties).length === 1) {return false;}}++ if (_changedProperties.has("asset")) {+ this.onAssetChanged(this.asset);+ }+return super.shouldUpdate(_changedProperties);}public onAttributeEvent(event: AttributeEvent) {- if (event.attributeState!.attributeRef!.attributeName !== AttributeType.LOCATION.attributeName) {- return;+ if (event.attributeState!.attributeRef!.attributeName === AttributeType.LOCATION.attributeName) {+ this._updateLocation(event.attributeState!.value as GeoJSONPoint);}-- this._updateLocation(event.attributeState!.value as GeoJSONPoint);-}public onAssetEvent(event: AssetEvent) {switch (event.cause) {case AssetEventCause.READ:- const attr = event.asset && event.asset.attributes && event.asset.attributes.hasOwnProperty("location") ? event.asset.attributes.location as Attribute : null;- this._updateLocation(attr ? attr.value as GeoJSONPoint : null);case AssetEventCause.CREATE:case AssetEventCause.UPDATE:- this.type = event.asset!.type;+ this.onAssetChanged(event.asset);break;case AssetEventCause.DELETE:- this.type = undefined;- this.lat = undefined;- this.lng = undefined;+ this.onAssetChanged(undefined);break;}}+ protected onAssetChanged(asset?: Asset) {+ if (asset) {+ const attr = Util.getAssetAttribute(asset, AttributeType.LOCATION.attributeName!);+ this._updateLocation(attr ? attr.value as GeoJSONPoint : null);+ this.type = asset.type;+ } else {+ this.lat = undefined;+ this.lng = undefined;+ }+ }+protected _updateLocation(location: GeoJSONPoint | null) {this.lat = location && location.coordinates ? (location.coordinates as any)[1] : undefined;this.lng = location && location.coordinates ? (location.coordinates as any)[0] : undefined;}++ protected getColor() {+ if (this.markerColor && !this.color) {+ return "#" + this.markerColor;+ }+ return super.getColor();+ }++ protected getActiveColor() {+ if (this.markerColor && !this.activeColor) {+ return "#" + this.markerColor;+ }+ return super.getActiveColor();+ }}diff --git a/ui/component/or-map/src/markers/or-map-marker.ts b/ui/component/or-map/src/markers/or-map-marker.tsindex 342080163..473c95d85 100644--- a/ui/component/or-map/src/markers/or-map-marker.ts+++ b/ui/component/or-map/src/markers/or-map-marker.ts@@ -1,4 +1,5 @@-import {css, customElement, LitElement, property, PropertyValues, query, html} from "lit-element";+import {customElement, html, LitElement, property, PropertyValues, query} from "lit-element";+import {markerActiveColorVar, markerColorVar} from "../style";export class OrMapMarkerChangedEvent extends CustomEvent<MarkerChangedEventDetail> {@@ -46,43 +47,6 @@ declare global {}}-export const MarkerStyle = css`- .or-map-marker {- position: absolute; /* This makes mapboxJS behave like mapboxGL */- }-- .marker-container {- position: relative;- transform: var(--or-map-marker-transform, translate(-24px, -45px));- cursor: pointer;- --or-icon-width: var(--or-map-marker-width, 48px);- --or-icon-height: var(--or-map-marker-height, 48px);- --or-icon-fill: var(--or-map-marker-fill, #1D5632);- --or-icon-stroke: var(--or-map-marker-stroke, none);- }-- .or-map-marker.interactive .marker-container {- pointer-events: all;- }-- .or-map-marker-default.interactive .marker-container {- pointer-events: none;- --or-icon-pointer-events: visible;- }-- .or-map-marker .marker-icon {- position: absolute;- left: 50%;- top: 50%;- z-index: 1000;- --or-icon-fill: var(--or-map-marker-icon-fill, #FFF);- --or-icon-stroke: var(--or-map-marker-icon-stroke, none);- --or-icon-width: var(--or-map-marker-icon-width, 24px);- --or-icon-height: var(--or-map-marker-icon-height, 24px);- transform: var(--or-map-marker-icon-transform, translate(-50%, -19px));- }-`;-/*** Base class for all map markers.*@@ -111,6 +75,12 @@ export class OrMapMarker extends LitElement {@property({type: String})public icon?: string;+ @property({type: String})+ public color?: string;++ @property({type: String})+ public activeColor?: string;+@property({type: Boolean})public interactive: boolean = true;@@ -148,6 +118,7 @@ export class OrMapMarker extends LitElement {markerContainerElem.appendChild(content);this.updateInteractive(markerElem);this.updateVisibility(markerElem);+ this.updateColor(markerContainerElem);this.updateActive(markerElem);return markerElem;}@@ -183,6 +154,10 @@ export class OrMapMarker extends LitElement {this.refreshMarkerContent();}+ if (_changedProperties.has("color") || _changedProperties.has("activeColor")) {+ this.updateColor(this.markerContainer);+ }+if (_changedProperties.has("visible")) {this.updateVisibility(this._actualMarkerElement);}@@ -193,6 +168,7 @@ export class OrMapMarker extends LitElement {if (_changedProperties.has("active")) {this.updateActive(this._actualMarkerElement);+ this.updateColor(this.markerContainer);}_changedProperties.forEach((oldValue, prop) => this._raisePropertyChange(prop as string));@@ -209,6 +185,32 @@ export class OrMapMarker extends LitElement {}}++ protected getColor() {+ return this.color && this.color !== "unset" ? "#" + this.color : undefined;+ }++ protected getActiveColor() {+ return this.activeColor && this.activeColor !== "unset" ? "#" + this.activeColor : undefined;+ }++ protected updateColor(container?: HTMLDivElement) {+ if (container) {+ container.style.removeProperty(markerColorVar);+ container.style.removeProperty(markerActiveColorVar);++ const color = this.getColor();+ const activeColor = this.getActiveColor();++ if (color) {+ container.style.setProperty(markerColorVar, color);+ }+ if (activeColor) {+ container.style.setProperty(markerActiveColorVar, activeColor);+ }+ }+ }+protected updateActive(container?: HTMLDivElement) {if (container) {if (this.active) {diff --git a/ui/component/or-map/src/style.ts b/ui/component/or-map/src/style.tsnew file mode 100644index 000000000..65be5d3b5--- /dev/null+++ b/ui/component/or-map/src/style.ts@@ -0,0 +1,102 @@+import {css, unsafeCSS} from "lit-element";+import {DefaultColor1, DefaultColor4} from "@openremote/core";++export const markerColorVar = "--internal-or-map-marker-color";+export const markerActiveColorVar = "--internal-or-map-marker-active-color";++// language=CSS+export const style = css`+ :host {+ --internal-or-map-marker-transform: var(--or-map-marker-transform, translate(-24px, -45px));+ --internal-or-map-marker-width: var(--or-map-marker-width, 48px);+ --internal-or-map-marker-height: var(--or-map-marker-height, 48px);+ --internal-or-map-marker-color: var(--or-map-marker-color, var(--or-app-color4, ${unsafeCSS(DefaultColor4)}));+ --internal-or-map-marker-stroke: var(--or-map-marker-stroke, none);+ --internal-or-map-marker-icon-color: var(--or-map-marker-icon-color, var(--or-app-color1, ${unsafeCSS(DefaultColor1)}));+ --internal-or-map-marker-icon-stroke: var(--or-map-marker-icon-stroke, none);+ --internal-or-map-marker-icon-width: var(--or-map-marker-icon-width, 24px);+ --internal-or-map-marker-icon-height: var(--or-map-marker-icon-height, 24px);+ --internal-or-map-marker-icon-transform: var(--or-map-marker-icon-transform, translate(-50%, -19px));+ --internal-or-map-marker-active-transform: var(--or-map-marker-active-transform, translate(-30px, -57px));+ --internal-or-map-marker-active-width: var(--or-map-marker-active-width, 60px);+ --internal-or-map-marker-active-height: var(--or-map-marker-active-height, 60px);+ --internal-or-map-marker-active-color: var(--or-map-marker-active-color, var(--or-app-color4, ${unsafeCSS(DefaultColor4)}));+ --internal-or-map-marker-active-stroke: var(--or-map-marker-active-stroke, none);+ --internal-or-map-marker-icon-active-color: var(--or-map-marker-icon-active-color, var(--or-app-color1, ${unsafeCSS(DefaultColor1)}));+ --internal-or-map-marker-icon-active-stroke: var(--or-map-marker-icon-active-stroke, none);+ --internal-or-map-marker-icon-active-width: var(--or-map-marker-icon-active-width, 32px);+ --internal-or-map-marker-icon-active-height: var(--or-map-marker-icon-active-height, 32px);+ --internal-or-map-marker-icon-active-transform: var(--or-map-marker-icon-active-transform, translate(-50%, -24px));+ display: block;+ overflow: hidden;+ }++ :host([hidden]) {+ display: none;+ }++ slot {+ display: none;+ }++ #map {+ position: relative;+ width: 100%;+ height: 100%;+ }++ .leaflet-marker-icon, .mapboxgl-marker {+ pointer-events: none !important;+ }++ .or-map-marker {+ position: absolute; /* This makes mapboxJS behave like mapboxGL */+ }++ .marker-container {+ position: relative;+ cursor: pointer;+ transform: var(--internal-or-map-marker-transform);+ --or-icon-fill: var(--internal-or-map-marker-color);+ --or-icon-width: var(--internal-or-map-marker-width);+ --or-icon-height: var(--internal-or-map-marker-height);+ --or-icon-stroke: var(--internal-or-map-marker-stroke);+ }++ .or-map-marker.active .marker-container {+ transform: var(--internal-or-map-marker-active-transform);+ --or-icon-fill: var(--internal-or-map-marker-active-color);+ --or-icon-width: var(--internal-or-map-marker-active-width);+ --or-icon-height: var(--internal-or-map-marker-active-height);+ --or-icon-stroke: var(--internal-or-map-marker-active-stroke);+ }++ .or-map-marker.interactive .marker-container {+ pointer-events: all;+ }++ .or-map-marker-default.interactive .marker-container {+ pointer-events: none;+ --or-icon-pointer-events: visible;+ }++ .or-map-marker .marker-icon {+ position: absolute;+ left: 50%;+ top: 50%;+ z-index: 1000;+ --or-icon-fill: var(--internal-or-map-marker-icon-color);+ --or-icon-stroke: var(--internal-or-map-marker-icon-stroke);+ --or-icon-width: var(--internal-or-map-marker-icon-width);+ --or-icon-height: var(--internal-or-map-marker-icon-height);+ transform: var(--internal-or-map-marker-icon-transform);+ }++ .or-map-marker.active .marker-icon {+ transform: var(--internal-or-map-marker-icon-active-transform);+ --or-icon-fill: var(--internal-or-map-marker-icon-active-color);+ --or-icon-stroke: var(--internal-or-map-marker-icon-active-stroke);+ --or-icon-width: var(--internal-or-map-marker-icon-active-width);+ --or-icon-height: var(--internal-or-map-marker-icon-active-height);+ }+`;\ No newline at end of filediff --git a/ui/demo/demo-or-map/package.json b/ui/demo/demo-or-map/package.jsonindex 58e1452bd..7ea6a0f68 100644--- a/ui/demo/demo-or-map/package.json+++ b/ui/demo/demo-or-map/package.json@@ -15,7 +15,7 @@"license": "AGPL-3.0-or-later","dependencies": {"@openremote/demo-core": "^1.0.0",- "@openremote/or-map": "^1.0.0-alpha",+ "@openremote/or-map": "^1.0.2-alpha","source-map-loader": "^0.2.4"},"devDependencies": {diff --git a/ui/demo/demo-or-map/src/index.ts b/ui/demo/demo-or-map/src/index.tsindex 51d4d134f..7e9dbf88d 100644--- a/ui/demo/demo-or-map/src/index.ts+++ b/ui/demo/demo-or-map/src/index.ts@@ -39,7 +39,7 @@ openremote.init({if (apartment1) {// Add an or-map-marker-asset to the vector mapconst assetMarker = document.createElement("or-map-marker-asset");- assetMarker.setAttribute("asset", apartment1.id!);+ assetMarker.setAttribute("assetid", apartment1.id!);vectorMap.appendChild(assetMarker);}});