Я довольно новичок в JavaScript и API карт Google. Я не могу понять, что не так.
InfoWindow - это класс, который я нашел "InfoBubble".
http://google -maps-utility-library-v3.googlecode.com / SVN / багажник / infobubble / примеры / example.html /
Вот ситуация:
1. I create my map and add a 'click' event. The event creates Markers.
2. I create one global infoWindow.
3. I click the map, a Marker appears.
4. I click the map, a Marker appears.
5. I click the map, a Marker appears. Step 3-5 can be repeated lots and lots.
6. I click marker number X
6.1. An infoWindow pops up.
7. I click marker number Y
7.1. The infoWindow is closed. (.close())
7.2. Its content and position is changed
7.3. It is opened on the new position (.open(map,marker))
7.4. Also Marker number X is removed.
Попробуйте сами: http://dl.dropbox.com/u/6084360/test/index.html
Почему шаг 7.4. происходит? После того, как это произошло, я могу нажимать на маркеры, но чувствую, что ничего не исчезает. Почему?
Я попытался отладить что-то с помощью Google Chrome, но после выполнения шага 7.3 это приводит меня к некоторому уменьшенному коду и я теряюсь.
Вот строка, которая удаляет маркер. Я понятия не имею, почему это удаляет его или как узнать, с чего начать.
R.addDomListenerOnce=function(a,b,c,d){var e=R[yc](a,b,function(){e[wb]();return c[Cc](this,arguments)},d);return e};R.R=function(a,b,c,d){c=cf(c,d);return R[yc](a,b,c)};function cf(a,b){return function(c){return b[oc](a,c,this)}}R.bind=function(a,b,c,d){return R[G](a,b,P(c,d))};R.addListenerOnce=function(a,b,c){var d=R[G](a,b,function(){d[wb]();return c[Cc](this,arguments)});return d};R.forward=function(a,b,c){return R[G](a,b,df(b,c))};R.ua=function(a,b,c,d){return R[yc](a,b,df(b,c,!d))};
Мой код:
var times = 0;
var treasureLocation = new google.maps.LatLng(62.05350309096103, 15.373047874999997);
var map, infoBubble = null;
function initialize()
{
// Create the actual map.
map = new google.maps.Map(document.getElementById("map_canvas"),
{
zoom: 4,
center: new google.maps.LatLng(62.05350309096103, 15.373047874999997),
mapTypeId: google.maps.MapTypeId.ROADMAP
}
);
infoBubble = new InfoBubble({
disableAutoPan: true
});
// Add an eventlistener to the map.
google.maps.event.addListener
(
map,
'click',
function(ev)
{
addMarker(ev);
}
);
}
function addMarker(ev)
{
// Get the distance.
var distance = getDistance( ev.latLng , treasureLocation );
// Skriv ut vart man klickade.
document.getElementById("click_info").innerHTML = "Du klickade " + distance + " ifrån skatten, försök igen!";
// Create a marker
var marker = new google.maps.Marker({
position: ev.latLng,
map: map,
clickable: true,
title: "Härifån är det bara " + distance + " till skatten!",
icon: "shovel.png"
});
// Hook the click on the created marker to show the created popup
google.maps.event.addListener
(
marker,
'click',
function(ev)
{
if( infoBubble != null ){infoBubble.close();}
infoBubble.setContent(marker.title);
infoBubble.setPosition(marker.position);
infoBubble.open(map, marker);
}
);
}