2013-10-29 69 views
0

這種情況如下:我有一個圖層,上面有兩個點。第一個是在澳大利亞,第二個是在美國。大陸或點的確切位置不計算在內。基本部分是點之間的很大距離。當應用程序啓動時,出現第一個點(縮放級別爲18)。第二點不顯示,因爲它離這裏很遠,縮放級別很高。然後我用第二個點的位置調用panTo函數。地圖跳轉到正確的位置,但第二個點不出現。只有當我放大/縮小瀏覽器窗口或調整瀏覽器窗口大小時纔會出現此點。 GWT代碼:當它們之間有很大的距離時顯示點(GWT-Openlayers)

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重現這種情況,但它工作正常。這裏是link 所以我認爲問題是與GWT的Openlayers。有沒有人經歷過這種行爲?還是有人有解決這個問題?

回答

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

Knarf,謝謝你的回覆。該解決方法正在工作:)我希望GWT-OL的人會發現這個問題的原因。 – Imreking