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()); }
@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()); }