gpt4 book ai didi

gis - Openlayers 3.5 和 GeoJSON

转载 作者:行者123 更新时间:2023-12-01 00:52:01 26 4
gpt4 key购买 nike

我在使用 OpenLayers 3.5 时遇到问题。我正在尝试使用一次性加载策略从 GeoJSON 文件中获取特征。我正在向已经实例化的 map 添加一个新图层。我的代码如下所示:

var vectorSource = new ol.source.Vector({
url: layerInfo.url,
format: new ol.format.GeoJSON()
});

var pointsLayer = new ol.layer.Vector({
source: vectorSource,
style: styleFunc
});

that.map.addLayer(pointsLayer);
pointsLayer.setVisible(true);

但是,没有任何显示,当我检查 pointsLayer.getSource().getFeatures() 时,我发现实际上没有加载任何功能。

所以,现在我尝试以不同的方式加载功能:

var that = this;

$.get(layerInfo.url, function(response) {

var vectorSource = new ol.source.Vector({
features: (new ol.format.GeoJSON()).readFeatures(response)
});

var pointsLayer = new ol.layer.Vector({
source: vectorSource,
style: styleFunc
});

that.map.addLayer(pointsLayer);
pointsLayer.setVisible(true);
});

这确实有效。我正在用头撞墙。有没有人有任何想法?非常感谢!

最佳答案

这就是我现在加载数据的方式,“数据”是我的 GJson

var wktTraffic = new ol.source.Vector({
});

var trafficLayer = new ol.layer.Vector({
source: wktTraffic,
style: new ol.style.Style({
stroke: new ol.style.Stroke({
color: 'blue',
width: 5
})
})
});

function showData(data) {
var format = new ol.format.WKT();
var feature;
$.each(data, function (i, link) {
feature = format.readFeature(link.geom);
wktTraffic.addFeature(feature);
})
console.log('done load map');
}

关于gis - Openlayers 3.5 和 GeoJSON,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30657032/

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