简体   繁体   中英

OpenLayers v3.5.0 map, loading features from a GeoJSON using bbox strategy

I'm trying to use the approach described in this question , but instead of using jQuery to perform the ajax request, I'm using angularJS $http method. I've already verified and the features are being loaded into the source of the layer, but nothing is shown.

Here is the definition of the source:

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
});

Is there any incompatibility problems with using angularJS and openlayers?

The problem was the mismatch of the projection of the data in my GeoJSON (EPSG:4326) and of the map (OpenLayers3 default, EPSG:3857).

To solve the problem, I changed the projection of the data that I was using to build the GeoJSON to EPSG:3857. Since the data was stored in a postGis database, I used the function ST_Transform to change the projection of the geom column contaning the objects.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM