我们如何在 google map api 中通过 javascript 设置标记标签内容?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/25165511/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
how we set marker label content by javascript in google map api?
提问by user3907798
I am using this code this code to change label text of marker label in google map api. But this code not working.
我正在使用此代码此代码来更改 google map api 中标记标签的标签文本。但是这段代码不起作用。
var marker = new MarkerWithLabel({
position : latlng,
draggable : true,
raiseOnDrag : true,
map : map,
labelContent : textVal,
labelAnchor : new google.maps.Point(22, 0),
title : "" + textCount,
labelClass : "someClass" + textCount,
icon:{}
});
marker.setLabelContent("sdda");
please can anybody let me know what's wrong in my code?
请有人让我知道我的代码有什么问题吗?
回答by alettieri
Try:
尝试:
marker.set('labelContent', 'sdda');
Reading through the marker label source code, the MarkerLabel object extends from google.maps.Marker.
通过读取标记标签的源代码,所述物体MarkerLabel从google.maps.Marker延伸。
Whenever you call the .set()
method on the MarkerLabel object, an event is raised which refreshes the marker.
每当您.set()
在 MarkerLabel 对象上调用该方法时,都会引发一个刷新标记的事件。
So calling marker.set('labelContent', 'sdda');
will raise a 'labelcontent_changed'
event, which in turn makes the marker set it's inner content this.setContent()
所以调用marker.set('labelContent', 'sdda');
将引发一个'labelcontent_changed'
事件,这反过来又使标记设置它的内部内容this.setContent()
Here is an excerpt from the source code:
以下是源代码的摘录:
@class This class represents the optional parameter passed to the {@link MarkerWithLabel} constructor.
The properties available are the same as for google.maps.Marker
with the addition of the properties listed below. To change any of these additional properties after the labeled
marker has been created, call google.maps.Marker.set(propertyName, propertyValue)
.
@class 此类表示传递给 {@link MarkerWithLabel} 构造函数的可选参数。google.maps.Marker
除了下面列出的属性外,可用的属性与 for 相同。要在创建标记标记后更改任何这些附加属性,请调用google.maps.Marker.set(propertyName, propertyValue)
。
回答by NELSON RODRIGUEZ
Try: var label= { color: '#333', fontWeight: 'bold', fontSize: '16px', text: data[i].deviceID.toUpperCase() }; marker.setLabel(label);
试试: var label= { color: '#333', fontWeight: 'bold', fontSize: '16px', text: data[i].deviceID.toUpperCase() }; 标记.setLabel(标签);