Search in sources :

Example 11 with ObjectValue

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;
}
Also used : ObjectValue(org.openremote.model.value.ObjectValue)

Example 12 with ObjectValue

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);
}
Also used : ObjectValue(org.openremote.model.value.ObjectValue)

Example 13 with ObjectValue

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());
}
Also used : ObjectValue(org.openremote.model.value.ObjectValue) ArrayValue(org.openremote.model.value.ArrayValue)

Example 14 with ObjectValue

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;
}
Also used : ObjectValue(org.openremote.model.value.ObjectValue)

Example 15 with 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;
}
Also used : ObjectValue(org.openremote.model.value.ObjectValue) HashMap(java.util.HashMap) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) MapAccess.getString(org.openremote.container.util.MapAccess.getString) ArrayValue(org.openremote.model.value.ArrayValue)

Aggregations

ObjectValue (org.openremote.model.value.ObjectValue)21 java.util (java.util)3 Logger (java.util.logging.Logger)3 Collectors (java.util.stream.Collectors)3 Stream (java.util.stream.Stream)3 EntityManager (javax.persistence.EntityManager)3 RouteBuilder (org.apache.camel.builder.RouteBuilder)3 Container (org.openremote.container.Container)3 ContainerService (org.openremote.container.ContainerService)3 GlobalLock.withLock (org.openremote.container.concurrent.GlobalLock.withLock)3 GlobalLock.withLockReturning (org.openremote.container.concurrent.GlobalLock.withLockReturning)3 MessageBrokerSetupService (org.openremote.container.message.MessageBrokerSetupService)3 PersistenceEvent (org.openremote.container.persistence.PersistenceEvent)3 TimerService (org.openremote.container.timer.TimerService)3 org.openremote.manager.asset (org.openremote.manager.asset)3 ManagerIdentityService (org.openremote.manager.security.ManagerIdentityService)3 VALUE_TIMESTAMP_FIELD_NAME (org.openremote.model.AbstractValueTimestampHolder.VALUE_TIMESTAMP_FIELD_NAME)3 AssetAttribute.attributesFromJson (org.openremote.model.asset.AssetAttribute.attributesFromJson)3 AssetAttribute.getAddedOrModifiedAttributes (org.openremote.model.asset.AssetAttribute.getAddedOrModifiedAttributes)3 Source (org.openremote.model.attribute.AttributeEvent.Source)3