Dictionary 如何在Openlayers中以编程方式添加半径、长度和纬度的圆?
我正在尝试添加带有Dictionary 如何在Openlayers中以编程方式添加半径、长度和纬度的圆?,dictionary,openlayers,draw,geometry,interaction,Dictionary,Openlayers,Draw,Geometry,Interaction,我正在尝试添加带有纬度、经度和半径(以米或公里为单位)的圆圈,这时单击了一个按钮 我可以在单击按钮时添加一个圆,但它将半径作为1-25之间的数字。 我需要以米为单位给出半径 注意:当我用手指手势画一个圆时,我可以用这个代码以米为单位得到它的半径 var radius = geometry.getRadius(); 我的手指手势绘图功能: function addInteraction() { draw = new ol.interaction.Draw({ source: sour
纬度
、经度
和半径
(以米或公里为单位)的圆圈,这时单击了一个按钮
我可以在单击按钮时添加一个圆,但它将半径作为1-25之间的数字。
我需要以米为单位给出半径
注意:当我用手指手势画一个圆时,我可以用这个代码以米为单位得到它的半径
var radius = geometry.getRadius();
我的手指手势绘图功能:
function addInteraction() {
draw = new ol.interaction.Draw({
source: source,
type: shapetype,
freehand: true
});
map.addInteraction(draw);
您只需要执行以下操作
var-coordslongitudelativity=[1,44]
#转换为地图坐标(通常为球形墨卡托,也称为EPSG 3857)
var中心=来自Lonlat的其他项目(合作关系)
#创建圆几何图形,4000=距离(米)
var圆几何=新的几何圆(中心,4000);
#如果要/需要将其转换为多边形
var polygonFromCircleGeometry=ol.geom.Polygon.fromCircle(circleGeometry);
您只需执行以下操作
var-coordslongitudelativity=[1,44]
#转换为地图坐标(通常为球形墨卡托,也称为EPSG 3857)
var中心=来自Lonlat的其他项目(合作关系)
#创建圆几何图形,4000=距离(米)
var圆几何=新的几何圆(中心,4000);
#如果要/需要将其转换为多边形
var polygonFromCircleGeometry=ol.geom.Polygon.fromCircle(circleGeometry);
要在地图上添加圆:
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);
代码片段:
var-map=新的ol.map({
目标:“地图”,
图层:[
新ol.layer.Tile({
来源:new ol.source.OSM()
})
],
视图:新ol.view({
中心:Lonlat的其他项目([-117.1610838,32.715738]),
缩放:12
})
});
var中心纵向相关性=Lonlat的其他项目([-117.1610838,32.715738]);
var layer=新ol.layer.Vector({
来源:新ol.source.Vector({
投影:‘EPSG:4326’,
//半径=4000米
特征:[新ol.特征(新ol.几何圆(中心纵向相关性,4000))]
}),
风格:[
新ol风格({
笔划:新的ol风格笔划({
颜色:“蓝色”,
宽度:3
}),
填充:新的ol.style.fill({
颜色:“rgba(0,0,255,0.1)”
})
})
]
});
map.addLayer(层)代码>
html,
身体{
身高:100%;
宽度:100%;
填充:0px;
边际:0px;
}
.地图{
身高:100%;
宽度:100%;
}
要在地图上添加圆:
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);
代码片段:
var-map=新的ol.map({
目标:“地图”,
图层:[
新ol.layer.Tile({
来源:new ol.source.OSM()
})
],
视图:新ol.view({
中心:Lonlat的其他项目([-117.1610838,32.715738]),
缩放:12
})
});
var中心纵向相关性=Lonlat的其他项目([-117.1610838,32.715738]);
var layer=新ol.layer.Vector({
来源:新ol.source.Vector({
投影:‘EPSG:4326’,
//半径=4000米
特征:[新ol.特征(新ol.几何圆(中心纵向相关性,4000))]
}),
风格:[
新ol风格({
笔划:新的ol风格笔划({
颜色:“蓝色”,
宽度:3
}),
填充:新的ol.style.fill({
颜色:“rgba(0,0,255,0.1)”
})
})
]
});
map.addLayer(层)代码>
html,
身体{
身高:100%;
宽度:100%;
填充:0px;
边际:0px;
}
.地图{
身高:100%;
宽度:100%;
}