@Test public void testNumLines() throws Exception { Configuration config = new Configuration(); Template template = new Template(); template.setConfiguration(config); PointGridStrategy pointGridStrategy = new PointGridStrategy(); GridParam layerData = new GridParam(); layerData.numberOfLines = new int[]{3, 2}; layerData.name = "grid"; layerData.postConstruct(); MapBounds bounds = new BBoxMapBounds(DefaultEngineeringCRS.GENERIC_2D, 100, 200, 500, 800); Dimension mapSize = new Dimension(400, 600); double rotation = 0; double dpi = 72; MapfishMapContext context = new MapfishMapContext(bounds, mapSize, rotation, dpi, true, true); FeatureSourceSupplier supplier = pointGridStrategy.createFeatureSource(template, layerData, new LabelPositionCollector()); SimpleFeatureSource featureSource = (SimpleFeatureSource) supplier.load(requestFactory, context); assertEquals(6, featureSource.getFeatures().size()); try (SimpleFeatureIterator features = featureSource.getFeatures().features()) { List<Coordinate> expectedPoints = Arrays.asList( new Coordinate(200, 400), new Coordinate(300, 400), new Coordinate(400, 400), new Coordinate(200, 600), new Coordinate(300, 600), new Coordinate(400, 600) ); while (features.hasNext()) { SimpleFeature next = features.next(); assertTrue(next.getDefaultGeometry().getClass().getName(), next.getDefaultGeometry() instanceof Point); Coordinate coord = ((Point) next.getDefaultGeometry()).getCoordinate(); assertTrue(coord + " is not one of the expected points", expectedPoints.contains(coord)); } } }
@Override public FeatureSourceSupplier createFeatureSource( final Template template, final GridParam layerData, final LabelPositionCollector labels) { return new FeatureSourceSupplier() { @Nonnull @Override public FeatureSource load( @Nonnull final MfClientHttpRequestFactory requestFactory, @Nonnull final MapfishMapContext mapContext) { SimpleFeatureType featureType = GridUtils.createGridFeatureType(mapContext, Point.class); SimpleFeatureBuilder featureBuilder = new SimpleFeatureBuilder(featureType); final DefaultFeatureCollection features; if (layerData.numberOfLines != null) { features = createFeaturesFromNumberOfLines(mapContext, featureBuilder, layerData, labels); } else { features = createFeaturesFromSpacing(mapContext, featureBuilder, layerData, labels); } return new CollectionFeatureSource(features); } }; }
PointGridStrategy implements GridType.GridTypeStrategy { @Override public FeatureSourceSupplier createFeatureSource( final Template template, final GridParam layerData, final LabelPositionCollector labels) { return new FeatureSourceSupplier() { @Nonnull @Override public FeatureSource load( @Nonnull final MfClientHttpRequestFactory requestFactory, @Nonnull final MapfishMapContext mapContext) { SimpleFeatureType featureType = GridUtils.createGridFeatureType(mapContext, Point.class); SimpleFeatureBuilder featureBuilder = new SimpleFeatureBuilder(featureType); final DefaultFeatureCollection features; if (layerData.numberOfLines != null) { features = createFeaturesFromNumberOfLines(mapContext, featureBuilder, layerData, labels); } else { features = createFeaturesFromSpacing(mapContext, featureBuilder, layerData, labels); } return new CollectionFeatureSource(features); } }; } }
PointGridStrategy implements GridType.GridTypeStrategy { @Override public FeatureSourceSupplier createFeatureSource( final Template template, final GridParam layerData, final LabelPositionCollector labels) { return new FeatureSourceSupplier() { @Nonnull @Override public FeatureSource load( @Nonnull final MfClientHttpRequestFactory requestFactory, @Nonnull final MapfishMapContext mapContext) { SimpleFeatureType featureType = GridUtils.createGridFeatureType(mapContext, Point.class); SimpleFeatureBuilder featureBuilder = new SimpleFeatureBuilder(featureType); final DefaultFeatureCollection features; if (layerData.numberOfLines != null) { features = createFeaturesFromNumberOfLines(mapContext, featureBuilder, layerData, labels); } else { features = createFeaturesFromSpacing(mapContext, featureBuilder, layerData, labels); } return new CollectionFeatureSource(features); } }; }  }
PointGridStrategy implements GridType.GridTypeStrategy { @Override public FeatureSourceSupplier createFeatureSource( final Template template, final GridParam layerData, final LabelPositionCollector labels) { return new FeatureSourceSupplier() { @Nonnull @Override public FeatureSource load( @Nonnull final MfClientHttpRequestFactory requestFactory, @Nonnull final MapfishMapContext mapContext) { SimpleFeatureType featureType = GridUtils.createGridFeatureType(mapContext, Point.class); SimpleFeatureBuilder featureBuilder = new SimpleFeatureBuilder(featureType); final DefaultFeatureCollection features; if (layerData.numberOfLines != null) { features = createFeaturesFromNumberOfLines(mapContext, featureBuilder, layerData, labels); } else { features = createFeaturesFromSpacing(mapContext, featureBuilder, layerData, labels); } return new CollectionFeatureSource(features); } }; }  @Override Style defaultStyle(final Template template, final GridParam layerData); @Override FeatureSourceSupplier createFeatureSource(
            final Template template,
            final GridParam layerData,
            final LabelPositionCollector labels); }
PointGridStrategy implements GridType.GridTypeStrategy { @Override public FeatureSourceSupplier createFeatureSource( final Template template, final GridParam layerData, final LabelPositionCollector labels) { return new FeatureSourceSupplier() { @Nonnull @Override public FeatureSource load( @Nonnull final MfClientHttpRequestFactory requestFactory, @Nonnull final MapfishMapContext mapContext) { SimpleFeatureType featureType = GridUtils.createGridFeatureType(mapContext, Point.class); SimpleFeatureBuilder featureBuilder = new SimpleFeatureBuilder(featureType); final DefaultFeatureCollection features; if (layerData.numberOfLines != null) { features = createFeaturesFromNumberOfLines(mapContext, featureBuilder, layerData, labels); } else { features = createFeaturesFromSpacing(mapContext, featureBuilder, layerData, labels); } return new CollectionFeatureSource(features); } }; }  @Override Style defaultStyle(final Template template, final GridParam layerData); @Override FeatureSourceSupplier createFeatureSource(
            final Template template,
            final GridParam layerData,
            final LabelPositionCollector labels);  }