use of org.openremote.model.value.ObjectValue in project openremote by openremote.
the class MapWidget method prepareSourceOptions.
protected ObjectValue prepareSourceOptions(String featureSourceId) {
ObjectValue sourceOptions = Values.createObject();
// Initialize with empty collection
ObjectValue initialData = GeoJSON.EMPTY_FEATURE_COLLECTION.getObjectValue();
LOG.fine("Preparing initial data on feature source: " + featureSourceId);
sourceOptions.put("type", create("geojson"));
sourceOptions.put("data", initialData);
return sourceOptions;
}
use of org.openremote.model.value.ObjectValue in project openremote by openremote.
the class MapWidget method showPopup.
public void showPopup(double lng, double lat, String text) {
if (!isMapReady())
throw new IllegalStateException("Map not ready");
ObjectValue popupOptions = Values.createObject();
popupOptions.put("closeOnClick", create(false));
popupOptions.put("closeButton", create(false));
popup = new Popup(popupOptions.asAny());
popup.setLngLat(new LngLat(lng, lat)).setText(text);
popup.addTo(mapboxMap);
}
use of org.openremote.model.value.ObjectValue in project openremote by openremote.
the class MapWidget method flyTo.
public void flyTo(double[] coordinates) {
if (!isMapReady())
throw new IllegalStateException("Map not ready");
if (coordinates == null || coordinates.length != 2)
return;
ObjectValue options = Values.createObject();
ArrayValue center = Values.createArray();
center.set(0, coordinates[0]);
center.set(1, coordinates[1]);
options.put("center", center);
mapboxMap.flyTo(options.asAny());
}
use of org.openremote.model.value.ObjectValue in project openremote by openremote.
the class MacroAction method toObjectValue.
public ObjectValue toObjectValue() {
ObjectValue objectValue = Values.createObject();
objectValue.put("attributeState", attributeState.toObjectValue());
objectValue.put("delay", Values.create(delayMilliseconds));
return objectValue;
}
use of org.openremote.model.value.ObjectValue 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;
}
Aggregations