return new Feature(layerName, extent, geometry, Collections.unmodifiableMap(attributes), feature.getId());
return new Feature(layerName, extent, geometry, Collections.unmodifiableMap(attributes));
@Test public void testMapBoxTileBuilder() throws Exception { MapBoxTileBuilderFactory builderFact = new MapBoxTileBuilderFactory(); Rectangle screenSize = new Rectangle(256, 256); ReferencedEnvelope mapArea = new ReferencedEnvelope(); MapBoxTileBuilder tileBuilder = builderFact.newBuilder(screenSize, mapArea); Geometry point = geom("POINT(1 10)"); Map<String, Object> pointProps = ImmutableMap.<String, Object> of("name", "point1"); Geometry line = geom("LINESTRING(0 0, 1 1, 2 2)"); Map<String, Object> lineProps = ImmutableMap.<String, Object> of("name", "line1"); tileBuilder.addFeature("Points", "unused", "unused", point, pointProps); tileBuilder.addFeature("Lines", "unused", "unused", line, lineProps); WMSMapContent mapContent = mock(WMSMapContent.class); RawMap map = tileBuilder.build(mapContent); ListMultimap<String, Feature> features = decode(map); assertEquals(2, features.size()); assertEquals(ImmutableSet.of("Points", "Lines"), features.keySet()); Feature pointFeature = features.get("Points").get(0); Feature lineFeature = features.get("Lines").get(0); assertTrue(pointFeature.getGeometry() instanceof Point); assertEquals(point, pointFeature.getGeometry()); assertEquals(pointProps, pointFeature.getAttributes()); assertTrue(lineFeature.getGeometry() instanceof LineString); assertEquals(line, lineFeature.getGeometry()); assertEquals(lineProps, lineFeature.getAttributes()); }
public void checkSimpleMVT(String mimeType) throws Exception { String request = "wms?service=WMS&version=1.1.0&request=GetMap&layers=" + getLayerId(MockData.ROAD_SEGMENTS) + "&styles=&bbox=-1,-1,1,1&width=768&height=330&srs=EPSG:4326" + "&format=" + mimeType; MockHttpServletResponse response = getAsServletResponse(request); // the standard mime type is returned assertEquals(MapBoxTileBuilderFactory.MIME_TYPE, response.getContentType()); byte[] responseBytes = response.getContentAsByteArray(); VectorTileDecoder decoder = new VectorTileDecoder(); List<VectorTileDecoder.Feature> featuresList = decoder.decode(responseBytes).asList(); assertEquals(5, featuresList.size()); assertEquals( 3, featuresList .stream() .filter(f -> "Route 5".equals(f.getAttributes().get("NAME"))) .count()); assertEquals( 1, featuresList .stream() .filter(f -> "Main Street".equals(f.getAttributes().get("NAME"))) .count()); assertEquals("Extent should be 12288", 12288, featuresList.get(0).getExtent()); }
@Test public void testMapBoxTileBuilder() throws Exception { MapBoxTileBuilderFactory builderFact = new MapBoxTileBuilderFactory(); Rectangle screenSize = new Rectangle(256, 256); ReferencedEnvelope mapArea = new ReferencedEnvelope(); MapBoxTileBuilder tileBuilder = builderFact.newBuilder(screenSize, mapArea); Geometry point = geom("POINT(1 10)"); Map<String, Object> pointProps = ImmutableMap.<String, Object>of("name", "point1"); Geometry line = geom("LINESTRING(0 0, 1 1, 2 2)"); Map<String, Object> lineProps = ImmutableMap.<String, Object>of("name", "line1"); tileBuilder.addFeature("Points", "unused", "unused", point, pointProps); tileBuilder.addFeature("Lines", "unused", "unused", line, lineProps); WMSMapContent mapContent = mock(WMSMapContent.class); RawMap map = tileBuilder.build(mapContent); ListMultimap<String, Feature> features = decode(map); assertEquals(2, features.size()); assertEquals(ImmutableSet.of("Points", "Lines"), features.keySet()); Feature pointFeature = features.get("Points").get(0); Feature lineFeature = features.get("Lines").get(0); assertTrue(pointFeature.getGeometry() instanceof Point); assertEquals(point, pointFeature.getGeometry()); assertEquals(pointProps, pointFeature.getAttributes()); assertTrue(lineFeature.getGeometry() instanceof LineString); assertEquals(line, lineFeature.getGeometry()); assertEquals(lineProps, lineFeature.getAttributes()); }
assertTrue(lineFeature.getGeometry() instanceof LineString); assertEquals(line, lineFeature.getGeometry()); // line should not be clipped
@Test public void testEncoderClipping() throws Exception { MapBoxTileBuilderFactory builderFact = new MapBoxTileBuilderFactory(); Rectangle screenSize = new Rectangle(256, 256); ReferencedEnvelope mapArea = new ReferencedEnvelope(); MapBoxTileBuilder tileBuilder = builderFact.newBuilder(screenSize, mapArea); Geometry line = geom("LINESTRING(-100 -100,300 300)"); //box is 0 to 256, so this is outside the box Map<String, Object> lineProps = ImmutableMap.<String, Object> of("name", "line1"); tileBuilder.addFeature("Lines", "unused", "unused", line, lineProps); WMSMapContent mapContent = mock(WMSMapContent.class); RawMap map = tileBuilder.build(mapContent); ListMultimap<String, Feature> features = decode(map); assertEquals(1, features.size()); assertEquals(ImmutableSet.of( "Lines"), features.keySet()); Feature lineFeature = features.get("Lines").get(0); assertTrue(lineFeature.getGeometry() instanceof LineString); assertEquals(line, lineFeature.getGeometry()); // line should not be clipped }
private ListMultimap<String, Feature> decode(RawMap map) throws IOException { ArrayListMultimap<String, VectorTileDecoder.Feature> byLayer = ArrayListMultimap.create(); ByteArrayOutputStream bos = new ByteArrayOutputStream(); map.writeTo(bos); bos.close(); VectorTileDecoder decoder = new VectorTileDecoder(); decoder.setAutoScale(false); for (Feature feat : decoder.decode(bos.toByteArray())) { // System.out.println(feat.getLayerName() + ": "); // System.out.print(feat.getAttributes()); // System.out.println(feat.getGeometry()); byLayer.put(feat.getLayerName(), feat); } return byLayer; }
private ListMultimap<String, Feature> decode(RawMap map) throws IOException { ArrayListMultimap<String, VectorTileDecoder.Feature> byLayer = ArrayListMultimap.create(); ByteArrayOutputStream bos = new ByteArrayOutputStream(); map.writeTo(bos); bos.close(); VectorTileDecoder decoder = new VectorTileDecoder(); decoder.setAutoScale(false); for (Feature feat : decoder.decode(bos.toByteArray())) { // System.out.println(feat.getLayerName() + ": "); // System.out.print(feat.getAttributes()); // System.out.println(feat.getGeometry()); byLayer.put(feat.getLayerName(), feat); } return byLayer; }