0 geometry dictionary interaction draw openlayers
我试图在单击按钮时用latitude、longitude和(以米或公里为单位)添加圆圈。radius
我可以在单击的按钮上添加一个圆圈,但它的半径为 1-25 之间的数字。我需要给出以米为单位的半径
注意:当我用手指画一个圆圈时,我可以使用此代码获取其半径(以米为单位)
var radius = geometry.getRadius();
Run Code Online (Sandbox Code Playgroud)
我用手指手势功能绘图:
function addInteraction() {
draw = new ol.interaction.Draw({
source: source,
type: shapetype,
freehand: true
});
map.addInteraction(draw);
Run Code Online (Sandbox Code Playgroud)
要将圆添加到地图:
var centerLongitudeLatitude = ol.proj.fromLonLat([longitude, latitude]);
var layer = new ol.layer.Vector({
source: new ol.source.Vector({
projection: 'EPSG:4326',
features: [new ol.Feature(new ol.geom.Circle(centerLongitudeLatitude, 4000))]
}),
style: [
new ol.style.Style({
stroke: new ol.style.Stroke({
color: 'blue',
width: 3
}),
fill: new ol.style.Fill({
color: 'rgba(0, 0, 255, 0.1)'
})
})
]
});
map.addLayer(layer);
Run Code Online (Sandbox Code Playgroud)
代码片段:
var centerLongitudeLatitude = ol.proj.fromLonLat([longitude, latitude]);
var layer = new ol.layer.Vector({
source: new ol.source.Vector({
projection: 'EPSG:4326',
features: [new ol.Feature(new ol.geom.Circle(centerLongitudeLatitude, 4000))]
}),
style: [
new ol.style.Style({
stroke: new ol.style.Stroke({
color: 'blue',
width: 3
}),
fill: new ol.style.Fill({
color: 'rgba(0, 0, 255, 0.1)'
})
})
]
});
map.addLayer(layer);
Run Code Online (Sandbox Code Playgroud)
var map = new ol.Map({
target: 'map',
layers: [
new ol.layer.Tile({
source: new ol.source.OSM()
})
],
view: new ol.View({
center: ol.proj.fromLonLat([-117.1610838, 32.715738]),
zoom: 12
})
});
var centerLongitudeLatitude = ol.proj.fromLonLat([-117.1610838, 32.715738]);
var layer = new ol.layer.Vector({
source: new ol.source.Vector({
projection: 'EPSG:4326',
// radius = 4000 meters
features: [new ol.Feature(new ol.geom.Circle(centerLongitudeLatitude, 4000))]
}),
style: [
new ol.style.Style({
stroke: new ol.style.Stroke({
color: 'blue',
width: 3
}),
fill: new ol.style.Fill({
color: 'rgba(0, 0, 255, 0.1)'
})
})
]
});
map.addLayer(layer);Run Code Online (Sandbox Code Playgroud)
html,
body {
height: 100%;
width: 100%;
padding: 0px;
margin: 0px;
}
.map {
height: 100%;
width: 100%;
}Run Code Online (Sandbox Code Playgroud)