Hi all,

I'm a new user of geotools, and I have the following problem.
In my application I have to develop a kind a "navigator". To do this, I
have a map layer in which I want to set up the position every two seconds.

I did a method called "updateVehiclePosition" in which a transaction
modifies the geometry value (Point). The problem is that this method works
until no timing function is called. When I insert the TimerTask, the
method stops at the transaction commit, and the map is not painted.

Can anyone help me in fixing this problem?
I report in the following the interested piece of code.

public static void updateVehiclePosition(Object object) throws IOException {

DefaultTransaction transaction = new DefaultTransaction("Example1");
FeatureStore fstore =  (FeatureStore) map.getLayer(5).getFeatureSource();
fstore.setTransaction( transaction );

FilterFactory ff =
CommonFactoryFinder.getFilterFactory(GeoTools.getDefaultHints() );
Filter filter = ff.id( Collections.singleton( ff.featureId("location.1")));

SimpleFeatureType featureType = (SimpleFeatureType) fstore.getSchema();
AttributeType attributeType = featureType.getType("Location");

try {
   fstore.modifyFeatures( attributeType.getName(), object, filter );
   transaction.commit();
}
catch( Exception eek){
    transaction.rollback();
}
finally{
   transaction.close();
}
}

public static void go() {
final java.util.Timer timer = new java.util.Timer();
TimerTask task = new TimerTask() {
int line = 1;
                        public void run() {
                                if(line>3){timer.cancel();}
                                leggi(line);
                                line++;
                        };
                };
                timer.scheduleAtFixedRate(task, 0, 2000);
        }

        private static void leggi(int line2) {
                System.out.println("in percorso line = "+line2);
                Object pos;
                pos=C2XVisualizer.readPosition(line2);
                try {
                        C2XVisualizer.updateVehiclePosition(pos);
                } catch (IOException e) {e.printStackTrace();}
        }

        }

-- 
Francesca Martelli, Computer Science Ph.D.
Algorithms and Computational Mathematics Group, IIT - CNR, Pisa
Phone: +39 050 315 3191 (office), +39 050 315 2333 (fax)
http://www.iit.cnr.it/francesca.martelli/
email: [email protected]



------------------------------------------------------------------------------
Download new Adobe(R) Flash(R) Builder(TM) 4
The new Adobe(R) Flex(R) 4 and Flash(R) Builder(TM) 4 (formerly 
Flex(R) Builder(TM)) enable the development of rich applications that run
across multiple browsers and platforms. Download your free trials today!
http://p.sf.net/sfu/adobe-dev2dev
_______________________________________________
Geotools-gt2-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users

Reply via email to