OK. The problem is that some recent changes I made to the map pane
don't work well if the pane is created with a null map context. And
then, some recent changes that Jody made to the map context related
classes mean that you can't give the map pane an empty map context. So
we have made life quite hard for you.
A partial work-around is to replace the openShapefile method in the
code I posted earlier with this one...
private void openShapefile() {
File file = JFileDataStoreChooser.showOpenFile("shp", this);
if (file != null) {
try {
FileDataStore dataStore =
FileDataStoreFinder.getDataStore(file);
SimpleFeatureSource source = dataStore.getFeatureSource();
Style style = SLD.createSimpleStyle(source.getSchema());
MapContext map = getMapContext();
if (map == null) {
// No map context set yet. Create one and also
// set a renderer
map = new DefaultMapContext();
map.addLayer(source, style);
setMapContext(map);
setRenderer(new StreamingRenderer());
// work-around for bug in JMapPane when it is
created with a
// null map context
JMapPane pane = getMapPane();
HierarchyBoundsListener listener =
pane.getHierarchyBoundsListeners()[0];
listener.ancestorResized(new HierarchyEvent(this,
0, null, null));
} else {
map.addLayer(source, style);
}
} catch (Exception ex) {
throw new RuntimeException(ex);
}
}
}
The HierarchyBoundsListener stuff is fooling the map pane into
thinking that is has just been resized. This forces it to create a new
base image and draw the shapefile. You could, of course, do the same
thing by manually resizing the frame.
However, it is a partial work-around because there is another bug -
one that must have been in there for ages but nobody spotted before
now. If you pass the map pane a MapContext with a layer in it, it
fails to add it to the map layer table. There is no easy work-around
for that one.
I'll fix these changes shortly. If you want, you can switch to using
version 2.7-SNAPSHOT and you will get the fixed code (it will take an
hour or two to commit the changes and for the jars to be rebuilt).
Alternatively you can download the sources for gt-swing after the
changes have been committed and re-build the jar yourself. If all else
fails you can wait for version 2.7.3 to be released.
Sorry for the problems. Consider it a learning experience :)
Michael
On 7 July 2011 23:08, Michael Bedward <[email protected]> wrote:
> On 7 July 2011 22:36, lexmc <[email protected]> wrote:
>> Even your example doesn't works. The repaint don't works. Maybe is an aclipse
>> problem????
>
> That's a lot of question marks.
>
> I've just checked it again, this time against GeoTools version 2.7.1,
> and there is a problem in JMapPane which your code has brought to
> light. So the good news is that this one is not your fault :)
>
> Just looking for a work-around now.
>
> Michael
>
------------------------------------------------------------------------------
All of the data generated in your IT infrastructure is seriously valuable.
Why? It contains a definitive record of application performance, security
threats, fraudulent activity, and more. Splunk takes this data and makes
sense of it. IT sense. And common sense.
http://p.sf.net/sfu/splunk-d2d-c2
_______________________________________________
Geotools-gt2-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users