use of org.openremote.model.value.ArrayValue in project openremote by openremote.
the class MapService method getMapSettings.
public ObjectValue getMapSettings(String realm, UriBuilder baseUriBuilder) {
ObjectValue mapSettings;
// Mix settings from file with database metadata, and some hardcoded magic
try {
String mapSettingsJson = new String(Files.readAllBytes(mapSettingsPath), "utf-8");
mapSettings = Values.<ObjectValue>parse(mapSettingsJson).orElseThrow(() -> new RuntimeException("Error parsing map settings: " + mapSettingsPath.toAbsolutePath()));
} catch (Exception ex) {
throw new RuntimeException("Error parsing map settings: " + mapSettingsPath.toAbsolutePath(), ex);
}
ObjectValue style = mapSettings.getObject("style").orElseThrow(() -> new RuntimeException("Missing 'style' field in map settings style: " + mapSettingsPath.toAbsolutePath()));
style.put("version", 8);
if (style.hasKey("sprite")) {
// Rewrite path to sprite file to our external host
String spritePath = style.getString("sprite").orElseThrow(() -> new RuntimeException("Missing 'sprite' field in map settings style: " + mapSettingsPath.toAbsolutePath()));
String spriteUri = baseUriBuilder.clone().replacePath(ManagerWebService.MANAGER_PATH).path(spritePath).build().toString();
style.put("sprite", spriteUri);
}
String glyphsUri = baseUriBuilder.clone().replacePath(ManagerWebService.MANAGER_PATH).path("/fonts/").build().toString() + "{fontstack}/{range}.pbf";
style.put("glyphs", glyphsUri);
ObjectValue sources = Values.createObject();
style.put("sources", sources);
ObjectValue vectorTiles = Values.createObject();
sources.put("vector_tiles", vectorTiles);
vectorTiles.put("type", "vector");
ArrayValue tilesArray = Values.createArray();
String tileUrl = baseUriBuilder.clone().replacePath(realm).path("map/tile").build().toString() + "/{z}/{x}/{y}";
tilesArray.set(0, tileUrl);
vectorTiles.put("tiles", tilesArray);
PreparedStatement query = null;
ResultSet result = null;
try {
query = connection.prepareStatement("select NAME, VALUE from METADATA");
result = query.executeQuery();
Map<String, String> resultMap = new HashMap<>();
while (result.next()) {
resultMap.put(result.getString(1), result.getString(2));
}
if (resultMap.size() == 0) {
throw new RuntimeException("Missing JSON metadata in map database");
}
ObjectValue metadataJson = Values.<ObjectValue>parse(resultMap.get("json")).orElseThrow(() -> new RuntimeException("Error parsing JSON metadata from map database"));
ArrayValue vectorLayers = metadataJson.getArray("vector_layers").orElseThrow(() -> new RuntimeException("Missing 'vector_layers' field in metadata from map database"));
vectorTiles.put("vector_layers", vectorLayers);
vectorTiles.put("maxzoom", Integer.valueOf(resultMap.get("maxzoom")));
vectorTiles.put("minzoom", Integer.valueOf(resultMap.get("minzoom")));
vectorTiles.put("attribution", resultMap.get("attribution"));
} catch (Exception ex) {
throw new RuntimeException("Error opening database: " + this, ex);
} finally {
closeQuietly(query, result);
}
return mapSettings;
}
use of org.openremote.model.value.ArrayValue in project openremote by openremote.
the class AttributeRef method toArrayValue.
public ArrayValue toArrayValue() {
ArrayValue arrayValue = Values.createArray();
arrayValue.set(0, Values.create(getEntityId()));
arrayValue.set(1, Values.create(getAttributeName()));
return arrayValue;
}
use of org.openremote.model.value.ArrayValue in project openremote by openremote.
the class GeoJSON method setFeatures.
public GeoJSON setFeatures(GeoJSONFeature... features) {
if (features != null) {
for (int i = 0; i < features.length; i++) {
GeoJSONFeature feature = features[i];
ArrayValue array = Values.createArray();
array.set(i, feature.getObjectValue());
objectValue.put("features", array);
}
} else {
return setEmptyFeatures();
}
return this;
}
Aggregations