Skip to content

Commit

Permalink
Used Function<WMSMapContent, LabelCache> to instantiate the custom La…
Browse files Browse the repository at this point in the history
…belCache instead of a simple Class
  • Loading branch information
mbarto committed Dec 6, 2017
1 parent 13023c2 commit 6788b9b
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.logging.Level;
import java.util.logging.Logger;

Expand Down Expand Up @@ -176,7 +177,7 @@ static class ReadingContext {
*/
private static LookupTableJAI IDENTITY_TABLE = new LookupTableJAI(getTable());

private Class<? extends LabelCache> labelCache = null;
private Function<WMSMapContent, LabelCache> labelCache = null;

private static byte[] getTable() {
byte[] arr = new byte[256];
Expand Down Expand Up @@ -274,7 +275,7 @@ public MapProducerCapabilities getCapabilities(String format) {
return capabilities.get(format);
}

public void setLabelCache(Class<? extends LabelCache> labelCache) {
public void setLabelCache(Function<WMSMapContent, LabelCache> labelCache) {
this.labelCache = labelCache;
}

Expand Down Expand Up @@ -484,7 +485,7 @@ public RenderedImageMap produceMap(final WMSMapContent mapContent, final boolean

if (labelCache != null) {
try {
rendererParams.put(StreamingRenderer.LABEL_CACHE_KEY, labelCache.newInstance());
rendererParams.put(StreamingRenderer.LABEL_CACHE_KEY, labelCache.apply(mapContent));
} catch (Exception e) {
throw new ServiceException(e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,64 @@
*/
package org.geoserver.wms.map;

import com.vividsolutions.jts.geom.Envelope;
import static org.geoserver.data.test.CiteTestData.STREAMS;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.Rectangle;
import java.awt.geom.NoninvertibleTransformException;
import java.awt.geom.Rectangle2D;
import java.awt.image.BufferedImage;
import java.awt.image.RenderedImage;
import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.logging.Level;
import java.util.logging.Logger;

import javax.media.jai.Interpolation;
import javax.media.jai.RenderedOp;
import javax.xml.namespace.QName;

import org.apache.commons.io.FileUtils;
import org.apache.commons.io.filefilter.RegexFileFilter;
import org.geoserver.catalog.*;
import org.geoserver.catalog.LayerInfo.WMSInterpolation;
import org.geoserver.catalog.Catalog;
import org.geoserver.catalog.CatalogBuilder;
import org.geoserver.catalog.CoverageInfo;
import org.geoserver.catalog.CoverageStoreInfo;
import org.geoserver.catalog.CoverageView;
import org.geoserver.catalog.CoverageView.CompositionType;
import org.geoserver.catalog.CoverageView.CoverageBand;
import org.geoserver.catalog.CoverageView.InputCoverageBand;
import org.geoserver.catalog.FeatureTypeInfo;
import org.geoserver.catalog.LayerInfo;
import org.geoserver.catalog.LayerInfo.WMSInterpolation;
import org.geoserver.catalog.StyleInfo;
import org.geoserver.data.test.MockData;
import org.geoserver.data.test.SystemTestData;
import org.geoserver.platform.ServiceException;
import org.geoserver.security.decorators.DecoratingFeatureSource;
import org.geoserver.wms.*;
import org.geoserver.wms.CachedGridReaderLayer;
import org.geoserver.wms.GetMapRequest;
import org.geoserver.wms.MapLayerInfo;
import org.geoserver.wms.WMS;
import org.geoserver.wms.WMSInfo;
import org.geoserver.wms.WMSMapContent;
import org.geoserver.wms.WMSPartialMapException;
import org.geoserver.wms.WMSTestSupport;
import org.geotools.coverage.grid.io.AbstractGridFormat;
import org.geotools.coverage.grid.io.GridCoverage2DReader;
import org.geotools.data.FeatureSource;
Expand All @@ -37,11 +81,17 @@
import org.geotools.map.Layer;
import org.geotools.parameter.Parameter;
import org.geotools.referencing.crs.DefaultGeographicCRS;
import org.geotools.renderer.label.LabelCacheImpl;
import org.geotools.renderer.lite.LabelCache;
import org.geotools.renderer.lite.StreamingRenderer;
import org.geotools.resources.coverage.FeatureUtilities;
import org.geotools.styling.*;
import org.geotools.styling.ChannelSelection;
import org.geotools.styling.ChannelSelectionImpl;
import org.geotools.styling.RasterSymbolizer;
import org.geotools.styling.SelectedChannelType;
import org.geotools.styling.SelectedChannelTypeImpl;
import org.geotools.styling.Style;
import org.geotools.styling.StyleBuilder;
import org.geotools.styling.TextSymbolizer;
import org.geotools.util.NumberRange;
import org.geotools.util.URLs;
import org.geotools.util.logging.Logging;
Expand All @@ -55,28 +105,7 @@
import org.opengis.referencing.crs.CoordinateReferenceSystem;
import org.opengis.referencing.operation.TransformException;

import javax.media.jai.Interpolation;
import javax.media.jai.RenderedOp;
import javax.xml.namespace.QName;
import java.awt.*;
import java.awt.geom.NoninvertibleTransformException;
import java.awt.geom.Rectangle2D;
import java.awt.image.BufferedImage;
import java.awt.image.RenderedImage;
import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;

import static org.geoserver.data.test.CiteTestData.STREAMS;
import static org.junit.Assert.*;
import com.vividsolutions.jts.geom.Envelope;

public class RenderedImageMapOutputFormatTest extends WMSTestSupport {

Expand Down Expand Up @@ -398,7 +427,12 @@ public void testCustomLabelCache() throws IOException {

request.setFormat(getMapFormat());

this.rasterMapProducer.setLabelCache(CustomLabelCache.class);
this.rasterMapProducer.setLabelCache(new Function<WMSMapContent, LabelCache>() {
@Override
public LabelCache apply(WMSMapContent mapContent) {
return new CustomLabelCache();
}
});
RenderedImageMap imageMap = this.rasterMapProducer.produceMap(map);
BufferedImage image = (BufferedImage) imageMap.getImage();
imageMap.dispose();
Expand Down

0 comments on commit 6788b9b

Please sign in to comment.