Skip to content

armgit / core

Public Imported from GitHub
0

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

Some cleanup and preparation for more map layers

Christian Bauerf72882baa501
diff --git a/manager/client/src/main/java/org/openremote/manager/client/interop/mapbox/Control.java b/manager/client/src/main/java/org/openremote/manager/client/interop/mapbox/Control.java
index a1231ab79..d904cd40f 100644
--- a/manager/client/src/main/java/org/openremote/manager/client/interop/mapbox/Control.java
+++ b/manager/client/src/main/java/org/openremote/manager/client/interop/mapbox/Control.java
@@ -24,7 +24,7 @@ import jsinterop.annotations.JsType;
@JsType(isNative = true, name = "Control")
public abstract class Control<T> {
- public native T addTo(Map map);
+ public native T addTo(MapboxMap mapboxMap);
public native void remove();
}
diff --git a/manager/client/src/main/java/org/openremote/manager/client/interop/mapbox/Map.java b/manager/client/src/main/java/org/openremote/manager/client/interop/mapbox/Map.java
deleted file mode 100644
index 45ebf6c4d..000000000
--- a/manager/client/src/main/java/org/openremote/manager/client/interop/mapbox/Map.java
+++ /dev/null
@@ -1,189 +0,0 @@
-/*
- * Copyright 2016, 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.manager.client.interop.mapbox;
-
-import com.google.gwt.core.client.JavaScriptObject;
-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(JavaScriptObject layer);
- public native Map addLayer(JavaScriptObject layer, String beforeLayerId);
-
- public native Map addSource(String id, GeoJSONSource 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 JavaScriptObject 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 sourceId);
-
- 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/client/src/main/java/org/openremote/manager/client/interop/mapbox/MapboxMap.java b/manager/client/src/main/java/org/openremote/manager/client/interop/mapbox/MapboxMap.java
new file mode 100644
index 000000000..674cb24fd
--- /dev/null
+++ b/manager/client/src/main/java/org/openremote/manager/client/interop/mapbox/MapboxMap.java
@@ -0,0 +1,190 @@
+/*
+ * Copyright 2016, 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.manager.client.interop.mapbox;
+
+import com.google.gwt.core.client.JavaScriptObject;
+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 MapboxMap {
+
+ @JsProperty
+ public boolean debug;
+
+ @JsProperty
+ public boolean loaded;
+
+ // TODO: Get this to work with MapOptions JsType
+ public MapboxMap(JsonObject options) {}
+
+ public native MapboxMap addClass(String className);
+ public native MapboxMap addClass(String className, JsonObject styleOptions);
+
+ public native MapboxMap addControl(Control control);
+
+ public native MapboxMap addLayer(JavaScriptObject layer);
+ public native MapboxMap addLayer(JavaScriptObject layer, String beforeLayerId);
+
+ public native MapboxMap addSource(String id, GeoJSONSource 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 MapboxMap easeTo(CameraOptions cameraOptions);
+ public native MapboxMap easeTo(AnimationOptions animationOptions);
+
+ public native MapboxMap featuresAt(Point point, JsonObject options, FeaturesCallbackFn callbackFn);
+
+ public native MapboxMap featuresIn(JsonObject options, FeaturesCallbackFn callbackFn);
+ public native MapboxMap featuresIn(Point[] bounds, JsonObject options, FeaturesCallbackFn callbackFn);
+
+ public native MapboxMap fitBounds(LngLatBounds bounds, JsonObject options);
+ public native MapboxMap fitBounds(LngLatBounds bounds, JsonObject options, EventData eventData);
+
+ public native MapboxMap flyTo(JsonObject options);
+
+ public native MapboxMap 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 JavaScriptObject 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 MapboxMap jumpTo(CameraOptions options);
+ public native MapboxMap jumpTo(CameraOptions options, EventData eventData);
+
+ public native MapboxMap panBy(int[] offset, AnimationOptions options);
+ public native MapboxMap panBy(int[] offset, AnimationOptions options, EventData eventData);
+
+ public native MapboxMap panTo(LngLat lngLat, AnimationOptions options);
+ public native MapboxMap panTo(LngLat lngLat, AnimationOptions options, EventData eventData);
+
+ public native JsonObject project(LngLat lngLat);
+
+ public native void remove();
+
+ public native MapboxMap removeClass(String className);
+ public native MapboxMap removeClass(String className, JsonObject options);
+
+ public native MapboxMap removeLayer(String layerId);
+
+ public native MapboxMap removeSource(String sourceId);
+
+ public native void repaint();
+
+ public native MapboxMap resetNorth();
+ public native MapboxMap resetNorth(EventData eventData);
+ public native MapboxMap resetNorth(AnimationOptions options);
+ public native MapboxMap resetNorth(AnimationOptions options, EventData eventData);
+
+ public native MapboxMap resize();
+
+ public native MapboxMap rotateTo(int bearing);
+ public native MapboxMap rotateTo(int bearing, EventData eventData);
+ public native MapboxMap rotateTo(int bearing, AnimationOptions options);
+ public native MapboxMap rotateTo(int bearing, AnimationOptions options, EventData eventData);
+
+ public native MapboxMap setBearing(int bearing);
+ public native MapboxMap setBearing(int bearing, EventData eventData);
+
+ public native MapboxMap setCenter(LngLat center);
+ public native MapboxMap setCenter(LngLat center, EventData eventData);
+
+ public native MapboxMap setClasses(String[] classNames);
+ public native MapboxMap setClasses(String[] classNames, JsonObject options);
+
+ public native MapboxMap setFilter(String layerId, JsonObject filter);
+
+ public native MapboxMap setLayerZoomRange(String layerId, int minZoom, int maxZoom);
+
+ public native MapboxMap setLayoutProperty(String layerId, String propertyName, JsonValue propertyValue);
+
+ public native MapboxMap setPaintProperty(String layerId, String propertyName, JsonValue propertyValue);
+ public native MapboxMap setPaintProperty(String layerId, String propertyName, JsonValue propertyValue, String classSpecifier);
+
+ public native MapboxMap setPitch(int pitch);
+ public native MapboxMap setPitch(int pitch, EventData eventData);
+
+ public native MapboxMap setStyle(JsonObject style);
+
+ public native MapboxMap setZoom(int zoom);
+ public native MapboxMap setZoom(int zoom, EventData eventData);
+
+ public native MapboxMap snapToNorth();
+ public native MapboxMap snapToNorth(AnimationOptions options);
+ public native MapboxMap snapToNorth(EventData eventData);
+ public native MapboxMap snapToNorth(AnimationOptions options, EventData eventData);
+
+ public native MapboxMap stop();
+
+ public native LngLat unproject(Point point);
+
+ public native MapboxMap zoomIn();
+ public native MapboxMap zoomIn(EventData eventData);
+ public native MapboxMap zoomIn(AnimationOptions options);
+ public native MapboxMap zoomIn(AnimationOptions options, EventData eventData);
+
+ public native MapboxMap zoomOut();
+ public native MapboxMap zoomOut(EventData eventData);
+ public native MapboxMap zoomOut(AnimationOptions options);
+ public native MapboxMap zoomOut(AnimationOptions options, EventData eventData);
+
+ public native MapboxMap zoomTo(int zoom);
+ public native MapboxMap zoomTo(int zoom, AnimationOptions options);
+ public native MapboxMap zoomTo(int zoom, EventData eventData);
+ public native MapboxMap zoomTo(int zoom, AnimationOptions options, EventData eventData);
+}
diff --git a/manager/client/src/main/java/org/openremote/manager/client/map/MapActivity.java b/manager/client/src/main/java/org/openremote/manager/client/map/MapActivity.java
index 52bdac250..5884ac2b8 100644
--- a/manager/client/src/main/java/org/openremote/manager/client/map/MapActivity.java
+++ b/manager/client/src/main/java/org/openremote/manager/client/map/MapActivity.java
@@ -86,17 +86,17 @@ public class MapActivity extends AssetBrowsingActivity<MapView, MapPlace> implem
@Override
protected void startCreateAsset() {
- getView().hideFeatures();
+ getView().hideFeaturesSelection();
}
@Override
protected void onAssetReady() {
- getView().showFeatures(asset.getMapFeatures());
+ getView().showFeaturesSelection(asset.getMapFeatures());
}
@Override
protected void onAssetsDeselected() {
- getView().hideFeatures();
+ getView().hideFeaturesSelection();
placeController.goTo(new MapPlace());
}
diff --git a/manager/client/src/main/java/org/openremote/manager/client/map/MapView.java b/manager/client/src/main/java/org/openremote/manager/client/map/MapView.java
index 9a155a223..717dbbcf6 100644
--- a/manager/client/src/main/java/org/openremote/manager/client/map/MapView.java
+++ b/manager/client/src/main/java/org/openremote/manager/client/map/MapView.java
@@ -33,8 +33,12 @@ public interface MapView extends AssetBrowsingView<MapView.Presenter> {
void refresh();
- void showFeatures(String mapFeaturesJson);
+ void showFeaturesAll(String mapFeaturesJson);
- void hideFeatures();
+ void hideFeaturesAll();
+
+ void showFeaturesSelection(String mapFeaturesJson);
+
+ void hideFeaturesSelection();
}
diff --git a/manager/client/src/main/java/org/openremote/manager/client/map/MapViewImpl.java b/manager/client/src/main/java/org/openremote/manager/client/map/MapViewImpl.java
index e4440a0f9..457431eda 100644
--- a/manager/client/src/main/java/org/openremote/manager/client/map/MapViewImpl.java
+++ b/manager/client/src/main/java/org/openremote/manager/client/map/MapViewImpl.java
@@ -61,12 +61,6 @@ public class MapViewImpl extends Composite implements MapView {
this.presenter = presenter;
}
- @Override
- public void hideFeatures() {
- // TODO ugly
- showFeatures("{ \"type\": \"FeatureCollection\", \"features\": [] }");
- }
-
@Override
public void initialiseMap(JsonObject mapOptions) {
mapLoadingLabel.setVisible(false);
@@ -90,7 +84,24 @@ public class MapViewImpl extends Composite implements MapView {
}
@Override
- public void showFeatures(String mapFeaturesJson) {
- mapWidget.showFeatures(mapFeaturesJson);
+ public void showFeaturesAll(String mapFeaturesJson) {
+ mapWidget.showFeatures(MapWidget.FEATURES_SOURCE_ALL, mapFeaturesJson);
+ }
+
+ @Override
+ public void hideFeaturesAll() {
+ // TODO ugly
+ showFeaturesAll("{ \"type\": \"FeatureCollection\", \"features\": [] }");
+ }
+
+ @Override
+ public void showFeaturesSelection(String mapFeaturesJson) {
+ mapWidget.showFeatures(MapWidget.FEATURES_SOURCE_SELECTION, mapFeaturesJson);
+ }
+
+ @Override
+ public void hideFeaturesSelection() {
+ // TODO ugly
+ showFeaturesSelection("{ \"type\": \"FeatureCollection\", \"features\": [] }");
}
}
diff --git a/manager/client/src/main/java/org/openremote/manager/client/map/MapWidget.java b/manager/client/src/main/java/org/openremote/manager/client/map/MapWidget.java
index 967c96391..edd035413 100644
--- a/manager/client/src/main/java/org/openremote/manager/client/map/MapWidget.java
+++ b/manager/client/src/main/java/org/openremote/manager/client/map/MapWidget.java
@@ -28,26 +28,121 @@ import elemental.json.Json;
import elemental.json.JsonObject;
import org.openremote.manager.client.interop.mapbox.EventType;
import org.openremote.manager.client.interop.mapbox.GeoJSONSource;
-import org.openremote.manager.client.interop.mapbox.Map;
+import org.openremote.manager.client.interop.mapbox.MapboxMap;
import org.openremote.manager.client.interop.mapbox.Navigation;
+import org.openremote.manager.client.util.JsUtil;
+import java.util.HashMap;
+import java.util.Map;
import java.util.logging.Logger;
public class MapWidget extends ComplexPanel {
private static final Logger LOG = Logger.getLogger(MapWidget.class.getName());
- public static final String FEATURES_SOURCE = "features";
- public static final String FEATURES_LAYER_TITLE = "features-title";
- public static final String FEATURES_LAYER_LOCATION = "features-location";
+ // Feature IDs
+ public static final String FEATURES_SOURCE_ALL = "features-source-all";
+ public static final String FEATURES_SOURCE_SELECTION = "features-source-selection";
+ public static final String FEATURES_LAYER_ALL = "features-layer-all";
+ public static final String FEATURES_LAYER_SELECTION_TEXT = "features-layer-selection-text";
+ public static final String FEATURES_LAYER_SELECTION_CIRCLE = "features-layer-selection-circle";
+
+ // Render a circle on location
+ @SuppressWarnings("GwtInconsistentSerializableClass")
+ static final public JsMapFromStringTo<Object> LAYER_ALL = JsMapFromStringTo.create();
+
+ // Render feature title as label on location
+ @SuppressWarnings("GwtInconsistentSerializableClass")
+ static final public JsMapFromStringTo<Object> LAYER_SELECTION_TEXT = JsMapFromStringTo.create();
+
+ // Render a circle on location
+ @SuppressWarnings("GwtInconsistentSerializableClass")
+ static final public JsMapFromStringTo<Object> LAYER_SELECTION_CIRCLE = JsMapFromStringTo.create();
+
+ static {
+ {
+ JsMapFromStringTo<Object> layout = JsMapFromStringTo.create();
+ layout.put("visibility", "visible");
+
+ JsMapFromStringTo<Object> paint = JsMapFromStringTo.create();
+ paint.put("circle-radius", 12.0); // This MUST be double!
+ paint.put("circle-opacity", 0.5);
+ // TODO Add color to theme settings
+ paint.put("circle-color", "rgb(73, 169, 66)");
+
+ LAYER_ALL.put("id", FEATURES_LAYER_ALL);
+ LAYER_ALL.put("type", "circle");
+ LAYER_ALL.put("source", FEATURES_SOURCE_ALL);
+ LAYER_ALL.put("layout", layout);
+ LAYER_ALL.put("paint", paint);
+ }
+ {
+ JsMapFromStringTo<Object> layout = JsMapFromStringTo.create();
+ layout.put("visibility", "visible");
+ layout.put("text-field", "{title}");
+ JsArrayOfString textFont = JsArrayOfString.create();
+ textFont.push("Open Sans Semibold");
+ layout.put("text-font", textFont);
+ JsMapFromStringTo<Object> textSize = JsMapFromStringTo.create();
+ JsArrayOfInt stop1 = JsArrayOfInt.create();
+ stop1.push(3);
+ stop1.push(8);
+ JsArrayOfInt stop2 = JsArrayOfInt.create();
+ stop2.push(10);
+ stop2.push(20);
+ JsArrayOf<JsArrayOfInt> stops = JsArrayOf.create();
+ stops.push(stop1);
+ stops.push(stop2);
+ textSize.put("stops", stops);
+ layout.put("text-size", textSize);
+ layout.put("text-allow-overlap", true);
+ JsArrayOfNumber offset = JsArrayOfNumber.create();
+ offset.push(0);
+ offset.push(1.2);
+ layout.put("text-offset", offset);
+
+ JsMapFromStringTo<Object> paint = JsMapFromStringTo.create();
+ // TODO Add color to theme settings
+ paint.put("text-color", "#000");
+ paint.put("text-halo-color", "#fff");
+ paint.put("text-halo-width", 4.0);
+ paint.put("text-halo-blur", 40.0);
+
+ LAYER_SELECTION_TEXT.put("id", FEATURES_LAYER_SELECTION_TEXT);
+ LAYER_SELECTION_TEXT.put("type", "symbol");
+ LAYER_SELECTION_TEXT.put("source", FEATURES_SOURCE_SELECTION);
+ LAYER_SELECTION_TEXT.put("layout", layout);
+ LAYER_SELECTION_TEXT.put("paint", paint);
+ }
+ {
+ JsMapFromStringTo<Object> layout = JsMapFromStringTo.create();
+ layout.put("visibility", "visible");
+
+ JsMapFromStringTo<Object> paint = JsMapFromStringTo.create();
+ paint.put("circle-radius", 15.0); // This MUST be double!
+ paint.put("circle-opacity", 0.9);
+ // TODO Add color to theme settings
+ paint.put("circle-color", "rgb(193, 215, 47)");
+
+ LAYER_SELECTION_CIRCLE.put("id", FEATURES_LAYER_SELECTION_CIRCLE);
+ LAYER_SELECTION_CIRCLE.put("type", "circle");
+ LAYER_SELECTION_CIRCLE.put("source", FEATURES_SOURCE_SELECTION);
+ LAYER_SELECTION_CIRCLE.put("layout", layout);
+ LAYER_SELECTION_CIRCLE.put("paint", paint);
+ }
+
+ }
protected FlowPanel host;
- protected String id;
- protected Map map;
- protected GeoJSONSource featuresSource;
- protected JsMapFromStringTo<Object> featuresLayerTitle; // Shows asset display name on asset location
- protected JsMapFromStringTo<Object> featuresLayerLocation; // Shows a circle on asset location
- protected JsonObject pendingFeaturesData;
+ protected String hostElementId;
+
+ protected MapboxMap mapboxMap;
+
+ // These sources can be initialized late, as we have to consider async arriving currentFeaturesData
+ protected boolean featuresReady = false;
+ protected GeoJSONSource sourceAll;
+ protected GeoJSONSource sourceSelection;
+ protected Map<String, JsonObject> currentFeatureSourceData = new HashMap<>(); // We hold GeoJSON data, keyed by feature ID
public MapWidget(JsonObject mapOptions) {
this();
@@ -58,38 +153,37 @@ public class MapWidget extends ComplexPanel {
setElement(Document.get().createDivElement());
}
- public Map getMap() {
- return map;
+ public MapboxMap getMapboxMap() {
+ return mapboxMap;
}
public boolean isInitialised() {
- return map != null;
+ return mapboxMap != null;
}
public void initialise(JsonObject mapOptions) {
- if (map != null) {
- map.remove();
- remove(host);
- }
-
if (mapOptions == null) {
return;
}
+ LOG.fine("Initializing Mapbox map");
+ if (mapboxMap != null) {
+ throw new IllegalStateException("Already initialized");
+ }
- id = Document.get().createUniqueId();
+ hostElementId = Document.get().createUniqueId();
host = new FlowPanel();
host.setStyleName("flex");
- host.getElement().setId(id);
+ host.getElement().setId(hostElementId);
add(host, (Element) getElement());
- mapOptions.put("container", id);
- map = new Map(mapOptions);
+ mapOptions.put("container", hostElementId);
+ mapboxMap = new MapboxMap(mapOptions);
- map.addControl(new Navigation());
+ mapboxMap.addControl(new Navigation());
- map.on(EventType.LOAD, eventData -> {
- addFeatures();
+ mapboxMap.on(EventType.LOAD, eventData -> {
+ addFeaturesOnLoad();
});
/*
@@ -99,115 +193,76 @@ public class MapWidget extends ComplexPanel {
.addTo(map);
*/
- map.on(EventType.CLICK, eventData -> {
+ mapboxMap.on(EventType.CLICK, eventData -> {
LOG.info("### COORDS: " + eventData.getLngLat());
- LOG.info("### BOUNDS: " + map.getBounds());
+ LOG.info("### BOUNDS: " + mapboxMap.getBounds());
});
}
public void refresh() {
// TODO: we might want to further define what "refresh" means, currently it's triggered on GoToPlaceEvent
- if (map != null) {
- map.resize();
+ if (mapboxMap != null) {
+ mapboxMap.resize();
}
}
- protected void addFeatures() {
+ protected JsonObject prepareSourceOptions(String featureSourceId) {
JsonObject sourceOptions = Json.createObject();
-
// We might have an async update waiting, initialize the map with this data
- if (pendingFeaturesData != null) {
- sourceOptions.put("data", pendingFeaturesData);
- pendingFeaturesData = null;
- }
-
- /*
- sourceOptions.put("maxzoom", 20);
- sourceOptions.put("buffer", 128);
- sourceOptions.put("tolerance", 0.375);
- sourceOptions.put("cluster", false);
- sourceOptions.put("clusterRadius", 50);
- sourceOptions.put("clusterMaxZoom", 15);
- */
-
- featuresSource = new GeoJSONSource(sourceOptions);
- map.addSource(FEATURES_SOURCE, featuresSource);
-
- featuresLayerTitle = createFeaturesLayerForTitle(FEATURES_LAYER_TITLE, FEATURES_SOURCE);
- map.addLayer(featuresLayerTitle);
-
- featuresLayerLocation = createFeaturesLayerForLocation(FEATURES_LAYER_LOCATION, FEATURES_SOURCE);
- map.addLayer(featuresLayerLocation, FEATURES_LAYER_TITLE);
- }
-
- public void showFeatures(String mapFeaturesJson) {
- if (featuresSource != null) {
- featuresSource.setData(Json.parse(mapFeaturesJson));
- } else {
- pendingFeaturesData = Json.parse(mapFeaturesJson);
+ JsonObject currentFeatureData = currentFeatureSourceData.remove(featureSourceId);
+ if (currentFeatureData == null) {
+ // Or initialize with empty collection (null doesn't work)
+ currentFeatureData = Json.parse("{\"type\":\"FeatureCollection\",\"features\":[]}");
}
+ LOG.fine("Preparing data on feature source: " + featureSourceId);
+ JsUtil.log(currentFeatureData);
+ sourceOptions.put("data", currentFeatureData);
+ return sourceOptions;
}
- protected JsMapFromStringTo<Object> createFeaturesLayerForTitle(String id, String source) {
-
- JsMapFromStringTo<Object> layout = JsMapFromStringTo.create();
- layout.put("visibility", "visible");
- layout.put("text-field", "{title}");
- JsArrayOfString textFont = JsArrayOfString.create();
- textFont.push("Open Sans Semibold");
- layout.put("text-font", textFont);
- JsMapFromStringTo<Object> textSize = JsMapFromStringTo.create();
- JsArrayOfInt stop1 = JsArrayOfInt.create();
- stop1.push(3);
- stop1.push(8);
- JsArrayOfInt stop2 = JsArrayOfInt.create();
- stop2.push(10);
- stop2.push(20);
- JsArrayOf<JsArrayOfInt> stops = JsArrayOf.create();
- stops.push(stop1);
- stops.push(stop2);
- textSize.put("stops", stops);
- layout.put("text-size", textSize);
- layout.put("text-allow-overlap", true);
- JsArrayOfNumber offset = JsArrayOfNumber.create();
- offset.push(0);
- offset.push(1.2);
- layout.put("text-offset", offset);
-
- JsMapFromStringTo<Object> paint = JsMapFromStringTo.create();
- paint.put("text-color", "rgb(0, 0, 0)");
- paint.put("text-halo-color", "rgb(255, 255, 255)");
- paint.put("text-halo-width", 1.2);
- paint.put("text-halo-blur", 0.4);
-
- JsMapFromStringTo<Object> layer = JsMapFromStringTo.create();
- layer.put("id", id);
- layer.put("type", "symbol");
- layer.put("source", source);
- layer.put("layout", layout);
- layer.put("paint", paint);
-
- return layer;
+ protected void addFeaturesOnLoad() {
+ LOG.fine("Adding GeoJSON feature sources and layers on map load");
+
+ JsonObject sourceOptionsSelection = prepareSourceOptions(FEATURES_SOURCE_SELECTION);
+ sourceSelection = new GeoJSONSource(sourceOptionsSelection);
+ mapboxMap.addSource(FEATURES_SOURCE_SELECTION, sourceSelection);
+ mapboxMap.addLayer(LAYER_SELECTION_CIRCLE);
+ mapboxMap.addLayer(LAYER_SELECTION_TEXT);
+
+ JsonObject sourceOptionsAll = prepareSourceOptions(FEATURES_SOURCE_ALL);
+ sourceOptionsAll.put("maxzoom", 20);
+ sourceOptionsAll.put("buffer", 128);
+ sourceOptionsAll.put("tolerance", 0.375);
+ sourceOptionsAll.put("cluster", false);
+ sourceOptionsAll.put("clusterRadius", 50);
+ sourceOptionsAll.put("clusterMaxZoom", 15);
+ sourceAll = new GeoJSONSource(sourceOptionsAll);
+ mapboxMap.addSource(FEATURES_SOURCE_ALL, sourceAll);
+ mapboxMap.addLayer(LAYER_ALL, FEATURES_LAYER_SELECTION_TEXT);
+
+ featuresReady = true;
}
- protected JsMapFromStringTo<Object> createFeaturesLayerForLocation(String id, String source) {
-
- JsMapFromStringTo<Object> layout = JsMapFromStringTo.create();
- layout.put("visibility", "visible");
-
- JsMapFromStringTo<Object> paint = JsMapFromStringTo.create();
- paint.put("circle-radius", 15.0);
- paint.put("circle-opacity", 0.8);
- paint.put("circle-color", "rgb(193, 215, 47)");
-
- JsMapFromStringTo<Object> layer = JsMapFromStringTo.create();
- layer.put("id", id);
- layer.put("type", "circle");
- layer.put("source", source);
- layer.put("layout", layout);
- layer.put("paint", paint);
-
- return layer;
+ public void showFeatures(String featureSourceId, String featuresJson) {
+ LOG.fine("Showing features on source " + featureSourceId + ": " + featuresJson);
+ JsonObject data = Json.parse(featuresJson);
+ JsUtil.log(data);
+ currentFeatureSourceData.put(featureSourceId, data);
+ if (featuresReady) {
+ LOG.fine("Feature layers are ready, setting data directly");
+ switch (featureSourceId) {
+ case FEATURES_SOURCE_ALL:
+ data = currentFeatureSourceData.remove(featureSourceId);
+ if (data != null)
+ sourceAll.setData(data);
+ break;
+ case FEATURES_SOURCE_SELECTION:
+ data = currentFeatureSourceData.remove(featureSourceId);
+ if (data != null)
+ sourceSelection.setData(data);
+ break;
+ }
+ }
}
}
diff --git a/manager/client/src/main/webapp/css/style.html b/manager/client/src/main/webapp/css/style.html
index 8737cf5be..40bb4ac51 100644
--- a/manager/client/src/main/webapp/css/style.html
+++ b/manager/client/src/main/webapp/css/style.html
@@ -277,6 +277,10 @@
.or-FormTreeItemValue {
outline: none;
margin-left: 0.2em;
+ -webkit-user-select: none;
+ -moz-user-select: none;
+ -ms-user-select: none;
+ user-select: none;;
}
.or-FormTreeOpenItem {
diff --git a/manager/server/sample/mapsettings.json b/manager/server/sample/mapsettings.json
index 36e7de933..ecf76db26 100644
--- a/manager/server/sample/mapsettings.json
+++ b/manager/server/sample/mapsettings.json
@@ -133,14 +133,15 @@
"text-font": ["Open Sans Semibold"],
"text-transform": "uppercase",
"text-size": {
- "base": 4,
- "stops": [[10, 10], [20, 30]]
+ "base": 5,
+ "stops": [[10, 15], [20, 30]]
}
},
"paint": {
"text-color": "#3B7BE7",
"text-halo-color": "rgba(255,255,255,0.2)",
- "text-halo-width": 2
+ "text-halo-width": 2,
+ "text-halo-blur": 2
}
},
{
@@ -282,7 +283,7 @@
"line-join": "round"
},
"paint": {
- "line-color": "#a0a0a0",
+ "line-color": "#b0b0b0",
"line-width": {
"base": 1.4,
"stops": [[6, 0.5], [20, 30]]
@@ -432,9 +433,9 @@
}
},
"paint": {
- "text-color": "#333",
+ "text-color": "#666",
"text-halo-color": "rgba(255,255,255,0.6)",
- "text-halo-width": 10
+ "text-halo-width": 5
}
},
{
@@ -454,7 +455,7 @@
}
},
"paint": {
- "text-color": "#bbbbbb"
+ "text-color": "#aaa"
}
},
{
@@ -474,9 +475,10 @@
}
},
"paint": {
- "text-color": "#666",
+ "text-color": "rgba(110,110,110,0.9)",
"text-halo-color": "rgba(255,255,255,0.6)",
- "text-halo-width": 5
+ "text-halo-width": 5,
+ "text-halo-blur": 5
}
}, {
"id": "place_label_other",
@@ -496,10 +498,10 @@
}
},
"paint": {
- "text-color": "#666",
+ "text-color": "rgba(110,110,110,0.9)",
"text-halo-color": "rgba(255,255,255,0.4)",
- "text-halo-width": 10,
- "text-halo-blur": 20
+ "text-halo-width": 2,
+ "text-halo-blur": 1
}
},
{
@@ -518,9 +520,9 @@
}
},
"paint": {
- "text-color": "#666",
+ "text-color": "rgba(110,110,110,0.9)",
"text-halo-color": "rgba(255,255,255,0.7)",
- "text-halo-width": 5,
+ "text-halo-width": 2,
"text-halo-blur": 1
}
},
@@ -540,7 +542,7 @@
}
},
"paint": {
- "text-color": "#666",
+ "text-color": "rgba(110,110,110,0.9)",
"text-halo-color": "rgba(255,255,255,0.75)",
"text-halo-width": 1,
"text-halo-blur": 1