我想在以公里为单位的特定半径的开放层中画一个圆。与特定地理点的中心?我遵循与http://demo.gwt-openlayers.org/gwt_ol_showcase/GwtOpenLayersShowcase.html?example=Draw%20Regular%20Polygon%20Example相同的方法,但我想使用预定义的值自动绘制。
问问题
19141 次
2 回答
7
以下代码将为您提供一个以当前地图为中心的浅蓝色圆圈,其半径以米为单位。如果你想要它的英尺,只需更换:
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 圆。而实际上,您可能想要更好地考虑地图投影(尤其是靠近两极)的东西。
于 2015-02-03T13:01:13.637 回答
0
就像是
Style stopPointStyle = new Style();
stopPointStyle.setPointRadius(15);
stopPointStyle.setFillColor("red");
stopPointStyle.setStrokeColor("blue");
stopPointStyle.setStrokeWidth(1);
stopPointStyle.setFillOpacity(0.5);
Point point = new Point(journalEntry.getLongitude(), journalEntry.getLatitude());
VectorFeature pointFeature = new VectorFeature(point, stopPointStyle);
于 2014-04-24T11:02:21.460 回答