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
Mapbox API JsInterop implementation added
Rich Turnerab9b6271390f
diff --git a/manager/src/main/java/org/openremote/manager/client/interop/mapbox/AnimationOptions.java b/manager/src/main/java/org/openremote/manager/client/interop/mapbox/AnimationOptions.javanew file mode 100644index 000000000..1cdad7b6e--- /dev/null+++ b/manager/src/main/java/org/openremote/manager/client/interop/mapbox/AnimationOptions.java@@ -0,0 +1,21 @@+package org.openremote.manager.client.interop.mapbox;++import elemental.json.JsonArray;+import elemental.json.JsonNumber;+import jsinterop.annotations.JsPackage;+import jsinterop.annotations.JsProperty;+import jsinterop.annotations.JsType;++public class AnimationOptions {+ @JsProperty+ public int duration;++ @JsProperty+ public EasingFn easing;++ @JsProperty+ public JsonArray offset;++ @JsProperty+ public boolean animate;+}diff --git a/manager/src/main/java/org/openremote/manager/client/interop/mapbox/CameraOptions.java b/manager/src/main/java/org/openremote/manager/client/interop/mapbox/CameraOptions.javanew file mode 100644index 000000000..c55da8916--- /dev/null+++ b/manager/src/main/java/org/openremote/manager/client/interop/mapbox/CameraOptions.java@@ -0,0 +1,20 @@+package org.openremote.manager.client.interop.mapbox;++import jsinterop.annotations.JsProperty;++public class CameraOptions {+ @JsProperty+ public LngLat center;++ @JsProperty+ public int zoom;++ @JsProperty+ public int bearing;++ @JsProperty+ public int pitch;++ @JsProperty+ public LngLat around;+}diff --git a/manager/src/main/java/org/openremote/manager/client/interop/mapbox/Control.java b/manager/src/main/java/org/openremote/manager/client/interop/mapbox/Control.javanew file mode 100644index 000000000..e15490bc2--- /dev/null+++ b/manager/src/main/java/org/openremote/manager/client/interop/mapbox/Control.java@@ -0,0 +1,11 @@+package org.openremote.manager.client.interop.mapbox;++import jsinterop.annotations.JsType;++@JsType(isNative = true, name = "Control")+public abstract class Control<T> {++ public native T addTo(Map map);++ public native void remove();+}diff --git a/manager/src/main/java/org/openremote/manager/client/interop/mapbox/EasingFn.java b/manager/src/main/java/org/openremote/manager/client/interop/mapbox/EasingFn.javanew file mode 100644index 000000000..b069e5b23--- /dev/null+++ b/manager/src/main/java/org/openremote/manager/client/interop/mapbox/EasingFn.java@@ -0,0 +1,9 @@+package org.openremote.manager.client.interop.mapbox;++import jsinterop.annotations.JsFunction;++@FunctionalInterface+@JsFunction+public interface EasingFn {+ void ease(double easeFactor);+}diff --git a/manager/src/main/java/org/openremote/manager/client/interop/mapbox/EventData.java b/manager/src/main/java/org/openremote/manager/client/interop/mapbox/EventData.javanew file mode 100644index 000000000..698d4efd1--- /dev/null+++ b/manager/src/main/java/org/openremote/manager/client/interop/mapbox/EventData.java@@ -0,0 +1,15 @@+package org.openremote.manager.client.interop.mapbox;++import elemental.events.Event;+import jsinterop.annotations.JsProperty;++public class EventData {+ @JsProperty+ public native Event getOriginalEvent();++ @JsProperty+ public native Point getPoint();++ @JsProperty+ public native LngLat getLngLat();+}diff --git a/manager/src/main/java/org/openremote/manager/client/interop/mapbox/EventDataFn.java b/manager/src/main/java/org/openremote/manager/client/interop/mapbox/EventDataFn.javanew file mode 100644index 000000000..55ee54c12--- /dev/null+++ b/manager/src/main/java/org/openremote/manager/client/interop/mapbox/EventDataFn.java@@ -0,0 +1,9 @@+package org.openremote.manager.client.interop.mapbox;++import jsinterop.annotations.JsFunction;++@FunctionalInterface+@JsFunction+public interface EventDataFn {+ void onFire(EventData eventData);+}diff --git a/manager/src/main/java/org/openremote/manager/client/interop/mapbox/EventType.java b/manager/src/main/java/org/openremote/manager/client/interop/mapbox/EventType.javanew file mode 100644index 000000000..1f18e8645--- /dev/null+++ b/manager/src/main/java/org/openremote/manager/client/interop/mapbox/EventType.java@@ -0,0 +1,23 @@+package org.openremote.manager.client.interop.mapbox;++public class EventType {+ private EventType(){}++ public static final String CLICK = "click";+ public static final String DOUBLE_CLICK = "dblclick";+ public static final String DRAG = "drag";+ public static final String DRAG_START = "dragstart";+ public static final String DRAG_END = "dragend";+ public static final String MOUSE_DOWN = "mousedown";+ public static final String MOUSE_MOVE = "mousemove";+ public static final String MOUSE_UP = "mouseup";+ public static final String MOVE = "move";+ public static final String MOVE_END = "moveend";+ public static final String MOUSE_START = "movestart";+ public static final String ROTATE = "rotate";+ public static final String ROTATE_END = "rotateend";+ public static final String ROTATE_START = "rotatestart";+ public static final String ZOOM = "zoom";+ public static final String ZOOM_END = "zoomend";+ public static final String ZOOM_START = "zoomstart";+}diff --git a/manager/src/main/java/org/openremote/manager/client/interop/mapbox/FeaturesCallbackFn.java b/manager/src/main/java/org/openremote/manager/client/interop/mapbox/FeaturesCallbackFn.javanew file mode 100644index 000000000..fb6da3d0a--- /dev/null+++ b/manager/src/main/java/org/openremote/manager/client/interop/mapbox/FeaturesCallbackFn.java@@ -0,0 +1,11 @@+package org.openremote.manager.client.interop.mapbox;++import elemental.json.JsonArray;+import elemental.json.JsonObject;+import jsinterop.annotations.JsFunction;++@FunctionalInterface+@JsFunction+public interface FeaturesCallbackFn {+ void onCallback(JsonObject error, JsonArray features);+}diff --git a/manager/src/main/java/org/openremote/manager/client/interop/mapbox/LngLat.java b/manager/src/main/java/org/openremote/manager/client/interop/mapbox/LngLat.javanew file mode 100644index 000000000..4d20e93ae--- /dev/null+++ b/manager/src/main/java/org/openremote/manager/client/interop/mapbox/LngLat.java@@ -0,0 +1,16 @@+package org.openremote.manager.client.interop.mapbox;++import jsinterop.annotations.JsProperty;+import jsinterop.annotations.JsType;++@JsType(isNative = true, name = "LngLat", namespace = "mapboxgl")+public class LngLat {+ public LngLat(double lng, double lat) {}++ @JsProperty+ public native double getLat();++ @JsProperty+ public native double getLng();++}diff --git a/manager/src/main/java/org/openremote/manager/client/interop/mapbox/LngLatBounds.java b/manager/src/main/java/org/openremote/manager/client/interop/mapbox/LngLatBounds.javanew file mode 100644index 000000000..02197c8a6--- /dev/null+++ b/manager/src/main/java/org/openremote/manager/client/interop/mapbox/LngLatBounds.java@@ -0,0 +1,31 @@+package org.openremote.manager.client.interop.mapbox;++import jsinterop.annotations.JsProperty;+import jsinterop.annotations.JsType;++@JsType(isNative = true, name = "LngLatBounds", namespace = "mapboxgl")+public class LngLatBounds {+ public LngLatBounds(LngLat sw, LngLat ne) {}++ public native LngLat getNorthEast();++ public native LngLat getSouthWest();++ public native LngLat getSouthEast();++ public native LngLat getNorthWest();++ public native LngLat getCenter();++ public native double getNorth();++ public native double getEast();++ public native double getSouth();++ public native double getWest();++ public native LngLatBounds extend(LngLat includeLngLat);++ public native LngLatBounds extend(LngLatBounds includeBounds);+}diff --git a/manager/src/main/java/org/openremote/manager/client/interop/mapbox/Map.java b/manager/src/main/java/org/openremote/manager/client/interop/mapbox/Map.javanew file mode 100644index 000000000..bbde7c87c--- /dev/null+++ b/manager/src/main/java/org/openremote/manager/client/interop/mapbox/Map.java@@ -0,0 +1,169 @@+package org.openremote.manager.client.interop.mapbox;++import elemental.dom.Node;+import elemental.json.JsonArray;+import elemental.json.JsonObject;+import elemental.json.JsonValue;+import jsinterop.annotations.JsProperty;+import jsinterop.annotations.JsType;++@JsType(isNative = true, name = "Map", namespace = "mapboxgl")+public class Map {+ @JsProperty+ public boolean debug;++ @JsProperty+ public boolean loaded;++ // TODO: Get this to work with MapOptions JsType+ public Map(JsonObject options) {}++ public native Map addClass(String className);+ public native Map addClass(String className, JsonObject styleOptions);++ public native Map addControl(Control control);++ public native Map addLayer(Object layer);+ public native Map addLayer(Object layer, String beforeLayerId);++ public native Map addSource(String id, Object source);++ // TODO: add batch method fucntionality to map+// public native void batch(WorkFn work);++ // TODO: Add bounding box event support to the map+ public native void on(String eventType, EventDataFn eventDataFn);++ public native Map easeTo(CameraOptions cameraOptions);+ public native Map easeTo(AnimationOptions animationOptions);++ public native Map featuresAt(Point point, JsonObject options, FeaturesCallbackFn callbackFn);++ public native Map featuresIn(JsonObject options, FeaturesCallbackFn callbackFn);+ public native Map featuresIn(Point[] bounds, JsonObject options, FeaturesCallbackFn callbackFn);++ public native Map fitBounds(LngLatBounds bounds, JsonObject options);+ public native Map fitBounds(LngLatBounds bounds, JsonObject options, EventData eventData);++ public native Map flyTo(JsonObject options);++ public native Map flyTo(JsonObject options, EventData eventData);++ public native double getBearing();++ public native LngLatBounds getBounds();++ public native Node getCanvas();++ public native Node getCanvasContainer();++ public native LngLat getCenter();++ public native String[] getClasses();++ public native Node getContainer();++ public native JsonArray getFilter(String layerId);++ public native JsonObject getLayer(String layerId);++ public native JsonValue getLayoutProperty(String layerId, String propertyName);+ public native JsonValue getLayoutProperty(String layerId, String propertyName, String className);++ public native JsonValue getPaintProperty(String layerId, String propertyName);+ public native JsonValue getPaintProperty(String layerId, String propertyName, String className);++ public native double getPitch();++ public native JsonObject getSource(String sourceId);++ public native JsonObject getStyle();++ public native int getZoom();++ public native boolean hasClass(String className);++ public native Map jumpTo(CameraOptions options);+ public native Map jumpTo(CameraOptions options, EventData eventData);++ public native Map panBy(int[] offset, AnimationOptions options);+ public native Map panBy(int[] offset, AnimationOptions options, EventData eventData);++ public native Map panTo(LngLat lngLat, AnimationOptions options);+ public native Map panTo(LngLat lngLat, AnimationOptions options, EventData eventData);++ public native JsonObject project(LngLat lngLat);++ public native void remove();++ public native Map removeClass(String className);+ public native Map removeClass(String className, JsonObject options);++ public native Map removeLayer(String layerId);++ public native Map removeSource(String layerId);++ public native void repaint();++ public native Map resetNorth();+ public native Map resetNorth(EventData eventData);+ public native Map resetNorth(AnimationOptions options);+ public native Map resetNorth(AnimationOptions options, EventData eventData);++ public native Map resize();++ public native Map rotateTo(int bearing);+ public native Map rotateTo(int bearing, EventData eventData);+ public native Map rotateTo(int bearing, AnimationOptions options);+ public native Map rotateTo(int bearing, AnimationOptions options, EventData eventData);++ public native Map setBearing(int bearing);+ public native Map setBearing(int bearing, EventData eventData);++ public native Map setCenter(LngLat center);+ public native Map setCenter(LngLat center, EventData eventData);++ public native Map setClasses(String[] classNames);+ public native Map setClasses(String[] classNames, JsonObject options);++ public native Map setFilter(String layerId, JsonObject filter);++ public native Map setLayerZoomRange(String layerId, int minZoom, int maxZoom);++ public native Map setLayoutProperty(String layerId, String propertyName, JsonValue propertyValue);++ public native Map setPaintProperty(String layerId, String propertyName, JsonValue propertyValue);+ public native Map setPaintProperty(String layerId, String propertyName, JsonValue propertyValue, String classSpecifier);++ public native Map setPitch(int pitch);+ public native Map setPitch(int pitch, EventData eventData);++ public native Map setStyle(JsonObject style);++ public native Map setZoom(int zoom);+ public native Map setZoom(int zoom, EventData eventData);++ public native Map snapToNorth();+ public native Map snapToNorth(AnimationOptions options);+ public native Map snapToNorth(EventData eventData);+ public native Map snapToNorth(AnimationOptions options, EventData eventData);++ public native Map stop();++ public native LngLat unproject(Point point);++ public native Map zoomIn();+ public native Map zoomIn(EventData eventData);+ public native Map zoomIn(AnimationOptions options);+ public native Map zoomIn(AnimationOptions options, EventData eventData);++ public native Map zoomOut();+ public native Map zoomOut(EventData eventData);+ public native Map zoomOut(AnimationOptions options);+ public native Map zoomOut(AnimationOptions options, EventData eventData);++ public native Map zoomTo(int zoom);+ public native Map zoomTo(int zoom, AnimationOptions options);+ public native Map zoomTo(int zoom, EventData eventData);+ public native Map zoomTo(int zoom, AnimationOptions options, EventData eventData);+}diff --git a/manager/src/main/java/org/openremote/manager/client/interop/mapbox/MapOptions.java b/manager/src/main/java/org/openremote/manager/client/interop/mapbox/MapOptions.javanew file mode 100644index 000000000..a94b937f0--- /dev/null+++ b/manager/src/main/java/org/openremote/manager/client/interop/mapbox/MapOptions.java@@ -0,0 +1,169 @@+package org.openremote.manager.client.interop.mapbox;++import elemental.json.JsonArray;+import elemental.json.JsonObject;+import jsinterop.annotations.JsProperty;+import jsinterop.annotations.JsType;++@JsType+ public class MapOptions {+ @JsProperty+ public boolean touchZoomRotate;++ @JsProperty+ public int zoom;++ @JsProperty+ public int minZoom;++ @JsProperty+ public int maxZoom;++ @JsProperty+ public JsonObject style;++ @JsProperty+ public boolean hash;++ @JsProperty+ public boolean interactive;++ @JsProperty+ public int bearingSnap;++ @JsProperty+ public JsonArray classes;++ @JsProperty+ public boolean attributionControl;++ @JsProperty+ public String container;++ @JsProperty+ public boolean preserveDrawingBuffer;++ @JsProperty+ public LngLatBounds maxBounds;++ @JsProperty+ public boolean scrollZoom;++ @JsProperty+ public boolean boxZoom;++ @JsProperty+ public boolean dragRotate;++ @JsProperty+ public boolean dragPan;++ @JsProperty+ public boolean keyboard;++ @JsProperty+ public boolean doubleclickZoom;++ @JsProperty+ public boolean failIfMajorPerformanceCaveat;++// @JsProperty+// boolean getTouchZoomRotate();+// @JsProperty+// void setTouchZoomRotate(boolean value);+//+// @JsProperty+// int getZoom();+// @JsProperty+// void setZoom(int value);+//+// @JsProperty+// int getMinZoom();+// @JsProperty+// void setMinZoom(int value);+//+// @JsProperty+// int getMaxZoom();+// @JsProperty+// void setMaxZoom(int value);+//+// @JsProperty+// JsonObject getStyle();+// @JsProperty+// void setStyle(JsonObject value);+//+// @JsProperty+// boolean getHash();+// @JsProperty+// void setHash(boolean value);+//+// @JsProperty+// boolean getInteractive();+// @JsProperty+// void setInteractive(boolean value);+//+// @JsProperty+// int getBearingSnap();+// @JsProperty+// void setBearingSnap(int value);+//+// @JsProperty+// JsonArray getClasses();+// @JsProperty+// void setClasses(JsonArray value);+//+// @JsProperty+// boolean getAttributionControl();+// @JsProperty+// void setAttributionControl(boolean value);+//+// @JsProperty+// String getContainer();+// @JsProperty+// void setContainer(String value);+//+// @JsProperty+// boolean getPreserveDrawingBuffer();+// @JsProperty+// void setPreserveDrawingBuffer(boolean value);+//+// @JsProperty+// LngLatBounds getMaxBounds();+// @JsProperty+// void setMaxBounds(LngLatBounds value);+//+// @JsProperty+// boolean getScrollZoom();+// @JsProperty+// void setScrollZoom(boolean value);+//+// @JsProperty+// boolean getBoxZoom();+// @JsProperty+// void setBoxZoom(boolean value);+//+// @JsProperty+// boolean getDragRotate();+// @JsProperty+// void setDragRotate(boolean value);+//+// @JsProperty+// boolean getDragPan();+// @JsProperty+// void setDragPen(boolean value);+//+// @JsProperty+// boolean getKeyboard();+// @JsProperty+// void setKeyboard(boolean value);+//+// @JsProperty+// boolean getDoubleclickZoom();+// @JsProperty+// void setDoubleClickZoom(boolean value);+//+// @JsProperty+// boolean getFailIfMajorPerformanceCaveat();+// @JsProperty+// void setFailIfMajorPerformanceCaveat(boolean value);+}diff --git a/manager/src/main/java/org/openremote/manager/client/interop/mapbox/Mapbox.java b/manager/src/main/java/org/openremote/manager/client/interop/mapbox/Mapbox.javanew file mode 100644index 000000000..22dbd8f31--- /dev/null+++ b/manager/src/main/java/org/openremote/manager/client/interop/mapbox/Mapbox.java@@ -0,0 +1,9 @@+package org.openremote.manager.client.interop.mapbox;++import jsinterop.annotations.JsPackage;+import jsinterop.annotations.JsType;++@JsType(isNative = true, name = "mapboxgl", namespace = JsPackage.GLOBAL)+public class Mapbox {++}diff --git a/manager/src/main/java/org/openremote/manager/client/interop/mapbox/Navigation.java b/manager/src/main/java/org/openremote/manager/client/interop/mapbox/Navigation.javanew file mode 100644index 000000000..a473857f1--- /dev/null+++ b/manager/src/main/java/org/openremote/manager/client/interop/mapbox/Navigation.java@@ -0,0 +1,8 @@+package org.openremote.manager.client.interop.mapbox;++import jsinterop.annotations.JsType;++@JsType(isNative = true, name = "Navigation", namespace = "mapboxgl")+public class Navigation extends Control<Navigation> {+ public Navigation() {}+}diff --git a/manager/src/main/java/org/openremote/manager/client/interop/mapbox/Point.java b/manager/src/main/java/org/openremote/manager/client/interop/mapbox/Point.javanew file mode 100644index 000000000..fa4f46806--- /dev/null+++ b/manager/src/main/java/org/openremote/manager/client/interop/mapbox/Point.java@@ -0,0 +1,16 @@+package org.openremote.manager.client.interop.mapbox;++import jsinterop.annotations.JsPackage;+import jsinterop.annotations.JsProperty;+import jsinterop.annotations.JsType;++@JsType(isNative = true, name = "Point", namespace = JsPackage.GLOBAL)+public class Point {+ @JsProperty+ public int x;++ @JsProperty+ public int y;++ public Point(int x, int y) {}+}diff --git a/manager/src/main/java/org/openremote/manager/client/interop/mapbox/Popup.java b/manager/src/main/java/org/openremote/manager/client/interop/mapbox/Popup.javanew file mode 100644index 000000000..5009107d9--- /dev/null+++ b/manager/src/main/java/org/openremote/manager/client/interop/mapbox/Popup.java@@ -0,0 +1,19 @@+package org.openremote.manager.client.interop.mapbox;++import elemental.json.JsonObject;+import jsinterop.annotations.JsType;++@JsType(isNative = true, name = "Popup", namespace = "mapboxgl")+public class Popup extends Control<Popup> {+ public Popup() {}++ public Popup(JsonObject options) {}++ public native LngLat getLngLat();++ public native Popup setLngLat(LngLat lngLat);++ public native Popup setHTML(String html);++ public native Popup setText(String text);+}diff --git a/manager/src/main/java/org/openremote/manager/client/presenter/MapActivity.java b/manager/src/main/java/org/openremote/manager/client/presenter/MapActivity.javaindex 5fe200131..b63df4ce2 100644--- a/manager/src/main/java/org/openremote/manager/client/presenter/MapActivity.java+++ b/manager/src/main/java/org/openremote/manager/client/presenter/MapActivity.java@@ -5,11 +5,11 @@ import com.google.gwt.place.shared.PlaceController;import com.google.gwt.user.client.ui.AcceptsOneWidget;import com.google.web.bindery.event.shared.EventBus;import com.workingflows.js.jscore.client.api.promise.Promise;-import elemental.json.Json;+import elemental.js.util.Json;import elemental.json.JsonObject;import org.fusesource.restygwt.client.Method;-import org.fusesource.restygwt.client.MethodCallback;import org.fusesource.restygwt.client.TextCallback;+import org.openremote.manager.client.interop.mapbox.MapOptions;import org.openremote.manager.client.rest.MapRestService;import org.openremote.manager.client.view.MapView;@@ -67,8 +67,8 @@ public class MapActivity});p.then(obj -> {- JsonObject settings = Json.parse((String) obj);- view.initialiseMap(settings);+ JsonObject mapOptions = Json.parse((String) obj);+ view.initialiseMap(mapOptions);return null;}).catchException(obj -> {return null;diff --git a/manager/src/main/java/org/openremote/manager/client/rest/MapRestService.java b/manager/src/main/java/org/openremote/manager/client/rest/MapRestService.javaindex 7ecd19749..6dc4c27f8 100644--- a/manager/src/main/java/org/openremote/manager/client/rest/MapRestService.java+++ b/manager/src/main/java/org/openremote/manager/client/rest/MapRestService.java@@ -1,6 +1,5 @@package org.openremote.manager.client.rest;-import org.fusesource.restygwt.client.MethodCallback;import org.fusesource.restygwt.client.RestService;import org.fusesource.restygwt.client.TextCallback;@@ -14,6 +13,6 @@ public interface MapRestService extends RestService {@GET@Path("/map")- void getOptions(TextCallback getOptionsCallback);+ void getOptions(TextCallback optionsCallback);}diff --git a/manager/src/main/java/org/openremote/manager/client/ui/Map.java b/manager/src/main/java/org/openremote/manager/client/ui/Map.javadeleted file mode 100644index 3c600b6b3..000000000--- a/manager/src/main/java/org/openremote/manager/client/ui/Map.java+++ /dev/null@@ -1,47 +0,0 @@-package org.openremote.manager.client.ui;--import com.google.gwt.dom.client.Document;-import com.google.gwt.dom.client.Element;-import com.google.gwt.user.client.ui.ComplexPanel;-import elemental.json.JsonObject;--/**- * Created by Richard on 24/02/2016.- */-public class Map extends ComplexPanel {- boolean initialised = false;-- public Map() {- setElement(Document.get().createDelElement());- }-- @Override- protected void onLoad() {- resize();- super.onLoad();- }-- public void setOptions(JsonObject mapOptions) {- initMap(getElement(), mapOptions);- resize();- }-- public boolean isInitialised() {- return initialised;- }-- private native void resize() /*-{- if ($wnd.map === null || typeof($wnd.map) === 'undefined') {- return;- }- $wnd.map.resize();- }-*/;-- private native void initMap(Element mapContainer, JsonObject mapSettings) /*-{- mapSettings.container = mapContainer;- var map = new $wnd.mapboxgl.Map(mapSettings);- map.addControl(new $wnd.mapboxgl.Navigation());- // Add map to window scope as no obvious way of getting it later- $wnd.map = map;- }-*/;-}diff --git a/manager/src/main/java/org/openremote/manager/client/ui/MapWidget.java b/manager/src/main/java/org/openremote/manager/client/ui/MapWidget.javanew file mode 100644index 000000000..7d1033f07--- /dev/null+++ b/manager/src/main/java/org/openremote/manager/client/ui/MapWidget.java@@ -0,0 +1,70 @@+package org.openremote.manager.client.ui;++import com.google.gwt.dom.client.Document;+import com.google.gwt.dom.client.Element;+import com.google.gwt.user.client.Window;+import com.google.gwt.user.client.ui.ComplexPanel;+import com.google.gwt.user.client.ui.ResizeLayoutPanel;+import com.google.web.bindery.event.shared.HandlerRegistration;+import elemental.json.JsonObject;+import org.openremote.manager.client.interop.mapbox.*;++public class MapWidget extends ComplexPanel {+ ResizeLayoutPanel host;+ HandlerRegistration resizeHandler;+ private String id;+ private org.openremote.manager.client.interop.mapbox.Map map;++ public MapWidget(JsonObject mapOptions) {+ this();+ initialise(mapOptions);+ }++ public MapWidget() {+ setElement(Document.get().createDivElement());+ }++ public Map getJsMap() {+ return map;+ }++ public void initialise(JsonObject mapOptions) {+ if (map != null) {+ map.remove();+ resizeHandler.removeHandler();+ remove(host);+ }++ if (mapOptions == null) {+ return;+ }++ id = Document.get().createUniqueId();+ host = new ResizeLayoutPanel();+ host.setWidth("100%");+ host.setHeight("100%");+ host.getElement().setId(id);+ resizeHandler = host.addResizeHandler(event -> {+ resizeMap();+ });+ add(host, (Element)getElement());+ mapOptions.put("container", id);+ map = new Map(mapOptions);+ map.addControl(new Navigation());+ map.on(EventType.CLICK, eventData -> {+ CameraOptions opts = new CameraOptions();+ opts.center = eventData.getLngLat();+ map.jumpTo(opts);+ });+ }++ public boolean isInitialised() {+ return map != null;+ }++ private void resizeMap() {+ if (map != null) {+ map.resize();+ }+ }+}diff --git a/manager/src/main/java/org/openremote/manager/client/view/MapView.java b/manager/src/main/java/org/openremote/manager/client/view/MapView.javaindex 2c608e4fa..af3429ed9 100644--- a/manager/src/main/java/org/openremote/manager/client/view/MapView.java+++ b/manager/src/main/java/org/openremote/manager/client/view/MapView.java@@ -3,6 +3,7 @@ package org.openremote.manager.client.view;import com.google.gwt.place.shared.Place;import com.google.gwt.user.client.ui.IsWidget;import elemental.json.JsonObject;+import org.openremote.manager.client.interop.mapbox.MapOptions;public interface MapView extends IsWidget {@@ -12,7 +13,7 @@ public interface MapView extends IsWidget {void setPresenter(Presenter presenter);- void initialiseMap(JsonObject mapSettings);+ void initialiseMap(JsonObject mapOptions);boolean isMapInitialised();}diff --git a/manager/src/main/java/org/openremote/manager/client/view/MapViewImpl.java b/manager/src/main/java/org/openremote/manager/client/view/MapViewImpl.javaindex 1358249c2..f0157d63e 100644--- a/manager/src/main/java/org/openremote/manager/client/view/MapViewImpl.java+++ b/manager/src/main/java/org/openremote/manager/client/view/MapViewImpl.java@@ -1,19 +1,18 @@package org.openremote.manager.client.view;import com.google.gwt.core.client.GWT;-import com.google.gwt.dom.client.Element;import com.google.gwt.uibinder.client.UiBinder;import com.google.gwt.uibinder.client.UiField;import com.google.gwt.user.client.ui.Composite;-import com.google.gwt.user.client.ui.HTMLPanel;import elemental.json.JsonObject;-import org.openremote.manager.client.ui.Map;+import org.openremote.manager.client.interop.mapbox.MapOptions;+import org.openremote.manager.client.ui.MapWidget;import javax.inject.Inject;public class MapViewImpl extends Composite implements MapView {- interface UI extends UiBinder<HTMLPanel, MapViewImpl> {+ interface UI extends UiBinder<MapWidget, MapViewImpl> {}private UI ui = GWT.create(UI.class);@@ -21,7 +20,7 @@ public class MapViewImpl extends Composite implements MapView {Presenter presenter;@UiField- Map map;+ MapWidget mapWidget;@Injectpublic MapViewImpl() {@@ -34,12 +33,12 @@ public class MapViewImpl extends Composite implements MapView {}@Override- public void initialiseMap(JsonObject mapSettings) {- map.setOptions(mapSettings);+ public void initialiseMap(JsonObject mapOptions) {+ mapWidget.initialise(mapOptions);}@Overridepublic boolean isMapInitialised() {- return map.isInitialised();+ return mapWidget.isInitialised();}}diff --git a/manager/src/main/java/org/openremote/manager/client/view/MapViewImpl.ui.xml b/manager/src/main/java/org/openremote/manager/client/view/MapViewImpl.ui.xmlindex c42dccf89..0b93e8145 100644--- a/manager/src/main/java/org/openremote/manager/client/view/MapViewImpl.ui.xml+++ b/manager/src/main/java/org/openremote/manager/client/view/MapViewImpl.ui.xml@@ -12,10 +12,6 @@}</ui:style>- <g:HTMLPanel>-- <o:Map ui:field="map" addStyleNames="{style.mapContainer}"></o:Map>-- </g:HTMLPanel>+ <o:MapWidget ui:field="mapWidget" addStyleNames="{style.mapContainer}"></o:MapWidget></ui:UiBinder>\ No newline at end of filediff --git a/manager/src/main/java/org/openremote/manager/server/map/MapRouter.java b/manager/src/main/java/org/openremote/manager/server/map/MapRouter.javaindex 9d5ad79fa..b7eb0ed5e 100644--- a/manager/src/main/java/org/openremote/manager/server/map/MapRouter.java+++ b/manager/src/main/java/org/openremote/manager/server/map/MapRouter.java@@ -52,7 +52,7 @@ public class MapRouter extends HttpRouter {response.putHeader(CONTENT_ENCODING, "gzip");response.end(Buffer.buffer(tile));} else {- LOG.fine("Map tile not found: " + request.absoluteURI());+ LOG.fine("MapWidget tile not found: " + request.absoluteURI());response.setStatusCode(404);}} catch (Exception ex) {diff --git a/manager/src/main/java/org/openremote/manager/server/map/MapService.java b/manager/src/main/java/org/openremote/manager/server/map/MapService.javaindex 73cd2b376..c9f99b649 100644--- a/manager/src/main/java/org/openremote/manager/server/map/MapService.java+++ b/manager/src/main/java/org/openremote/manager/server/map/MapService.java@@ -41,14 +41,14 @@ public class MapService {Path mapTilesPath = Paths.get(config.getString(MAP_TILES_PATH, MAP_TILES_PATH_DEFAULT));if (!Files.isRegularFile(mapTilesPath)) {throw new IllegalStateException(- "Map tiles data file not found: " + mapTilesPath.toAbsolutePath()+ "MapWidget tiles data file not found: " + mapTilesPath.toAbsolutePath());}mapSettingsPath = Paths.get(config.getString(MAP_SETTINGS_PATH, MAP_SETTINGS_PATH_DEFAULT));if (!Files.isRegularFile(mapSettingsPath)) {throw new IllegalStateException(- "Map settings file not found: " + mapSettingsPath.toAbsolutePath()+ "MapWidget settings file not found: " + mapSettingsPath.toAbsolutePath());}