Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ruby-on-rails-3/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mapbox 听录音,点击;X";地图盒地理编码器的按钮_Mapbox_Mapbox Gl Js_Geocoder - Fatal编程技术网

Mapbox 听录音,点击;X";地图盒地理编码器的按钮

Mapbox 听录音,点击;X";地图盒地理编码器的按钮,mapbox,mapbox-gl-js,geocoder,Mapbox,Mapbox Gl Js,Geocoder,我想使用MapBox地理编码器(在地图外)可视化和隐藏/清除地图上的点 每当用户搜索地址时, 我用 geocoder.on('result',函数(e){…} 要创建点,请填充图层并在地图上可视化 每当用户单击“x”按钮时,我想清除/清洁该层 关于如何收听MapBox地理编码器“X”按钮的点击,有什么想法吗 我看了一眼,但到现在为止运气不太好 我的代码如下所示: function point (){ geocoder.on('result', function (e) { consol

我想使用MapBox地理编码器(在地图外)可视化和隐藏/清除地图上的点

每当用户搜索地址时, 我用

geocoder.on('result',函数(e){…}

要创建点,请填充图层并在地图上可视化

每当用户单击“x”按钮时,我想清除/清洁该层

关于如何收听MapBox地理编码器“X”按钮的点击,有什么想法吗

我看了一眼,但到现在为止运气不太好

我的代码如下所示:

function point (){
geocoder.on('result', function (e) {
    console.log(e)
    if (e.result.place_name && e.result.center) {
        var point = create_feature(e.result.place_name, e.result.center[0], e.result.center[1])

        //Add points on the map
        map.getSource('blablabla').setData({
            type: 'FeatureCollection',
            features: [point]
        });
    }

})
};

function create_feature(userId, x, y) {
    var user_feature = {
        'type': 'Feature',
        'properties': {
            'description': userId
        },
        'geometry': {
            'type': 'Point',
            'coordinates': [x, y]
        }
    };
    return user_feature;
};

可用事件和传递到各自事件中的数据 对象包括:

  • 清除输入时发出的清除
因此,这应该是可行的:

geocoder.on('clear', function () {
})

非常感谢阿纳托利!!