繁体   English   中英

如何更改标记标签文本颜色?

[英]How to change the Markers label text color?

我有一个问题,即使在 JavaScript 中使用 labelColor 属性,标签也会保持黑色,但我想让它变成白色,有什么办法吗? 也许是一种解决方法?

for (i = 0; i < locations.length; i++) {var myLatLng = new google.maps.LatLng(locations[i][1], locations[i][2]);
marker = new google.maps.Marker({
    position: myLatLng,
    map: map,
    label: labels[i],
    labelClass: "labels", // the CSS class for the label
    labelColor: '#fff',
    labelInBackground: false,
    icon: locations[i][4]
});

问题是我有想要使用的自定义图标,我不想先创建一些 SVG。 感谢任何可以在这里帮助我的人。

要为google.maps.Marker设置标签属性,您需要使用MarkerLabel对象:

var marker = new google.maps.Marker({
  position: new google.maps.LatLng(37.4419, -122.1419),
  map: map,
  label: {
    text: 'A',
    color: 'white',
  }
});

代码片段:

 var geocoder; var map; function initialize() { var map = new google.maps.Map( document.getElementById("map_canvas"), { center: new google.maps.LatLng(37.4419, -122.1419), zoom: 13, mapTypeId: google.maps.MapTypeId.ROADMAP }); var marker = new google.maps.Marker({ position: new google.maps.LatLng(37.4419, -122.1419), map: map, label: { text: 'A', color: 'white', } }); } google.maps.event.addDomListener(window, "load", initialize);
 html, body, #map_canvas { height: 100%; width: 100%; margin: 0px; padding: 0px }
 <script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyCkUOdZ5y7hMm0yrcCQoCvLwzdM6M8s5qk"></script> <div id="map_canvas"></div>

尝试检查 CSS 中的“.labels”类,也许您应该更改 css 文件中的颜色。

暂无
暂无

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

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