如何更改标记标签文本颜色?
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。
感谢任何能在这里帮助我的人。
尝试检查 CSS 中的“.labels”class,也许您应该更改 css 文件中的颜色。
要设置 google.maps.Marker you need to use a 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>
我遇到的问题是,即使在 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。 感谢任何能在这里帮助我的人。
尝试检查 CSS 中的“.labels”class,也许您应该更改 css 文件中的颜色。
要设置 google.maps.Marker you need to use a 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>