diff --git a/baremaps-core/src/main/java/org/apache/baremaps/config/ConfigReader.java b/baremaps-core/src/main/java/org/apache/baremaps/config/ConfigReader.java index 8c08a2569..d19e4316e 100644 --- a/baremaps-core/src/main/java/org/apache/baremaps/config/ConfigReader.java +++ b/baremaps-core/src/main/java/org/apache/baremaps/config/ConfigReader.java @@ -39,14 +39,19 @@ public String read(Path path) throws IOException { } private String eval(Path path) throws IOException { - try (var context = Context.newBuilder("js").option("js.esm-eval-returns-exports", "true") - .option("js.scripting", "true").allowExperimentalOptions(true).allowIO(true).build()) { + try (var context = Context.newBuilder("js") + .option("js.esm-eval-returns-exports", "true") + .option("js.scripting", "true") + .allowExperimentalOptions(true) + .allowIO(true) + .build()) { var script = String.format(""" import config from '%s'; export default JSON.stringify(config); - """, path.toAbsolutePath()); + """, path.toAbsolutePath().toUri()); var source = Source.newBuilder("js", new StringReader(script), "script.js") - .mimeType("application/javascript+module").build(); + .mimeType("application/javascript+module") + .build(); var value = context.eval(source); return value.getMember("default").toString(); } catch (Exception e) { diff --git a/baremaps-core/src/main/java/org/apache/baremaps/vectortile/style/StyleSource.java b/baremaps-core/src/main/java/org/apache/baremaps/vectortile/style/StyleSource.java index 8ac5cfd61..09fae5c98 100644 --- a/baremaps-core/src/main/java/org/apache/baremaps/vectortile/style/StyleSource.java +++ b/baremaps-core/src/main/java/org/apache/baremaps/vectortile/style/StyleSource.java @@ -15,21 +15,52 @@ import com.fasterxml.jackson.annotation.JsonProperty; +import java.util.List; /** * A source is a collection of data that is used as a single input to style layers. * * @see https://docs.mapbox.com/mapbox-gl-js/style-spec/sources/ + * "https://maplibre.org/maplibre-style-spec/sources/">https://maplibre.org/maplibre-style-spec/sources/ */ public class StyleSource { @JsonProperty("type") private String type; + @JsonProperty("attribution") + private String attribution; + + @JsonProperty("bounds") + private List bounds; + + @JsonProperty("minzoom") + private Integer minzoom; + + @JsonProperty("maxzoom") + private Integer maxzoom; + + @JsonProperty("promoteId") + private String promoteId; + + @JsonProperty("scheme") + private String scheme; + + @JsonProperty("tiles") + private List tiles; + @JsonProperty("url") private String url; + @JsonProperty("volatile") + private Boolean isVolatile; + + @JsonProperty("tileSize") + private Integer tileSize; + + @JsonProperty("encoding") + private String encoding; + /** * Constructs a style source. */ @@ -84,4 +115,204 @@ public StyleSource setUrl(String url) { this.url = url; return this; } + + /** + * Returns the tiles of the source. + * + * @return the tiles of the source + */ + public String getAttribution() { + return attribution; + } + + /** + * Sets the attribution of the source. + * + * @param attribution the attribution of the source + * @return the source + */ + public StyleSource setAttribution(String attribution) { + this.attribution = attribution; + return this; + } + + /** + * Returns the bounds of the source. + * + * @return the bounds of the source + */ + public List getBounds() { + return bounds; + } + + /** + * Sets the bounds of the source. + * + * @param bounds the bounds of the source + * @return the source + */ + public StyleSource setBounds(List bounds) { + this.bounds = bounds; + return this; + } + + /** + * Returns the minzoom of the source. + * + * @return the minzoom of the source + */ + public Integer getMinzoom() { + return minzoom; + } + + /** + * Sets the minzoom of the source. + * + * @param minzoom the minzoom of the source + * @return the source + */ + public StyleSource setMinzoom(Integer minzoom) { + this.minzoom = minzoom; + return this; + } + + /** + * Returns the maxzoom of the source. + * + * @return the maxzoom of the source + */ + public Integer getMaxzoom() { + return maxzoom; + } + + /** + * Sets the maxzoom of the source. + * + * @param maxzoom the maxzoom of the source + * @return the source + */ + public StyleSource setMaxzoom(Integer maxzoom) { + this.maxzoom = maxzoom; + return this; + } + + /** + * Returns the promoteId of the source. + * + * @return the promoteId of the source + */ + public String getPromoteId() { + return promoteId; + } + + /** + * Sets the promoteId of the source. + * + * @param promoteId the promoteId of the source + * @return the source + */ + public StyleSource setPromoteId(String promoteId) { + this.promoteId = promoteId; + return this; + } + + /** + * Returns the scheme of the source. + * + * @return the scheme of the source + */ + public String getScheme() { + return scheme; + } + + /** + * Sets the scheme of the source. + * + * @param scheme the scheme of the source + * @return the source + */ + public StyleSource setScheme(String scheme) { + this.scheme = scheme; + return this; + } + + /** + * Returns the tiles of the source. + * + * @return the tiles of the source + */ + public List getTiles() { + return tiles; + } + + /** + * Sets the tiles of the source. + * + * @param tiles the tiles of the source + * @return the source + */ + public StyleSource setTiles(List tiles) { + this.tiles = tiles; + return this; + } + + /** + * Returns the volatile of the source. + * + * @return the volatile of the source + */ + public Boolean getVolatile() { + return isVolatile; + } + + /** + * Sets the volatile of the source. + * + * @param isVolatile the volatile of the source + * @return the source + */ + public StyleSource setVolatile(Boolean isVolatile) { + this.isVolatile = isVolatile; + return this; + } + + /** + * Returns the tileSize of the source. + * + * @return the tileSize of the source + */ + public Integer getTileSize() { + return tileSize; + } + + /** + * Sets the tileSize of the source. + * + * @param tileSize the tileSize of the source + * @return the source + */ + public StyleSource setTileSize(Integer tileSize) { + this.tileSize = tileSize; + return this; + } + + /** + * Returns the encoding of the source. + * + * @return the encoding of the source + */ + public String getEncoding() { + return encoding; + } + + /** + * Sets the encoding of the source. + * + * @param encoding the encoding of the source + * @return the source + */ + public StyleSource setEncoding(String encoding) { + this.encoding = encoding; + return this; + } } diff --git a/baremaps-core/src/test/java/org/apache/baremaps/config/ConfigReaderTest.java b/baremaps-core/src/test/java/org/apache/baremaps/config/ConfigReaderTest.java new file mode 100644 index 000000000..d4a39abb4 --- /dev/null +++ b/baremaps-core/src/test/java/org/apache/baremaps/config/ConfigReaderTest.java @@ -0,0 +1,33 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing permissions and limitations under + * the License. + */ + +package org.apache.baremaps.config; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +import java.io.IOException; +import org.apache.baremaps.testing.TestFiles; +import org.apache.baremaps.vectortile.style.Style; +import org.junit.jupiter.api.Test; +import org.testcontainers.shaded.com.fasterxml.jackson.databind.ObjectMapper; + +class ConfigReaderTest { + + @Test + void readStyle() throws IOException { + var config = new ConfigReader().read(TestFiles.STYLE_JS); + var style = new ObjectMapper().readValue(config, Style.class); + var source = style.getSources().get("mymap"); + assertEquals("http://my.server.com/{z}/{y}/{x}.mvt", source.getTiles().get(0)); + assertEquals(14, source.getMaxzoom()); + } +} diff --git a/baremaps-core/src/test/java/org/apache/baremaps/stream/StreamUtilsTest.java b/baremaps-core/src/test/java/org/apache/baremaps/stream/StreamUtilsTest.java index fedb1c6ae..734feba59 100644 --- a/baremaps-core/src/test/java/org/apache/baremaps/stream/StreamUtilsTest.java +++ b/baremaps-core/src/test/java/org/apache/baremaps/stream/StreamUtilsTest.java @@ -23,7 +23,7 @@ class StreamUtilsTest { @Test void partition() { - List list = IntStream.range(0, 100).mapToObj(i -> i).toList(); + List list = IntStream.range(0, 100).boxed().toList(); List> partitions = StreamUtils.partition(list.stream(), 10) .map(stream -> stream.collect(Collectors.toList())).toList(); assertEquals(partitions.size(), 10); diff --git a/baremaps-core/src/test/java/org/apache/baremaps/testing/TestFiles.java b/baremaps-core/src/test/java/org/apache/baremaps/testing/TestFiles.java index e1c82db9a..450c0acec 100644 --- a/baremaps-core/src/test/java/org/apache/baremaps/testing/TestFiles.java +++ b/baremaps-core/src/test/java/org/apache/baremaps/testing/TestFiles.java @@ -48,9 +48,11 @@ public class TestFiles { public static final Path MONACO_STATE_TXT = resolve("monaco/monaco-state.txt"); + public static final Path STYLE_JS = resolve("style.js"); + public static Path resolve(String resource) { Path cwd = Path.of("").toAbsolutePath(); Path pathFromRoot = Path.of("baremaps-core", "src", "test", "resources", resource); - return cwd.resolveSibling(pathFromRoot); + return cwd.resolveSibling(pathFromRoot).toAbsolutePath(); } } diff --git a/baremaps-core/src/test/resources/style.js b/baremaps-core/src/test/resources/style.js new file mode 100644 index 000000000..1d22a158b --- /dev/null +++ b/baremaps-core/src/test/resources/style.js @@ -0,0 +1,26 @@ +/** + Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except + in compliance with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software distributed under the License + is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + or implied. See the License for the specific language governing permissions and limitations under + the License. + **/ +export default { + "version": 8, + "name": "MyMap", + "center": [0, 0], + "zoom": 10, + "sources": { + "mymap": { + "type": "vector", + "tiles": [ + "http://my.server.com/{z}/{y}/{x}.mvt" + ], + "maxzoom": 14, + } + }, +};