Inheritance 我***是否需要***扩展传单';要添加属性的标记类?
这是我很少做的事情——给传单标记添加属性 我在读一本书,上面说我们应该Inheritance 我***是否需要***扩展传单';要添加属性的标记类?,inheritance,leaflet,Inheritance,Leaflet,这是我很少做的事情——给传单标记添加属性 我在读一本书,上面说我们应该 customMarker = L.Marker.extend({ options: { name: '', type: '' } }); var marker = new customMarker([28.63278, 77.21972],{ clickable: true, name: 'Connaught Place', type: 'Neighbourhood'
customMarker = L.Marker.extend({
options: {
name: '',
type: ''
}
});
var marker = new customMarker([28.63278, 77.21972],{
clickable: true,
name: 'Connaught Place',
type: 'Neighbourhood'
}).addTo(map);
我从一些旧的代码中看到
let marker = L.marker(markerLatLng, {
name: 'Connaught Place',
type: 'Neighbourhood'
因为这是可行的,所以传单似乎足够智能,可以将任何非传单属性视为L.Marker类的扩展
是否有“正确”的方法(有正确的技术原因)?不,您确实不需要为了添加自己的数据而扩展传单层 你链接到的博客文章始于2013年,因此当时的情况可能有所不同 使用今天的传单版本(撰写本文时为1.7.1),如果您:
const myMarker=L.marker(latLng{
myData:someData
});
…然后您可以使用以下工具检索某些数据:
myMarker.options.myData;//一些数据
也就是说,当您想要扩展博客文章中显示的这些选项时,可能会有一些用例:如果您想要一些默认值,如中所述
[…]便于管理对象和默认值的配置
否则,您还可以使用其他方法将数据附加到传单层,请参见“
”您链接到的博客文章日期为2013年,因此当时可能是另一个故事
”-这是我所怀疑的,但感谢您的澄清。