如何更改Google Maps API V3中的图标颜色? [英] How do I change icon colour in Google Maps API V3?

查看:91
本文介绍了如何更改Google Maps API V3中的图标颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将COUNTY图标更改为蓝色(除红色外)。

I want to change the COUNTY icon to blue (anything but red).

有没有方法可以为特定点定义不同的图标颜色?

Is there a way to define different icon colour for a specific point ?

    <script type="text/javascript"> 
    //<![CDATA[
    var map = null;
function initialize() {
 var myOptions = {
  zoom: 8,
  center: new google.maps.LatLng(39.831125875,-112.15968925),
  mapTypeControl: true,
  mapTypeControlOptions: {style: google.maps.MapTypeControlStyle.DROPDOWN_MENU},
  navigationControl: true,
  mapTypeId: google.maps.MapTypeId.ROADMAP
 }
    map = new google.maps.Map(document.getElementById("map_canvas"),
                            myOptions);

   google.maps.event.addListener(map, 'click', function() {
    infowindow.close();
    });

  // Add markers to the map
  // Set up three markers with info windows 


   var point = new google.maps.LatLng(40.970826,-112.048187)
   var marker = createMarker(point,'Utah-Davis County');


   var point = new google.maps.LatLng(40.235509,-111.660576)
   var marker = createMarker(point,'Utah-Provo');

   var point = new google.maps.LatLng(40.766502,-111.897812)
   var marker = createMarker(point,'Utah-Salt Lake City');


  }

   var infowindow = new google.maps.InfoWindow(
   { 
     size: new google.maps.Size(150,50)
    });




 function createMarker(latlng, html) {
   var contentString = html;
   var marker = new google.maps.Marker({
    position: latlng,
    map: map,
    zIndex: Math.round(latlng.lat()*-100000)<<5
    });

   google.maps.event.addListener(marker, 'click', function() {
    infowindow.setContent(contentString); 
    infowindow.open(map,marker);
    });
   }


function animate(lati,long) {
    var latLng = new google.maps.LatLng(lati, long); //Makes a latlng
    map.panTo(latLng); //Make map global
}


//]]>
</script> 

有没有一种方法可以为特定点定义不同的图标颜色?

Is there a way to define different icon colour for a specific point ?

推荐答案

我认为这会有所帮助。您必须创建自定义标记。

I think this will help. You have to create a custom marker though.

Google Maps API 3 - 默认(点)标记的自定义标记颜色

特别针对您的问题,你可以这样做:

Specifically for your question, you can do something like this:

var pinColor = "2F76EE"; // a random blue color that i picked
var pinImage = new google.maps.MarkerImage("http://chart.apis.google.com/chart?chst=d_map_pin_letter&chld=%E2%80%A2|" + pinColor,
            new google.maps.Size(21, 34),
            new google.maps.Point(0,0),
            new google.maps.Point(10, 34));
var pinShadow = new google.maps.MarkerImage("http://chart.apis.google.com/chart?chst=d_map_pin_shadow",
            new google.maps.Size(40, 37),
            new google.maps.Point(0, 0),
            new google.maps.Point(12, 35));

然后

then

var marker = new google.maps.Marker({
            position: new google.maps.LatLng(0,0), 
            map: map,
            icon: pinImage,
            shadow: pinShadow
        });

存入亚光烧伤

这篇关于如何更改Google Maps API V3中的图标颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆