如何格式化谷歌地图标记的标签
How can I format the label of a google maps marker
我一直在寻找如何在谷歌地图中设置自定义标记上的文本格式。我发现了一些东西,但它们都使用了至少一个我想避免的外部js文件。我在谷歌网站上阅读了API文档(见链接和Marker Labels下的链接),它说标签可以格式化,但没有例子。我希望能够增加文本的大小并更改颜色。有人能帮我吗?
这里的链接显示了可以设置的属性。https://developers.google.com/maps/documentation/javascript/reference#MarkerLabel
var icon_img = {
url: "../img/custom_marker.png",
scaledSize: new google.maps.Size(40, 50),
origin: new google.maps.Point(0, 0),
anchor: new google.maps.Point(20, 50),
};
var sample_marker = new google.maps.Marker({
position: {lat: my_lat, lng: my_lng},
map: my_map,
label: "1",
icon: icon_img
});
来自谷歌地图开发者文档标记
标记标签是单个文本字符,将出现在标记。如果您将其与自定义标记一起使用,则可以使用Icon类中的labelOrigin属性重新定位它。
对于这个单一字符,您可以配置的唯一属性是
color string The color of the label text.
Default color is black.
fontFamily string The font family of the label text
(equivalent to the CSS font-family property).
fontSize string The font size of the label text
(equivalent to the CSS font-size property).
Default size is 14px.
fontWeight string The font weight of the label text
(equivalent to the CSS font-weight property).
text string The text to be displayed in the label.
Only the first character of this string will be shown.
然后你可以用这种方式格式化例如:
var sample_marker = new google.maps.Marker({
position: {lat: my_lat, lng: my_lng},
map: my_map,
label: {
text: "1",
color: "#F00"
},
icon: {
url: "image_url.png",
origin: {x: 0, y: 0}
}
});
我正在使用label.js 标记
通过为标签DIV 定义一个具有所需属性的CSS类,可以最容易地为标签设置样式
http://google-maps-utility-library-v3.googlecode.com/svn/trunk/markerwithlabel/docs/examples.html
相关文章:
- Javascript更改图标
- 在<页眉>标签
- Ckeditor-plugin:插入虚假元素add不情愿<p>标签前后
- 单击更改图标并通过javascript添加一个css类
- iframe正在添加标签,需要删除它们
- Dijit 按钮显示图标,但不以编程方式显示标签
- javaScript-如何将png图标插入标签
- D3 强制布局与文本标签和图标
- 如何在我的高图表饼图中获取一个数据标签,这是一个字体很棒的图标
- 在 dijit PopupMenuBarItem 中显示图标和标签
- openlayers 3中带有标签或文本的图标,偏移
- 棱角分明的谷歌地图标签覆盖了图标
- 为什么在页面运行时更改dojo IconMenuItem上的标签或图标不会更改页面
- 谷歌地图标记-为每个标记添加一个具有唯一标签的自定义图标
- Sencha触摸顶部标签图标
- 悬停在href标签和jquery图标上
- 如何更改输入标签之间的文本,并将标签复选框和图标对齐在一行上
- 我正在锚标签的前面添加一个图标,但是,我想阻止它添加图标多次
- 谷歌地图标记与标签和自定义图标无法正常工作
- 如何在编辑标签时选择(-)图标,在Iphone ui自动化