javascript - 使用 Javascript 将图钉添加到 map

标签 javascript virtual-earth

如何通过单击鼠标来放置图钉?鉴于这是代码:

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

它指向中心..

您知道如何将图像添加到图钉悬停吗?

最佳答案

下面的示例在 map 的 OnClick 事件期间添加图钉,并设置形状的照片 URL 以在 InfoxBox 中显示图像。

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<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&mkt=en-US"></script>
    <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>

关于javascript - 使用 Javascript 将图钉添加到 map ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/756332/

相关文章:

javascript - LocalStorage 没有传递给独立的网络应用程序

c# - 缓冲折线以创建多边形的有效算法?

c# - 检测 Bing map 上 VE 形状内的图钉

javascript - 启动时虚拟地球 map 不显示为显示 :none

c# - 网络服务接口(interface)?

javascript - 为什么我的 page-mod contentStyle font-face 规则在 Firefox Addon 中不起作用?

javascript - 除非我按下 'back' 按钮,否则 jQuery 结果不会显示

javascript - 在一个页面中为多个实例应用 CSS 动画类

c# - 扩展一个类,编译器提示 Microsoft.MapPoint.PlugIns.PlugIn 不包含

javascript - 尝试将对象数组分组到相同的键下,从而产生新的对象数组