2016-09-20 103 views
0

将宽度和高度属性添加到PushpinOptions对象时,根据此处找到的文档https://msdn.microsoft.com/en-us/library/gg427629.aspx,pushin拒绝使用指定的大小。相反,它似乎将其尺寸基于用于它的图像的大小。如何更改Bing Maps图钉的尺寸?

您可以通过添加自己试试看“的高度:50,宽度:50”在这里: http://www.bing.com/api/maps/sdk/mapcontrol/isdk#setPushpinColor+JS

谁能告诉我什么,我做错了什么?

回答

0

显然我已经混淆了V7的V8文档。不支持实际调整图钉图像的大小。

如果你希望能够缩放图钉的大小,你将需要使用HTML5的画布来渲染图像的缩放版本

你可以找到在这里的代码示例: https://social.msdn.microsoft.com/Forums/en-US/909162ea-3ac5-4960-82ed-6ddf02eb6ead/alter-size-of-custom-pushpin-isnt-working?forum=bingmaps

下面是链接采取上述代码:

<!DOCTYPE html> 
<html> 
<head> 
    <title></title> 
    <meta charset="utf-8" /> 
    <script type='text/javascript' 
      src='http://www.bing.com/api/maps/mapcontrol?callback=GetMap' 
      async defer></script> 
    <script type='text/javascript'> 
    function GetMap() { 
     var map = new Microsoft.Maps.Map('#myMap', { 
      credentials: 'Your Bing Maps Key' 
     }); 

     createScaledPushpin(map.getCenter(), 'images/myPushpinIcon.png', 2, function (pin) { 
      map.entities.push(pin); 
     }); 
    } 

    function createScaledPushpin(location, imgUrl, scale, callback) { 
     var img = new Image(); 
     img.onload = function() { 
      var c = document.createElement('canvas'); 
      c.width = img.width * scale; 
      c.height = img.height * scale; 

      var context = c.getContext('2d'); 

      //Draw scaled image 
      context.drawImage(img, 0, 0, c.width, c.height); 

      var pin = new Microsoft.Maps.Pushpin(location, { 
       //Generate a base64 image URL from the canvas. 
       icon: c.toDataURL(), 

       //Anchor based on the center of the image. 
       anchor: new Microsoft.Maps.Point(c.width/2, c.height/2) 
      }); 

      if (callback) { 
       callback(pin); 
      } 
     }; 

     img.src = imgUrl; 
    } 
    </script> 
</head> 
<body> 
    <div id="myMap" style=";width:600px;height:400px;"></div> 
</body> 
</html>