[geotk] Objects animation/movement on map
Gopinath Asutosh
asutosh_gopinath at yahoo.com
Thu Oct 13 20:44:51 PDT 2016
Hi Johann Sorel,Thanks for responding.
I adapted SquareGraphics demo to take care of screen flickering issue. Now every eqpt id refreshing its location in background and map.getCanvas().repaint() is invoked from a separate thread every 15 secs to update locations of all eqpt on screen .
But now i am having another problem. The squares are not changing size when the map is zoomed in/out. How do I fix it?
Code attached below:
===import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.Shape;
import java.awt.geom.Rectangle2D;
import java.awt.geom.RoundRectangle2D;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Collection;
import java.util.List;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import org.apache.sis.geometry.GeneralDirectPosition;
import org.apache.sis.storage.DataStoreException;
import org.geotoolkit.display.canvas.AbstractReferencedCanvas2D;
import org.geotoolkit.display.canvas.RenderingContext;
import org.geotoolkit.display.canvas.VisitFilter;
import org.geotoolkit.display.primitive.SearchArea;
//import org.geotoolkit.display.VisitFilter;
//import org.geotoolkit.display.SearchArea;
import org.geotoolkit.display2d.canvas.J2DCanvas;
import org.geotoolkit.display2d.canvas.RenderingContext2D;
import org.geotoolkit.display2d.primitive.GraphicJ2D;
import org.geotoolkit.referencing.CRS;
import org.opengis.display.primitive.Graphic;
import org.opengis.geometry.DirectPosition;
import org.opengis.geometry.Envelope;
import org.opengis.geometry.MismatchedDimensionException;
import org.opengis.referencing.crs.CoordinateReferenceSystem;
import org.opengis.referencing.operation.MathTransform;
import org.opengis.referencing.operation.TransformException;
import org.opengis.util.FactoryException;
import org.openide.util.Exceptions;
import org.openide.util.Lookup;
public class SquaresGraphicTorpedo implements GraphicJ2D, Runnable {
double lat = 22.796212;
double lon = 86.198888;
String eqptId = null;
ScheduledExecutorService executor = Executors.newScheduledThreadPool(1);
public SquaresGraphicTorpedo(String eqptId) {
this.eqptId = eqptId;
int initialDelay = 0;
int period = 1;
executor.scheduleWithFixedDelay(this, initialDelay, period, TimeUnit.MINUTES);
}
@Override
public void paint(RenderingContext2D context) {
final Graphics2D g2d = context.getGraphics();
// context.switchToObjectiveCRS();
try {
CoordinateReferenceSystem sourceCRS = CRS.decode("EPSG:4326");
CoordinateReferenceSystem targetCRS = context.getDisplayCRS();
MathTransform tr = CRS.findMathTransform(sourceCRS, targetCRS);
/*
* From this point we can convert an arbitrary amount of coordinates using the
* same MathTransform object. It could be in concurrent threads if we wish.
*/
DirectPosition sourcePt = new GeneralDirectPosition(
lat, // 27°59'17"N
lon); // 86°55'31"E
DirectPosition targetPt = tr.transform(sourcePt, null);
// System.out.println("ptDst.x: " + targetPt.getCoordinate()[0] + " ptDst.y: " + targetPt.getCoordinate()[1]);
RoundRectangle2D.Double rect = new RoundRectangle2D.Double(targetPt.getCoordinate()[0], targetPt.getCoordinate()[1], 20, 10, 10, 10);
g2d.setPaint(Color.RED);
g2d.fill(rect);
} catch (FactoryException | MismatchedDimensionException | TransformException ex) {
Exceptions.printStackTrace(ex);
}
}
@Override
public void run() {
getLastLocationOfTheDay();
}
private void getLastLocationOfTheDay() {
}
@Override
public List<Graphic> getGraphicAt(RenderingContext context, SearchArea mask, VisitFilter filter, List<Graphic> graphics) {
return graphics;
}
@Override
public Object getUserObject() {
return null;
}
@Override
public Envelope getEnvelope() {
return null;
}
@Override
public double getZOrderHint() {
return 0.0;
}
@Override
public void setZOrderHint(double d) {
}
==
Thanks and regards
Asutosh Gopinath
On Thursday, October 13, 2016 1:54 PM, johann sorel <johann.sorel at geomatys.com> wrote:
Hello,
The rendering engine is stateless by default, but we have some possible alternatives.
Solution 1 :
final JMap2D jmap = new JMap2D();
jmap.getCanvas().setRenderingHint(GO2Hints.KEY_BEHAVIOR_MODE, GO2Hints.BEHAVIOR_KEEP_TILE);
This will ask the swing widget to replace the image at the last moment when possible, it should reduce the flickering.
You can also try the 'GO2Hints.BEHAVIOR_ON_FINISH'
Solution 2 :
final JMap2D jmap = new JMap2D(true);
The boolean argument is for 'statefull', the engine will cache more informations and use separate buffers
for each layer. But it use more memory.
Solution 3 :
There is also the solution to create a custom decoration over the map,
A demo is available in the demo-samples module, package : org.geotoolkit.pending.demo.rendering.customdecoration
But it require a lot more work.
Johann Sorel
On 12/10/2016 06:51, Gopinath Asutosh wrote:
Hi , I want to show over 100 objects representing vehicles moving on GIS map. The locations of vehicle change every 10 secs. I tried to create a circle with its center located on GPS coordinates obtained from devices mounted on vehicles. Whenever new coordinates are received I create a new circle and call store.updateFeatures. This plots the circles on new location but it also simultaneously causes the screen to flicker a lot due to which the animation effect is lost.
It is possible to animate any object using geotoolkit without causing the screen to flicker.
Thanks and regards Asutosh Gopinath
_______________________________________________
Geotoolkit mailing list
Geotoolkit at lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/geotoolkit
_______________________________________________
Geotoolkit mailing list
Geotoolkit at lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/geotoolkit
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/geotoolkit/attachments/20161014/824b1201/attachment-0001.html>
More information about the Geotoolkit
mailing list