获取图层圈的坐标

问题描述

我正在使用 MapBox 地理编码,我想在控制台中打印创建的圆的坐标,但我不知道如何访问它。有人能帮我吗?不知何故,我必须访问我认为的结果,但我不知道我必须使用哪个命令。

var geocoder = new MapBoxGeocoder({
    accesstoken: mapBoxgl.accesstoken,mapBoxgl: mapBoxgl,marker: false,zoom: 13
});

// After the map style has loaded on the page,// add a source layer and default styling for a single point
mymap.on('load',function() {
    mymap.addSource('single-point',{
        type: 'geojson',data: {
            type: 'FeatureCollection',features: []
        }
    });
});

// Listen for the `result` event from the Geocoder
// `result` event is triggered when a user makes a selection
//  Add a marker at the result's coordinates
geocoder.on('result',function(e) {

    mymap.addLayer({
        id: 'point',source: 'single-point',type: 'circle',paint: {
            'circle-radius': 10,'circle-color': '#448ee4'
        }
    })
    
    mymap.getSource('single-point').setData(e.result.geometry);
    
    console.log(e.result.lngLat); /*this line*/
    currentMarkers[0].remove();
});


document.getElementById('geocode').appendChild(geocoder.onAdd(mymap));

解决方法

您可以访问几何结果: e.result.geometry.coordinates

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...