|
From: Martin D. <mar...@no...> - 2005-10-10 08:53:57
|
Bernhard Kastner a =E9crit :
> [solved]
> Using org.geotools.renderer.j2d.GeoMouseEvent.getMapCoordinate();
Sorry for having been slow to answer... Glad you find it.
>> 2. How do I change the behaviour of the mouse on a map? When clicking=20
>> and draging the mouse, it generates a zoom-pane with the selected=20
>> area. I want to change this behaviour to pan the map. So, when moving=20
>> the mouse, the map also moves, but doesn't zoom or anything else. Is=20
>> this possible?
You can create yours own subclass of StyledMapPane and override the=20
following method:
protected void mouseSelectionPerformed(Shape area) {
}
See ZoomPane javadoc for details about this method. There is some other=20
methods that you can override in order to control different events.
>> And another question: As already mentioned, I'm using the methods as=20
>> in the Spearfish Sample, which uses J2D-renderer. I experienced=20
>> OutOfMemoryExceptions when dealing with larger shapefiles (3x 30 MB).=20
>> Is there a possibility to avoid that?
Technically yes, but it is hard to use at this time.
There is some chances that the shapefile datastore stores the geometries=20
as JTS object with arrays of CoordinatePoint. This storage scheme is=20
expensive. You can "compress" them, but with a cost: the lost of the=20
underlying JTS geometries. Explanation:
J2D renderer internally stores all geometries as=20
org.geotools.renderer.geom.Geometry objects using an abstract PointArray=20
structure. The point array may be JTS's Coordinate[] array, a plain=20
double[] array, etc. The idea is to switch from the Coordinate[]=20
representation to a float[] representation.
We first need to find the underlying Geometry objects. One possible way=20
is to invokes MapPane.getRenderer().getLayers(). Then iterates through=20
those layers and search for "if (layer instanceof RenderedGeometries)".=20
Invokes RenderedGeometries.getGeometry(). You should not have a=20
GeometryCollection (maybe not the only one, the search should continue=20
for other layers).
Invoke Geometry.compress(CompressionLevel.DIRECT_AS_FLOATS). If you get=20
an UnmodifiableGeometryException, try to clone the geometry before to=20
compress it.
Set the new geometry to the RenderedGeometries layer.
Make sure that there is no reference to the original JTS geometry=20
floating around (you may need to checks in a profiler to make sure that=20
their memory is reclaimed).
Martin.
|