我正在研究一個WordPress插件,用戶可以在其中創建路線圖並在其網站上顯示它。在管理面板中,它會顯示地圖上現有路線的預覽,並且還會顯示一個標記,以便將其拖動到他們想要添加到地圖的新位置。刪除部分折線
地圖的默認縮放位置在歐洲設置。但是,如果他們例如在澳大利亞添加了幾個站點,那麼只有世界的那一部分可見,並且您不會再看到用於指定新位置的可拖動圖標,這是一個問題。
所以我想用fitbounds來修復它,所以它總會讓可拖動的標記和已經創建的路線適合屏幕。我的代碼確實顯示了地圖上的所有位置,但由於我在訪問過的位置之間繪製了多段線,因此它也在歐洲繪製了一條可拖動的標記,不應該這樣做,因爲它不是路線的一部分。
你可以在這裏看到一個例子 - >http://jsfiddle.net/tijmen/HctvT/1/
部分代碼:
/* Draw lines between the markers */
function drawFlightPlan(flightPlanCoordinates) {
var flightPath = new google.maps.Polyline({
path: flightPlanCoordinates,
geodesic: true,
strokeColor: "#ad1700",
strokeOpacity: 1.0,
strokeWeight: 2
});
flightPath.setMap(map);
fitBounds(flightPlanCoordinates);
}
/* Zoom the map so that all markers fit in the window */
function fitBounds(flightPlanCoordinates) {
var bounds = new google.maps.LatLngBounds();
/* Include this latlng value in europe, but I dont want a line going to that latng... */
var defaultLatlng = new google.maps.LatLng('52.378153', '4.899363');
flightPlanCoordinates.push(defaultLatlng);
for (var i = 0, flightPlanLen = flightPlanCoordinates.length; i < flightPlanLen; i++) {
bounds.extend (flightPlanCoordinates[i]);
}
map.fitBounds(bounds);
}
的澳大利亞標記之間的線條都很好,但行至歐洲不應該在那裏(通常在歐洲會有一個不同的彩色標記)。
我真的不明白爲什麼有一條線路首先要去歐洲。 flightPath.setMap(map);在drawFlightPlan函數內運行。而且,直到fitBounds函數還沒有將歐洲的latlng值添加到flightPlanCoordinates數組中。
我搜索了一種方法來刪除部分折線,但我找不到任何有效的方法。我知道如何去除所有的標記或多段線,但不是一個單獨的多段線部分。這甚至有可能嗎?
任何想法或建議如何解決這個問題,或者這是不能按我想要的方式修復的東西?
修復它,謝謝:) – tijmen