gis - Openlayers 3.5 和 GeoJSON

标签 gis geojson openlayers-3

我在使用 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/

相关文章:

javascript - 如何使用 OpenLayers 3 添加标记

javascript - 无法第二次设置 WFS 过滤器

sql - 如何在 SQL 连接中使用 lat/lng 半径进行选择

php - Nearmap架构

r - 提取 R 中对应点位置的像素值

geojson - 如何根据 map 范围将 GeoJSON 数据动态加载到 OpenLayers 3.5.0 map 图层中?

python - 栅格化 GDAL 层

javascript - 从 d3.js 中的 GeoJson 多边形获取每个多边形的质心

python - 如何为 MongoEngine PointField 格式化数据

javascript - ol.interaction.Draw 鼠标移动条件?