Skip to content

armgit / core

Public Imported from GitHub
0

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

Remove mapbox.js and old raster map implementation (#2473)

Koene1713394aaa4
diff --git a/manager/src/main/java/org/openremote/manager/map/MapResourceImpl.java b/manager/src/main/java/org/openremote/manager/map/MapResourceImpl.java
index 840edd9e6..88f7e1282 100644
--- a/manager/src/main/java/org/openremote/manager/map/MapResourceImpl.java
+++ b/manager/src/main/java/org/openremote/manager/map/MapResourceImpl.java
@@ -59,14 +59,6 @@ public class MapResourceImpl extends WebResource implements MapResource {
);
}
- @Override
- public ObjectNode getSettingsJs(RequestParams requestParams) {
- return mapService.getMapSettingsJs(
- getAuthenticatedRealmName(),
- requestParams.getExternalSchemeHostAndPort()
- );
- }
-
@Override
public Response getTile(int zoom, int column, int row) {
byte[] tile = mapService.getMapTile(zoom, column, row);
diff --git a/manager/src/main/java/org/openremote/manager/map/MapService.java b/manager/src/main/java/org/openremote/manager/map/MapService.java
index 07878f7ae..43d3b9fab 100644
--- a/manager/src/main/java/org/openremote/manager/map/MapService.java
+++ b/manager/src/main/java/org/openremote/manager/map/MapService.java
@@ -377,7 +377,7 @@ public class MapService implements ContainerService {
}
/**
- * Dynamically build Mapbox GL settings based on mapsettings.json
+ * Dynamically build MapLibre GL settings based on mapsettings.json
*/
public ObjectNode getMapSettings(String realm, URI host) {
String realmUriKey = realm + host.toString();
@@ -469,35 +469,6 @@ public class MapService implements ContainerService {
return settings;
}
- /**
- * Dynamically build Mapbox JS settings based on mapsettings.json
- */
- public ObjectNode getMapSettingsJs(String realm, URI host) {
- String realmUriKey = realm + host.toString();
- if (mapSettingsJs.containsKey(realmUriKey)) {
- return mapSettingsJs.get(realmUriKey);
- }
-
- final ObjectNode settings = mapSettingsJs.computeIfAbsent(realmUriKey, r -> ValueUtil.JSON.createObjectNode());
-
- if (!metadata.isValid() || mapConfig.isEmpty()) {
- return settings;
- }
-
- ArrayNode tilesArray = ValueUtil.JSON.createArrayNode();
- String tileUrl = UriBuilder.fromUri(host).replacePath(RASTER_MAP_TILE_PATH).build().toString() + "/{z}/{x}/{y}.png";
- tilesArray.insert(0, tileUrl);
-
- settings.replace("options", mapConfig.has("options") && mapConfig.get("options").isObject() ? (ObjectNode)mapConfig.get("options") : null);
-
- settings.put("attribution", metadata.attribution);
- settings.put("format", "png");
- settings.put("type", "baselayer");
- settings.replace("tiles", tilesArray);
-
- return settings;
- }
-
public byte[] getMapTile(int zoom, int column, int row) {
// Flip y, oh why
row = Double.valueOf(Math.pow(2, zoom) - 1 - row).intValue();
diff --git a/model/src/main/java/org/openremote/model/manager/ManagerConfig.java b/model/src/main/java/org/openremote/model/manager/ManagerConfig.java
index 2a7ddab4c..8b23e79e1 100644
--- a/model/src/main/java/org/openremote/model/manager/ManagerConfig.java
+++ b/model/src/main/java/org/openremote/model/manager/ManagerConfig.java
@@ -39,7 +39,6 @@ public class ManagerConfig {
protected Auth auth;
protected UsernamePassword credentials;
protected EventProviderType eventProviderType;
- protected MapType mapType;
protected Object configureTranslationsOptions;
protected Object basicLoginProvider;
protected String defaultLanguage;
diff --git a/model/src/main/java/org/openremote/model/manager/MapType.java b/model/src/main/java/org/openremote/model/manager/MapType.java
deleted file mode 100644
index d315c649c..000000000
--- a/model/src/main/java/org/openremote/model/manager/MapType.java
+++ /dev/null
@@ -1,24 +0,0 @@
-/*
- * Copyright 2022, OpenRemote Inc.
- *
- * See the CONTRIBUTORS.txt file in the distribution for a
- * full listing of individual contributors.
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-package org.openremote.model.manager;
-
-public enum MapType {
- VECTOR, RASTER
-}
diff --git a/model/src/main/java/org/openremote/model/map/MapResource.java b/model/src/main/java/org/openremote/model/map/MapResource.java
index a597c6980..74651de38 100644
--- a/model/src/main/java/org/openremote/model/map/MapResource.java
+++ b/model/src/main/java/org/openremote/model/map/MapResource.java
@@ -46,26 +46,16 @@ public interface MapResource {
ObjectNode saveSettings(@BeanParam RequestParams requestParams, MapConfig mapConfig);
/**
- * Returns style used to initialise Mapbox GL
+ * Returns style used to initialise MapLibre GL
* @return
*/
@GET
@Produces(MediaType.APPLICATION_JSON)
- @Operation(operationId = "getSettings", summary = "Retrieve the style used for Mapbox GL")
+ @Operation(operationId = "getSettings", summary = "Retrieve the style used for MapLibre GL")
ObjectNode getSettings(@BeanParam RequestParams requestParams);
/**
- * Returns tileJSON object used to initialise Mapbox JS
- * @return
- */
- @GET
- @Path("js")
- @Produces(MediaType.APPLICATION_JSON)
- @Operation(operationId = "getSettingsJs", summary = "Retrieve the tileJSON object used for Mapbox GL")
- ObjectNode getSettingsJs(@BeanParam RequestParams requestParams);
-
- /**
- * Gets vector tile data for Mapbox GL
+ * Gets vector tile data for MapLibre GL
*/
@GET
@Produces("application/vnd.mapbox-vector-tile")
diff --git a/ui/app/storybook/rsbuild.config.ts b/ui/app/storybook/rsbuild.config.ts
index 3993a02ed..694b5ebb9 100644
--- a/ui/app/storybook/rsbuild.config.ts
+++ b/ui/app/storybook/rsbuild.config.ts
@@ -52,10 +52,10 @@ export default defineConfig({
},
tools: {
bundlerChain: (chain, { CHAIN_ID }) => {
- chain.module.rule(CHAIN_ID.RULE.CSS).exclude.add(/(maplibre|mapbox|@material|gridstack|@mdi).*\.css$/); // Exclude the external CSS imports from default bundling.
+ chain.module.rule(CHAIN_ID.RULE.CSS).exclude.add(/(maplibre|@material|gridstack|@mdi).*\.css$/); // Exclude the external CSS imports from default bundling.
},
rspack: (config, { addRules }) => {
- addRules([{test: /(maplibre|mapbox|@material|gridstack|@mdi).*\.css$/, type: "asset/source"}]); // Add rule to treat external CSS imports as raw strings.
+ addRules([{test: /(maplibre|@material|gridstack|@mdi).*\.css$/, type: "asset/source"}]); // Add rule to treat external CSS imports as raw strings.
return config;
}
}
diff --git a/ui/component/core/src/index.ts b/ui/component/core/src/index.ts
index d0629a9b2..2fae52251 100644
--- a/ui/component/core/src/index.ts
+++ b/ui/component/core/src/index.ts
@@ -12,7 +12,6 @@ import {
ConsoleAppConfig,
EventProviderType,
ManagerConfig,
- MapType,
Role,
User,
UsernamePassword
@@ -271,10 +270,6 @@ export class Manager implements EventProviderFactory {
return this.events;
}
- get mapType() {
- return this._config.mapType || MapType.VECTOR;
- }
-
protected static MAX_RECONNECT_DELAY = 45000;
private _error?: ORError;
private _config!: ManagerConfig;
diff --git a/ui/component/or-map/README.md b/ui/component/or-map/README.md
index 520e8fc9e..090b38d69 100644
--- a/ui/component/or-map/README.md
+++ b/ui/component/or-map/README.md
@@ -3,7 +3,7 @@
[![Linux Build][travis-image]][travis-url]
[![Test Coverage][coveralls-image]][coveralls-url]
-Web Component for displaying a Mapbox map; either raster or vector (default). This component requires an OpenRemote
+Web Component for displaying a MapLibre map; either raster or vector (default). This component requires an OpenRemote
Manager to retrieve map settings and tiles.
## Install
@@ -19,19 +19,13 @@ For a full list of properties, methods and options refer to the TypeDoc generate
<or-map center="5.454250, 51.445990" zoom="5" style="height: 500px; width: 100%;" />
```
-For a raster map (raster tile serving in the OpenRemote Manager must be properly configured):
-
-```$html
-<or-map type="RASTER" center="5.454250, 51.445990" zoom="5" style="height: 500px; width: 100%;" />
-```
-
The center and zoom are optional overrides for the defaults that will be defined in the `mapsettings` loaded from the
OpenRemote Manager; each realm can have different `mapsettings` with a fallback to the default.
Markers can be added via markup as children:
```$html
-<or-map id="vectorMap" center="5.454250, 51.445990" zoom="5" style="height: 500px; width: 100%;">
+<or-map id="map" center="5.454250, 51.445990" zoom="5" style="height: 500px; width: 100%;">
<or-map-marker id="demo-marker" lng="5.454250" class="marker" icon="or:logo-plain"></or-map-marker>
</or-map>
```
@@ -39,10 +33,10 @@ Markers can be added via markup as children:
Or programmatically:
```$typescript
-const vectorMap = docuemnt.getElementById("vectorMap");
+const map = document.getElementById("map");
const assetMarker = document.createElement("or-map-marker-asset");
assetMarker.setAttribute("asset", apartment1.id!);
-vectorMap.appendChild(assetMarker);
+map.appendChild(assetMarker);
```
There are two types of built in markers:
diff --git a/ui/component/or-map/package.json b/ui/component/or-map/package.json
index 9ecaecf7e..1e9fe7b72 100644
--- a/ui/component/or-map/package.json
+++ b/ui/component/or-map/package.json
@@ -32,13 +32,11 @@
"lit": "^3.3.1",
"lit-html": "^3.3.1",
"lodash.debounce": "^4.0.8",
- "mapbox.js": "^3.3.1",
"maplibre-gl": "^5.12.0"
},
"devDependencies": {
"@types/geojson": "^7946.0.7",
- "@types/lodash.debounce": "^4",
- "@types/mapbox": "^1.6.42"
+ "@types/lodash.debounce": "^4"
},
"publishConfig": {
"access": "public"
diff --git a/ui/component/or-map/rspack.config.js b/ui/component/or-map/rspack.config.js
index 1161dade8..7135862dc 100644
--- a/ui/component/or-map/rspack.config.js
+++ b/ui/component/or-map/rspack.config.js
@@ -4,7 +4,6 @@ bundles = {
"index": {
vendor: {
"maplibre-gl": "maplibre",
- "mapbox.js": "L.mapbox",
"moment": "moment"
},
excludeOr: true
diff --git a/ui/component/or-map/src/index.ts b/ui/component/or-map/src/index.ts
index e03b26c9c..c4df26eef 100644
--- a/ui/component/or-map/src/index.ts
+++ b/ui/component/or-map/src/index.ts
@@ -17,7 +17,7 @@ import {OrMwcDialog, showDialog} from "@openremote/or-mwc-components/or-mwc-dial
import {getMarkerIconAndColorFromAssetType} from "./util";
import {i18next} from "@openremote/or-translate";
import debounce from "lodash.debounce";
-import { Asset, Attribute, GeoJsonConfig, GeoJSONPoint, MapType, WellknownAttributes } from "@openremote/model";
+import { Asset, Attribute, GeoJsonConfig, GeoJSONPoint, WellknownAttributes } from "@openremote/model";
import { CoordinatesControl, CoordinatesRegexPattern, getCoordinatesInputKeyHandler } from "./controls/coordinates";
import { CenterControl } from "./controls/center";
@@ -307,9 +307,6 @@ export class OrMap extends LitElement {
public static styles = style;
- @property({type: String})
- public type: MapType = manager.mapType;
-
@property({type: Object})
public cluster?: ClusterConfig;
@@ -452,7 +449,7 @@ export class OrMap extends LitElement {
}
if (this._mapContainer && this._slotElement) {
- this._map = new MapWidget(this.type, this.shadowRoot!, this._mapContainer, this.showGeoCodingControl, this.showBoundaryBoxControl, this.useZoomControl, this.showGeoJson, this.cluster)
+ this._map = new MapWidget(this.shadowRoot!, this._mapContainer, this.showGeoCodingControl, this.showBoundaryBoxControl, this.useZoomControl, this.showGeoJson, this.cluster)
.setCenter(this.center)
.setZoom(this.zoom)
.setControls(this.controls)
diff --git a/ui/component/or-map/src/mapwidget.ts b/ui/component/or-map/src/mapwidget.ts
index 8e09fd078..1b7f7fc72 100644
--- a/ui/component/or-map/src/mapwidget.ts
+++ b/ui/component/or-map/src/mapwidget.ts
@@ -1,17 +1,18 @@
import manager, { DefaultColor4 } from "@openremote/core";
-import maplibregl,{
+import maplibregl, {
AddLayerObject,
IControl,
GeolocateControl,
LngLat,
LngLatLike,
Map as MapGL,
- MapOptions as OptionsGL,
+ MapOptions,
MapMouseEvent,
- Marker as MarkerGL,
+ Marker,
NavigationControl,
StyleSpecification,
GeoJSONSourceSpecification,
+ MapSourceDataEvent,
} from "maplibre-gl";
import MaplibreGeocoder from "@maplibre/maplibre-gl-geocoder";
import "@maplibre/maplibre-gl-geocoder/dist/maplibre-gl-geocoder.css";
@@ -27,13 +28,12 @@ import {
AssetWithLocation,
} from "./index";
import { OrMapMarker } from "./markers/or-map-marker";
-import { getLatLngBounds, getLngLat, getMarkerIconAndColorFromAssetType, isWebglSupported } from "./util";
-import { Asset, GeoJsonConfig, MapType } from "@openremote/model";
+import { getLngLat, getMarkerIconAndColorFromAssetType, isWebglSupported } from "./util";
+import { Asset, GeoJsonConfig } from "@openremote/model";
import { Feature, FeatureCollection, Geometry } from "geojson";
import { isMapboxURL, transformMapboxUrl } from "./util/mapbox-url";
import { OrClusterMarker, Slice } from "./markers/or-cluster-marker";
-const mapboxJsStyles = require("mapbox.js/dist/mapbox.css");
const maplibreGlStyles = require("maplibre-gl/dist/maplibre-gl.css");
const maplibreGeoCoderStyles = require("@maplibre/maplibre-gl-geocoder/dist/maplibre-gl-geocoder.css");
@@ -44,31 +44,26 @@ export interface ClusterConfig {
clusterMaxZoom: number
}
-// TODO: fix any type
-const metersToPixelsAtMaxZoom = (meters: number, latitude: number) =>
- meters / 0.075 / Math.cos(latitude * Math.PI / 180);
+const metersToPixelsAtMaxZoom = (meters: number, latitude: number) => meters / 0.075 / Math.cos(latitude * Math.PI / 180);
let pkey: string | null;
export class MapWidget {
- protected _mapJs?: L.mapbox.Map;
- protected _mapGl?: MapGL;
- protected _type: MapType;
+ protected _map?: MapGL;
protected _styleParent: Node;
protected _mapContainer: HTMLElement;
- protected _loaded: boolean = false;
- protected _markersJs: Map<OrMapMarker, L.Marker> = new Map();
- protected _markersGl: Map<OrMapMarker, MarkerGL> = new Map();
+ protected _loaded = false;
+ protected _markers: Map<OrMapMarker, Marker> = new Map();
protected _geoJsonConfig?: GeoJsonConfig;
protected _geoJsonSources: string[] = [];
protected _geoJsonLayers: Map<string, any> = new Map();
protected _viewSettings?: ViewSettings;
protected _center?: LngLatLike;
protected _zoom?: number;
- protected _showGeoCodingControl: boolean = false;
- protected _showBoundaryBox: boolean = false;
- protected _useZoomControls: boolean = true;
- protected _showGeoJson: boolean = true;
+ protected _showGeoCodingControl = false;
+ protected _showBoundaryBox = false;
+ protected _useZoomControls = true;
+ protected _showGeoJson = true;
protected _controls?: (IControl | [IControl, ControlPosition?])[];
protected _clickHandlers: Map<OrMapMarker, (ev: MouseEvent) => void> = new Map();
protected _geocoder?: any;
@@ -79,12 +74,11 @@ export class MapWidget {
};
protected _assetTypeColors: any = {};
- protected _cachedMarkers: Record<string, maplibregl.Marker> = {};
- protected _markersOnScreen: Record<string, maplibregl.Marker> = {};
+ protected _cachedMarkers: Record<string, Marker> = {};
+ protected _markersOnScreen: Record<string, Marker> = {};
protected _assetsOnScreen: Record<string, AssetWithLocation> = {};
- constructor(type: MapType, styleParent: Node, mapContainer: HTMLElement, showGeoCodingControl: boolean = false, showBoundaryBox = false, useZoomControls = true, showGeoJson = true, clusterConfig?: ClusterConfig) {
- this._type = type;
+ constructor(styleParent: Node, mapContainer: HTMLElement, showGeoCodingControl = false, showBoundaryBox = false, useZoomControls = true, showGeoJson = true, clusterConfig?: ClusterConfig) {
this._styleParent = styleParent;
this._mapContainer = mapContainer;
this._showGeoCodingControl = showGeoCodingControl;
@@ -94,115 +88,79 @@ export class MapWidget {
this._clusterConfig = clusterConfig;
}
- public setCenter(center?: LngLatLike): this {
+ protected _onMove = () => debounce(this._updateMarkers);
+ protected _onMoveEnd = () => this._updateMarkers();
+ protected _onData = (e: MapSourceDataEvent) => {
+ if (this._map && e.isSourceLoaded && e.sourceId === "mapPoints") {
+ this._map.on('move', this._onMove);
+ this._map.on('moveend', this._onMoveEnd);
+ this._updateMarkers();
+ }
+ };
+ public setCenter(center?: LngLatLike): this {
this._center = getLngLat(center);
-
- switch (this._type) {
- case MapType.RASTER:
- if (this._mapJs) {
- const latLng = getLngLat(this._center) || (this._viewSettings ? getLngLat(this._viewSettings.center) : undefined);
- if (latLng) {
- this._mapJs.setView(latLng, undefined, {pan: {animate: false}, zoom: {animate: false}});
- }
- }
- break;
- case MapType.VECTOR:
- if (this._mapGl && this._center) {
- this._mapGl.setCenter(this._center);
- }
- break;
+ if (this._map && this._center) {
+ this._map.setCenter(this._center);
}
-
return this;
}
public flyTo(coordinates?:LngLatLike, zoom?: number): this {
- switch (this._type) {
- case MapType.RASTER:
- if (this._mapJs) {
- // TODO implement fylTo
- }
- break;
- case MapType.VECTOR:
- if (!coordinates) {
- coordinates = this._center ? this._center : this._viewSettings ? this._viewSettings.center : undefined;
- }
+ if (!coordinates) {
+ coordinates = this._center ? this._center : this._viewSettings ? this._viewSettings.center : undefined;
+ }
- if (!zoom) {
- zoom = this._zoom ? this._zoom : this._viewSettings && this._viewSettings.zoom ? this._viewSettings.zoom : undefined;
- }
+ if (!zoom) {
+ zoom = this._zoom ? this._zoom : this._viewSettings && this._viewSettings.zoom ? this._viewSettings.zoom : undefined;
+ }
- if (this._mapGl) {
- // Only do flyTo if it has valid LngLat value
- if(coordinates) {
- this._mapGl.flyTo({
- center: coordinates,
- zoom: zoom
- });
- }
- } else {
- this._center = coordinates;
- this._zoom = zoom;
- }
- break;
+ if (this._map) {
+ // Only do flyTo if it has valid LngLat value
+ if (coordinates) {
+ this._map.flyTo({
+ center: coordinates,
+ zoom: zoom
+ });
+ }
+ } else {
+ this._center = coordinates;
+ this._zoom = zoom;
}
return this;
}
public resize(): this {
-
- switch (this._type) {
- case MapType.RASTER:
- if (this._mapJs) {
- }
- break;
- case MapType.VECTOR:
- if (this._mapGl) {
- this._mapGl.resize()
- }
- break;
+ if (this._map) {
+ this._map.resize()
}
-
return this;
}
public setZoom(zoom?: number): this {
-
this._zoom = zoom;
-
- switch (this._type) {
- case MapType.RASTER:
- if (this._mapJs && this._zoom) {
- this._mapJs.setZoom(this._zoom, {animate: false});
- }
- break;
- case MapType.VECTOR:
- if (this._mapGl && this._zoom) {
- this._mapGl.setZoom(this._zoom);
- }
- break;
+ if (this._map && this._zoom) {
+ this._map.setZoom(this._zoom);
}
-
return this;
}
public setControls(controls?: (IControl | [IControl, ControlPosition?])[]): this {
this._controls = controls;
- if (this._mapGl) {
+ if (this._map) {
if (this._controls) {
this._controls.forEach((control) => {
if (Array.isArray(control)) {
const controlAndPosition: [IControl, ControlPosition?] = control;
- this._mapGl!.addControl(controlAndPosition[0], controlAndPosition[1]);
+ this._map!.addControl(controlAndPosition[0], controlAndPosition[1]);
} else {
- this._mapGl!.addControl(control);
+ this._map!.addControl(control);
}
});
} else {
// Add zoom and rotation controls to the map
- this._mapGl.addControl(new NavigationControl());
+ this._map.addControl(new NavigationControl());
}
}
return this;
@@ -210,8 +168,8 @@ export class MapWidget {
public setGeoJson(geoJsonConfig?: GeoJsonConfig): this {
this._geoJsonConfig = geoJsonConfig;
- if(this._mapGl) {
- if(this._geoJsonConfig) {
+ if (this._map) {
+ if (this._geoJsonConfig) {
this._loadGeoJSON(this._geoJsonConfig);
} else {
this._loadGeoJSON(this._viewSettings?.geoJson);
@@ -221,14 +179,8 @@ export class MapWidget {
}
public async loadViewSettings() {
-
- let settingsResponse;
- if (this._type === MapType.RASTER) {
- settingsResponse = await manager.rest.api.MapResource.getSettingsJs();
- } else {
- settingsResponse = await manager.rest.api.MapResource.getSettings();
- }
- const settings = settingsResponse.data as any;
+ const response = await manager.rest.api.MapResource.getSettings();
+ const settings = response.data as any;
if (settings.override) {
return settings.override
@@ -241,11 +193,11 @@ export class MapWidget {
if (this._viewSettings) {
// If Map was already present, so only ran during updates such as realm switches
- if (this._mapGl) {
- this._mapGl.setMinZoom(this._viewSettings.minZoom);
- this._mapGl.setMaxZoom(this._viewSettings.maxZoom);
+ if (this._map) {
+ this._map.setMinZoom(this._viewSettings.minZoom);
+ this._map.setMaxZoom(this._viewSettings.maxZoom);
if (this._viewSettings.bounds){
- this._mapGl.setMaxBounds(this._viewSettings.bounds);
+ this._map.setMaxBounds(this._viewSettings.bounds);
}
// Unload all GeoJSON that is present, and load new layers if present
if(this._geoJsonConfig) {
@@ -272,228 +224,175 @@ export class MapWidget {
return;
}
- if (this._type === MapType.RASTER) {
-
- // Add style to shadow root
- const style = document.createElement("style");
- style.id = "mapboxJsStyle";
- style.textContent = mapboxJsStyles;
- this._styleParent.appendChild(style);
- const settings = await this.loadViewSettings();
-
- let options: L.mapbox.MapOptions | undefined;
- if (this._viewSettings) {
- options = {};
-
- // JS zoom is out compared to GL
- options.zoom = this._viewSettings.zoom ? this._viewSettings.zoom + 1 : undefined;
-
- if (this._useZoomControls){
- options.maxZoom = this._viewSettings.maxZoom ? this._viewSettings.maxZoom - 1 : undefined;
- options.minZoom = this._viewSettings.minZoom ? this._viewSettings.minZoom + 1 : undefined;
- }
- options.boxZoom = this._viewSettings.boxZoom;
-
- // JS uses lat then lng unlike GL
- if (this._viewSettings.bounds) {
- options.maxBounds = getLatLngBounds(this._viewSettings.bounds);
- }
- if (this._viewSettings.center) {
- const lngLat = getLngLat(this._viewSettings.center);
- options.center = lngLat ? L.latLng(lngLat.lat, lngLat.lng) : undefined;
- }
- if (this._center) {
- const lngLat = getLngLat(this._center);
- options.center = lngLat ? L.latLng(lngLat.lat, lngLat.lng) : undefined;
- }
- if (this._zoom) {
- options.zoom = this._zoom + 1;
- }
+ // Add style to shadow root
+ let style = document.createElement("style");
+ style.id = "maplibreGlStyle";
+ style.textContent = maplibreGlStyles;
+ this._styleParent.appendChild(style);
+
+ style = document.createElement("style");
+ style.id = "maplibreGeoCoderStyles";
+ style.textContent = maplibreGeoCoderStyles;
+ this._styleParent.appendChild(style);
+
+ const map: typeof import("maplibre-gl") = await import(/* webpackChunkName: "maplibre-gl" */ "maplibre-gl");
+ const settings = await this.loadViewSettings();
+
+ const options: MapOptions = {
+ attributionControl: {compact: true},
+ container: this._mapContainer,
+ style: settings as StyleSpecification,
+ transformRequest: (url, resourceType) => {
+ if (!pkey) {
+ pkey = new URL(url).searchParams.get("access_token") || ''
+ }
+ if (isMapboxURL(url)) {
+ return transformMapboxUrl(url, pkey, resourceType)
+ }
+ // Cross-domain tile servers usually have the following headers specified "access-control-allow-methods GET", "access-control-allow-origin *", "allow GET,HEAD". The "Access-Control-Request-Headers: Authorization" may not be set e.g. with Mapbox tile servers. The CORS preflight request (OPTION) will in this case fail if the "authorization" header is being requested cross-domain. The only headers allowed are so called "simple request" headers, see https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS#simple_requests.
+ const headers = new URL(window.origin).hostname === new URL(url).hostname
+ ? {Authorization: manager.getAuthorizationHeader()} : {}
+ return {
+ headers,
+ url
+ };
}
+ };
- this._mapJs = L.mapbox.map(this._mapContainer, settings, options);
-
- this._mapJs.on("click", (e: any)=> {
- this._onMapClick(e.latlng);
- });
-
- if (options && options.maxBounds) {
- const minZoom = this._mapJs.getBoundsZoom(options.maxBounds, true);
- if (!options.minZoom || options.minZoom < minZoom) {
- (this._mapJs as any).setMinZoom(minZoom);
- }
+ if (this._viewSettings) {
+ if (this._useZoomControls){
+ options.maxZoom = this._viewSettings.maxZoom;
+ options.minZoom = this._viewSettings.minZoom;
}
- } else {
- // Add style to shadow root
- let style = document.createElement("style");
- style.id = "maplibreGlStyle";
- style.textContent = maplibreGlStyles;
- this._styleParent.appendChild(style);
-
- style = document.createElement("style");
- style.id = "maplibreGeoCoderStyles";
- style.textContent = maplibreGeoCoderStyles;
- this._styleParent.appendChild(style);
-
- const map: typeof import("maplibre-gl") = await import(/* webpackChunkName: "maplibre-gl" */ "maplibre-gl");
- const settings = await this.loadViewSettings();
-
- const options: OptionsGL = {
- attributionControl: {compact: true},
- container: this._mapContainer,
- style: settings as StyleSpecification,
- transformRequest: (url, resourceType) => {
- if (!pkey) {
- pkey = new URL(url).searchParams.get("access_token") || ''
- }
- if (isMapboxURL(url)) {
- return transformMapboxUrl(url, pkey, resourceType)
- }
- // Cross-domain tile servers usually have the following headers specified "access-control-allow-methods GET", "access-control-allow-origin *", "allow GET,HEAD". The "Access-Control-Request-Headers: Authorization" may not be set e.g. with Mapbox tile servers. The CORS preflight request (OPTION) will in this case fail if the "authorization" header is being requested cross-domain. The only headers allowed are so called "simple request" headers, see https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS#simple_requests.
- const headers = new URL(window.origin).hostname === new URL(url).hostname
- ? {Authorization: manager.getAuthorizationHeader()} : {}
- return {
- headers,
- url
- };
- }
- };
-
- if (this._viewSettings) {
- if (this._useZoomControls){
- options.maxZoom = this._viewSettings.maxZoom
- options.minZoom = this._viewSettings.minZoom
- }
- if (this._viewSettings.bounds && !this._showBoundaryBox){
- options.maxBounds = this._viewSettings.bounds;
- }
-
- options.boxZoom = this._viewSettings.boxZoom;
- options.zoom = this._viewSettings.zoom;
- options.center = this._viewSettings.center;
+ if (this._viewSettings.bounds && !this._showBoundaryBox){
+ options.maxBounds = this._viewSettings.bounds;
}
- this._center = this._center || (this._viewSettings ? this._viewSettings.center : undefined);
- options.center = this._center;
-
- if (this._zoom) {
- options.zoom = this._zoom;
- }
+ options.boxZoom = this._viewSettings.boxZoom;
+ options.zoom = this._viewSettings.zoom;
+ options.center = this._viewSettings.center;
+ }
- // Firefox headless mode does not support webgl, see https://bugzilla.mozilla.org/show_bug.cgi?id=1375585
- if (!isWebglSupported()) {
- console.warn("WebGL is not supported in this environment. The map cannot be initialized.");
- return;
- }
+ this._center = this._center || (this._viewSettings ? this._viewSettings.center : undefined);
+ options.center = this._center;
- this._mapGl = new map.Map(options);
+ if (this._zoom) {
+ options.zoom = this._zoom;
+ }
- await this._styleLoaded();
+ // Firefox headless mode does not support webgl, see https://bugzilla.mozilla.org/show_bug.cgi?id=1375585
+ if (!isWebglSupported()) {
+ console.warn("WebGL is not supported in this environment. The map cannot be initialized.");
+ return;
+ }
- this._mapGl.on("click", (e: MapMouseEvent) => {
- this._onMapClick(e.lngLat);
- });
+ this._map = new map.Map(options);
- this._mapGl.on("dblclick", (e: MapMouseEvent) => {
- this._onMapClick(e.lngLat, true);
- });
+ await this._styleLoaded();
- if (this._showGeoCodingControl && this._viewSettings && this._viewSettings.geocodeUrl) {
- this._geocoder = new MaplibreGeocoder({forwardGeocode: this._forwardGeocode.bind(this), reverseGeocode: this._reverseGeocode }, { maplibregl: maplibregl, showResultsWhileTyping: true });
- // Override the _onKeyDown function from MaplibreGeocoder which has a bug getting the value from the input element
- this._geocoder._onKeyDown = debounce((e: KeyboardEvent) => {
- var ESC_KEY_CODE = 27,
- TAB_KEY_CODE = 9;
-
- if (e.keyCode === ESC_KEY_CODE && this._geocoder.options.clearAndBlurOnEsc) {
- this._geocoder._clear(e);
- return this._geocoder._inputEl.blur();
- }
-
- // if target has shadowRoot, then get the actual active element inside the shadowRoot
- var value = this._geocoder._inputEl.value || e.key;
-
- if (!value) {
- this._geocoder.fresh = true;
- // the user has removed all the text
- if (e.keyCode !== TAB_KEY_CODE) this._geocoder.clear(e);
- return (this._geocoder._clearEl.style.display = "none");
- }
-
- // TAB, ESC, LEFT, RIGHT, UP, DOWN
- if (
- e.metaKey ||
- [TAB_KEY_CODE, ESC_KEY_CODE, 37, 39, 38, 40].indexOf(e.keyCode) !== -1
- )
- return;
-
- // ENTER
- if (e.keyCode === 13) {
- if (!this._geocoder.options.showResultsWhileTyping) {
- if (!this._geocoder._typeahead.list.selectingListItem)
- this._geocoder._geocode(value);
- } else {
- if (this._geocoder.options.showResultMarkers) {
- this._geocoder._fitBoundsForMarkers();
- }
- this._geocoder._inputEl.value = this._geocoder._typeahead.query;
- this._geocoder.lastSelected = null;
- this._geocoder._typeahead.selected = null;
- return;
- }
- }
-
- if (
- value.length >= this._geocoder.options.minLength &&
- this._geocoder.options.showResultsWhileTyping
- ) {
- this._geocoder._geocode(value);
- }
- }, 300);
- this._mapGl!.addControl(this._geocoder, 'top-left');
-
- // There's no callback parameter in the options of the MaplibreGeocoder,
- // so this is how we get the selected result.
- this._geocoder._inputEl.addEventListener("change", () => {
- var selected = this._geocoder._typeahead.selected;
- this._onGeocodeChange(selected);
- });
- }
+ this._map.on("click", (e: MapMouseEvent) => {
+ this._onMapClick(e.lngLat);
+ });
- // Add custom controls
- if (this._controls) {
- this._controls.forEach((control) => {
- if (Array.isArray(control)) {
- const controlAndPosition: [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._map.on("dblclick", (e: MapMouseEvent) => {
+ this._onMapClick(e.lngLat, true);
+ });
- // Unload all GeoJSON that is present, and load new layers if present
- if(this._geoJsonConfig) {
- await this._loadGeoJSON(this._geoJsonConfig);
- } else {
- await this._loadGeoJSON(this._viewSettings?.geoJson);
- }
+ if (this._showGeoCodingControl && this._viewSettings && this._viewSettings.geocodeUrl) {
+ this._geocoder = new MaplibreGeocoder({forwardGeocode: this._forwardGeocode.bind(this), reverseGeocode: this._reverseGeocode }, { maplibregl, showResultsWhileTyping: true });
+ // Override the _onKeyDown function from MaplibreGeocoder which has a bug getting the value from the input element
+ this._geocoder._onKeyDown = debounce((e: KeyboardEvent) => {
+ var ESC_KEY_CODE = 27,
+ TAB_KEY_CODE = 9;
+
+ if (e.keyCode === ESC_KEY_CODE && this._geocoder.options.clearAndBlurOnEsc) {
+ this._geocoder._clear(e);
+ return this._geocoder._inputEl.blur();
+ }
+
+ // if target has shadowRoot, then get the actual active element inside the shadowRoot
+ var value = this._geocoder._inputEl.value || e.key;
+
+ if (!value) {
+ this._geocoder.fresh = true;
+ // the user has removed all the text
+ if (e.keyCode !== TAB_KEY_CODE) this._geocoder.clear(e);
+ return (this._geocoder._clearEl.style.display = "none");
+ }
+
+ // TAB, ESC, LEFT, RIGHT, UP, DOWN
+ if (
+ e.metaKey ||
+ [TAB_KEY_CODE, ESC_KEY_CODE, 37, 39, 38, 40].indexOf(e.keyCode) !== -1
+ )
+ return;
+
+ // ENTER
+ if (e.keyCode === 13) {
+ if (!this._geocoder.options.showResultsWhileTyping) {
+ if (!this._geocoder._typeahead.list.selectingListItem)
+ this._geocoder._geocode(value);
+ } else {
+ if (this._geocoder.options.showResultMarkers) {
+ this._geocoder._fitBoundsForMarkers();
+ }
+ this._geocoder._inputEl.value = this._geocoder._typeahead.query;
+ this._geocoder.lastSelected = null;
+ this._geocoder._typeahead.selected = null;
+ return;
+ }
+ }
+
+ if (
+ value.length >= this._geocoder.options.minLength &&
+ this._geocoder.options.showResultsWhileTyping
+ ) {
+ this._geocoder._geocode(value);
+ }
+ }, 300);
+ this._map!.addControl(this._geocoder, 'top-left');
+
+ // There's no callback parameter in the options of the MaplibreGeocoder,
+ // so this is how we get the selected result.
+ this._geocoder._inputEl.addEventListener("change", () => {
+ var selected = this._geocoder._typeahead.selected;
+ this._onGeocodeChange(selected);
+ });
+ }
- this._initLongPressEvent();
- this._mapGl.on("load", async () => await this.load());
+ // Add custom controls
+ if (this._controls) {
+ this._controls.forEach((control) => {
+ if (Array.isArray(control)) {
+ const controlAndPosition: [IControl, ControlPosition?] = control;
+ this._map!.addControl(controlAndPosition[0], controlAndPosition[1]);
+ } else {
+ this._map!.addControl(control);
+ }
+ });
+ } else {
+ // Add zoom and rotation controls to the map
+ this._map.addControl(new NavigationControl());
+ // Add current location controls to the map
+ this._map.addControl(new GeolocateControl({
+ positionOptions: {
+ enableHighAccuracy: true
+ },
+ showAccuracyCircle: true,
+ showUserLocation: true
+ }));
+ }
+
+ // Unload all GeoJSON that is present, and load new layers if present
+ if(this._geoJsonConfig) {
+ await this._loadGeoJSON(this._geoJsonConfig);
+ } else {
+ await this._loadGeoJSON(this._viewSettings?.geoJson);
}
+ this._initLongPressEvent();
+ this._map.on("load", async () => await this.load());
+
this._mapContainer.dispatchEvent(new OrMapLoadedEvent());
this._loaded = true;
this.createBoundaryBox()
@@ -501,8 +400,8 @@ export class MapWidget {
protected _styleLoaded(): Promise<void> {
return new Promise(resolve => {
- if (this._mapGl) {
- this._mapGl.once('style.load', resolve);
+ if (this._map) {
+ this._map.once('style.load', resolve);
}
});
}
@@ -511,25 +410,25 @@ export class MapWidget {
* Load map sources, layers and events
*/
public async load() {
- if (!this._mapGl || !this._loaded) {
+ if (!this._map || !this._loaded) {
console.warn("MapLibre Map not initialized!");
return;
}
- if (this._mapGl.getSource('mapPoints')) {
- if (this._mapGl.getLayer('unclustered-point')) {
- this._mapGl.removeLayer('unclustered-point');
+ if (this._map.getSource('mapPoints')) {
+ if (this._map.getLayer('unclustered-point')) {
+ this._map.removeLayer('unclustered-point');
}
- if (this._mapGl.getLayer('clusters')) {
- this._mapGl.removeLayer('clusters');
+ if (this._map.getLayer('clusters')) {
+ this._map.removeLayer('clusters');
}
- if (this._mapGl.getLayer('cluster-count')) {
- this._mapGl.removeLayer('cluster-count');
+ if (this._map.getLayer('cluster-count')) {
+ this._map.removeLayer('cluster-count');
}
- this._mapGl.removeSource('mapPoints');
+ this._map.removeSource('mapPoints');
}
- this._mapGl.addSource('mapPoints', {
+ this._map.addSource('mapPoints', {
'type': 'geojson',
'cluster': this._clusterConfig?.cluster ?? true,
'clusterRadius': this._clusterConfig?.clusterRadius ?? 180,
@@ -538,8 +437,8 @@ export class MapWidget {
'clusterProperties': Object.fromEntries(Object.keys(this._assetTypeColors).map(t => [t,["+", ["case", ["==", ["get", "assetType"], t], 1, 0]]]))
});
- if (!this._mapGl.getLayer('unclustered-point')) {
- this._mapGl.addLayer({
+ if (!this._map.getLayer('unclustered-point')) {
+ this._map.addLayer({
id: 'unclustered-point',
type: 'circle',
source: 'mapPoints',
@@ -548,29 +447,15 @@ export class MapWidget {
});
}
- this._mapGl.on("data", async (e: any) => {
- if (!this._mapGl) return;
- if (e.sourceId !== 'mapPoints' || !e.isSourceLoaded) return;
-
- this._mapGl.off('move', () => this._updateMarkers());
- this._mapGl.off('moveend', () => this._updateMarkers());
-
- this._mapGl.on('move', debounce(() => this._updateMarkers()));
- this._mapGl.on('moveend', () => this._updateMarkers());
- this._updateMarkers()
- })
+ this._map.on("data", this._onData);
}
// Clean up of internal resources associated with the map.
// Normally used during disconnectedCallback
public unload() {
- if(this._mapGl) {
- this._mapGl.remove();
- this._mapGl = undefined;
- }
- if(this._mapJs) {
- this._mapJs.remove();
- this._mapJs = undefined;
+ if (this._map) {
+ this._map.remove();
+ this._map = undefined;
}
}
@@ -582,12 +467,12 @@ export class MapWidget {
// Remove old layers
if(this._geoJsonLayers.size > 0) {
- this._geoJsonLayers.forEach((layer, layerId) => this._mapGl!.removeLayer(layerId));
+ this._geoJsonLayers.forEach((layer, layerId) => this._map!.removeLayer(layerId));
this._geoJsonLayers = new Map();
}
// Remove old sources
if(this._geoJsonSources.length > 0) {
- this._geoJsonSources.forEach((sourceId) => this._mapGl!.removeSource(sourceId));
+ this._geoJsonSources.forEach((sourceId) => this._map!.removeSource(sourceId));
this._geoJsonSources = [];
}
@@ -595,7 +480,7 @@ export class MapWidget {
if (this._showGeoJson && geoJsonConfig) {
// If array of features (most of the GeoJSONs use this)
- if(geoJsonConfig.source.type == "FeatureCollection") {
+ if (geoJsonConfig.source.type == "FeatureCollection") {
const groupedSources = this.groupSourcesByGeometryType(geoJsonConfig.source);
groupedSources?.forEach((features, type) => {
const newSource = {
@@ -612,7 +497,7 @@ export class MapWidget {
})
// Or only 1 feature is added
- } else if(geoJsonConfig.source.type == "Feature") {
+ } else if (geoJsonConfig.source.type == "Feature") {
const sourceInfo = this.addGeoJSONSource(geoJsonConfig.source);
if(sourceInfo) {
this.addGeoJSONLayer(sourceInfo.source.type, sourceInfo.sourceId);
@@ -626,8 +511,7 @@ export class MapWidget {
public groupSourcesByGeometryType(sources: FeatureCollection): Map<string, Feature[]> | undefined {
const groupedSources: Map<string, Feature[]> = new Map();
sources.features.forEach((feature) => {
- let sources: Feature[] | undefined = groupedSources.get(feature.geometry.type);
- if(sources == undefined) { sources = []; }
+ const sources = groupedSources.get(feature.geometry.type) ?? [];
sources.push(feature);
groupedSources.set(feature.geometry.type, sources);
})
@@ -635,11 +519,11 @@ export class MapWidget {
}
public addGeoJSONSource(source: GeoJSONSourceSpecification): { source: GeoJSONSourceSpecification, sourceId: string } | undefined {
- if(!this._mapGl) {
+ if (!this._map) {
console.error("mapGl instance not found!"); return;
}
const id = Date.now() + "-" + (this._geoJsonSources.length + 1);
- this._mapGl.addSource(id, source)
+ this._map.addSource(id, source)
this._geoJsonSources.push(id);
return {
source: source,
@@ -648,7 +532,7 @@ export class MapWidget {
}
public addGeoJSONLayer(typeString: string, sourceId: string) {
- if(!this._mapGl) {
+ if (!this._map) {
console.error("mapGl instance not found!"); return;
}
@@ -679,7 +563,7 @@ export class MapWidget {
'circle-color': realmColor
}
this._geoJsonLayers.set(layerId, layer);
- this._mapGl.addLayer(layer);
+ this._map.addLayer(layer);
break;
}
case "LineString":
@@ -690,7 +574,7 @@ export class MapWidget {
'line-width': 4
};
this._geoJsonLayers.set(layerId, layer);
- this._mapGl.addLayer(layer);
+ this._map.addLayer(layer);
break;
}
case "Polygon":
@@ -701,7 +585,7 @@ export class MapWidget {
'fill-opacity': 0.3
};
this._geoJsonLayers.set(layerId, layer);
- this._mapGl.addLayer(layer);
+ this._map.addLayer(layer);
// Add extra layer with outline
const outlineId = layerId + "-outline";
@@ -715,7 +599,7 @@ export class MapWidget {
},
} as AddLayerObject
this._geoJsonLayers.set(outlineId, outlineLayer);
- this._mapGl.addLayer(outlineLayer);
+ this._map.addLayer(outlineLayer);
break;
}
case "GeometryCollection": {
@@ -733,10 +617,10 @@ export class MapWidget {
}
protected _updateMarkers() {
- if (!this._mapGl) return;
+ if (!this._map) return;
- const newMarkers: Record<string, maplibregl.Marker> = {};
- const features = this._mapGl.querySourceFeatures('mapPoints');
+ const newMarkers: Record<string, Marker> = {};
+ const features = this._map.querySourceFeatures('mapPoints');
// Asset markers
for (const feature of features) {
@@ -748,12 +632,12 @@ export class MapWidget {
let marker = this._cachedMarkers[id]
if (!marker) {
const placeholder = document.createElement("div");
- marker = this._cachedMarkers[id] = new maplibregl.Marker({ element: placeholder }).setLngLat(coords);
+ marker = this._cachedMarkers[id] = new Marker({ element: placeholder }).setLngLat(coords);
}
newMarkers[id] = marker;
if (!this._markersOnScreen[id]) {
- marker.addTo(this._mapGl);
+ marker.addTo(this._map);
this._assetsOnScreen[id] = JSON.parse(feature.properties.asset);
};
}
@@ -771,13 +655,13 @@ export class MapWidget {
.filter(([k]) => this._assetTypeColors.hasOwnProperty(k))
.map(([type, count]) => [type, this._assetTypeColors[type], count]);
- marker = this._cachedMarkers[id] = new maplibregl.Marker({
- element: new OrClusterMarker(slices, id, lng, lat, this._mapGl),
+ marker = this._cachedMarkers[id] = new Marker({
+ element: new OrClusterMarker(slices, id, lng, lat, this._map),
}).setLngLat([lng, lat]);
}
newMarkers[id] = marker;
- if (!this._markersOnScreen[id]) marker.addTo(this._mapGl);
+ if (!this._markersOnScreen[id]) marker.addTo(this._map);
}
for (const id in this._markersOnScreen) {
@@ -846,110 +730,59 @@ export class MapWidget {
}
protected _updateMarkerPosition(marker: OrMapMarker) {
- switch (this._type) {
- case MapType.RASTER:
- const m: L.Marker | undefined = this._markersJs.get(marker);
- if (m) {
- m.setLatLng([marker.lat!, marker.lng!]);
- }
- break;
- case MapType.VECTOR:
- const mGl: MarkerGL | undefined = this._markersGl.get(marker);
- if (mGl) {
- mGl.setLngLat([marker.lng!, marker.lat!]);
- }
- break;
- }
+ this._markers.get(marker)?.setLngLat([marker.lng!, marker.lat!]);
this._createMarkerRadius(marker);
}
protected _updateMarkerElement(marker: OrMapMarker, doAdd: boolean) {
+ let mGl = this._markers.get(marker);
+ if (mGl) {
+ marker._actualMarkerElement = undefined;
+ this._removeMarkerClickHandler(marker, mGl.getElement());
+ mGl.remove();
+ this._markers.delete(marker);
+ }
- switch (this._type) {
- case MapType.RASTER:
- let m = this._markersJs.get(marker);
- if (m) {
- this._removeMarkerClickHandler(marker, marker.markerContainer as HTMLElement);
- marker._actualMarkerElement = undefined;
- (m as any).removeFrom(this._mapJs!);
- this._markersJs.delete(marker);
- }
-
- if (doAdd) {
- const elem = marker._createMarkerElement();
- if (elem) {
- const icon = L.divIcon({html: elem.outerHTML, className: "or-marker-raster"});
- m = L.marker([marker.lat!, marker.lng!], {icon: icon, clickable: marker.interactive});
- m.addTo(this._mapJs!);
- marker._actualMarkerElement = (m as any).getElement() ? (m as any).getElement().firstElementChild as HTMLDivElement : undefined;
- if (marker.interactive) {
- this._addMarkerClickHandler(marker, marker.markerContainer as HTMLElement);
- }
-
- this._markersJs.set(marker, m);
- }
- if(marker.radius) {
- this._createMarkerRadius(marker);
- }
- }
-
- break;
- case MapType.VECTOR:
- let mGl = this._markersGl.get(marker);
- if (mGl) {
- marker._actualMarkerElement = undefined;
- this._removeMarkerClickHandler(marker, mGl.getElement());
- mGl.remove();
- this._markersGl.delete(marker);
- }
-
- if (doAdd) {
- const elem = marker._createMarkerElement();
+ if (doAdd) {
+ const elem = marker._createMarkerElement();
- if (elem) {
- mGl = new MarkerGL({
- element: elem,
- anchor: "top-left"
- })
- .setLngLat([marker.lng!, marker.lat!])
- .addTo(this._mapGl!);
+ if (elem) {
+ mGl = new Marker({
+ element: elem,
+ anchor: "top-left"
+ })
+ .setLngLat([marker.lng!, marker.lat!])
+ .addTo(this._map!);
- this._markersGl.set(marker, mGl);
+ this._markers.set(marker, mGl);
- marker._actualMarkerElement = mGl.getElement() as HTMLDivElement;
+ marker._actualMarkerElement = mGl.getElement() as HTMLDivElement;
- if (marker.interactive) {
- this._addMarkerClickHandler(marker, mGl.getElement());
- }
- }
- if(marker.radius) {
- this._createMarkerRadius(marker);
- }
+ if (marker.interactive) {
+ this._addMarkerClickHandler(marker, mGl.getElement());
}
-
-
- break;
+ }
+ if (marker.radius) {
+ this._createMarkerRadius(marker);
+ }
}
}
protected _removeMarkerRadius(marker:OrMapMarker){
-
- 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');
+ if (this._map && this._loaded && marker.radius && marker.lat && marker.lng) {
+ if (this._map.getSource('circleData')) {
+ this._map.removeLayer('marker-radius-circle');
+ this._map.removeSource('circleData');
}
}
-
}
protected _createMarkerRadius(marker:OrMapMarker){
- if(this._mapGl && this._loaded && marker.radius && marker.lat && marker.lng){
+ if (this._map && this._loaded && marker.radius && marker.lat && marker.lng){
this._removeMarkerRadius(marker);
- this._mapGl.addSource('circleData', {
+ this._map.addSource('circleData', {
type: 'geojson',
data: {
type: 'FeatureCollection',
@@ -964,7 +797,7 @@ export class MapWidget {
}
});
- this._mapGl.addLayer({
+ this._map.addLayer({
"id": "marker-radius-circle",
"type": "circle",
"source": "circleData",
@@ -985,11 +818,11 @@ export class MapWidget {
}
public createBoundaryBox(boundsArray: string[] = []){
- if(this._mapGl && this._loaded && this._showBoundaryBox && this._viewSettings?.bounds){
+ if (this._map && this._loaded && this._showBoundaryBox && this._viewSettings?.bounds) {
- if (this._mapGl.getSource('bounds')) {
- this._mapGl.removeLayer('bounds');
- this._mapGl.removeSource('bounds');
+ if (this._map.getSource('bounds')) {
+ this._map.removeLayer('bounds');
+ this._map.removeSource('bounds');
}
if (boundsArray.length !== 4){
@@ -1004,13 +837,13 @@ export class MapWidget {
[boundsArray[0], boundsArray[3]]
]
]
- this._mapGl.fitBounds([
+ this._map.fitBounds([
parseFloat(boundsArray[0]) + .01,
parseFloat(boundsArray[1]) - .01,
parseFloat(boundsArray[2]) - .01,
parseFloat(boundsArray[3]) + .01,
])
- this._mapGl.addSource('bounds', {
+ this._map.addSource('bounds', {
'type': 'geojson',
'data': {
'type': 'Feature',
@@ -1023,7 +856,7 @@ export class MapWidget {
}
});
- this._mapGl.addLayer({
+ this._map.addLayer({
'id': 'bounds',
'type': 'fill',
'source': 'bounds',
@@ -1117,12 +950,12 @@ export class MapWidget {
}
protected _initLongPressEvent() {
- if (this._mapGl) {
+ if (this._map) {
let pressTimeout: NodeJS.Timeout | null;
let pos: LngLat;
let clearTimeoutFunc = () => { if (pressTimeout) clearTimeout(pressTimeout); pressTimeout = null; };
- this._mapGl.on('touchstart', (e) => {
+ this._map.on('touchstart', (e) => {
if (e.originalEvent.touches.length > 1) {
return;
}
@@ -1132,7 +965,7 @@ export class MapWidget {
}, 500);
});
- this._mapGl.on('mousedown', (e) => {
+ this._map.on('mousedown', (e) => {
if (!pressTimeout) {
pos = e.lngLat;
pressTimeout = setTimeout(() => {
@@ -1142,15 +975,15 @@ export class MapWidget {
}
});
- this._mapGl.on('dragstart', clearTimeoutFunc);
- this._mapGl.on('mouseup', clearTimeoutFunc);
- this._mapGl.on('touchend', clearTimeoutFunc);
- this._mapGl.on('touchcancel', clearTimeoutFunc);
- this._mapGl.on('touchmove', clearTimeoutFunc);
- this._mapGl.on('moveend', clearTimeoutFunc);
- this._mapGl.on('gesturestart', clearTimeoutFunc);
- this._mapGl.on('gesturechange', clearTimeoutFunc);
- this._mapGl.on('gestureend', clearTimeoutFunc);
+ this._map.on('dragstart', clearTimeoutFunc);
+ this._map.on('mouseup', clearTimeoutFunc);
+ this._map.on('touchend', clearTimeoutFunc);
+ this._map.on('touchcancel', clearTimeoutFunc);
+ this._map.on('touchmove', clearTimeoutFunc);
+ this._map.on('moveend', clearTimeoutFunc);
+ this._map.on('gesturestart', clearTimeoutFunc);
+ this._map.on('gesturechange', clearTimeoutFunc);
+ this._map.on('gestureend', clearTimeoutFunc);
}
};
diff --git a/ui/component/or-map/src/style.ts b/ui/component/or-map/src/style.ts
index 07149d3ed..ff217bdb6 100644
--- a/ui/component/or-map/src/style.ts
+++ b/ui/component/or-map/src/style.ts
@@ -64,7 +64,6 @@ export const style = css`
top: 0;
bottom: 0;
}
- .mapboxgl-ctrl-geocoder,
.maplibregl-ctrl-geocoder--input {
width: calc(100% - 20px)
}
@@ -73,14 +72,10 @@ export const style = css`
.maplibregl-ctrl-bottom-left,.maplibregl-ctrl-bottom-right, .maplibregl-ctrl-top-left, .maplibregl-ctrl-top-right {
z-index: 1;
}
- .leaflet-marker-icon, .maplibregl-marker, .mapboxgl-marker {
+ .maplibregl-marker {
pointer-events: none !important;
}
- .or-map-marker {
- position: absolute; /* This makes mapboxJS behave like mapboxGL */
- }
-
.or-map-marker.active {
z-index: 1;
}
diff --git a/ui/component/or-map/src/util/index.ts b/ui/component/or-map/src/util/index.ts
index 5be844374..49888f197 100644
--- a/ui/component/or-map/src/util/index.ts
+++ b/ui/component/or-map/src/util/index.ts
@@ -84,13 +84,6 @@ export function getLngLatBounds(lngLatBoundsLike?: LngLatBoundsLike): LngLatBoun
}
}
-export function getLatLngBounds(lngLatBoundsLike?: LngLatBoundsLike): L.LatLngBounds | undefined {
- const lngLatBounds = getLngLatBounds(lngLatBoundsLike);
- if (lngLatBounds) {
- return L.latLngBounds(lngLatBounds.getNorthEast()!, lngLatBounds.getSouthWest()!);
- }
-}
-
export interface OverrideConfigSettings {
markerConfig: MapMarkerColours;
currentValue: any;
diff --git a/ui/knip.jsonc b/ui/knip.jsonc
index 3efb01051..db90212c1 100644
--- a/ui/knip.jsonc
+++ b/ui/knip.jsonc
@@ -10,7 +10,6 @@
],
"ignoreDependencies": [
"@types/react", // Required by mdx which is used in Storybook
- "@types/mapbox", // Global types under the L namespace (no direct import)
"@webcomponents/webcomponentsjs", // Imported through index.html files for apps
"@types/offscreencanvas", // Referenced in the tsconfig file
"@vaadin/vaadin-lumo-styles", // Only imports CSS files
diff --git a/ui/util/webpack.util.js b/ui/util/webpack.util.js
index 06bd957b2..8b15aa4e7 100644
--- a/ui/util/webpack.util.js
+++ b/ui/util/webpack.util.js
@@ -8,12 +8,12 @@ function getStandardModuleRules() {
return {
rules: [
{
- test: /(maplibre|mapbox|@material|gridstack|@mdi).*\.css$/, //output css as strings
+ test: /(maplibre|@material|gridstack|@mdi).*\.css$/, //output css as strings
type: "asset/source"
},
{
test: /\.css$/, //
- exclude: /(maplibre|mapbox|@material|gridstack|@mdi).*\.css$/,
+ exclude: /(maplibre|@material|gridstack|@mdi).*\.css$/,
use: [
{ loader: "css-loader" }
]
diff --git a/yarn.lock b/yarn.lock
index 9a032a827..385035d25 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -849,13 +849,6 @@ __metadata:
languageName: node
linkType: hard
-"@mapbox/corslite@npm:0.0.7":
- version: 0.0.7
- resolution: "@mapbox/corslite@npm:0.0.7"
- checksum: 10c0/9b7818377d6f1b44c1c39782fa37350894da03663f6c050e7b340fb7f45100a26c0a1eeb0c478612a43cf60ba55f85c5dfe2184b06230734e059d2c5c458ecbd
- languageName: node
- linkType: hard
-
"@mapbox/geojson-rewind@npm:^0.5.2":
version: 0.5.2
resolution: "@mapbox/geojson-rewind@npm:0.5.2"
@@ -882,13 +875,6 @@ __metadata:
languageName: node
linkType: hard
-"@mapbox/sanitize-caja@npm:^0.1.4":
- version: 0.1.4
- resolution: "@mapbox/sanitize-caja@npm:0.1.4"
- checksum: 10c0/9b4d58f25ab746b1fdee11ae692f7d6ae16baf20540fb8c85195d6a2ec651db697cc0608982e0e76ce97bc4b0b944937748b6920f2029385cb1db22469e622e3
- languageName: node
- linkType: hard
-
"@mapbox/tiny-sdf@npm:^2.0.7":
version: 2.0.7
resolution: "@mapbox/tiny-sdf@npm:2.0.7"
@@ -2075,11 +2061,9 @@ __metadata:
"@openremote/or-translate": "workspace:*"
"@types/geojson": "npm:^7946.0.7"
"@types/lodash.debounce": "npm:^4"
- "@types/mapbox": "npm:^1.6.42"
lit: "npm:^3.3.1"
lit-html: "npm:^3.3.1"
lodash.debounce: "npm:^4.0.8"
- mapbox.js: "npm:^3.3.1"
maplibre-gl: "npm:^5.12.0"
languageName: unknown
linkType: soft
@@ -3370,15 +3354,6 @@ __metadata:
languageName: node
linkType: hard
-"@types/leaflet@npm:^0":
- version: 0.7.40
- resolution: "@types/leaflet@npm:0.7.40"
- dependencies:
- "@types/geojson": "npm:*"
- checksum: 10c0/6375d03e83f870b46398a8761daf6f1995177977aaa463ef8d24c47fe0e03e14fed82ff09680126b95981b8a2d1db531ddfdae265d2ce4a91fdbb8918088162d
- languageName: node
- linkType: hard
-
"@types/lodash.debounce@npm:^4":
version: 4.0.9
resolution: "@types/lodash.debounce@npm:4.0.9"
@@ -3413,15 +3388,6 @@ __metadata:
languageName: node
linkType: hard
-"@types/mapbox@npm:^1.6.42":
- version: 1.6.45
- resolution: "@types/mapbox@npm:1.6.45"
- dependencies:
- "@types/leaflet": "npm:^0"
- checksum: 10c0/dacb4ea52a0293ca9275086aab1f951d9930200f52234e4720f9ba40c64d204658fc3e86705afb44e92e546a7d5c26019d60c2999134a351e1fcba15e9ef4b9c
- languageName: node
- linkType: hard
-
"@types/mdx@npm:^2.0.0":
version: 2.0.13
resolution: "@types/mdx@npm:2.0.13"
@@ -8234,13 +8200,6 @@ __metadata:
languageName: node
linkType: hard
-"leaflet@npm:1.4.0":
- version: 1.4.0
- resolution: "leaflet@npm:1.4.0"
- checksum: 10c0/a50445a03da005ff89ba022098d811bf54b31d359b210f6b4304e062d1e9aa7ab01e237bb45f0bc745d474b4d0a21822de25ef6ab1561a279961c2bba2e68160
- languageName: node
- linkType: hard
-
"levn@npm:^0.4.1":
version: 0.4.1
resolution: "levn@npm:0.4.1"
@@ -8439,18 +8398,6 @@ __metadata:
languageName: node
linkType: hard
-"mapbox.js@npm:^3.3.1":
- version: 3.3.1
- resolution: "mapbox.js@npm:3.3.1"
- dependencies:
- "@mapbox/corslite": "npm:0.0.7"
- "@mapbox/sanitize-caja": "npm:^0.1.4"
- leaflet: "npm:1.4.0"
- mustache: "npm:3.0.1"
- checksum: 10c0/4fb1106548961485612c19f0870376e1308847fa39ea1d575b9c3de7c2c7b170445900835b2818b1e2124d9665837dfbadeb7ff6f3894715e635b2238c8b6100
- languageName: node
- linkType: hard
-
"maplibre-gl@npm:^5.12.0":
version: 5.12.0
resolution: "maplibre-gl@npm:5.12.0"
@@ -8802,15 +8749,6 @@ __metadata:
languageName: node
linkType: hard
-"mustache@npm:3.0.1":
- version: 3.0.1
- resolution: "mustache@npm:3.0.1"
- bin:
- mustache: ./bin/mustache
- checksum: 10c0/2d2b2f17e9b798b74c548674bdd5bdee76fad2e8a1723da45f3822417b589aec964d5fb05f5eefb12b3d2e8305afdbecc91057ae8ce54bf5278a05c57b613a47
- languageName: node
- linkType: hard
-
"nanoid@npm:^2.1.0":
version: 2.1.11
resolution: "nanoid@npm:2.1.11"