获取Layer-circle的坐标
Get coordinates of Layer-circle
我正在使用 Mapbox geocode,我想在控制台中打印创建的圆的坐标,但我不知道如何访问它。有人能帮我吗?我想我必须以某种方式访问结果,但我不知道我必须使用哪个命令。
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
我正在使用 Mapbox geocode,我想在控制台中打印创建的圆的坐标,但我不知道如何访问它。有人能帮我吗?我想我必须以某种方式访问结果,但我不知道我必须使用哪个命令。
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