On 12 July 2016 at 13:02, Julian Hagenauer <[email protected]> wrote:
> Shouldn't
>
> for( Layer l : mc.layers() )
> mc.removeLayer(l);
>
> give a ConcurrentModification-Exception?
>
I think you get away with it as you only have one layer. In general I
suspect you are running in to locking issues (possibly as you are sending
redraw events from the main thread? my swing threading knowledge is hazy
here.
If all you want to do is rapidly update the map may be some sort of
updatable layer would help? Try using https://gitlab.com/snippets/22341 like
this
*if(layer==null) { layer = new UpdatableLayer(fc,
SLD.wrapSymbolizers(sym)); mc.addLayer(layer); }else {
layer.addFeatures(fc); }*
I had to add a sleep call to slow things down enough to see it changing but
it seems to work.
Ian
> >>>
> *Von: * "Julian Hagenauer" <[email protected]>
> *An:* <[email protected]>
> *Datum: * 12.07.2016 11:50
> *Betreff: * [Geotools-gt2-users] Synchronization issue when updating
> MapContent?
> Hi again,
>
> I stumbled again upon an issue with my small test program. The program
> does nothing but create repeatedly a collection of points, clear all
> existing MapLayers, and add a new layer consisting of the collection.
> However, the programm hangs after about 265 iterations. I assume on your
> machine this number might vary. I am using geotools 15-RC1.
>
> Here is the small program:
>
> public class JMapPaneTest extends JFrame {
>
> public JMapPane mp;
>
> public JMapPaneTest() {
> mp = new JMapPane();
> mp.setMapContent(new MapContent());
> add(mp);
> setSize(400,400);
> setVisible(true);
> }
>
> public void updateMP() {
> GeometryFactory gf = new GeometryFactory();
> SimpleFeatureTypeBuilder typeBuilder = new SimpleFeatureTypeBuilder();
> typeBuilder.setName("Points");
> typeBuilder.add("the_geom",Point.class);
>
> SimpleFeatureBuilder featureBuilder = new
> SimpleFeatureBuilder(typeBuilder.buildFeatureType());
> Random r = new Random();
> DefaultFeatureCollection fc = new DefaultFeatureCollection();
> for( int i = 0; i < 1000; i++ ) {
> Point p = gf.createPoint(new Coordinate(r.nextDouble(),r.nextDouble()));
> featureBuilder.set("the_geom", p);
> fc.add( featureBuilder.buildFeature(""+fc.size()));
> }
> MapContent mc = mp.getMapContent();
>
> for( Layer l : mc.layers() )
> mc.removeLayer(l);
>
> Symbolizer sym = new StyleBuilder().createPointSymbolizer();
> mc.addLayer(new FeatureLayer(fc, SLD.wrapSymbolizers(sym)));
> mc.setViewport( new MapViewport(fc.getBounds()));
> }
>
> public static void main(String[] args) {
> JMapPaneTest t = new JMapPaneTest();
> for( int i = 0; i < 1000; i++ ) {
> System.out.println(i);
> t.updateMP();
> }
> System.exit(1);
> }
> }
>
>
>
>
> ------------------------------------------------------------------------------
> What NetFlow Analyzer can do for you? Monitors network bandwidth and
> traffic
> patterns at an interface-level. Reveals which users, apps, and protocols
> are
> consuming the most bandwidth. Provides multi-vendor support for NetFlow,
> J-Flow, sFlow and other flows. Make informed decisions using capacity
> planning
> reports.http://sdm.link/zohodev2dev
> _______________________________________________
> GeoTools-GT2-Users mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users
>
>
--
Ian Turton
------------------------------------------------------------------------------
What NetFlow Analyzer can do for you? Monitors network bandwidth and traffic
patterns at an interface-level. Reveals which users, apps, and protocols are
consuming the most bandwidth. Provides multi-vendor support for NetFlow,
J-Flow, sFlow and other flows. Make informed decisions using capacity planning
reports.http://sdm.link/zohodev2dev
_______________________________________________
GeoTools-GT2-Users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users