4

我遇到了动态 Ovi / Nokia 地图的问题,我想每 30 秒重新加载一次标记 - 标记是从 XML 中读取并具有动态内容。一切正常,除了泡沫。它仅在加载时显示,然后在第一次刷新标记时不再可单击(单击时更改为缩放)。我希望更新的标记也能在气泡中显示最新的 html 内容:

<script> 
var markerCoords;
var mapContainer;
var container;
var myMap;
var bubbles=new Array();

// When the HTML page body section is loaded this function will be called.
// This function gets passed the marker XML data file name
var updateTime=30;   
var updateTime=1000*updateTime;
var markerUpdate=self.setInterval("placeMarkersOnMaps('geomarkers.xml')",updateTime);
function placeMarkersOnMaps(filename) 
{
var counter = 0;
$.ajax({
    type: "GET",
    url: filename ,
    dataType: "xml",
    success: parseXml,
              error : err
  });

}
function err (){
        alert("An Error has occurred.");
}

// Here we create an Nokia Maps within a Container.

mapContainer = document.getElementById("mapContainer");


myMap = nokia.maps.map,     
                map = new myMap.Display(mapContainer, {
                    center: [52.59, 13.3], zoomLevel: 2,
                    components: [ new myMap.component.Behavior(),
                                  new nokia.maps.map.component.ZoomBar(),
                                  new nokia.maps.map.component.Overview(),                             
                                  new nokia.maps.map.component.TypeSelector(),     
                                  new nokia.maps.map.component.ScaleBar()
                   ]
                });



  placeMarkersOnMaps('geomarkers.xml');






        function deleteMarker(coords) {
            var marker;
            for (i=0; i< map.objects.getLength(); i++) {
                if ( map.objects.get(i) instanceof nokia.maps.map.StandardMarker ) {
                    if ( coords.latitude ==  map.objects.get(i)..coords.latitude
                    && coords.longitude ==  map.objects.get(i)..coords.longitude ){
                        marker = map.objects.get(i);
                        marker.removeListener("click", function(evt) { infoBubbles.addBubble(evt.target.$html, evt.target.coordinate);}, false);;
                        map.objects.remove (marker);
                        break;
                    }
                }
            }
            return marker;
        }
function parseXml(xml)
{
    var infoBubbles = new nokia.maps.map.component.InfoBubbles();   
    map.addComponent( infoBubbles); 
    var container = new nokia.maps.map.Container();
    $(xml).find("marker").each(function(){

            //Read the name, address, latitude and longitude for each Marker
            var nme = $(this).find('name').text();
            var address = $(this).find('address').text();
            var lat = $(this).find('lat').text();
            var lng = $(this).find('lng').text();
            var zhtml = $(this).find('zhtml').text();
            var zcolor = $(this).find('zcolor').text();

            //Put each marker on the map as the data has been read.

            var markerCoords = new nokia.maps.geo.Coordinate(parseFloat(lat), parseFloat(lng));    

            var marker = new nokia.maps.map.StandardMarker(markerCoords, {text:nme, brush:{color:zcolor}, $html:zhtml});
            marker.addListener('click' ,  function(evt) { infoBubbles.addBubble(evt.target.$html, evt.target.coordinate);}, false); 
            container.objects.add(marker);      

        });
        // Add the marker container .
        map.objects.add(container);
        // Zoom into the markers.



}


</script>
4

1 回答 1

2

看起来初始化信息气泡的行在错误的位置:

var infoBubbles = new nokia.maps.map.component.InfoBubbles();   
    map.addComponent( infoBubbles); 

应该放在行前

  placeMarkersOnMaps('geomarkers.xml');

否则,每次运行 placeMarkersOnMaps() 时,您都会尝试添加信息气泡组件。通常只有一个。

您的 deleteMarkers 函数也可以替换为

 myMap.objects.clear();
于 2012-02-09T22:24:23.087 回答