簡體   English   中英

OpenLayers 6 + Angular 8:LineString(s) 未顯示在矢量圖層上(JS 沒有錯誤)

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

我遇到的問題是我的 LineString(s) 沒有出現在 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 上看不到它們。

我錯過了什么嗎?

PS 每個變量都被正確分配,沒有什么奇怪的,也沒有未定義的錯誤...

在 OL 中,坐標必須首先表示為經度,然后是緯度。

嘗試交換坐標:

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

暫無
暫無

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

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