删除属性不是函数

remove attribution is not a function

大家好,我正在尝试删除传单地图上的传单徽标,但每当我尝试使用 removeattribution 删除徽标时,它都说这不是一个功能。我是这样做的 L.removeattribution().addTo(map)。请告诉我我做的是否正确或有什么问题。

使用L.MapattributionControl选项:

Whether the attribution control is added to the map by default.

http://leafletjs.com/reference.html#map-attributioncontrol

new L.Map('container', {
    'attributionControl': false
});

如果您想在初始化地图后删除它,您可以使用 L.MapremoveControl 方法:

Removes the given control from the map.

http://leafletjs.com/reference.html#map-removecontrol

属性控制实例存储为您的L.Map实例的属性attributionControl

var map = new L.Map('container');

map.removeControl(map.attributionControl);

可以在初始化的时候做。尝试这样做。

L.Map('container', {
    'attributionControl': false
});

removeAttribution(注意大写'A')不是L的静态函数,而是L.Control.Attribution的实例方法。所以使用该方法的正确方法是首先获取地图的默认属性控件:

var map = L.map('map');
var control = map.attributionControl;

然后用您要删除的字符串调用 removeAttribution,例如:

control.removeAttribution('© OpenStreetMap');

如果使用 react-leaflet,您可以通过将 attributionControl={false} 附加到 Map 组件来删除属性:

<Map attributionControl={false} center={this.props.mapCenter} zoom={this.props.zoom}>

您可以在 MapContainer 标签中添加 attributionControl 属性来移除属性。

<MapContainer attributionControl={false}>...</MapContainer>