0

I'm try to display my points set from Geoserver in Openlayers map. I want to use WFS service, but at the moment I see one point, additionally in wrong place! I want to display all at EPSG 4326. I transformed map to this coordinate system and my points on Geoserver (imported from PostGIS database) are at EPSG 4326. I use Geoserver 2.15.1.

My code:

var wfs = new ol.layer.Vector({
    source: new ol.source.Vector({
        loader: function (extent) {
            $.ajax('http://localhost:8080/geoserver/pilgrimages/ows', {
                type: 'GET',
                data: {
                    service: 'WFS',
                    version: '1.1.0',
                    request: 'GetFeature',
                    typename: 'travels',
                    srsname: 'EPSG:4326',
                    outputFormat: 'application/json',
                    bbox: extent.join(',') + ',EPSG:4326'
                }
            }).done(function (response) {
                wfs
                .getSource()
                .addFeatures(new ol.format.GeoJSON()
                  .readFeatures(response));
            });
        },
        strategy: ol.loadingstrategy.bbox,
        projection: 'EPSG:4326'
    })
});

var map = new ol.Map({
    target: 'map',
    layers: [
        new ol.layer.Tile({
        source: new ol.source.OSM()
        }),
        wfs
    ],
    view: new ol.View({
        center: ol.proj.transform([0,0], 'EPSG:4326', 'EPSG:3857'),
        zoom: 6
    })
});

Can you help me?

3
  • 1
    If your view is EPSG:3857 you must display features on it using EPSG:3857 coordinates.
    – Mike
    Commented Jan 10, 2020 at 20:01
  • @Mike So this means that automatic client side reprojection in OpenLayers works only for raster layers?
    – TomazicM
    Commented Jan 10, 2020 at 20:30
  • Some vector formats may be reprojected automatically if loaded from a url, see the description of the url option openlayers.org/en/latest/apidoc/… If using a loader function data projection and feature projection options should be passed to readFeatures
    – Mike
    Commented Jan 10, 2020 at 20:50

0

Browse other questions tagged or ask your own question.