活动结束后我将在地图上添加标记
viewchangeend
。有时我可以看到我的标记,有时我看不到...我认为这可能与地图未完全渲染有关,但当我向标记添加标题时,我能够看到标题!我看不到红色圆圈,也看不到标记的文本。
我还尝试在标记层中添加一条折线,以确保它可见,是的,我也可以看到折线。
addMapMarker(latitude: number, longitude: number, index: number):
Microsoft.Maps.Pushpin
{
// Check if it is safe to add markers to the map (i.e if both map's height and width
are > 0)
// Otherwise start a timer to check when it is safe to add markers.
if (this.isMapSafe())
{
const location = new Microsoft.Maps.Location(latitude, longitude);
const pushPin = new Microsoft.Maps.Pushpin(location, {
title: 'My Pin',
text: 'lalala' + location.latitude + ' ' + location.longitude,
color:'red'
});
var center = this.map.getCenter();
//Create array of locations
var coords = [center, new Microsoft.Maps.Location(center.latitude + 1, center.longitude + 1)];
//Create a polyline
var line = new Microsoft.Maps.Polyline(coords, {
strokeColor: 'red',
strokeThickness: 3,
strokeDashArray: [4, 4]
});
if ((pushPin) &&
(this.mapMarkerLayer))
{
this.mapMarkerLayer.add(line);
this.mapMarkerLayer.add(pushPin);
}
return pushPin;
}
else
{
this.restartTimerToAddMarkers();
return null;
}
}
我做错了什么吗?发生这种情况有原因吗?我该如何解决?预先感谢您!
我无法重现这个。这是我用来测试的代码块:
var map = new Microsoft.Maps.Map(document.getElementById('myMap'), {});
var layer = new Microsoft.Maps.Layer();
map.layers.insert(layer);
Microsoft.Maps.Events.addHandler(map, 'viewchangeend', function () {
const pushpin = new Microsoft.Maps.Pushpin(map.getCenter(), {
title: 'My Pin',
text: 'lalala' + location.latitude + ' ' + location.longitude,
color:'red'
});
layer.add(pushpin);
});
虽然我很惊讶它的效果,因为标题很长。这是截图。