使用svg元素作为bingmap图钉图标

时间:2014-09-26 08:01:11

标签: bing-maps

有没有办法将svg元素用作Microsoft.Maps.Pushpin的图标?

我创建了一个svg

像这样的

元素:

var fillcolor = "#ff0222";
var svg1 = document.createElementNS("http://www.w3.org/2000/svg", "svg");
svg1.setAttribute("height",50);
svg1.setAttribute("width",50);

var circles = document.createElementNS("http://www.w3.org/2000/svg", "circle");
circles.setAttribute("cx",25);
circles.setAttribute("cy",25);
circles.setAttribute("r",25);
circles.setAttribute("fill",fillcolor);
svg1.appendChild(circles);

1 个答案:

答案 0 :(得分:0)

在Microsoft.Maps.Pushpin上,可以设置选项(PushpinOptions),您可以在其中将htmlContent属性指定为您选择的值。

请参阅:http://msdn.microsoft.com/en-us/library/gg427629.aspx

iSDK样本:http://www.bingmapsportal.com/isdk/ajaxv7#Pushpins15

代码应该受到以下内容的启发:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
   <head>
      <title>Add pushpin with options</title>
      <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
      <script type="text/javascript" src="http://ecn.dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=7.0"></script>
      <script type="text/javascript">
      var map = null;

      function getMap()
      {
        map = new Microsoft.Maps.Map(document.getElementById('myMap'), {credentials: 'Your Bing Maps Key'});
      }

      function addCustomPushpin()
      {
        var pushpinOptions = {width: null, height: null, htmlContent: "<div style='font-size:12px;font-weight:bold;border:solid 2px;background-color:LightBlue;width:100px;'>Custom Pushpin</div>"}; 
        var pushpin= new Microsoft.Maps.Pushpin(map.getCenter(), pushpinOptions);
        map.entities.push(pushpin);
      }
      </script>
   </head>
   <body onload="getMap();">
      <div id='myMap' style="position:relative; width:400px; height:400px;"></div>
      <div>
         <input type="button" value="AddCustomPushpin" onclick="addCustomPushpin();" />
      </div>
   </body>
</html>