【发布时间】:2021-10-12 09:00:21
【问题描述】:
我有一张带有 openlayers 6.8 的基本地图。 我显示来自 geojson 的标记。
geojson 示例:
const geoMoscow = new ol.layer.Vector({
source: new ol.source.Vector({
url: './assets/moscow.geojson',
format: new ol.format.GeoJSON()
}),
visible: true,
title: 'geojson',
style: new ol.style.Style({
fill: fillStyle,
stroke: strokeStyle,
image: new ol.style.Circle({
fill: new ol.style.Fill({
color: [245, 49, 5, 1]
}),
radius: 10,
}),
})
})
我想获取此 geojson 坐标以供进一步使用。 我一直在阅读许多使用 geojson.getSource().getFeatures() 的代码示例,这些示例允许从每个功能访问 getCoordinates() 方法。
不幸的是 geoMoscow.getSource().getFeatures() 给出了一个空数组。
我显然遗漏了一些关于 openlayers 逻辑的东西。 这似乎完全可行,因为我的 geojson 包含一个带有坐标的要素对象,但我无法访问它。
TLDR:如何从这个 geojson Vector 访问坐标等信息。
【问题讨论】:
标签: javascript openlayers geojson