gpt4 book ai didi

javascript - 如何在 Google map API 中设置数据层特征标签的样式?

转载 作者:行者123 更新时间:2023-11-29 17:54:10 24 4
gpt4 key购买 nike

我有这个有效的 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);

代码生成此输出:

image :

如何设置标签“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
}
}
});

proof of concept fiddle

screenshot of resulting labelled marker on map

代码片段:

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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com