javascript - 如何在 Openlayers 中绘制 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);
推荐阅读
- unity3d - Unity 3D UWP 构建失败:找不到 System.Xml
- windows - 在批处理文件中捕获命令的完整输出(仅捕获第一个字符)
- android - 我在哪里可以找到 Android 的 onDestroy() 方法
- ruby-on-rails - NoMethodError:nil 的未定义方法“匹配”:NilClass
- javascript - 在没有 jquery 的情况下制作可拖动元素
- php - 意外的“回声”(T_ECHO)
- vb.net - ConnectionString 属性尚未初始化。视觉基础 2015
- uitableview - 自定义 ViewCell 可绑定属性不起作用
- c - 从列表中删除保存在节点中的字符串
- python - Python 两个字符串在比较中显示为假