Skip to content

armgit / core

Public Imported from GitHub
0

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

Show selected asset on map

Christian Bauerf40edefb8d21
diff --git a/container/src/main/resources/org/openremote/container/web/jsapi/client.js b/container/src/main/resources/org/openremote/container/web/jsapi/client.js
index 9275b1c68..ee1d62c77 100644
--- a/container/src/main/resources/org/openremote/container/web/jsapi/client.js
+++ b/container/src/main/resources/org/openremote/container/web/jsapi/client.js
@@ -254,8 +254,7 @@ REST._complete = function (request, callback) {
REST.log("Request ready state: " + request.readyState);
if (request.readyState == 4) {
var entity;
- REST.log("Request status: " + request.status);
- REST.log("Request response: " + request.responseText);
+ REST.log("Request response status: " + request.status);
if (request.status >= 200 && request.status < 300) {
request.onreadystatechange = null;
diff --git a/gradle.properties b/gradle.properties
index 8db839291..ac7c323c7 100644
--- a/gradle.properties
+++ b/gradle.properties
@@ -18,7 +18,7 @@ keycloakVersion = 1.9.4.Final
gwtVersion = 2.8.0-beta1
ginVersion = 2.1.2
cglibVersion = 3.2.0
-gwtJacksonVersion = 0.12.0
+gwtJacksonVersion = 0.13.0
jacksonVersion = 2.6.3
groovyVersion = 2.4.1
sqliteVersion = 3.8.11.2
@@ -30,4 +30,5 @@ junitVersion = 4.12
spockVersion = 1.0-groovy-2.4
objenesisVersion = 2.2
camelVersion = 2.16.2
-tyrusVersion = 1.10
\ No newline at end of file
+tyrusVersion = 1.10
+geojsonJacksonVersion = 1.6
\ No newline at end of file
diff --git a/manager/client/src/main/java/org/openremote/manager/client/assets/SampleAssets.java b/manager/client/src/main/java/org/openremote/manager/client/assets/SampleAssets.java
new file mode 100644
index 000000000..5a145e2f4
--- /dev/null
+++ b/manager/client/src/main/java/org/openremote/manager/client/assets/SampleAssets.java
@@ -0,0 +1,193 @@
+/*
+ * 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.assets;
+
+import org.geojson.Point;
+import org.openremote.manager.client.assets.asset.Asset;
+
+import java.util.*;
+
+/**
+ * TODO Remove this test class
+ */
+public class SampleAssets {
+
+ public static String getMapFeaturesJson(String id, String title, Point location) {
+ return "{" +
+ "\"type\":\"FeatureCollection\",\"features\":" +
+ "[" +
+ "{" +
+ "\"type\":\"Feature\"," +
+ "\"properties\":" +
+ "{" +
+ "\"id\":\"" + id + "\"," +
+ "\"title\":\"" + title + "\"}," +
+ "\"geometry\":" +
+ "{" +
+ "\"type\":\"Point\"," +
+ "\"coordinates\":" +
+ "[" +
+ location.getCoordinates().getLongitude() + ", " +
+ location.getCoordinates().getLatitude() +
+ "]" +
+ "}" +
+ "}" +
+ "]" +
+ "}";
+ }
+
+ public static List<Asset> queryAll(Asset parent) {
+ if (Asset.isRoot(parent)) {
+ return ROOT_CHILDREN;
+ } else if (parent.getType().equals(Asset.Type.COMPOSITE.name())) {
+ if (parent.getId().equals("composite:gateways")) {
+ return GATEWAYS;
+ }
+
+ if (parent.getId().equals("1000")) {
+ return SENSORS;
+ }
+ }
+ return new ArrayList<>();
+ }
+
+ public static final Asset ROOT = new Asset(
+ Asset.ROOT_ID,
+ Asset.ROOT_TYPE,
+ Asset.ROOT_LABEL,
+ getMapFeaturesJson(Asset.ROOT_ID, Asset.ROOT_LABEL, Asset.ROOT_LOCATION)
+ );
+
+ public static final List<Asset> ROOT_CHILDREN = new ArrayList<Asset>() {{
+ addAll(Arrays.asList(
+ new Asset(
+ "composite:gateways",
+ Asset.Type.COMPOSITE.name(),
+ "Gateways",
+ getMapFeaturesJson("composite:gateways", "Gateways", new Point(5.460315214821094, 51.44541688237109, 0))
+ ),
+ new Asset(
+ "composite:buildings",
+ Asset.Type.COMPOSITE.name(),
+ "Buildings",
+ getMapFeaturesJson("composite:buildings", "Buildings", new Point(5.479108567142475, 51.43873552530604, 0))
+ ),
+ new Asset(
+ "composite:rooms",
+ Asset.Type.COMPOSITE.name(),
+ "Rooms",
+ getMapFeaturesJson("composite:rooms", "Rooms", new Point(5.454904312991857, 51.42830131622847, 0))
+ ),
+ new Asset(
+ "composite:thermostats",
+ Asset.Type.COMPOSITE.name(),
+ "Thermostats",
+ getMapFeaturesJson("composite:thermostats", "Thermostats", new Point(5.4866616677283275, 51.432154224794346, 0))
+ )
+ ));
+ }};
+
+ public static final List<Asset> GATEWAYS = new ArrayList<Asset>() {{
+
+ for (int i = 1000; i < 1100; i++) {
+ add(
+ new Asset(
+ Integer.toString(i),
+ Asset.Type.COMPOSITE.name(),
+ "Gateway " + i,
+ getMapFeaturesJson(Integer.toString(i), "Gateway" + i, new Point(5.460315214821094, 51.44541688237109, 0))
+ )
+ );
+ }
+ }};
+
+ public static final List<Asset> SENSORS = Arrays.asList(
+ new Asset(
+ "11",
+ Asset.Type.SENSOR.name(),
+ "Sensor 1",
+ getMapFeaturesJson("11", "Sensor 1", new Point(5.460315214821094, 51.44541688237109, 0))
+ ),
+ new Asset(
+ "22",
+ Asset.Type.SENSOR.name(),
+ "Sensor 2",
+ getMapFeaturesJson("22", "Sensor 2", new Point(5.460315214821094, 51.44541688237109, 0))
+ ),
+ new Asset(
+ "33",
+ Asset.Type.SENSOR.name(),
+ "Sensor 3",
+ getMapFeaturesJson("33", "Sensor 3", new Point(5.460315214821094, 51.44541688237109, 0))
+ )
+ );
+
+ public static List<String> getSelectedAssetPath(String assetId) {
+ List<String> path = new ArrayList<>();
+ // TODO: We must build the asset path here, by finding the asset first, then its parents recursively
+ switch (assetId) {
+ case "composite:gateways":
+ path.add("composite:gateways");
+ break;
+ case "composite:buildings":
+ path.add("composite:buildings");
+ break;
+ case "composite:rooms":
+ path.add("composite:rooms");
+ break;
+ case "composite:thermostats":
+ path.add("composite:thermostats");
+ break;
+ case "11":
+ path.add("composite:gateways");
+ path.add("1000");
+ path.add("11");
+ break;
+ case "22":
+ path.add("composite:gateways");
+ path.add("1000");
+ path.add("22");
+ break;
+ case "33":
+ path.add("composite:gateways");
+ path.add("1000");
+ path.add("33");
+ break;
+ default:
+ path.add("composite:gateways");
+ path.add(assetId);
+ break;
+ }
+ return path;
+ }
+
+ public static final Map<String, Asset> ALL_BY_ID = new LinkedHashMap<String, Asset>() {{
+ for (Asset asset : ROOT_CHILDREN) {
+ put(asset.getId(), asset);
+ }
+ for (Asset asset : GATEWAYS) {
+ put(asset.getId(), asset);
+ }
+ for (Asset asset : SENSORS) {
+ put(asset.getId(), asset);
+ }
+
+ }};
+}
diff --git a/manager/client/src/main/java/org/openremote/manager/client/assets/asset/Asset.java b/manager/client/src/main/java/org/openremote/manager/client/assets/asset/Asset.java
index 6675c6837..cb41687af 100644
--- a/manager/client/src/main/java/org/openremote/manager/client/assets/asset/Asset.java
+++ b/manager/client/src/main/java/org/openremote/manager/client/assets/asset/Asset.java
@@ -19,7 +19,7 @@
*/
package org.openremote.manager.client.assets.asset;
-import org.openremote.manager.client.interop.mapbox.LngLat;
+import org.geojson.Point;
public class Asset {
@@ -35,21 +35,21 @@ public class Asset {
public static final String ROOT_ID = null;
public static final String ROOT_TYPE = Type.COMPOSITE.name();
public static final String ROOT_LABEL = "ROOT";
- public static final LngLat ROOT_LOCATION = new LngLat(0, 0);
+ public static final Point ROOT_LOCATION = new Point(0, 0, 0);
public String id;
public String type;
public String displayName;
- public LngLat location;
+ public String mapFeatures;
public Asset() {
}
- public Asset(String id, String type, String displayName, LngLat location) {
+ public Asset(String id, String type, String displayName, String mapFeatures) {
this.id = id;
this.type = type;
this.displayName = displayName;
- this.location = location;
+ this.mapFeatures = mapFeatures;
}
public String getId() {
@@ -68,12 +68,12 @@ public class Asset {
this.displayName = displayName;
}
- public LngLat getLocation() {
- return location;
+ public String getMapFeatures() {
+ return mapFeatures;
}
- public void setLocation(LngLat location) {
- this.location = location;
+ public void setMapFeatures(String mapFeatures) {
+ this.mapFeatures = mapFeatures;
}
public String getType() {
@@ -90,7 +90,7 @@ public class Asset {
"id='" + id + '\'' +
", type='" + type + '\'' +
", displayName='" + displayName + '\'' +
- ", location='" + location + '\'' +
+ ", mapFeatures ='" + mapFeatures + '\'' +
'}';
}
}
diff --git a/manager/client/src/main/java/org/openremote/manager/client/assets/browser/AssetBrowserImpl.java b/manager/client/src/main/java/org/openremote/manager/client/assets/browser/AssetBrowserImpl.java
index f08fa2733..2936180f6 100644
--- a/manager/client/src/main/java/org/openremote/manager/client/assets/browser/AssetBrowserImpl.java
+++ b/manager/client/src/main/java/org/openremote/manager/client/assets/browser/AssetBrowserImpl.java
@@ -28,6 +28,7 @@ import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.HTMLPanel;
import com.google.gwt.user.client.ui.SimplePanel;
import com.google.gwt.user.client.ui.TextBox;
+import org.openremote.manager.client.assets.SampleAssets;
import org.openremote.manager.client.assets.asset.Asset;
import org.openremote.manager.client.i18n.ManagerMessages;
import org.openremote.manager.client.style.FormTreeStyle;
@@ -75,7 +76,7 @@ public class AssetBrowserImpl extends Composite implements AssetBrowser {
assetTree = new AssetTree(
new AssetTreeModel(presenter),
- new Asset(Asset.ROOT_ID, Asset.ROOT_TYPE, Asset.ROOT_LABEL, Asset.ROOT_LOCATION),
+ SampleAssets.ROOT,
formTreeStyle,
new CellTree.CellTreeMessages() {
@Override
diff --git a/manager/client/src/main/java/org/openremote/manager/client/assets/browser/AssetBrowserPresenter.java b/manager/client/src/main/java/org/openremote/manager/client/assets/browser/AssetBrowserPresenter.java
index 6514ac582..0635979e0 100644
--- a/manager/client/src/main/java/org/openremote/manager/client/assets/browser/AssetBrowserPresenter.java
+++ b/manager/client/src/main/java/org/openremote/manager/client/assets/browser/AssetBrowserPresenter.java
@@ -23,15 +23,13 @@ import com.google.gwt.place.shared.PlaceController;
import com.google.gwt.user.client.Timer;
import com.google.gwt.view.client.HasData;
import com.google.gwt.view.client.Range;
+import org.openremote.manager.client.assets.SampleAssets;
import org.openremote.manager.client.assets.asset.Asset;
import org.openremote.manager.client.event.bus.EventBus;
import org.openremote.manager.client.event.bus.EventListener;
import org.openremote.manager.client.event.bus.EventRegistration;
-import org.openremote.manager.client.interop.mapbox.LngLat;
import javax.inject.Inject;
-import java.util.ArrayList;
-import java.util.Arrays;
import java.util.List;
import java.util.logging.Logger;
@@ -46,11 +44,8 @@ public class AssetBrowserPresenter implements AssetBrowser.Presenter {
protected Asset selectedAsset;
@Inject
- public AssetBrowserPresenter(AssetBrowser view,
- PlaceController placeController) {
-
+ public AssetBrowserPresenter(AssetBrowser view, PlaceController placeController) {
this.internalEventBus = new EventBus();
-
this.view = view;
this.placeController = placeController;
@@ -66,67 +61,17 @@ public class AssetBrowserPresenter implements AssetBrowser.Presenter {
public void loadAssetChildren(Asset parent, HasData<Asset> display) {
final Range range = display.getVisibleRange();
// TODO: Real assets query
- Timer t = null;
- if (Asset.isRoot(parent)) {
- t = new Timer() {
- public void run() {
- List<Asset> assets = Arrays.asList(
- new Asset("composite:gateways", Asset.Type.COMPOSITE.name(), "Gateways", new LngLat(5.460315214821094, 51.44541688237109)),
- new Asset("composite:buildings", Asset.Type.COMPOSITE.name(), "Buildings", new LngLat(5.460315214821094, 51.44541688237109)),
- new Asset("composite:rooms", Asset.Type.COMPOSITE.name(), "Rooms", new LngLat(5.460315214821094, 51.44541688237109)),
- new Asset("composite:thermostats", Asset.Type.COMPOSITE.name(), "Thermostats", new LngLat(5.460315214821094, 51.44541688237109))
- );
- display.setRowData(0, assets);
- onAssetsRefreshed(parent, assets);
- }
- };
- } else if (parent.getType().equals(Asset.Type.COMPOSITE.name())) {
- if (parent.getId().equals("composite:gateways")) {
- t = new Timer() {
- public void run() {
- List<Asset> assets = new ArrayList<>();
- for (int i = 1000; i < 1100; i++) {
- assets.add(
- new Asset(
- Integer.toString(i),
- Asset.Type.COMPOSITE.name(),
- "Gateway " + i,
- new LngLat(5.460315214821094, 51.44541688237109)
- )
- );
- }
- display.setRowData(0, assets);
- onAssetsRefreshed(parent, assets);
- }
- };
- }
-
- if (parent.getId().equals("1000")) {
- t = new Timer() {
- public void run() {
- List<Asset> assets = Arrays.asList(
- new Asset("11", Asset.Type.SENSOR.name(), "Sensor 1", new LngLat(5.460315214821094, 51.44541688237109)),
- new Asset("22", Asset.Type.SENSOR.name(), "Sensor 2", new LngLat(5.460315214821094, 51.44541688237109)),
- new Asset("33", Asset.Type.SENSOR.name(), "Sensor 3", new LngLat(5.460315214821094, 51.44541688237109))
- );
- display.setRowData(0, assets);
- onAssetsRefreshed(parent, assets);
- }
- };
+ List<Asset> result = SampleAssets.queryAll(parent);
+ Timer t = new Timer() {
+ public void run() {
+ display.setRowData(0, result);
+ display.setRowCount(result.size(), true);
+ onAssetsRefreshed(parent, result);
}
- }
-
- if (t != null) {
-
- // TODO: Simulates network delay
- t.schedule(25);
- //t.run();
-
- } else {
- display.setRowData(0, new ArrayList<>());
- display.setRowCount(0, true);
- onAssetsRefreshed(parent, new ArrayList<>());
- }
+ };
+ // TODO: Simulates network delay
+ t.schedule(25);
+ //t.run();
}
@Override
@@ -163,7 +108,11 @@ public class AssetBrowserPresenter implements AssetBrowser.Presenter {
protected void updateViewSelection(boolean scrollIntoView) {
// Find the last selected asset after a data refresh and select it again
if (selectedAsset != null) {
- view.showAndSelectAsset(getSelectedAssetPath(), selectedAsset.getId(), scrollIntoView);
+ view.showAndSelectAsset(
+ SampleAssets.getSelectedAssetPath(selectedAsset.getId()),
+ selectedAsset.getId(),
+ scrollIntoView
+ );
}
}
@@ -178,43 +127,4 @@ public class AssetBrowserPresenter implements AssetBrowser.Presenter {
updateViewSelection(scroll);
}
}
-
- protected List<String> getSelectedAssetPath() {
- List<String> path = new ArrayList<>();
- // TODO: We must build the asset path here, by finding the asset first, then its parents recursively
- switch (selectedAsset.getId()) {
- case "composite:gateways":
- path.add("composite:gateways");
- break;
- case "composite:buildings":
- path.add("composite:buildings");
- break;
- case "composite:rooms":
- path.add("composite:rooms");
- break;
- case "composite:thermostats":
- path.add("composite:thermostats");
- break;
- case "11":
- path.add("composite:gateways");
- path.add("1000");
- path.add("11");
- break;
- case "22":
- path.add("composite:gateways");
- path.add("1000");
- path.add("22");
- break;
- case "33":
- path.add("composite:gateways");
- path.add("1000");
- path.add("33");
- break;
- default:
- path.add("composite:gateways");
- path.add(selectedAsset.getId());
- break;
- }
- return path;
- }
}
diff --git a/manager/client/src/main/java/org/openremote/manager/client/assets/browser/AssetBrowsingActivity.java b/manager/client/src/main/java/org/openremote/manager/client/assets/browser/AssetBrowsingActivity.java
index b509431fc..ec44a414a 100644
--- a/manager/client/src/main/java/org/openremote/manager/client/assets/browser/AssetBrowsingActivity.java
+++ b/manager/client/src/main/java/org/openremote/manager/client/assets/browser/AssetBrowsingActivity.java
@@ -21,10 +21,10 @@ package org.openremote.manager.client.assets.browser;
import com.google.gwt.user.client.Timer;
import com.google.gwt.user.client.ui.AcceptsOneWidget;
+import org.openremote.manager.client.assets.SampleAssets;
import org.openremote.manager.client.assets.asset.Asset;
import org.openremote.manager.client.event.bus.EventBus;
import org.openremote.manager.client.event.bus.EventRegistration;
-import org.openremote.manager.client.interop.mapbox.LngLat;
import org.openremote.manager.client.mvp.AppActivity;
import java.util.Collection;
@@ -114,7 +114,7 @@ abstract public class AssetBrowsingActivity<V extends AssetBrowsingView, T exten
onBeforeAssetLoad();
new Timer() {
public void run() {
- asset = new Asset(assetId, "DUMMY", "DUMMY FOR ID " + assetId, new LngLat(5.460315214821094, 51.44541688237109));
+ asset = SampleAssets.ALL_BY_ID.get(assetId);
assetBrowserPresenter.selectAsset(asset);
onAssetReady();
}
diff --git a/manager/client/src/main/java/org/openremote/manager/client/interop/mapbox/EventType.java b/manager/client/src/main/java/org/openremote/manager/client/interop/mapbox/EventType.java
index 32ab0ba60..34b2337eb 100644
--- a/manager/client/src/main/java/org/openremote/manager/client/interop/mapbox/EventType.java
+++ b/manager/client/src/main/java/org/openremote/manager/client/interop/mapbox/EventType.java
@@ -22,6 +22,7 @@ package org.openremote.manager.client.interop.mapbox;
public class EventType {
private EventType(){}
+ public static final String LOAD = "load";
public static final String CLICK = "click";
public static final String DOUBLE_CLICK = "dblclick";
public static final String DRAG = "drag";
diff --git a/manager/client/src/main/java/org/openremote/manager/client/interop/mapbox/GeoJSONSource.java b/manager/client/src/main/java/org/openremote/manager/client/interop/mapbox/GeoJSONSource.java
new file mode 100644
index 000000000..6e01861bf
--- /dev/null
+++ b/manager/client/src/main/java/org/openremote/manager/client/interop/mapbox/GeoJSONSource.java
@@ -0,0 +1,31 @@
+/*
+ * 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 elemental.json.JsonObject;
+import jsinterop.annotations.JsType;
+
+@JsType(isNative = true, namespace = "mapboxgl")
+public class GeoJSONSource {
+
+ public GeoJSONSource(JsonObject options) {}
+
+ public native void setData(JsonObject data);
+}
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
index d1cc2a95d..45ebf6c4d 100644
--- 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
@@ -19,6 +19,7 @@
*/
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;
@@ -42,10 +43,10 @@ public class Map {
public native Map addControl(Control control);
- public native Map addLayer(Object layer);
- public native Map addLayer(Object layer, String beforeLayerId);
+ public native Map addLayer(JavaScriptObject layer);
+ public native Map addLayer(JavaScriptObject layer, String beforeLayerId);
- public native Map addSource(String id, Object source);
+ public native Map addSource(String id, GeoJSONSource source);
// TODO: add batch method fucntionality to map
// public native void batch(WorkFn work);
@@ -84,7 +85,7 @@ public class Map {
public native JsonArray getFilter(String layerId);
- public native JsonObject getLayer(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);
@@ -120,7 +121,7 @@ public class Map {
public native Map removeLayer(String layerId);
- public native Map removeSource(String layerId);
+ public native Map removeSource(String sourceId);
public native void repaint();
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 9393ee28e..52bdac250 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
@@ -34,11 +34,14 @@ import org.openremote.manager.shared.map.MapResource;
import javax.inject.Inject;
import java.util.Collection;
+import java.util.logging.Logger;
import static org.openremote.manager.client.http.RequestExceptionHandler.handleRequestException;
public class MapActivity extends AssetBrowsingActivity<MapView, MapPlace> implements MapView.Presenter {
+ private static final Logger LOG = Logger.getLogger(MapActivity.class.getName());
+
final MapResource mapResource;
final ManagerMessages managerMessages;
final RequestService requestService;
@@ -81,14 +84,19 @@ public class MapActivity extends AssetBrowsingActivity<MapView, MapPlace> implem
);
}
+ @Override
+ protected void startCreateAsset() {
+ getView().hideFeatures();
+ }
+
@Override
protected void onAssetReady() {
- getView().addPopup(asset.getDisplayName(), asset.getLocation());
- // TODO Write data
+ getView().showFeatures(asset.getMapFeatures());
}
@Override
protected void onAssetsDeselected() {
+ getView().hideFeatures();
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 99e2fe456..9a155a223 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
@@ -21,7 +21,6 @@ package org.openremote.manager.client.map;
import elemental.json.JsonObject;
import org.openremote.manager.client.assets.browser.AssetBrowsingView;
-import org.openremote.manager.client.interop.mapbox.LngLat;
public interface MapView extends AssetBrowsingView<MapView.Presenter> {
@@ -34,6 +33,8 @@ public interface MapView extends AssetBrowsingView<MapView.Presenter> {
void refresh();
- void addPopup(String text, LngLat location);
+ void showFeatures(String mapFeaturesJson);
+
+ void hideFeatures();
}
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 44ef107f2..e4440a0f9 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
@@ -27,7 +27,6 @@ import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.HTMLPanel;
import com.google.gwt.user.client.ui.Label;
import elemental.json.JsonObject;
-import org.openremote.manager.client.interop.mapbox.LngLat;
import javax.inject.Inject;
@@ -62,6 +61,12 @@ 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);
@@ -84,9 +89,8 @@ public class MapViewImpl extends Composite implements MapView {
mapWidget.refresh();
}
- public void addPopup(String text, LngLat location) {
- if (isMapInitialised()) {
- mapWidget.addPopup(text, location);
- }
+ @Override
+ public void showFeatures(String mapFeaturesJson) {
+ mapWidget.showFeatures(mapFeaturesJson);
}
}
diff --git a/manager/client/src/main/java/org/openremote/manager/client/map/MapViewImpl.ui.xml b/manager/client/src/main/java/org/openremote/manager/client/map/MapViewImpl.ui.xml
index 7608fee63..39361eed7 100644
--- a/manager/client/src/main/java/org/openremote/manager/client/map/MapViewImpl.ui.xml
+++ b/manager/client/src/main/java/org/openremote/manager/client/map/MapViewImpl.ui.xml
@@ -1,6 +1,7 @@
<ui:UiBinder xmlns:ui="urn:ui:com.google.gwt.uibinder"
xmlns:map="urn:import:org.openremote.manager.client.map"
- xmlns:g="urn:import:com.google.gwt.user.client.ui">
+ xmlns:g="urn:import:com.google.gwt.user.client.ui"
+ xmlns:w="urn:import:org.openremote.manager.client.widget">
<ui:with field="managerMessages" type="org.openremote.manager.client.i18n.ManagerMessages"/>
<ui:with field="widgetStyle" type="org.openremote.manager.client.style.WidgetStyle"/>
@@ -11,6 +12,10 @@
position: relative;
}
+ .navItem {
+ margin: 0 1em;
+ }
+
.mapWidget {
position: absolute;
top: 0;
@@ -34,6 +39,13 @@
<g:HTMLPanel
styleName="flex layout horizontal center end-justified {style.mapControls} {widgetStyle.SecondaryNav} {themeStyle.SecondaryNav}">
+
+ <w:Hyperlink addStyleNames="{style.navItem} {widgetStyle.SecondaryNavItem} {themeStyle.SecondaryNavItem}"
+ icon="map"
+ targetHistoryToken="map:"
+ text="Show all assets"/>
+
+
<div>TODO: Move map navigation action items here</div>
</g:HTMLPanel>
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 6bb27b01f..967c96391 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
@@ -23,9 +23,13 @@ import com.google.gwt.dom.client.Document;
import com.google.gwt.dom.client.Element;
import com.google.gwt.user.client.ui.ComplexPanel;
import com.google.gwt.user.client.ui.FlowPanel;
-import elemental.js.util.JsMapFromStringTo;
+import elemental.js.util.*;
+import elemental.json.Json;
import elemental.json.JsonObject;
-import org.openremote.manager.client.interop.mapbox.*;
+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.Navigation;
import java.util.logging.Logger;
@@ -33,10 +37,17 @@ 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";
+
protected FlowPanel host;
protected String id;
protected Map map;
- protected Popup popup;
+ 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;
public MapWidget(JsonObject mapOptions) {
this();
@@ -77,15 +88,22 @@ public class MapWidget extends ComplexPanel {
map.addControl(new Navigation());
+ map.on(EventType.LOAD, eventData -> {
+ addFeatures();
+ });
+
+ /*
JsMapFromStringTo<Object> popupOptions = JsMapFromStringTo.create();
popupOptions.put("closeOnClick", false);
popup = new Popup(popupOptions.cast())
.addTo(map);
+ */
map.on(EventType.CLICK, eventData -> {
LOG.info("### COORDS: " + eventData.getLngLat());
LOG.info("### BOUNDS: " + map.getBounds());
});
+
}
public void refresh() {
@@ -95,9 +113,101 @@ public class MapWidget extends ComplexPanel {
}
}
- public void addPopup(String text, LngLat location) {
- if (popup != null) {
- popup.setText(text).setLngLat(location);
+ protected void addFeatures() {
+ 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);
}
}
+
+ 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 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;
+ }
}
diff --git a/manager/client/src/main/java/org/openremote/manager/client/service/RequestServiceImpl.java b/manager/client/src/main/java/org/openremote/manager/client/service/RequestServiceImpl.java
index 9100ae362..250213c33 100644
--- a/manager/client/src/main/java/org/openremote/manager/client/service/RequestServiceImpl.java
+++ b/manager/client/src/main/java/org/openremote/manager/client/service/RequestServiceImpl.java
@@ -167,7 +167,7 @@ public class RequestServiceImpl implements RequestService {
OUT out = null;
if (responseText != null && responseText.length() > 0 && entityReader != null) {
if (LOG.isLoggable(Level.FINE))
- LOG.fine("Reading response text: " + responseText);
+ LOG.fine("Reading response text, length: " + responseText.length());
try {
out = entityReader.read(responseText);
} catch (Exception ex) {
diff --git a/manager/client/src/main/resources/org/geojson/GeoJSON.gwt.xml b/manager/client/src/main/resources/org/geojson/GeoJSON.gwt.xml
new file mode 100644
index 000000000..f678a1c95
--- /dev/null
+++ b/manager/client/src/main/resources/org/geojson/GeoJSON.gwt.xml
@@ -0,0 +1,8 @@
+<!DOCTYPE module PUBLIC "-//Google Inc.//DTD Google Web Toolkit 2.0//EN"
+ "http://google-web-toolkit.googlecode.com/svn/releases/2.0/distro-source/core/src/gwt-module.dtd">
+
+<module rename-to="GeoJSON">
+
+ <source path=""/>
+
+</module>
\ No newline at end of file
diff --git a/manager/client/src/main/resources/org/openremote/manager/Manager.gwt.xml b/manager/client/src/main/resources/org/openremote/manager/Manager.gwt.xml
index 95bf2c9d7..19a09d24f 100644
--- a/manager/client/src/main/resources/org/openremote/manager/Manager.gwt.xml
+++ b/manager/client/src/main/resources/org/openremote/manager/Manager.gwt.xml
@@ -17,6 +17,7 @@
<inherits name="com.github.nmorel.gwtjackson.GwtJackson"/>
<inherits name="org.jboss.resteasy.api.validation.ResteasyValidation"/>
<inherits name="org.keycloak.representations.idm.KeycloakIDM"/>
+ <inherits name="org.geojson.GeoJSON"/>
<!-- ##################################################################### -->
diff --git a/manager/shared/build.gradle b/manager/shared/build.gradle
index d8e81c363..0c1fb8040 100644
--- a/manager/shared/build.gradle
+++ b/manager/shared/build.gradle
@@ -11,6 +11,8 @@ dependencies {
compile "org.keycloak:keycloak-core:$keycloakVersion"
compile "org.keycloak:keycloak-core:$keycloakVersion:sources"
compile "org.hibernate:hibernate-validator:$hibernateValidatorVersion"
+ compile "de.grundid.opendatalab:geojson-jackson:$geojsonJacksonVersion"
+ compile "de.grundid.opendatalab:geojson-jackson:$geojsonJacksonVersion:sources"
apt "org.hibernate:hibernate-jpamodelgen:$hibernateVersion"
}