Skip to content

Commit 2c2ecf9

Browse files
committed
mvt layer性能优化
1 parent 25da7b6 commit 2c2ecf9

File tree

2 files changed

+30
-12
lines changed

2 files changed

+30
-12
lines changed

giscat-vector/giscat-vector-mvt/src/main/java/org/wowtools/giscat/vector/mvt/MvtBuilder.java

+24-6
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,28 @@ public MvtBuilder(byte z, int x, int y, int extent, int clipBuffer, @NotNull Geo
7676

7777
}
7878

79+
/**
80+
* 新建一个图层,按simplifyDistance的值简化geometry
81+
*
82+
* @param layerName 图层名 本方法没有对图层名进行唯一校验,故若图层已存在,则原图层会被覆盖
83+
* @param simplifyDistance 对geometry进行简化的长度,单位是瓦片像素,取值范围[0,extent+clipBuffer],为0时表示不做简化
84+
* @return MvtLayer
85+
*/
86+
public MvtLayer createLayer(String layerName, int simplifyDistance) {
87+
MvtLayer layer = new MvtLayer(this, simplifyDistance);
88+
layers.put(layerName, layer);
89+
return layer;
90+
}
91+
/**
92+
* 新建一个图层,不对geometry进行简化
93+
*
94+
* @param layerName 图层名 本方法没有对图层名进行唯一校验,故若图层已存在,则原图层会被覆盖
95+
* @return MvtLayer
96+
*/
97+
public MvtLayer createLayer(String layerName) {
98+
return createLayer(layerName, 0);
99+
}
100+
79101
/**
80102
* 新建或获取一个图层,按simplifyDistance的值简化geometry
81103
*
@@ -88,9 +110,7 @@ public MvtBuilder(byte z, int x, int y, int extent, int clipBuffer, @NotNull Geo
88110
if (layer != null) {
89111
return layer;
90112
}
91-
layer = new MvtLayer(this, simplifyDistance);
92-
layers.put(layerName, layer);
93-
return layer;
113+
return createLayer(layerName, simplifyDistance);
94114
}
95115

96116
/**
@@ -104,9 +124,7 @@ public MvtBuilder(byte z, int x, int y, int extent, int clipBuffer, @NotNull Geo
104124
if (layer != null) {
105125
return layer;
106126
}
107-
layer = new MvtLayer(this, 0);
108-
layers.put(layerName, layer);
109-
return layer;
127+
return createLayer(layerName, 0);
110128
}
111129

112130

giscat-vector/giscat-vector-mvt/src/main/java/org/wowtools/giscat/vector/mvt/MvtLayer.java

+6-6
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@
2525
import org.locationtech.jts.geom.GeometryCollection;
2626
import org.locationtech.jts.geom.TopologyException;
2727
import org.locationtech.jts.simplify.TopologyPreservingSimplifier;
28-
import org.wowtools.giscat.vector.util.analyse.Bbox;
2928
import org.wowtools.giscat.vector.pojo.Feature;
29+
import org.wowtools.giscat.vector.util.analyse.Bbox;
3030

3131
import java.util.*;
3232

@@ -38,7 +38,7 @@
3838
*/
3939
public final class MvtLayer {
4040

41-
protected final List<MvtFeature> features = new ArrayList<>();
41+
protected final List<MvtFeature> features = new LinkedList<>();
4242

4343
private final Map<String, Integer> keys = new LinkedHashMap<>();
4444
private final Map<Object, Integer> values = new LinkedHashMap<>();
@@ -145,16 +145,16 @@ private ArrayList<Integer> tags(@Nullable Map<String, ?> attributes) {
145145
return keys.computeIfAbsent(key, k -> keys.size());
146146
}
147147

148-
protected @NotNull List<String> keys() {
149-
return new ArrayList<>(keys.keySet());
148+
protected @NotNull Set<String> keys() {
149+
return keys.keySet();
150150
}
151151

152152
private @NotNull Integer value(Object value) {
153153
return values.computeIfAbsent(value, k -> values.size());
154154
}
155155

156-
protected List<Object> values() {
157-
return List.copyOf(values.keySet());
156+
protected Set<Object> values() {
157+
return values.keySet();
158158
}
159159

160160

0 commit comments

Comments
 (0)