org.mapfish.print.map.geotools.grid.GridLayerPlugin Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of print-lib Show documentation
Show all versions of print-lib Show documentation
Library for generating PDFs and images from online webmapping services
package org.mapfish.print.map.geotools.grid;
import org.geotools.data.FeatureSource;
import org.geotools.styling.Style;
import org.mapfish.print.config.Template;
import org.mapfish.print.http.MfClientHttpRequestFactory;
import org.mapfish.print.map.geotools.AbstractFeatureSourceLayerPlugin;
import org.mapfish.print.map.geotools.FeatureSourceSupplier;
import org.mapfish.print.map.geotools.StyleSupplier;
import org.springframework.beans.factory.annotation.Autowired;
import java.util.concurrent.ForkJoinPool;
import javax.annotation.Nonnull;
/**
* A layer which is a spatial grid of lines on the map.
* Type: grid
* [[examples=crosses_point_grid]]
*/
public final class GridLayerPlugin extends AbstractFeatureSourceLayerPlugin {
private static final String TYPE = "grid";
@Autowired
private ForkJoinPool pool;
/**
* Constructor.
*/
public GridLayerPlugin() {
super(TYPE);
}
@Override
public GridParam createParameter() {
return new GridParam();
}
@Nonnull
@Override
public GridLayer parse(
@Nonnull final Template template,
@Nonnull final GridParam layerData) {
LabelPositionCollector labels = new LabelPositionCollector();
FeatureSourceSupplier featureSource = createFeatureSourceFunction(template, layerData, labels);
final StyleSupplier styleFunction = createStyleSupplier(template, layerData);
return new GridLayer(this.pool, featureSource, styleFunction,
template.getConfiguration().renderAsSvg(layerData.renderAsSvg),
layerData, labels);
}
private StyleSupplier createStyleSupplier(
final Template template, final GridParam layerData) {
return new StyleSupplier() {
@Override
public Style load(
final MfClientHttpRequestFactory requestFactory,
final FeatureSource featureSource) {
String styleRef = layerData.style;
return template.getStyle(styleRef)
.or(GridLayerPlugin.super.parser.loadStyle(
template.getConfiguration(),
requestFactory, styleRef))
.or(layerData.gridType.strategy.defaultStyle(template, layerData));
}
};
}
private FeatureSourceSupplier createFeatureSourceFunction(
final Template template,
final GridParam layerData,
final LabelPositionCollector labels) {
return layerData.gridType.strategy.createFeatureSource(template, layerData, labels);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy