簡體   English   中英

如何在Openlayers中繪制LinearRing

[英]how to draw a LinearRing in 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);

如果要使其表現為圓線,則需要從corrdinates創建線串

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM