views:

1768

answers:

3

How will I be able to put a pin using a click of my mouse? given this is the code:

function AddPushpin()
  {
      var shape = new VEShape(VEShapeType.Pushpin, **map.GetCenter()**);
      shape.SetTitle('sample');
      shape.SetDescription('This is shape number '+pinid);
      pinid++;
      map.AddShape(shape);
  }

it's pointing to the center..

do you have any idea on how to add an image to the pushpin hover?

A: 

check out this article...

function InitMap ()
{
// add code to init your map....

// attach the onclick event...
map.AttachEvent("onclick", MouseClick);

}

function MouseClick(e)
    {
     map.AddPushpin('pin', 
     e.view.latlong.latitude, 
     e.view.latlong.longitude,
     88,
     34,
     'pin',
     'MyPin',
     1);  
    }
Muad'Dib
I tried this but I cannot do it. :(
bluestella
+1  A: 

Here's an example that adds a pushpin during the OnClick event of the Map, and sets the Shape's Photo URL to display an image within the InfoxBox.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
<html>
<head>
    <title></title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <script type="text/javascript" src="http://dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=6.2&amp;mkt=en-US"&gt;&lt;/script&gt;
    <script type="text/javascript">
    var map = null;

    function GetMap()
    {
        map = new VEMap("myMap");
        map.LoadMap();

        // Attach the OnClick event
        map.AttachEvent("onclick", OnClick_Handler);

        // You could Dettach the OnClick event like this
        //map.DetachEvent("onclick", OnClick_Handler);
    }

    function OnClick_Handler(e){
        // "sender" is the VEMap that raised the event
        // "e" is the VE Map Event Object

        // Get the Lat/Long where the Mouse was clicked
        var pushpinLocation = map.PixelToLatLong(new VEPixel(e.mapX, e.mapY));

        // Create the Pushpin Shape
        var s = new VEShape(VEShapeType.Pushpin, pushpinLocation);
        s.SetTitle("test pushpin");
        s.SetDescription("test description");

        s.SetPhotoURL("http://i.stackoverflow.com/Content/Img/stackoverflow-logo-250.png");

        // Plot a Shape at the Clicked location
        map.AddShape(s);
    }
    </script>
</head>
    <body onload="GetMap();">
        <div id='myMap' style="position:relative; width:400px; height:400px;"></div>
    </body>
</html>
Chris Pietschmann
it has a vertical scrollbar, thanks Chris :)
bluestella
Oh, now it does. It didn't when I first posted it. Hmm... I'll delete my note about it.
Chris Pietschmann
ehhehe.. its okay.. :) thanks alot.. i'll try this in a while :)
bluestella
A: 

Hi, How to add PushPins for Bing maps through c# programming without Using JavaScript.

-------------Prasanna Yelsangikar

prasanna.yelsangikar