Search in sources :

Example 1 with API_PATH

use of org.openremote.manager.web.ManagerWebService.API_PATH in project openremote by openremote.

the class MapService method getMapSettings.

/**
 * Dynamically build Mapbox GL settings based on mapsettings.json
 */
public ObjectNode getMapSettings(String realm, UriBuilder baseUriBuilder) {
    if (mapSettings.containsKey(realm)) {
        return mapSettings.get(realm);
    }
    final ObjectNode settings = mapSettings.computeIfAbsent(realm, r -> {
        if (metadata.isValid() && !mapConfig.isEmpty()) {
            // Use config as a settings base and convert URLs
            return mapConfig.deepCopy();
        }
        return mapConfig.objectNode();
    });
    if (!metadata.isValid() || mapConfig.isEmpty()) {
        return settings;
    }
    // Set vector_tiles URL to MapResource getSource endpoint
    Optional.ofNullable(settings.get("sources")).map(s -> s.get("vector_tiles")).filter(JsonNode::isObject).ifPresent(vectorTilesNode -> {
        ObjectNode vectorTilesObj = (ObjectNode) vectorTilesNode;
        vectorTilesObj.remove("url");
        vectorTilesObj.put("attribution", metadata.attribution);
        vectorTilesObj.put("maxzoom", metadata.maxZoom);
        vectorTilesObj.put("minzoom", metadata.minZoom);
        vectorTilesObj.replace("vector_layers", metadata.vectorLayers);
        Optional.ofNullable(mapConfig.get("center")).ifPresent(center -> Optional.ofNullable(mapConfig.has("zoom") && mapConfig.get("zoom").isInt() ? mapConfig.get("zoom") : null).ifPresent(zoom -> {
            ArrayNode centerArray = center.deepCopy();
            centerArray.add(zoom);
            vectorTilesObj.replace("center", centerArray);
        }));
        ArrayNode tilesArray = mapConfig.arrayNode();
        String tileUrl = baseUriBuilder.clone().replacePath(API_PATH).path(realm).path("map/tile").build().toString() + "/{z}/{x}/{y}";
        tilesArray.insert(0, tileUrl);
        vectorTilesObj.replace("tiles", tilesArray);
    // vectorTilesObj.put(
    // "url",
    // baseUriBuilder.clone()
    // .replacePath(API_PATH)
    // .path(realm)
    // .path("map/source")
    // .build()
    // .toString());
    });
    // Set sprite URL to shared folder
    Optional.ofNullable(settings.has("sprite") && settings.get("sprite").isTextual() ? settings.get("sprite").asText() : null).ifPresent(sprite -> {
        String spriteUri = baseUriBuilder.clone().replacePath(MAP_SHARED_DATA_BASE_URI).path(sprite).build().toString();
        settings.put("sprite", spriteUri);
    });
    // Set glyphs URL to shared folder (tileserver-gl glyphs url cannot contain a path segment so add /fonts here
    Optional.ofNullable(settings.has("glyphs") && settings.get("glyphs").isTextual() ? settings.get("glyphs").asText() : null).ifPresent(glyphs -> {
        String glyphsUri = baseUriBuilder.clone().replacePath(MAP_SHARED_DATA_BASE_URI).build().toString() + "/fonts/" + glyphs;
        settings.put("glyphs", glyphsUri);
    });
    return settings;
}
Also used : Connection(java.sql.Connection) WebService(org.openremote.container.web.WebService) HashMap(java.util.HashMap) ValueUtil(org.openremote.model.util.ValueUtil) MapAccess.getInteger(org.openremote.container.util.MapAccess.getInteger) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) MapAccess.getString(org.openremote.container.util.MapAccess.getString) Level(java.util.logging.Level) API_PATH(org.openremote.manager.web.ManagerWebService.API_PATH) ResultSet(java.sql.ResultSet) Map(java.util.Map) JsonNode(com.fasterxml.jackson.databind.JsonNode) UriBuilder(javax.ws.rs.core.UriBuilder) TextUtil(org.openremote.model.util.TextUtil) ManagerWebService(org.openremote.manager.web.ManagerWebService) Path(java.nio.file.Path) ManagerIdentityService(org.openremote.manager.security.ManagerIdentityService) Files(java.nio.file.Files) ContainerService(org.openremote.model.ContainerService) PreparedStatement(java.sql.PreparedStatement) Logger(java.util.logging.Logger) HttpHandler(io.undertow.server.HttpHandler) Container(org.openremote.model.Container) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) Paths(java.nio.file.Paths) ProxyHandler(io.undertow.server.handlers.proxy.ProxyHandler) ResponseCodeHandler(io.undertow.server.handlers.ResponseCodeHandler) Optional(java.util.Optional) DriverManager(java.sql.DriverManager) WebService.pathStartsWithHandler(org.openremote.container.web.WebService.pathStartsWithHandler) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) MapAccess.getString(org.openremote.container.util.MapAccess.getString)

Aggregations

JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)1 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 HttpHandler (io.undertow.server.HttpHandler)1 ResponseCodeHandler (io.undertow.server.handlers.ResponseCodeHandler)1 ProxyHandler (io.undertow.server.handlers.proxy.ProxyHandler)1 Files (java.nio.file.Files)1 Path (java.nio.file.Path)1 Paths (java.nio.file.Paths)1 Connection (java.sql.Connection)1 DriverManager (java.sql.DriverManager)1 PreparedStatement (java.sql.PreparedStatement)1 ResultSet (java.sql.ResultSet)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Optional (java.util.Optional)1 Level (java.util.logging.Level)1 Logger (java.util.logging.Logger)1 UriBuilder (javax.ws.rs.core.UriBuilder)1 MapAccess.getInteger (org.openremote.container.util.MapAccess.getInteger)1