作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有这个有效的 js 代码:
var p;
p = new google.maps.Data();
p.loadGeoJson('http://mysource.example.com');
p.setStyle( function(feature){
var icon = feature.getProperty('icon');
var title = feature.getProperty('title');
return {
icon: icon,
label: title
}
});
p.setMap(map);
代码生成此输出:
如何设置标签“L1PIAZZA”的样式?
最佳答案
使用记录的属性来设置 MarkerLabel 的样式:
Properties
color Type: string
The color of the label text. Default color is black.
fontFamily Type: string
The font family of the label text (equivalent to the CSS font-family property).
fontSize Type: string
The font size of the label text (equivalent to the CSS font-size property). Default size is 14px.
fontWeight Type: string
The font weight of the label text (equivalent to the CSS font-weight property).
text Type: string
The text to be displayed in the label.
p.setStyle(function(feature) {
var icon = feature.getProperty('icon');
var title = feature.getProperty('title');
return {
icon: {
url: icon,
labelOrigin: new google.maps.Point(15, -10)
},
label: {
color: "blue",
fontFamily: "Courier",
fontSize: "24px",
fontWeight: "bold",
text: title
}
}
});
代码片段:
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 p;
p = new google.maps.Data();
p.addGeoJson({
"type": "FeatureCollection",
"features": [{
"type": "Feature",
"properties": {
"icon": "http://maps.google.com/mapfiles/ms/micons/blue.png",
"title": "blue",
},
"geometry": {
"type": "Point",
"coordinates": [-122.1419, 37.4419]
}
}]
});
p.setStyle(function(feature) {
var icon = feature.getProperty('icon');
var title = feature.getProperty('title');
return {
icon: {
url: icon,
labelOrigin: new google.maps.Point(15, -10)
},
label: {
color: "blue",
fontFamily: "Courier",
fontSize: "24px",
fontWeight: "bold",
text: title
}
}
});
p.setMap(map);
}
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"></script>
<div id="map_canvas"></div>
关于javascript - 如何在 Google map API 中设置数据层特征标签的样式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40785053/
我是一名优秀的程序员,十分优秀!