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;
}
Aggregations