我使用 Mapbox Geocoder 和另外几个选择菜单来自定义地图。现在我想在用户从选择菜单中选择一个值后立即重置地理编码器 - 因此应该清除输入字段并删除标记。
在文档中描述了清除功能,并且默认输入字段中还有一个清除按钮,但是如果我从更改事件中调用它,则此功能不起作用。
这是我的尝试到目前为止的样子:
const select = $('#select');
const control = $('#geocoder');
const geocoder = new MapboxGeocoder({
accessToken: accessToken,
mapboxgl: mapboxgl
});
//Add the geocoder
document.getElementById(control).appendChild(geocoder.onAdd(map));
//Now reset the geocoder if the user selects something
select.change(function() {
geocoder.clear();
});
Run Code Online (Sandbox Code Playgroud)
我希望重置输入字段并删除标记,但实际输出是“geocoder.clear is not a function”