geometry - 获取图层圆的坐标
问题描述
我正在使用 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
推荐阅读
- azure-data-explorer - KQL 加入最大值
- reactjs - 在功能组件中更新状态时进行浅拷贝有什么风险或副作用?
- python - 编辑多个 json 文件中的值
- macos - Mac-launchctl load 后服务未在启动时启动
- laravel - 从 git 克隆后 Laravel 数据库名称不正确
- javascript - CSS Flex - 单击时元素底部的随机空白
- swift - 推送通知中未显示类别
- java - Google admob 和 Facebook 受众网络可以在不使用中介的情况下在同一个应用上投放广告吗?
- python - 如何将三层嵌套的dict转换为三层嵌套的defaultdict?
- java - 崩溃主细节流(Android Studio)应用程序〜在Mac上