简体   繁体   English

如何在 Openlayers6 中绘制 lineString

[英]How to draw a lineString in Openlayers6

I have a map that uses a WMTS source and is using EPSG:25832 for the projection.我有一张使用 WMTS 源并使用 EPSG:25832 进行投影的地图。 I do not understand why it is so difficult for me to add a line between the 2 markers.我不明白为什么在 2 个标记之间添加一条线对我来说如此困难。 It should be a line with multiple coordinates but I cant find any documentation on how to add a line.它应该是具有多个坐标的线,但我找不到有关如何添加线的任何文档。 I am assuming that it should be a new vectorLayer with a lineString I will be adding, but the documentation is so hard to understand.我假设它应该是一个新的 vectorLayer,我将添加一个 lineString,但是文档很难理解。 Can someone point me in the right direction?有人可以指出我正确的方向吗?

I have been looking at this example, but I don't think it is very clear what is going on.我一直在看这个例子,但我认为不太清楚发生了什么。 And I will be using data, not allowing the user to draw the line.我将使用数据,不允许用户画线。

var map = new Map({
    target: 'map',
    layers: [
        new TileLayer({
            opacity: 0.7,
            source: new WMTS({
                crossOrigin: 'Anonymous',
                url: `https://kortforsyningen.kms.dk/topo_skaermkort_daempet?TICKET=${TOKEN}`,
                layer: 'dtk_skaermkort_daempet',
                matrixSet: 'View1',
                format: 'image/jpeg',
                tileGrid: tileGrid,
                style: 'default',
                size: SIZE
            })
        }),
        new VectorLayer({
            source: new VectorSource({
                features: [originMarker]
            }),
            style: new Style({
                image: new Icon({
                    anchor: [0.5, 1],
                    src: A_ICON,
                })
            })
        }),
        new VectorLayer({
            source: new VectorSource({
                features: [destinationMarker]
            }),
            style: new Style({
                image: new Icon({
                    anchor: [0.5, 1],
                    src: B_ICON,
                })
            })
        })
    ],
    view: new View({
        center: fromLonLat(centerPoint, 'EPSG:25832'),
        zoom: 3,
        resolutions: tileGrid.getResolutions(),
        projection: projection,
        extent: EXTENT
    })
});

To create a LineString feature joining two Point features创建连接两个点要素的 LineString 要素

new Feature(new LineString([
  originMarker.getGeometry().getCoordinates(),
  destination.getGeometry().getCoordinates()
]))

then add it to a new layer, or to an existing vector source.然后将其添加到新图层或现有矢量源。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM