trackingGull.setLocationListener(new Seagull.SeagullLocationListener(){
public void gullMoved( final Coordinate newLoc ) {
Display.getDefault().asyncExec(new Runnable(){
private void scroll(int newx, int newy, int startx, int starty){
ViewportModelImpl vm = (ViewportModelImpl)map.getViewportModel();
final ViewportPaneTiledSWT viewera = (ViewportPaneTiledSWT)viewer;
org.eclipse.swt.graphics.Point p = Display.getCurrent().map((Canvas)viewera, null, newx, newy);
org.eclipse.swt.graphics.Point p2 = Display.getCurrent().map((Canvas)viewera, null, startx, starty);
int xdiff = p2.x - p.x;
int ydiff = p2.y - p.y;
((Canvas)viewera).scroll(xdiff, ydiff, 0,0, map.getRenderManager().getMapDisplay().getWidth(), map.getRenderManager().getMapDisplay().getHeight(), true);
}
public void run() {
ViewportModelImpl vm = (ViewportModelImpl)map.getViewportModel();
final ViewportPaneTiledSWT viewera = (ViewportPaneTiledSWT)viewer;
final ReferencedEnvelope bounds = vm.getBounds();
Coordinate currentc = vm.getCenter();
final Point newpnt = vm.worldToPixel(newLoc);
final Point oldpnt = vm.worldToPixel(currentc);
vm.setIsBoundsChanging(true);
int xoffset = oldpnt.x - newpnt.x;
int yoffset = oldpnt.y - newpnt.y;
int diffx = 0;
int diffy = 0;
int xdiff = (int)(xoffset / 10.0);
int ydiff = (int)(yoffset / 10.0);
if (xdiff == 0){
if (xoffset > 0){
xdiff = 1;
}else{
xdiff = -1;
}
}
if (ydiff == 0){
if (yoffset > 0){
ydiff = 1;
}else{
ydiff = -1;
}
}
int lastx = oldpnt.x;
int lasty = oldpnt.y;
while(Math.abs(diffx) < Math.abs(xoffset) || Math.abs(diffy) < Math.abs(yoffset) ){
if (Math.abs(diffx) < Math.abs(xoffset))
diffx += xdiff;
if (Math.abs(diffy) < Math.abs(yoffset))
diffy += ydiff;
scroll(lastx - xdiff, lasty-ydiff, lastx,lasty );
lastx -= xdiff;
lasty -= ydiff;
}
lastx -= xdiff;
lasty -=ydiff;
Coordinate newCoo = vm.pixelToWorld(lastx, lasty);
vm.setIsBoundsChanging(false);
vm.setCenter(newCoo);
}});
// SetViewportCenterCommand cmd = new SetViewportCenterCommand(newLoc);
// map.sendCommandASync(cmd);
}