Fix build

This commit is contained in:
Alexey Kulish 2017-05-16 22:11:17 +03:00
parent 631db5a903
commit d453a2ed72
8 changed files with 169 additions and 7 deletions

View file

@ -1,6 +1,6 @@
package com.wdtinc.mapbox_vector_tile.adapt.jts;
import com.wdtinc.mapbox_vector_tile.build.MvtLayerProps;
import com.wdtinc.mapbox_vector_tile.builder.MvtLayerProps;
import net.osmand.binary.VectorTile;

View file

@ -16,8 +16,8 @@ import com.vividsolutions.jts.geom.Polygon;
import com.vividsolutions.jts.geom.TopologyException;
import com.vividsolutions.jts.geom.util.AffineTransformation;
import com.vividsolutions.jts.simplify.TopologyPreservingSimplifier;
import com.wdtinc.mapbox_vector_tile.build.MvtLayerParams;
import com.wdtinc.mapbox_vector_tile.build.MvtLayerProps;
import com.wdtinc.mapbox_vector_tile.builder.MvtLayerParams;
import com.wdtinc.mapbox_vector_tile.builder.MvtLayerProps;
import com.wdtinc.mapbox_vector_tile.encoding.GeomCmd;
import com.wdtinc.mapbox_vector_tile.encoding.GeomCmdHdr;
import com.wdtinc.mapbox_vector_tile.encoding.MvtUtil;

View file

@ -3,7 +3,7 @@ package com.wdtinc.mapbox_vector_tile.adapt.jts;
import com.vividsolutions.jts.geom.Envelope;
import com.vividsolutions.jts.geom.Geometry;
import com.vividsolutions.jts.geom.GeometryFactory;
import com.wdtinc.mapbox_vector_tile.build.MvtLayerParams;
import com.wdtinc.mapbox_vector_tile.builder.MvtLayerParams;
import java.util.List;

View file

@ -1,6 +1,6 @@
package com.wdtinc.mapbox_vector_tile.adapt.jts;
import com.wdtinc.mapbox_vector_tile.build.MvtLayerProps;
import com.wdtinc.mapbox_vector_tile.builder.MvtLayerProps;
import net.osmand.binary.VectorTile;

View file

@ -1,11 +1,10 @@
package com.wdtinc.mapbox_vector_tile.adapt.jts;
import com.wdtinc.mapbox_vector_tile.build.MvtLayerProps;
import com.wdtinc.mapbox_vector_tile.builder.MvtLayerProps;
import net.osmand.binary.VectorTile;
import java.util.Map;
import java.util.Objects;
/**
* Convert simple user data {@link Map} where the keys are {@link String} and values are {@link Object}. Supports

View file

@ -0,0 +1,46 @@
package com.wdtinc.mapbox_vector_tile.builder;
import com.wdtinc.mapbox_vector_tile.encoding.MvtValue;
import net.osmand.binary.VectorTile;
/**
* Utility methods for building Mapbox-Vector-Tile layers.
*/
public final class MvtLayerBuild {
/**
* Create a new {@link com.wdtinc.mapbox_vector_tile.VectorTile.Tile.Layer.Builder} instance with
* initialized version, name, and extent metadata.
*
* @param layerName name of the layer
* @param mvtLayerParams tile creation parameters
* @return new layer builder instance with initialized metadata.
*/
public static VectorTile.Tile.Layer.Builder newLayerBuilder(String layerName, MvtLayerParams mvtLayerParams) {
final VectorTile.Tile.Layer.Builder layerBuilder = VectorTile.Tile.Layer.newBuilder();
layerBuilder.setVersion(2);
layerBuilder.setName(layerName);
layerBuilder.setExtent(mvtLayerParams.extent);
return layerBuilder;
}
/**
* Modifies {@code layerBuilder} to contain properties from {@code layerProps}.
*
* @param layerBuilder layer builder to write to
* @param layerProps properties to write
*/
public static void writeProps(VectorTile.Tile.Layer.Builder layerBuilder, MvtLayerProps layerProps) {
// Add keys
layerBuilder.addAllKeys(layerProps.getKeys());
// Add values
final Iterable<Object> vals = layerProps.getVals();
for(Object o:vals){
layerBuilder.addValues(MvtValue.toValue(o));
}
}
}

View file

@ -0,0 +1,49 @@
package com.wdtinc.mapbox_vector_tile.builder;
/**
* Immutable parameters collection for Mapbox-Vector-Tile creation.
*/
public final class MvtLayerParams {
/** the resolution of the tile in 'pixel' dimensions */
public final int tileSize;
/** the resolution of the MVT local coordinate system */
public final int extent;
/** ratio of tile 'pixel' dimensions to tile extent dimensions */
public final float ratio;
/**
* Uses defaults:
* <ul>
* <li>{@link #tileSize} = 256</li>
* <li>{@link #extent} = 4096</li>
* </ul>
*
* @see #MvtLayerParams(int, int)
*/
public MvtLayerParams() {
this(256, 4096);
}
/**
* @param tileSize the resolution of the tile in pixel coordinates, must be > 0
* @param extent the resolution of the MVT local coordinate system, must be > 0
*/
public MvtLayerParams(int tileSize, int extent) {
if(tileSize <= 0) {
throw new IllegalArgumentException("tileSize must be > 0");
}
if(extent <= 0) {
throw new IllegalArgumentException("extent must be > 0");
}
this.tileSize = tileSize;
this.extent = extent;
this.ratio = extent / tileSize;
}
}

View file

@ -0,0 +1,68 @@
package com.wdtinc.mapbox_vector_tile.builder;
import com.wdtinc.mapbox_vector_tile.encoding.MvtValue;
import java.util.*;
/**
* Support MVT features that must reference properties by their key and value index.
*/
public final class MvtLayerProps {
private LinkedHashMap<String, Integer> keys;
private LinkedHashMap<Object, Integer> vals;
public MvtLayerProps() {
keys = new LinkedHashMap<>();
vals = new LinkedHashMap<>();
}
public Integer keyIndex(String k) {
return keys.get(k);
}
public Integer valueIndex(Object v) {
return vals.get(v);
}
/**
* Add the key and return it's index code. If the key already is present, the previous
* index code is returned and no insertion is done.
*
* @param key key to add
* @return index of the key
*/
public int addKey(String key) {
Objects.requireNonNull(key);
int nextIndex = keys.size();
final Integer mapIndex = keys.putIfAbsent(key, nextIndex);
return mapIndex == null ? nextIndex : mapIndex;
}
/**
* Add the value and return it's index code. If the value already is present, the previous
* index code is returned and no insertion is done. If {@code value} is an unsupported type
* for encoding in a MVT, then it will not be added.
*
* @param value value to add
* @return index of the value, -1 on unsupported value types
* @see MvtValue#isValidPropValue(Object)
*/
public int addValue(Object value) {
Objects.requireNonNull(value);
if(!MvtValue.isValidPropValue(value)) {
return -1;
}
int nextIndex = vals.size();
final Integer mapIndex = vals.putIfAbsent(value, nextIndex);
return mapIndex == null ? nextIndex : mapIndex;
}
public Iterable<String> getKeys() {
return keys.keySet();
}
public Iterable<Object> getVals() {
return vals.keySet();
}
}