You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@baremaps.apache.org by "swerky (via GitHub)" <gi...@apache.org> on 2023/03/31 08:18:22 UTC

[GitHub] [incubator-baremaps] swerky commented on a diff in pull request #617: Implement the vector tile specification

swerky commented on code in PR #617:
URL: https://github.com/apache/incubator-baremaps/pull/617#discussion_r1154158774


##########
baremaps-core/src/main/java/org/apache/baremaps/vectortile/VectorTileEncoder.java:
##########
@@ -0,0 +1,360 @@
+/*
+ * 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.vectortile;
+
+import static org.apache.baremaps.vectortile.VectorTileUtils.*;
+
+import com.google.common.collect.Lists;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.function.Consumer;
+import org.apache.baremaps.mvt.binary.VectorTile;
+import org.locationtech.jts.geom.*;
+
+/**
+ * A vector tile encoder.
+ *
+ * This implementation is based on the Vector Tile Specification 2.1.
+ */
+public class VectorTileEncoder {
+
+  private int cx = 0;
+
+  private int cy = 0;
+
+  private List<String> keys = new ArrayList<>();
+
+  private List<Object> values = new ArrayList<>();
+
+  /**
+   * Constructs a vector tile encoder.
+   */
+  public VectorTileEncoder() {
+
+  }
+
+  /**
+   * Encodes a tile into a vector tile.
+   * 
+   * @param tile The tile to encode
+   * @return The vector tile
+   */
+  public VectorTile.Tile encodeTile(Tile tile) {
+    VectorTile.Tile.Builder builder = VectorTile.Tile.newBuilder();
+    tile.getLayers().forEach(layer -> builder.addLayers(encodeLayer(layer)));
+    return builder.build();
+  }
+
+  /**
+   * Encodes a layer into a vector tile layer.
+   * 
+   * @param layer The layer to encode
+   * @return The vector tile layer
+   */
+  public VectorTile.Tile.Layer encodeLayer(Layer layer) {
+    keys = new ArrayList<>();
+    values = new ArrayList<>();
+
+    VectorTile.Tile.Layer.Builder builder = VectorTile.Tile.Layer.newBuilder();
+    builder.setName(layer.getName());
+    builder.setVersion(2);

Review Comment:
   Is this hard-coded value needed, or can it be a constant or embedded in the Builder ?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@baremaps.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org