use of org.geotools.map.MapContent in project sldeditor by robward-scisys.
the class MapRender method internalRenderStyle.
/**
* Internal render style.
*/
private void internalRenderStyle() {
if (!underTest) {
if (hasError()) {
mapPane.resetRenderer();
mapPane.getRenderer().addRenderListener(this);
resetError();
}
wmsEnvVarValues.setImageWidth(mapPane.getWidth());
wmsEnvVarValues.setImageHeight(mapPane.getHeight());
MapContent mapContent = mapPane.getMapContent();
if (mapContent == null) {
mapContent = new MapContent();
mapPane.setMapContent(mapContent);
}
Map<Object, Object> hints = new HashMap<>();
clearLabelCache();
hints.put(StreamingRenderer.LABEL_CACHE_KEY, labelCache);
mapPane.getRenderer().setRendererHints(hints);
// Add the layers back with the updated style
renderUpdatedStyle(mapContent);
}
}
use of org.geotools.map.MapContent in project sldeditor by robward-scisys.
the class RenderPanelImpl method renderRasterMap.
/**
* Render raster map.
*
* @param imageSize the image size
* @param style the style
* @param dpi the dpi
*/
private void renderRasterMap(Rectangle imageSize, Style style, int dpi) {
DataSourceInterface dataSource = DataSourceFactory.getDataSource();
AbstractGridCoverage2DReader gridCoverage = dataSource.getGridCoverageReader();
if (gridCoverage == null) {
validSymbol = false;
}
GridReaderLayer rasterLayer = null;
MapViewport viewport = null;
List<Layer> layerList = new ArrayList<>();
if (style != null) {
rasterLayer = new GridReaderLayer(gridCoverage, style);
layerList.add(rasterLayer);
viewport = new MapViewport(rasterLayer.getBounds());
}
boolean hasGeometry = validSymbol;
MapContent map = new MapContent();
map.addLayers(layerList);
map.setViewport(viewport);
try {
Map<Object, Object> hints = new HashMap<>();
if (OVERRIDE_DPI) {
hints.put(StreamingRenderer.DPI_KEY, dpi);
}
// This ensures all the labelling is cleared
hints.put(StreamingRenderer.LABEL_CACHE_KEY, new LabelCacheImpl());
renderer.setRendererHints(hints);
renderer.setMapContent(map);
BufferedImage image = new BufferedImage(imageSize.width, imageSize.height, BufferedImage.TYPE_INT_ARGB);
Graphics2D graphics = image.createGraphics();
if (useAntiAlias) {
graphics.setRenderingHints(new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON));
}
try {
if (!hasGeometry) {
graphics.setColor(Color.BLACK);
int y = imageSize.height / 2;
Font font = new Font(Font.SERIF, Font.BOLD, 14);
graphics.setFont(font);
graphics.drawString(Localisation.getString(RenderPanelImpl.class, "RenderPanelImpl.error1"), 10, y - 14);
} else {
if (rasterLayer != null) {
ReferencedEnvelope bounds = rasterLayer.getBounds();
renderer.paint(graphics, imageSize, bounds);
}
this.bImage = image;
}
} finally {
graphics.dispose();
}
} finally {
map.dispose();
}
}
use of org.geotools.map.MapContent in project sldeditor by robward-scisys.
the class RenderPanelImpl method internalRenderMap.
/**
* Internal render map.
*
* @param layers the layers
* @param bounds the bounds
* @param imageSize the image size
* @param hasGeometry the has geometry
* @param dpi the dpi
*/
private void internalRenderMap(List<Layer> layers, ReferencedEnvelope bounds, Rectangle imageSize, boolean hasGeometry, int dpi) {
MapContent map = new MapContent();
map.addLayers(layers);
try {
Map<Object, Object> hints = new HashMap<>();
if (OVERRIDE_DPI) {
hints.put(StreamingRenderer.DPI_KEY, dpi);
}
// This ensures all the labelling is cleared
hints.put(StreamingRenderer.LABEL_CACHE_KEY, new LabelCacheImpl());
renderer.setRendererHints(hints);
renderer.setMapContent(map);
BufferedImage image = new BufferedImage(imageSize.width, imageSize.height, BufferedImage.TYPE_INT_ARGB);
Graphics2D graphics = image.createGraphics();
if (useAntiAlias) {
graphics.setRenderingHints(new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON));
}
try {
if (!hasGeometry) {
graphics.setColor(Color.BLACK);
int y = imageSize.height / 2;
Font font = new Font(Font.SERIF, Font.BOLD, 14);
graphics.setFont(font);
graphics.drawString(Localisation.getString(RenderPanelImpl.class, "RenderPanelImpl.error1"), 10, y - 14);
} else {
renderer.paint(graphics, imageSize, bounds);
this.bImage = image;
}
} finally {
graphics.dispose();
}
} finally {
map.dispose();
}
}
Aggregations