locked
Add click event for bing map javascript RRS feed

  • Question

  • I am using bing map in javascript.
    I am plotting regions , pushpin on map.
    What I have done is added click event for map.

    var _MapClickHandler=null;
    _MapClickHandler = MM.Events.addHandler(map, 'click', _MapMouseDownHandler);
    What I want is I want to pass additional paramertes to _MapMouseDownHandler this event handler as I want to do something extra in it with the additional parameters. Currently, its taking 'e' as single parameter.
    Please tell me how to do this.

    Thanks

    Thursday, January 24, 2013 10:56 AM

Answers

  • What you can do is add the parameter as a property to your pushpin and then in the event handler access the pushpin using e.target.

    var pin = new Microsoft.Maps.Pushpin(new Microsoft.Maps.Location(0,0));
    pin.MyProperty = "value";
    Microsoft.Maps.Events.addHandler(pin, 'click', pinClicked);
    map.entities.push(pin);
    function pinClicked(e){
       if(e.target){
           alert(e.target.MyProperty);
       }
    }


    http://rbrundritt.wordpress.com

    Thursday, January 24, 2013 12:23 PM

All replies

  • What you can do is add the parameter as a property to your pushpin and then in the event handler access the pushpin using e.target.

    var pin = new Microsoft.Maps.Pushpin(new Microsoft.Maps.Location(0,0));
    pin.MyProperty = "value";
    Microsoft.Maps.Events.addHandler(pin, 'click', pinClicked);
    map.entities.push(pin);
    function pinClicked(e){
       if(e.target){
           alert(e.target.MyProperty);
       }
    }


    http://rbrundritt.wordpress.com

    Thursday, January 24, 2013 12:23 PM
  • Thanks for the reply.
    I am creating the map dynamcially in javascript. The divs that are displaying the map are created in c# dynamically and I am acessing that. I have multiple map control on page so i think can I do the way you suggested. But will try for that solution.
    Thanks
    Thursday, January 24, 2013 1:07 PM
  • I want to have map click event as well as pushpin, polyline, polygon even. means I want event for all the things that are drawn on map.

    Also , event though I set the disablePanning:false I am not able to drag the map with mouse.

    How can I get that.

    Thanks

    Friday, January 25, 2013 4:15 AM