Skip to content

armgit / core

Public Imported from GitHub
0

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

Map style improvements

Christian Bauer2e6b11784383
diff --git a/manager/sample/mapsettings.json b/manager/sample/mapsettings.json
index 79375c44d..c0a7bc81c 100644
--- a/manager/sample/mapsettings.json
+++ b/manager/sample/mapsettings.json
@@ -1,6 +1,6 @@
{
"center": [5.4774, 51.4370],
- "maxBounds": [5.3547,51.3757,5.586,51.5364],
+ "maxBounds": [5.3547, 51.3757, 5.586, 51.5364],
"zoom": 12,
"maxZoom": 18,
"style": {
@@ -12,12 +12,32 @@
"background-color": "#e0e0e0"
}
},
+ {
+ "id": "landuse_industrial",
+ "type": "fill",
+ "source": "vector_tiles",
+ "source-layer": "landuse",
+ "filter": ["all", ["==", "class", "industrial"], ["==", "$type", "Polygon"]],
+ "paint": {
+ "fill-color": "#cfcfcf"
+ }
+ },
+ {
+ "id": "landuse_cemetery",
+ "type": "fill",
+ "source": "vector_tiles",
+ "source-layer": "landuse",
+ "filter": ["all", ["==", "class", "cemetery"], ["==", "$type", "Polygon"]],
+ "paint": {
+ "fill-color": "#C9E3A8"
+ }
+ },
{
"id": "landuse_wood",
"type": "fill",
"source": "vector_tiles",
"source-layer": "landuse",
- "filter": ["in", "class", "park", "wood"],
+ "filter": ["all", ["in", "class", "park", "wood", "forest"], ["==", "$type", "Polygon"]],
"paint": {
"fill-color": "#d2edae"
}
@@ -96,7 +116,7 @@
"filter": ["all", ["==", "$type", "LineString"], ["==", "type", "runway"]],
"minzoom": 11,
"paint": {
- "line-color": "#666",
+ "line-color": "#888",
"line-width": {
"base": 5,
"stops": [[11, 4], [20, 10]]
@@ -146,7 +166,7 @@
["in", "class", "motorway_link", "street", "street_limited", "service", "driveway", "path"]
],
"paint": {
- "line-color": "#888",
+ "line-color": "#666",
"line-width": {
"base": 1.55,
"stops": [[4, 0.25], [20, 30]]
@@ -186,7 +206,7 @@
"line-color": "#bbb",
"line-width": {
"base": 1.8,
- "stops": [[4, 0.25], [20, 30]]
+ "stops": [[4, 1], [20, 30]]
}
}
},
@@ -208,6 +228,36 @@
}
}
},
+ {
+ "id": "road_major_rail",
+ "type": "line",
+ "source": "vector_tiles",
+ "source-layer": "road",
+ "filter": ["all", ["==", "$type", "LineString"], ["in", "class", "major_rail"]],
+ "layout": {
+ "line-cap": "round",
+ "line-join": "round"
+ },
+ "paint": {
+ "line-color": "#ccc",
+ "line-width": {
+ "base": 1.4,
+ "stops": [[6, 0.5], [20, 10]]
+ }
+ }
+ },
+ {
+ "id": "road_major_rail_hatching",
+ "ref": "road_major_rail",
+ "paint": {
+ "line-color": "#888",
+ "line-width": {
+ "base": 1.4,
+ "stops": [[6, 0.5], [20, 10]]
+ },
+ "line-dasharray": [3, 3]
+ }
+ },
{
"id": "bridge_minor_case",
"type": "line",
@@ -225,7 +275,7 @@
},
"line-gap-width": {
"base": 1.55,
- "stops": [[4, 0.25], [20, 30]]
+ "stops": [[4, 0.25], [20, 15]]
}
}
},
@@ -234,7 +284,7 @@
"type": "line",
"source": "vector_tiles",
"source-layer": "bridge",
- "filter": ["all", ["==", "$type", "LineString"], ["in", "class", "motorway", "main"]],
+ "filter": ["all", ["==", "$type", "LineString"], ["in", "class", "motorway", "main", "major_rail"]],
"paint": {
"line-color": "#bbc",
"line-width": {
@@ -243,7 +293,7 @@
},
"line-gap-width": {
"base": 1.4,
- "stops": [[6, 0.5], [20, 30]]
+ "stops": [[6, 0.5], [20, 20]]
}
}
},
@@ -261,10 +311,10 @@
"line-join": "round"
},
"paint": {
- "line-color": "#aab",
+ "line-color": "#889",
"line-width": {
"base": 1.55,
- "stops": [[4, 0.25], [20, 30]]
+ "stops": [[4, 0.25], [20, 15]]
}
}
},
@@ -273,16 +323,16 @@
"type": "line",
"source": "vector_tiles",
"source-layer": "bridge",
- "filter": ["all", ["==", "$type", "LineString"], ["in", "class", "motorway", "main"]],
+ "filter": ["all", ["==", "$type", "LineString"], ["in", "class", "motorway", "main", "major_rail"]],
"layout": {
"line-cap": "round",
"line-join": "round"
},
"paint": {
- "line-color": "#aab",
+ "line-color": "#889",
"line-width": {
"base": 1.4,
- "stops": [[6, 0.5], [20, 30]]
+ "stops": [[6, 0.5], [20, 20]]
}
}
},
diff --git a/manager/src/main/java/org/openremote/manager/server/service/MapService.java b/manager/src/main/java/org/openremote/manager/server/service/MapService.java
index 1d0f52faa..871ed01b3 100644
--- a/manager/src/main/java/org/openremote/manager/server/service/MapService.java
+++ b/manager/src/main/java/org/openremote/manager/server/service/MapService.java
@@ -13,6 +13,9 @@ import java.util.HashMap;
import java.util.Map;
import java.util.logging.Logger;
+import static org.openremote.manager.server.Constants.DEV_MODE;
+import static org.openremote.manager.server.Constants.DEV_MODE_DEFAULT;
+
public class MapService {
private static final Logger LOG = Logger.getLogger(MapService.class.getName());
@@ -25,9 +28,14 @@ public class MapService {
// Shared SQL connection is fine concurrently in SQLite
protected Connection connection;
- protected elemental.json.JsonObject mapSettings;
+ protected Vertx vertx;
+ protected boolean devMode;
+ protected Path mapSettingsPath;
+ protected JsonObject mapSettings;
public void start(Vertx vertx, io.vertx.core.json.JsonObject config) {
+ this.vertx = vertx;
+ this.devMode = config.getBoolean(DEV_MODE, DEV_MODE_DEFAULT);
Path mapTilesPath = Paths.get(config.getString(MAP_TILES_PATH, MAP_TILES_PATH_DEFAULT));
if (!Files.isRegularFile(mapTilesPath)) {
@@ -36,7 +44,7 @@ public class MapService {
);
}
- Path mapSettingsPath = Paths.get(config.getString(MAP_SETTINGS_PATH, MAP_SETTINGS_PATH_DEFAULT));
+ 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()
@@ -51,11 +59,7 @@ public class MapService {
throw new IllegalStateException(ex);
}
- mapSettings = Json.parse(
- vertx.fileSystem().readFileBlocking(mapSettingsPath.toAbsolutePath().toString()).toString()
- );
-
- adjustMapSettings();
+ readMapSettings();
}
public void stop() {
@@ -70,6 +74,12 @@ public class MapService {
}
public JsonObject getMapSettings(String mapTileBaseUrl) {
+
+ // Refresh map settings for every request in dev mode, cache it in production
+ if (devMode) {
+ readMapSettings();
+ }
+
// TODO: Maybe we should complete the URL on the client
JsonObject settingsCopy = Json.parse(mapSettings.toJson());
JsonArray tilesArray = Json.createArray();
@@ -103,8 +113,16 @@ public class MapService {
}
}
- protected void adjustMapSettings() {
+ protected void readMapSettings() {
+
// Mix settings from file with database metadata, and some hardcoded magic
+ try {
+ mapSettings = Json.parse(
+ vertx.fileSystem().readFileBlocking(mapSettingsPath.toAbsolutePath().toString()).toString()
+ );
+ } catch (Exception ex) {
+ throw new RuntimeException("Error parsing map settings: " + mapSettingsPath.toAbsolutePath(), ex);
+ }
JsonObject style = mapSettings.getObject("style");