简体   繁体   English

Google Maps Markers的动态图像

[英]Dynamic image for Google Maps Markers

I have a map on which I display public transit stops. 我有一张显示公共交通站点的地图。 I would like to color code those stops according to various parameters. 我想根据各种参数对这些停止点进行颜色编码。 I would also like to use my own icon. 我也想使用自己的图标。 I have figured out how to take a png image and change its color in javascript, but I'm not sure how to get the Google Map to use it as the Marker image. 我已经弄清楚了如何拍摄png图像并在javascript中更改其颜色,但是我不确定如何获取Google Map来将其用作标记图像。

I've seen the Styled Marker library but as far as I can tell, you can't use your own image with it--and from an (admittedly cursory) look at its source, I don't think I can change it to use my image as it seems to use URL parameters with a set of default markers to achieve the color change. 我已经看过Styled Marker库,但是据我所知,您不能将其与自己的图像一起使用-并且(从粗略的角度来看)它的来源,我认为我无法将其更改为使用我的图片,因为它似乎使用带有一组默认标记的URL参数来实现颜色更改。

Any suggestions? 有什么建议么?

You want something like this: 您想要这样的东西:

  marker = new google.maps.Marker({
    draggable: false,
    raiseOnDrag: false,
    icon: {
      size: new google.maps.Size(32, 42),
      origin: new google.maps.Point(0, 0),
      anchor: new google.maps.Point(15, 42),
      url: // path to png
    },
    animation: google.maps.Animation.DROP,
    position: new google.maps.LatLng(lat, lng),
    map: map
  });

Here's the full documentation . 这是完整的文档

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM