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
OrMap & style improvements - Marker radius - Map loaded event
robindekkers8356cbab58cb
diff --git a/ui/component/or-header/src/or-header-style.ts b/ui/component/or-header/src/or-header-style.tsindex 951907d32..78a4a3943 100644--- a/ui/component/or-header/src/or-header-style.ts+++ b/ui/component/or-header/src/or-header-style.ts@@ -11,7 +11,6 @@ export const OrHeaderStyle = css`color: rgba(255, 255, 255, 0.8);line-height: 60px;padding: 0 5px;- text-transform: uppercase;font-size: 14px;text-decoration: none !important;cursor: pointer;@@ -32,7 +31,8 @@ export const OrHeaderStyle = css`}or-header or-icon {- margin-right: 10px;+ margin-right: 5px;+ --or-icon-width: 18px;}[slot="mobile-top"] > a,@@ -70,7 +70,7 @@ export const OrHeaderStyle = css`[slot="desktop-left"] > a {display: none;line-height: 60px;- padding: 0 24px;+ padding: 0 20px;}diff --git a/ui/component/or-map/src/index.ts b/ui/component/or-map/src/index.tsindex 188280f13..fa2d74646 100644--- a/ui/component/or-map/src/index.ts+++ b/ui/component/or-map/src/index.ts@@ -22,10 +22,27 @@ export interface ViewSettings {"boxZoom": boolean;}+export interface MapLoadedEventDetail {++}+export interface MapEventDetail {lngLat: LngLatLike;}+export class OrMapLoadedEvent extends CustomEvent<MapLoadedEventDetail> {++ public static readonly NAME = "or-map-loaded";++ constructor() {+ super(OrMapLoadedEvent.NAME, {+ detail: {},+ bubbles: true,+ composed: true+ });+ }+}+export class OrMapClickedEvent extends CustomEvent<MapEventDetail> {public static readonly NAME = "or-map-clicked";@@ -44,6 +61,7 @@ export class OrMapClickedEvent extends CustomEvent<MapEventDetail> {declare global {export interface HTMLElementEventMap {[OrMapClickedEvent.NAME]: OrMapClickedEvent;+ [OrMapLoadedEvent.NAME]: OrMapLoadedEvent;}}diff --git a/ui/component/or-map/src/mapwidget.ts b/ui/component/or-map/src/mapwidget.tsindex 780805d97..7772f9131 100644--- a/ui/component/or-map/src/mapwidget.ts+++ b/ui/component/or-map/src/mapwidget.ts@@ -3,7 +3,7 @@ import rest from "@openremote/rest";import {LngLatLike, Map as MapGL, MapboxOptions as OptionsGL, Marker as MarkerGL, Style as StyleGL, LngLat,MapMouseEvent} from "mapbox-gl";import L, {Map as MapJS, MapOptions as OptionsJS, Marker as MarkerJS} from "mapbox.js";-import {OrMapClickedEvent, Type, ViewSettings} from "./index";+import {OrMapClickedEvent, OrMapLoadedEvent, Type, ViewSettings} from "./index";import {OrMapMarker} from "./markers/or-map-marker";@@ -200,15 +200,31 @@ export class MapWidget {}this._mapGl = new map.Map(options);++ await this.styleLoaded();+this._mapGl.on("click", (e: MapMouseEvent)=> {this._onMapClick(e.lngLat);});+}+ this._mapContainer.dispatchEvent(new OrMapLoadedEvent());this._loaded = true;}+ protected styleLoaded(): Promise<void> {+ return new Promise(resolve => {+ if (this._mapGl) {++ this._mapGl.once('style.load', () => {+ resolve();+ });+ }+ });+ }+protected _onMapClick(lngLat: LngLatLike) {this._mapContainer.dispatchEvent(new OrMapClickedEvent(lngLat));}@@ -234,14 +250,12 @@ export class MapWidget {if (marker.lat && marker.lng) {if (marker._actualMarkerElement) {this._updateMarkerPosition(marker);- this._createMarkerRadius(marker);} else {this._updateMarkerElement(marker, true);-}+} else if (marker._actualMarkerElement) {this._updateMarkerElement(marker, false);-}break;}@@ -262,6 +276,7 @@ export class MapWidget {}break;}+ this._createMarkerRadius(marker);}protected _updateMarkerElement(marker: OrMapMarker, doAdd: boolean) {@@ -290,6 +305,9 @@ export class MapWidget {this._markersJs.set(marker, m);}}+ if(marker.radius) {+ this._createMarkerRadius(marker);+ }break;case Type.VECTOR:let mGl = this._markersGl.get(marker);@@ -319,48 +337,60 @@ export class MapWidget {this._addMarkerClickHandler(marker, mGl.getElement());}++}}++ if(marker.radius) {+ this._createMarkerRadius(marker);+ }break;}}protected _createMarkerRadius(marker:OrMapMarker){- if(this._mapGl && marker.radius && marker.lat && marker.lng){- // this._mapGl.addSource('circleData', {- // type: 'geojson',- // data: {- // type: 'FeatureCollection',- // features: [{- // type: "Feature",- // geometry: {- // "type": "Point",- // "coordinates": [marker.lng, marker.lat]- // },- // properties: {- // "title": "You Found Me",- // }- // }]- // }- // });- //- // this._mapGl.addLayer({- // "id":"marker-radius-circle",- // "type": "circle",- // "source": "circleData",- // "paint": {- // "circle-radius": {- // stops: [- // [5, 1],- // [15, 1024]- // ],- // base: 2- // },- // "circle-color": "red",- // "circle-opacity": 0.6- // }- // });- }+ if(this._mapGl && this._loaded && marker.radius && marker.lat && marker.lng){++ if (this._mapGl.getSource('circleData')) {+ this._mapGl.removeLayer('marker-radius-circle');+ this._mapGl.removeSource('circleData');+ }++ this._mapGl.addSource('circleData', {+ type: 'geojson',+ data: {+ type: 'FeatureCollection',+ features: [{+ type: "Feature",+ geometry: {+ "type": "Point",+ "coordinates": [marker.lng, marker.lat]+ },+ properties: {+ "title": "You Found Me",+ }+ }]+ }+ });++ this._mapGl.addLayer({+ "id": "marker-radius-circle",+ "type": "circle",+ "source": "circleData",+ "paint": {+ "circle-radius": {+ stops: [+ [0, 0],+ [20, metersToPixelsAtMaxZoom(marker.radius, marker.lat)]+ ],+ base: 2+ },+ "circle-color": "red",+ "circle-opacity": 0.3+ }+ });+ }}protected _addMarkerClickHandler(marker: OrMapMarker, elem: HTMLElement) {diff --git a/ui/component/or-rules-editor/src/style.ts b/ui/component/or-rules-editor/src/style.tsindex 2671be250..942577eeb 100644--- a/ui/component/or-rules-editor/src/style.ts+++ b/ui/component/or-rules-editor/src/style.ts@@ -44,7 +44,11 @@ export const rulesEditorStyle = css`border-top: 1px solid var(--app-lightgrey-color);background-color: var(--internal-or-rule-toolbar-background-color);}-++ .bottom-toolbar or-icon {+ --or-icon-height: 16px;+ }+icon {cursor: pointer;padding: 5px;@@ -193,7 +197,6 @@ export const ruleListStyle = css`padding: 30px 30px 5px 20px;text-transform: uppercase;color: var(--app-grey-color, #808080);- opacity: 0.87;font-size:14px;font-weight: bold;text-align: left;@@ -201,9 +204,8 @@ export const ruleListStyle = css`.list-item {text-decoration: none;- height: 24px;- font-size: 15px;- padding: 17px 0 17px 17px;+ font-size: 14px;+ padding: 13px 0 13px 15px;border-left: 5px solid transparent;color: var(--app-grey-color, #808080);cursor: pointer;@@ -235,7 +237,7 @@ export const ruleListStyle = css`width: 8px;height: 8px;border-radius: 8px;- margin: 8px 10px;+ margin: 6px 10px 0 0;}.bg-green {@@ -260,7 +262,7 @@ export const headerStyle = css`}.rule-container {- padding: 20px;+ padding: 20px 30px;}.layout.horizontal {@@ -275,6 +277,9 @@ export const headerStyle = css`background-color: transparent;border-bottom: 2px solid transparent;transition: all 150ms ease-in;++ width: 350px;+ max-width: 100%;}input:hover {