Hi all,
We are trying to use geotools 2.3 in our system (we are currenly using 2.1, and receive many suggestion from the list to update :). We are trying 2.3.0-M0 release. Currently we are having problem displaying more than 1 layers using JMapPane and StreamingRenderer. Basically, things work fine for us if we just have 1 layer in JMapPane. However, if we add more than 1 layers, only the 1st layer got displayed (through we noticed that sometimes that same layers will be rendered multiple times using different styles that belongs to the other added-but-not-displayed layers).
Bellow is the testing code that we use (we modified it from an example created by Jody Garnett). Please let us know if we miss anything, or give us some direction on what we should do to solve our problem.
Thank you all,
Trung
-------------------------------
Test case: Please note that we added two layers, but in our machine, we can always see only the one and added first.
public class SLDExample {
public static void main(String args[]) {
try {
localSLD();
} catch (Exception ignore) {
ignore.printStackTrace();
}
}
public static void supressInfo() {
Logger.getLogger("org.geotools.gml").setLevel(Level.SEVERE);
Logger.getLogger("net.refractions.xml").setLevel(Level.SEVERE);
}
public static void localSLD() throws Exception {
final FeatureSource[] source = demoFeatureSource();
final Style style1 = demoStyle(source[0].getSchema().getTypeName(), source[0]
.getSchema().getDefaultGeometry().getName(), "#00FF00");
final Style style2 = demoStyle(source[1].getSchema().getTypeName(), source[1]
.getSchema().getDefaultGeometry().getName(), "#FF0000");
show(source, style1, style2);
}
static FeatureSource[] demoFeatureSource() throws Exception {
File destination = new File("C:/Shapefiles/Montrose/sections/sections.shp");
Map shapefileParams = new HashMap();
shapefileParams.put("url", destination.toURL());
DataStore data = "" ShapefileDataStoreFactory().createDataStore(shapefileParams);
String typeName = data.getTypeNames()[0];
FeatureSource featureSource = data.getFeatureSource(typeName);
File destination2 = new File("C:/Shapefiles/Montrose/gpsroads/gpsrds.shp");
Map shapefileParams2 = new HashMap();
shapefileParams2.put("url", destination2.toURL());
DataStore data2 = new ShapefileDataStoreFactory().createDataStore(shapefileParams2);
String typeName2 = data2.getTypeNames()[0];
FeatureSource featureSource2 = data2.getFeatureSource(typeName2);
FeatureSource[] result = new FeatureSource[2];
result[0] = featureSource;
result[1] = featureSource2;
return result;
}
static Style demoStyle(String typeName, String geometryName, String color)
throws Exception {
StyleFactory sf = StyleFactoryFinder.createStyleFactory();
FilterFactory ff = FilterFactoryFinder.createFilterFactory();
Stroke stroke = sf.createStroke(ff.createLiteralExpression(color),
ff.createLiteralExpression(2));
LineSymbolizer lineSymbolizer = sf.createLineSymbolizer();
lineSymbolizer.setStroke(stroke);
lineSymbolizer.setGeometryPropertyName(geometryName);
Rule rule = sf.createRule();
rule.setFilter(Filter.NONE);
rule.setSymbolizers(new Symbolizer[] { lineSymbolizer });
FeatureTypeStyle type = sf.createFeatureTypeStyle();
type.setFeatureTypeName(typeName);
type.addRule(rule);
Style style = sf.createStyle();
style.addFeatureTypeStyle(type);
return style;
}
public static void show(FeatureSource source[], Style style1, Style style2) throws Exception {
JFrame frame = new JFrame("FOSS4G");
frame.setBounds(20, 20, 450, 200);
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
JMapPane mp = new JMapPane();
frame.getContentPane().add(mp);
mp.setMapArea(source[0].getBounds());
MapContext context = new DefaultMapContext(source[0].getSchema()
.getDefaultGeometry().getCoordinateSystem());
context.setAreaOfInterest(source[0].getBounds());
context.addLayer(source[1], style2);
context.addLayer(source[0], style1);
context.getLayerBounds();
GTRenderer renderer = new StreamingRenderer();
HashMap hints = new HashMap();
hints.put("memoryPreloadingEnabled", Boolean.TRUE);
renderer.setRendererHints(hints);
mp.setRenderer(renderer);
mp.setContext(context);
frame.setVisible(true);
}
}
We are trying to use geotools 2.3 in our system (we are currenly using 2.1, and receive many suggestion from the list to update :). We are trying 2.3.0-M0 release. Currently we are having problem displaying more than 1 layers using JMapPane and StreamingRenderer. Basically, things work fine for us if we just have 1 layer in JMapPane. However, if we add more than 1 layers, only the 1st layer got displayed (through we noticed that sometimes that same layers will be rendered multiple times using different styles that belongs to the other added-but-not-displayed layers).
Bellow is the testing code that we use (we modified it from an example created by Jody Garnett). Please let us know if we miss anything, or give us some direction on what we should do to solve our problem.
Thank you all,
Trung
-------------------------------
Test case: Please note that we added two layers, but in our machine, we can always see only the one and added first.
public class SLDExample {
public static void main(String args[]) {
try {
localSLD();
} catch (Exception ignore) {
ignore.printStackTrace();
}
}
public static void supressInfo() {
Logger.getLogger("org.geotools.gml").setLevel(Level.SEVERE);
Logger.getLogger("net.refractions.xml").setLevel(Level.SEVERE);
}
public static void localSLD() throws Exception {
final FeatureSource[] source = demoFeatureSource();
final Style style1 = demoStyle(source[0].getSchema().getTypeName(), source[0]
.getSchema().getDefaultGeometry().getName(), "#00FF00");
final Style style2 = demoStyle(source[1].getSchema().getTypeName(), source[1]
.getSchema().getDefaultGeometry().getName(), "#FF0000");
show(source, style1, style2);
}
static FeatureSource[] demoFeatureSource() throws Exception {
File destination = new File("C:/Shapefiles/Montrose/sections/sections.shp");
Map shapefileParams = new HashMap();
shapefileParams.put("url", destination.toURL());
DataStore data = "" ShapefileDataStoreFactory().createDataStore(shapefileParams);
String typeName = data.getTypeNames()[0];
FeatureSource featureSource = data.getFeatureSource(typeName);
File destination2 = new File("C:/Shapefiles/Montrose/gpsroads/gpsrds.shp");
Map shapefileParams2 = new HashMap();
shapefileParams2.put("url", destination2.toURL());
DataStore data2 = new ShapefileDataStoreFactory().createDataStore(shapefileParams2);
String typeName2 = data2.getTypeNames()[0];
FeatureSource featureSource2 = data2.getFeatureSource(typeName2);
FeatureSource[] result = new FeatureSource[2];
result[0] = featureSource;
result[1] = featureSource2;
return result;
}
static Style demoStyle(String typeName, String geometryName, String color)
throws Exception {
StyleFactory sf = StyleFactoryFinder.createStyleFactory();
FilterFactory ff = FilterFactoryFinder.createFilterFactory();
Stroke stroke = sf.createStroke(ff.createLiteralExpression(color),
ff.createLiteralExpression(2));
LineSymbolizer lineSymbolizer = sf.createLineSymbolizer();
lineSymbolizer.setStroke(stroke);
lineSymbolizer.setGeometryPropertyName(geometryName);
Rule rule = sf.createRule();
rule.setFilter(Filter.NONE);
rule.setSymbolizers(new Symbolizer[] { lineSymbolizer });
FeatureTypeStyle type = sf.createFeatureTypeStyle();
type.setFeatureTypeName(typeName);
type.addRule(rule);
Style style = sf.createStyle();
style.addFeatureTypeStyle(type);
return style;
}
public static void show(FeatureSource source[], Style style1, Style style2) throws Exception {
JFrame frame = new JFrame("FOSS4G");
frame.setBounds(20, 20, 450, 200);
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
JMapPane mp = new JMapPane();
frame.getContentPane().add(mp);
mp.setMapArea(source[0].getBounds());
MapContext context = new DefaultMapContext(source[0].getSchema()
.getDefaultGeometry().getCoordinateSystem());
context.setAreaOfInterest(source[0].getBounds());
context.addLayer(source[1], style2);
context.addLayer(source[0], style1);
context.getLayerBounds();
GTRenderer renderer = new StreamingRenderer();
HashMap hints = new HashMap();
hints.put("memoryPreloadingEnabled", Boolean.TRUE);
renderer.setRendererHints(hints);
mp.setRenderer(renderer);
mp.setContext(context);
frame.setVisible(true);
}
}
------------------------------------------------------------------------- Using Tomcat but need to do more? Need to support web services, security? Get stuff done quickly with pre-integrated technology to make your job easier Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________ Geotools-gt2-users mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users
