我使用Google's My Maps創建了自己的地圖。我做了一個新層,並在上面放置了一些標記。
是否可以與這些標記進行交互?與Google的我的地圖互動
我想按照時間順序對這些標記進行「迭代」。
請考慮以下地圖:Remote Islands of the World。
我會在我的網站上製作一個按鈕「Next」。每當用戶點擊按鈕,地圖從「布維島」跳到「聖赫勒拿島」,然後再點擊跳到「伊豆羣島 - 三宅島」等。
我甚至不知道是否有可能或在哪裏找到更多關於如何實現它的信息。
我使用Google's My Maps創建了自己的地圖。我做了一個新層,並在上面放置了一些標記。
是否可以與這些標記進行交互?與Google的我的地圖互動
我想按照時間順序對這些標記進行「迭代」。
請考慮以下地圖:Remote Islands of the World。
我會在我的網站上製作一個按鈕「Next」。每當用戶點擊按鈕,地圖從「布維島」跳到「聖赫勒拿島」,然後再點擊跳到「伊豆羣島 - 三宅島」等。
我甚至不知道是否有可能或在哪裏找到更多關於如何實現它的信息。
一種選擇是創建一個Google Maps JavaScript API v3地圖並通過代理使用第三方KML分析器(如geoxml3)從MyMaps訪問KML數據。
example(使用geoxml3顯示側邊欄中的KML點名稱,但可以修改爲添加一個按順序排列的「下一個」按鈕)。
example with "next"/"previous" links in infowindow and next button above the map
將此添加代碼的useTheData
函數內(和等同物對於多邊形和折線):
if (placemark.marker) {
google.maps.event.addListener(placemark.marker, 'click', function(i) {
return function(evt) {
// add next and previous links to infowindow when the placemark is clicked
infowindow.setContent(infowindow.getContent()+"<br><a href='javascript:next("+i+");'>next</a> - <a href='javascript:prev("+i+");'>previous</a>");
// track the last opened placemark
openInfoWindow = i;
}}(i));
然後這些函數來打開下一個信息窗口:
function next(i) {
var next = (i+1) % geoXmlDoc.placemarks.length;
if (geoXmlDoc.placemarks[next].marker) {
google.maps.event.trigger(geoXmlDoc.placemarks[next].marker, "click");
} else if (geoXmlDoc.placemarks[next].polyline) {
google.maps.event.trigger(geoXmlDoc.placemarks[next].polyline, "click");
} else if (geoXmlDoc.placemarks[next].polygon) {
google.maps.event.trigger(geoXmlDoc.placemarks[next].polygon, "click");
}
}
function nextBtn() {
// handle case where button is clicked before any placemarks on the map
if (!openInfoWindow) openInfoWindow = 0;
next(openInfoWindow);
}
注意由於geoxml3使用XmlHttpRequest訪問數據,因此必須在顯示頁面的域上使用代理來克服對XmlHttpRequest有相同的域限制。