诺基亚/Ovi 地图问题 - 标记动态刷新
我在使用动态 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>
I am having an issue with a dynamic Ovi / Nokia map whereby I want to reload the markers every 30 seconds - markers are read from XML and have dynamic content. Everything works fine except for the bubble. It shows on load only and then on first refresh marker is no longer clickable (changes to zoom when clicked on it). I want the updated marker to show the latest html content in the bubble too:
<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>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看起来初始化信息气泡的行位于错误的位置:
应该放置在该行之前,
否则您将在每次运行 placeMarkersOnMaps() 时尝试添加信息气泡组件。通常只有一个。
您的deleteMarkers函数也可以替换为
It looks like the lines intialising the infobubble are in the wrong place:
Should be placed before the line
Otherwise you are attempting to add an info bubble component every time placeMarkersOnMaps() is run. There is usually only one.
Also your deleteMarkers function could be replaced by