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
Added longpress functionality to or-map. #562
Michael Rademakerdd632b374aa7
diff --git a/ui/component/or-map/src/index.ts b/ui/component/or-map/src/index.tsindex 7ce012f4b..b00b557bb 100644--- a/ui/component/or-map/src/index.ts+++ b/ui/component/or-map/src/index.ts@@ -69,10 +69,27 @@ export class OrMapClickedEvent extends CustomEvent<MapEventDetail> {}}+export class OrMapLongPressEvent extends CustomEvent<MapEventDetail> {++ public static readonly NAME = "or-map-long-press";++ constructor(lngLat: LngLat) {+ super(OrMapLongPressEvent.NAME, {+ detail: {+ doubleClick: false,+ lngLat: lngLat+ },+ bubbles: true,+ composed: true+ });+ }+}+declare global {export interface HTMLElementEventMap {[OrMapClickedEvent.NAME]: OrMapClickedEvent;[OrMapLoadedEvent.NAME]: OrMapLoadedEvent;+ [OrMapLongPressEvent.NAME]: OrMapLongPressEvent;}}@@ -277,7 +294,7 @@ export const geoJsonPointInputTemplateProvider: ValueInputProviderGenerator = (amargin: 3px 0;}</style>- <or-map id="geo-json-point-map" class="or-map" @or-map-clicked="${(ev: OrMapClickedEvent) => {if (ev.detail.doubleClick) {setPos(ev.detail.lngLat);}}}" .center="${center}" .controls="${controls}" .showGeoCodingControl=${!readonly}>+ <or-map id="geo-json-point-map" class="or-map" @or-map-long-press="${(ev: OrMapLongPressEvent) => {setPos(ev.detail.lngLat);}}" .center="${center}" .controls="${controls}" .showGeoCodingControl=${!readonly}><or-map-marker id="geo-json-point-marker" active .lng="${pos ? pos.lng : undefined}" .lat="${pos ? pos.lat : undefined}" .icon="${iconAndColor ? iconAndColor.icon : undefined}" .activeColor="${iconAndColor ? "#" + iconAndColor.color : undefined}" .colour="${iconAndColor ? "#" + iconAndColor.color : undefined}"></or-map-marker></or-map>`;diff --git a/ui/component/or-map/src/mapwidget.ts b/ui/component/or-map/src/mapwidget.tsindex c89143e8b..df5ef27ab 100644--- a/ui/component/or-map/src/mapwidget.ts+++ b/ui/component/or-map/src/mapwidget.ts@@ -8,7 +8,7 @@ import {LngLatLike, Map as MapGL, MapboxOptions as OptionsGL, Marker as MarkerGLimport MaplibreGeocoder from "@maplibre/maplibre-gl-geocoder";import '@maplibre/maplibre-gl-geocoder/dist/maplibre-gl-geocoder.css';import {debounce} from "lodash";-import {ControlPosition, OrMapClickedEvent, OrMapLoadedEvent, ViewSettings} from "./index";+import {ControlPosition, OrMapClickedEvent, OrMapLoadedEvent, OrMapLongPressEvent, ViewSettings} from "./index";import {OrMapMarker} from "./markers/or-map-marker";@@ -377,9 +377,11 @@ export class MapWidget {var selected = this._geocoder._typeahead.selected;if (selected) {// Set marker by calling _onMapClick and doubleClicked set to true- this._onMapClick(selected.center, true);+ this._onLongPress(selected.center);}});++ this._initLongPressEvent();}}@@ -629,4 +631,45 @@ export class MapWidget {protected async _reverseGeocode(config: any) {}++ protected _initLongPressEvent() {+ if (this._mapGl) {+ let pressTimeout: NodeJS.Timeout;+ let pos: LngLat;+ let clearTimeoutFunc = () => { if (pressTimeout) clearTimeout(pressTimeout); };++ this._mapGl.on('touchstart', (e) => {+ if (e.originalEvent.touches.length > 1) {+ return;+ }+ pos = e.lngLat;+ pressTimeout = setTimeout(() => {+ this._onLongPress(pos!);+ }, 500);+ });++ this._mapGl.on('mousedown', (e) => {+ pos = e.lngLat;+ pressTimeout = setTimeout(() => {+ this._onLongPress(pos!);+ }, 500);+ });++ this._mapGl.on('mousemove', clearTimeoutFunc);+ this._mapGl.on('mouseup', clearTimeoutFunc);+ this._mapGl.on('touchend', clearTimeoutFunc);+ this._mapGl.on('touchcancel', clearTimeoutFunc);+ this._mapGl.on('touchmove', clearTimeoutFunc);+ this._mapGl.on('pointerdrag', clearTimeoutFunc);+ this._mapGl.on('pointermove', clearTimeoutFunc);+ this._mapGl.on('moveend', clearTimeoutFunc);+ this._mapGl.on('gesturestart', clearTimeoutFunc);+ this._mapGl.on('gesturechange', clearTimeoutFunc);+ this._mapGl.on('gestureend', clearTimeoutFunc);+ }+ };++ protected _onLongPress(lngLat: LngLat) {+ this._mapContainer.dispatchEvent(new OrMapLongPressEvent(lngLat));+ }}