OpenLayers v3.5.0 地图,使用 bbox 策略从 GeoJSON 加载特征
OpenLayers v3.5.0 map, loading features from a GeoJSON using bbox strategy
我正在尝试使用 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) 和地图(OpenLayers3 默认值,EPSG:3857)中的数据投影不匹配。
为了解决这个问题,我将用于构建 GeoJSON 的数据投影更改为 EPSG:3857。由于数据存储在 postGis 数据库中,我使用函数 ST_Transform 更改包含对象的几何列的投影。
我正在尝试使用 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) 和地图(OpenLayers3 默认值,EPSG:3857)中的数据投影不匹配。
为了解决这个问题,我将用于构建 GeoJSON 的数据投影更改为 EPSG:3857。由于数据存储在 postGis 数据库中,我使用函数 ST_Transform 更改包含对象的几何列的投影。