Skip to content

armgit / core

Public Imported from GitHub
0

100% open-source IoT Platform - Integrate your devices, add intelligence, build custom apps

Add MapGeocoderEvent to or-map

Robin Dekkers159a1f361351
diff --git a/ui/component/or-map/src/index.ts b/ui/component/or-map/src/index.ts
index b00b557bb..66386f42e 100644
--- a/ui/component/or-map/src/index.ts
+++ b/ui/component/or-map/src/index.ts
@@ -40,7 +40,9 @@ export interface MapEventDetail {
lngLat: LngLat;
doubleClick: boolean;
}
-
+export interface MapGeocoderEventDetail {
+ geocode: any;
+}
export class OrMapLoadedEvent extends CustomEvent<void> {
public static readonly NAME = "or-map-loaded";
@@ -85,11 +87,27 @@ export class OrMapLongPressEvent extends CustomEvent<MapEventDetail> {
}
}
+export class OrMapGeocoderChangeEvent extends CustomEvent<MapGeocoderEventDetail> {
+
+ public static readonly NAME = "or-map-geocoder-change";
+
+ constructor(geocode: any) {
+ super(OrMapGeocoderChangeEvent.NAME, {
+ detail: {
+ geocode
+ },
+ bubbles: true,
+ composed: true
+ });
+ }
+}
+
declare global {
export interface HTMLElementEventMap {
[OrMapClickedEvent.NAME]: OrMapClickedEvent;
[OrMapLoadedEvent.NAME]: OrMapLoadedEvent;
[OrMapLongPressEvent.NAME]: OrMapLongPressEvent;
+ [OrMapGeocoderChangeEvent.NAME]: OrMapGeocoderChangeEvent;
}
}
diff --git a/ui/component/or-map/src/mapwidget.ts b/ui/component/or-map/src/mapwidget.ts
index 2f92c58e9..13cfa2435 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 MarkerGL
import MaplibreGeocoder from "@maplibre/maplibre-gl-geocoder";
import '@maplibre/maplibre-gl-geocoder/dist/maplibre-gl-geocoder.css';
import {debounce} from "lodash";
-import {ControlPosition, OrMapClickedEvent, OrMapLoadedEvent, OrMapLongPressEvent, ViewSettings} from "./index";
+import {ControlPosition, OrMapClickedEvent, OrMapLoadedEvent, OrMapLongPressEvent, OrMapGeocoderChangeEvent, ViewSettings} from "./index";
import {
OrMapMarker
} from "./markers/or-map-marker";
@@ -375,6 +375,7 @@ export class MapWidget {
// so this is how we get the selected result.
this._geocoder._inputEl.addEventListener("change", () => {
var selected = this._geocoder._typeahead.selected;
+ this._onGeocodeChange(selected);
if (selected) {
// Set marker by calling _onMapClick and doubleClicked set to true
this._onLongPress(selected.center);
@@ -669,8 +670,10 @@ export class MapWidget {
this._mapGl.on('gestureend', clearTimeoutFunc);
}
};
-
protected _onLongPress(lngLat: LngLat) {
this._mapContainer.dispatchEvent(new OrMapLongPressEvent(lngLat));
}
+ protected _onGeocodeChange(geocode:any) {
+ this._mapContainer.dispatchEvent(new OrMapGeocoderChangeEvent(geocode));
+ }
}