2015-08-19 23 views
0

我正在使用ArcGIS Javascript API在web地圖上工作,並且在顯示多段線的infoWindow時遇到問題。我想要做的是在selectFeatures執行後動態顯示infoWindow。基本上我已經設置了功能選擇的地方,地圖放大到該功能的位置,我有信息窗口彈出該功能。我有它的點和多邊形罰款,但我似乎無法得到它的多義線工作。我已經能夠成功地讓infoWindow顯示出來,但不在所需的位置。我可以將它顯示在左上角(使用map.infoWindow.show();)或在折線範圍的中心(使用map.infoWindow.show(features [0] .geometry.getExtent( ).getCenter();)但是後者通常並沒有指向線條和中間位置,因爲它使用的是範圍,我也使用了這些特徵的路徑點並獲得了中點這是最接近我成功的,但infoWindow從未出現在視圖空間中,將顯示一半或顯示四分之一 - 要求用戶平移才能看到它。有誰知道我該如何解決這個問題在我把它想要的方式更好地工作,請參見下面的代碼片段的,我在我的腳本執行此(else語句是爲多義線)區域Arcgis Javascript動態顯示多段線的infoWindow

代碼段:?

if (features[0].geometry.type == "point"){ 
    map.centerAndZoom(features[0].geometry, map.getMaxZoom()+2); 
    var center = features[0].geometry; 
    map.infoWindow.setFeatures(features); 
    map.infoWindow.show(center); 
}else if (features[0].geometry.type == "polygon"){ 
    var lyrExtent = features[0].geometry.getExtent().expand(2.0); 
    var center = features[0].geometry.getCentroid(); 
    map.setExtent(lyrExtent); 
    map.infoWindow.setFeatures(features); 
    map.infoWindow.show(center); 
}else{ 
    var lyrExtent = features[0].geometry.getExtent().expand(2.0); 
    var center = features[0].geometry.getExtent().getCenter(); 
    var centerCoords = features[0].geometry.paths[0][features[0].geometry.paths[0].length/2]; 
    var centerPt = new Point(centerCoords, map.spatialReference); 
    map.setExtent(lyrExtent); 
    map.infoWindow.setFeatures(features); 
    map.infoWindow.show(center); 
} 

回答

0

據我所知,您將不得不編寫自定義代碼來重新設置範圍,以便彈出窗口可見。你可以看到an example in the Bootstrap Map source code。您可以包含該庫並使用它來實例化您的地圖並免費獲得該行爲 - 即使您沒有使用Bootstrap。

或者,您可以使用extent's expand() method強制它縮小某些因素。