gpt4 book ai didi

openlayers - 如何在openlayers中绘制带有半径的圆

转载 作者:行者123 更新时间:2023-12-01 16:43:16 28 4
gpt4 key购买 nike

我想在 openlayers 中画一个特定半径以公里为单位的圆。与特定地理点的中心?我遵循与 http://demo.gwt-openlayers.org/gwt_ol_showcase/GwtOpenLayersShowcase.html?example=Draw%20Regular%20Polygon%20Example 相同的方法但我想用预定义的值自动绘制。

最佳答案

以下代码将为您提供一个以当前 map 中心为中心的浅蓝色圆圈,其半径以米为单位定义。如果您想要以英尺为单位,只需替换:

        var radius = (radius / ol.proj.METERS_PER_UNIT.m) * resolutionFactor;

与:

        var radius = (radius / ol.proj.METERS_PER_UNIT.ft) * resolutionFactor;

代码:

   var drawCircleInMeter = function(map, radius) {
var view = map.getView();
var projection = view.getProjection();
var resolutionAtEquator = view.getResolution();
var center = map.getView().getCenter();
var pointResolution = projection.getPointResolution(resolutionAtEquator, center);
var resolutionFactor = resolutionAtEquator/pointResolution;
var radius = (radius / ol.proj.METERS_PER_UNIT.m) * resolutionFactor;


var circle = new ol.geom.Circle(center, radius);
var circleFeature = new ol.Feature(circle);

// Source and vector layer
var vectorSource = new ol.source.Vector({
projection: 'EPSG:4326'
});
vectorSource.addFeature(circleFeature);
var vectorLayer = new ol.layer.Vector({
source: vectorSource
});

map.addLayer(vectorLayer);
}

注意。此处创建的 OpenLayers 圆始终是完美平坦的 2d 圆。而实际上,您可能想要更好地考虑 map 投影的东西(尤其是靠近两极的地方)。

关于openlayers - 如何在openlayers中绘制带有半径的圆,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23264721/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com