我创建了一个自定义控件,并将其添加到我的Leaflet地图中。即使我指定了“ topleft”的位置,为什么它也会出现在左下角?
L.Control.Custom = L.Control.extend({
options: {
position: "topleft"
},
onAdd: function(myMap) {
// Add reference to map
var div = L.DomUtil.create(
"div",
"leaflet-bar info hit-count-control"
);
return div;
},
onRemove: function(myMap) {
// Remove reference from map
delete myMap.hitCountControl;
},
});
您必须使用L.setOptions(this, options);
更新控制选项:
L.Control.Custom = L.Control.extend({
options: {
position: "bottomleft"
},
initialize(options) {
L.setOptions(this, options);
},
onAdd: function(myMap) {
// Add reference to map
var div = L.DomUtil.create(
"div",
"leaflet-bar info hit-count-control"
);
return div;
},
onRemove: function(myMap) {
// Remove reference from map
delete myMap.hitCountControl;
},
});
new L.Control.Custom({position: 'topleft'});