【发布时间】:2016-10-27 19:08:29
【问题描述】:
我正在尝试在 openlayers 地图上显示 geojson 文件。 openlayers 地图已经在工作,但是我无法弄清楚如何显示 geojson 文件中的功能。 The example on their website 不幸的是不是很有帮助,因为它只是将 geojson 对象直接写入文件,然后稍后访问。我希望从一个单独的 geojson 文件中获取特征并将它们显示在地图上。
这是我到目前为止的,直接从示例中复制的:
var vectorSource = new ol.source.Vector({
features: (new ol.format.GeoJSON()).readFeatures(geojsonObject)
});
var vectorLayer = new ol.layer.Vector({
source: vectorSource,
style: styleFunction
});
var map = new ol.Map({
layers: [
new ol.layer.Tile({
source: new ol.source.OSM()
}),
vectorLayer
],
target: 'map',
controls: ol.control.defaults({
attributionOptions: /** @type {olx.control.AttributionOptions} */ ({
collapsible: false
})
}),
view: new ol.View({
center: [0, 0],
zoom: 2
})
});
我需要知道的是如何“打开”文件并从 geojson 文件(当前位于 url ..\public\geojson\federal_ridings.geojson)中获取特征来代替已经存在的变量 geojsonObject?
【问题讨论】:
标签: gis openlayers-3 geojson