0

案例如下:我有一个图层,上面有两个点。第一个在澳大利亚,第二个在美国。大陆或点的确切位置不计算在内。重要的部分是点之间的距离很大。当应用程序启动时,第一个点出现(缩放级别为 18)。第二个点没有显示,因为它离这里很远,并且缩放级别很高。然后我用第二个点的位置调用 panTo 函数。地图跳转到正确的位置,但没有出现第二个点。该点仅在我放大/缩小或调整浏览器窗口大小时出现。GWT 代码:

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);

我试图用纯 Openlayers 重现这种情况,但效果很好。这是链接 所以我认为问题出在 GWT-Openlayers 上。有没有人经历过这样的行为?或者有没有人解决这个问题?

4

1 回答 1

1

多么奇怪的问题。

目前我只找到了解决它的方法,但没有找到真正的解决方法。正如你所说,似乎是 GWT-OL 中的一个错误,但我无法想象在哪里。

您可以做的是将以下 3 行添加到您的代码中:

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

(注:我是 GWT-OL 项目的贡献者,我也通知了其他贡献者这个问题,也许他们能找到更好的解决方案)

编辑:另一位 GWT-OL 贡献者对此进行了调查,但也找不到真正的解决方案,但另一种解决方法是使用 zoomToExtend 请求点:

Bounds b = new Bounds();
b.extend(new LonLat(usaPoint.getX(), usaPoint.getY()));
mapWidget.getMap().zoomToExtent(b);
于 2013-10-29T19:37:08.263 回答