gpt4 book ai didi

javascript - 如何在 Openlayers 中绘制 LinearRing

转载 作者:行者123 更新时间:2023-11-28 17:09:22 26 4
gpt4 key购买 nike

我编写了以下代码来创建 LinearRing。但是当我运行此代码时,屏幕上没有任何内容

 var circleGeom = new ol.geom.Circle(center, 250, 'XY');
var circleFeature = new ol.Feature();
var cordPoly = new ol.geom.Polygon.fromCircle(circleGeom);
var coordinates = cordPoly.getCoordinates();
var linearRing = new ol.geom.LinearRing(coordinates);
circleFeature.setGeometry(linearRing);
vectorlayer.getSource().addfeatures([circleFeature]);

谁能帮我找到这里的问题吗?

最佳答案

var vectorLayer = new ol.layer.Vector({
source: new ol.source.Vector(),
style: new ol.style.Style({
stroke: new ol.style.Stroke({
width: 2,
color: "red"
})
})
});

var circleGeom = new ol.geom.Circle([0, 0], 100, 'XY');
vectorLayer.getSource().addFeature(new ol.Feature(ol.geom.Polygon.fromCircle(circleGeom, 10)));

var map = new ol.Map({
layers: [vectorLayer],
target: document.getElementById("map"),
view: new ol.View({
center: [0, 0],
zoom: 16
})
});
html,
body,
#map {
width: 100%;
height: 100%;
overflow: hidden;
}
<link href="https://cdn.rawgit.com/openlayers/openlayers.github.io/master/en/v5.3.0/css/ol.css" rel="stylesheet"/>
<script src="https://cdn.rawgit.com/openlayers/openlayers.github.io/master/en/v5.3.0/build/ol.js"></script>
<body>
<div id="map" class="map"></div>
</body>

根据文档,LinearRing 无法单独渲染。请尝试:

circleFeature.setGeometry(cordPoly);

关于javascript - 如何在 Openlayers 中绘制 LinearRing,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54889954/

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