我正在尝试使用 this question 中描述的方法,但我没有使用 jQuery 来执行 ajax 请求,而是使用了 angularJS $http 方法。我已经验证并且正在将功能加载到层的源中,但没有显示任何内容。
这里是源码的定义:
var vectorSource = new ol.source.Vector({
loader: function(extent, resolution){
$http.get(url).success(function(data){
var formatGeo = new ol.format.GeoJSON();
var features = formatGeo.readFeatures(data,
{featureProjection: 'EPSG:4326'});
vectorSource.addFeatures(features);
console.log(vectorSource.getFeatures().length);
})},
strategy: ol.loadingstrategy.bbox
});
angularJS和openlayers有没有不兼容的问题?
最佳答案
问题是我的 GeoJSON (EPSG:4326) 和 map (OpenLayers3 默认值,EPSG:3857)中的数据投影不匹配。
为了解决这个问题,我将用于构建 GeoJSON 的数据投影更改为 EPSG:3857。由于数据存储在 postGis 数据库中,我使用函数 ST_Transform 更改包含对象的 geom 列的投影。
关于angularjs - OpenLayers v3.5.0 map ,使用 bbox 策略从 GeoJSON 加载特征,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30735051/