gpt4 book ai didi

javascript - OpenLayers 6 + Angular 8 : LineString(s) not showing up on Vector Layer (With no errors from JS)

转载 作者:行者123 更新时间:2023-11-28 03:23:44 32 4
gpt4 key购买 nike

我遇到的问题是我的 LineString 未显示在 map 上,并且控制台未给出任何错误。

我相信我的代码是正确的,但在 OpenLayers 方面我并不那么聪明,我可能是错的。

这就是我将矢量图层添加到 map 的方法

var vectorLayer = new ol.layer.Vector({
name: 'trailLayer',
type: "Vector",
source: new ol.source.Vector({ format: new ol.format.GeoJSON({ featureProjection:"EPSG:3857" }) }),
zoomMin: 8,
zoomMax: 18
});

this.map.addLayer(vectorLayer);

这就是我添加新 LineString 的方法

let layer;
this.map.getLayers().forEach(function (value) { if ( value.get('name') === 'trailLayer') { layer = value; } });
if(layer == null) { return; }

let coords = [[latA, lonA], [latB, lonB]];
let lineString = new ol.geom.LineString(coords);
lineString.transform('EPSG:4326', 'EPSG:3857');

var lineFeature = new ol.Feature({
name: callsign,
});

lineFeature.setGeometry(lineString);


var lineStyle = new ol.style.Style({
stroke: new ol.style.Stroke({
width: trailWidth,
color: trailColor
})
});

lineFeature.setStyle(lineStyle);

layer.getSource().addFeature(lineFeature);

如果我尝试使用 source.GetFeatures() 它会正确显示我的所有功能,但我在 map 上看不到它们。

我错过了什么吗?

附注每个变量都被正确分配,没有什么奇怪的,也没有未定义的 ecc...

最佳答案

在 OL 中坐标必须是 expressed首先是经度,然后是纬度。

尝试交换坐标:

let coords = [[lonA, latA], [lonB, latB]];

关于javascript - OpenLayers 6 + Angular 8 : LineString(s) not showing up on Vector Layer (With no errors from JS),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58874646/

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