Skip to content

armgit / core

Public Imported from GitHub
0

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

page-map now shows address search

Michael Rademaker59a7d6850f6e
diff --git a/ui/app/manager/src/pages/page-map.ts b/ui/app/manager/src/pages/page-map.ts
index c12e9405f..8a74d2f13 100644
--- a/ui/app/manager/src/pages/page-map.ts
+++ b/ui/app/manager/src/pages/page-map.ts
@@ -8,7 +8,8 @@ import {
OrMapAssetCardLoadAssetEvent,
OrMapClickedEvent,
OrMapMarkerAsset,
- OrMapMarkerClickedEvent
+ OrMapMarkerClickedEvent,
+ OrMapGeocoderChangeEvent
} from "@openremote/or-map";
import manager, {Util} from "@openremote/core";
import {createSelector} from "reselect";
@@ -289,6 +290,10 @@ export class PageMap extends Page<MapStateKeyed> {
return assets.find((asset) => asset.id === currentId);
});
+ protected _setCenter(geocode: any) {
+ this._map!.center = [geocode.geometry.coordinates[0], geocode.geometry.coordinates[1]];
+ }
+
get name(): string {
return "map";
}
@@ -304,7 +309,7 @@ export class PageMap extends Page<MapStateKeyed> {
${this._currentAsset ? html `<or-map-asset-card .config="${this.config?.card}" .assetId="${this._currentAsset.id}"></or-map-asset-card>` : ``}
- <or-map id="map" class="or-map">
+ <or-map id="map" class="or-map" showGeoCodingControl @or-map-geocoder-change="${(ev: OrMapGeocoderChangeEvent) => {this._setCenter(ev.detail.geocode);}}">
${
this._assets.filter((asset) => {
if (!asset.attributes) {
diff --git a/ui/component/or-map/src/mapwidget.ts b/ui/component/or-map/src/mapwidget.ts
index 72d666066..ce57a87a0 100644
--- a/ui/component/or-map/src/mapwidget.ts
+++ b/ui/component/or-map/src/mapwidget.ts
@@ -296,29 +296,6 @@ export class MapWidget {
this._onMapClick(e.lngLat, true);
});
- // Add custom controls
- if (this._controls) {
- this._controls.forEach((control) => {
- if (Array.isArray(control)) {
- const controlAndPosition: [Control | IControl, ControlPosition?] = control;
- this._mapGl!.addControl(controlAndPosition[0], controlAndPosition[1]);
- } else {
- this._mapGl!.addControl(control);
- }
- });
- } else {
- // Add zoom and rotation controls to the map
- this._mapGl.addControl(new NavigationControl());
- // Add current location controls to the map
- this._mapGl.addControl(new GeolocateControl({
- positionOptions: {
- enableHighAccuracy: true
- },
- showAccuracyCircle: true,
- showUserLocation: true
- }));
- }
-
if (this._showGeoCodingControl && this._viewSettings && this._viewSettings.geoCodeUrl) {
this._geocoder = new MaplibreGeocoder({forwardGeocode: this._forwardGeocode.bind(this), reverseGeocode: this._reverseGeocode }, { marker: false, showResultsWhileTyping: true });
// Override the _onKeyDown function from MaplibreGeocoder which has a bug getting the value from the input element
@@ -382,10 +359,33 @@ export class MapWidget {
// Set marker by calling _onMapClick and doubleClicked set to true
this._onLongPress(selected.center);
}
- });
+ });
+ }
- this._initLongPressEvent();
+ // Add custom controls
+ if (this._controls) {
+ this._controls.forEach((control) => {
+ if (Array.isArray(control)) {
+ const controlAndPosition: [Control | IControl, ControlPosition?] = control;
+ this._mapGl!.addControl(controlAndPosition[0], controlAndPosition[1]);
+ } else {
+ this._mapGl!.addControl(control);
+ }
+ });
+ } else {
+ // Add zoom and rotation controls to the map
+ this._mapGl.addControl(new NavigationControl());
+ // Add current location controls to the map
+ this._mapGl.addControl(new GeolocateControl({
+ positionOptions: {
+ enableHighAccuracy: true
+ },
+ showAccuracyCircle: true,
+ showUserLocation: true
+ }));
}
+
+ this._initLongPressEvent();
}
this._mapContainer.dispatchEvent(new OrMapLoadedEvent());