admin管理员组文章数量:1356595
I am currently learning about these maps. Now I would like to create a method which updates my push pin if I already have one.
a. I tried to use setLocation(newLocation) but unfortunately, when I did this, my client side code wasn't even reached (I'm thinking that the code syntax is incorrect, yet no error was given on chrome)
b. I then tried to learn how to delete it and create another one, yet I cannot find any resources from .aspx - maybe I am not searching well enough.
Can anyone provide me with some guide on how to move a push pin and how to delete one? Thank you all very very much
var loc = new Microsoft.Maps.Location(lat, lon);
var pin = new Microsoft.Maps.Pushpin(loc);
Edit: partial answer
Removing a push pin:
if (pin != null)
{
map.entities.remove(pin)
}
I am currently learning about these maps. Now I would like to create a method which updates my push pin if I already have one.
a. I tried to use setLocation(newLocation) but unfortunately, when I did this, my client side code wasn't even reached (I'm thinking that the code syntax is incorrect, yet no error was given on chrome)
b. I then tried to learn how to delete it and create another one, yet I cannot find any resources from http://msdn.microsoft./en-us/library/gg427610.aspx - maybe I am not searching well enough.
Can anyone provide me with some guide on how to move a push pin and how to delete one? Thank you all very very much
var loc = new Microsoft.Maps.Location(lat, lon);
var pin = new Microsoft.Maps.Pushpin(loc);
Edit: partial answer
Removing a push pin:
if (pin != null)
{
map.entities.remove(pin)
}
Share
Improve this question
edited Apr 11, 2012 at 20:47
test
asked Apr 11, 2012 at 20:12
testtest
2,6185 gold badges38 silver badges53 bronze badges
2 Answers
Reset to default 4To move a pushpin, setLocation()
is indeed the function you need to use. Are you trying to call setLocation from an event handler on the map? If that's the case, it's possible that the event handler wasn't set up properly so it is never called. However, if you already have defined a pushpin(with a variable name myPushpin) and inserted it into the map, then executing the follow code will move it:
// Move pushpin to "38.0", "-97.0"
var loc = new Microsoft.Maps.Location(38.0, -97.0);
myPushpin.setLocation(loc);
To see this in action, head over to the Ajax Bing Maps v7 interactive SDK, modify the code in blue on the lower center of the screen by putting in different coordinates, hit the Run button and see the pushpin move.
To delete a pushpin that has been added to the map, you need to remove it from the EntityCollection from which it was added to. For example, if you simply inserted the Pushpin into yourmap.entities, this is how you remove it:
var index = yourmap.entities.indexOf(myPushpin);
if (index != -1) {
yourmap.entities.removeAt(index);
}
Or you can just remove it directly without using an index:
yourmap.entities.remove(myPushpin);
UPDATE: To delete a pushpin when the user clicks on it, you essentially have to first identify the pushpin that was clicked in the click event handler. The pushpin can be obtained from the target Property of the MouseEventArgs Object that is passed into your click handler:
Microsoft.Maps.Events.addHandler(pushpin, 'click', function (mouseEvent) {
var pushPinThatWasClicked = mouseEvent.target;
// Do whatever you want with pushPinThatWasClicked
});
The following function can remove all the pushpins from the map:
//remove all the pushpins
function deletePushpin()
{
for(var i=map.entities.getLength()-1;i>=0;i--)
{
var pushpin= map.entities.get(i);
if (pushpin instanceof Microsoft.Maps.Pushpin) {
map.entities.remove(pushpin);
}
}
}
本文标签: javascriptAjax Bing Maps version 7move and delete push pinbeginner39s tutorialStack Overflow
版权声明:本文标题:javascript - Ajax Bing Maps version 7 - move and delete push pin - beginner's tutorial - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1743976965a2570917.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论