gwtopenlayersgwt-openlayers

Display points when there's great distance between them (GWT-Openlayers)


The case is the following: I have a layer and there are two points on it. The first is in Australia, the second is in the USA. The continent or the exact position of the points doesn't count. The essential part is the great distance between the points. When the application starts, the first point appears (zoomlevel is 18). The second point isn't displayed because it is far away from here and the zoomlevel is high. Then i call the panTo function with the location of the second point. The map jumps to the right location but the second point doesn't appear. The point appears only if i zoom in/out or resize the browser window. The GWT code:

LonLat center = new LonLat(151.304485, -33.807831);
final LonLat usaPoint = new LonLat(-106.356183, 35.842721);

MapOptions defaultMapOptions = new MapOptions();
defaultMapOptions.setNumZoomLevels(20);

// mapWidget
final MapWidget mapWidget = new MapWidget("100%", "100%", defaultMapOptions);

// google maps layer
GoogleV3Options gSatelliteOptions = new GoogleV3Options();
gSatelliteOptions.setIsBaseLayer(true);
gSatelliteOptions.setDisplayOutsideMaxExtent(true);
gSatelliteOptions.setSmoothDragPan(true);
gSatelliteOptions.setType(GoogleV3MapType.G_SATELLITE_MAP);
GoogleV3 gSatellite = new GoogleV3("Google Satellite", gSatelliteOptions);
mapWidget.getMap().addLayer(gSatellite);

// pointLayer
VectorOptions options = new VectorOptions();
options.setDisplayOutsideMaxExtent(true);
Vector vector = new Vector("layer1", options);
mapWidget.getMap().addLayer(vector);

mapWidget.getMap().addControl(new LayerSwitcher());
mapWidget.getMap().addControl(new MousePosition());
mapWidget.getMap().addControl(new ScaleLine());
mapWidget.getMap().addControl(new Scale());

// two points are added to the layer
center.transform(new Projection("EPSG:4326").getProjectionCode(), mapWidget.getMap().getProjection());
vector.addFeature(new VectorFeature(new Point(center.lon(), center.lat())));
usaPoint.transform(new Projection("EPSG:4326").getProjectionCode(), mapWidget.getMap().getProjection());
vector.addFeature(new VectorFeature(new Point(usaPoint.lon(), usaPoint.lat())));

// the center of the map is the first point
mapWidget.getMap().setCenter(center, 18);

// 3 sec later panTo second point
Timer t = new Timer() {
    @Override
    public void run() {
    mapWidget.getMap().panTo(usaPoint);
    }
};
t.schedule(3000);

I tried to reproduce this situation with pure Openlayers, but it worked fine. Here is the link So i think the problem is with GWT-Openlayers. Has anybody experienced such behaviour? Or has anybody got a solution to this problem?


Solution

  • What a strange problem.

    For now I did only found a way around it, but not a real fix. Seems to be a bug in GWT-OL as you say, but I can't imagine where.

    What you can do is add the following 3 lines to your code :

    mapWidget.getMap().panTo(usaPoint);
    int zoom = mapWidget.getMap().getZoom();
    mapWidget.getMap().setCenter(usaPoint, 0);
    mapWidget.getMap().setCenter(usaPoint, zoom);
    

    (note : I am a contributor to the GWT-OL project, I also informed other contributors of this problem, maybe they can find a better solution)

    Edit : Another GWT-OL contributor looked into this but also couldn't find a real solution but another workaround is to use zoomToExtend for the requested point :

    Bounds b = new Bounds();
    b.extend(new LonLat(usaPoint.getX(), usaPoint.getY()));
    mapWidget.getMap().zoomToExtent(b);