0

I am working in openlayers 2. I want to diaplay wfs layer in openlayers 2. But it is not displaying. When i tried the same in ol3 it is working fine. But my whole project is in openlayers 2. So i want wfs layer in ol2. Below is my code in both ol3 and ol2. Please tell me where i am doing mistake

OL3

 <script>
        var formatWFS = new ol.format.WFS();


  var sourceWFS = new ol.source.Vector({
   loader: function (extent) {
    $.ajax('http://localhost:8080/geoserver/cite/wfs/ows', {
        type: 'GET',
        data: {
            service: 'WFS',
            version: '1.1.0',
            request: 'GetFeature',
            typename: 'AMBALA_sma',
            srsname: 'EPSG:3857',
            bbox: extent.join(',') + ',EPSG:3857'
        }
    }).done(function (response) {
        sourceWFS.addFeatures(formatWFS.readFeatures(response));
    });
},

strategy: ol.loadingstrategy.bbox,
projection: 'EPSG:3857'
});

var layerWFS = new ol.layer.Vector({
source: sourceWFS
  });

var map = new ol.Map({
target: 'map',
controls: [],
interactions: [

    new ol.interaction.MouseWheelZoom(),
    new ol.interaction.DragPan()
],
layers: [
    new ol.layer.Tile({
        source: new ol.source.OSM({
           // url: 'https://cartodb-basemaps-{a-d}.global.ssl.fastly.net/dark_nolabels/{z}/{x}/{y}.png',
           // opaque: false,
            attributions: []
        })
    }),
    layerWFS
],
view: new ol.View({
   center: [8561898.130561389, 3547876.863311305],
    zoom: 12
  })
 });

        </script>

OPENLAYERS 2 and geoext

 wfslayer = new OpenLayers.Layer.Vector("WFS", {

    strategies: [new OpenLayers.Strategy.BBOX()],
    protocol: new OpenLayers.Protocol.WFS({

        url: 'http://localhost:8080/geoserver/ows',

  featureType: 'AMBALA_sma',
  featureNS: 'http://www.opengeospatial.net/',
  srsName: 'EPSG:3857',
  geometryName: 'the_geom',
  version: '1.0.0',
   outputFormat: "json",
        readFormat: new OpenLayers.Format.GeoJSON()
    })
});
 mapPanel.map.addLayers([layerWFS]);
1
  • try using the same URL for both requests
    – Ian Turton
    Mar 9, 2017 at 9:03

1 Answer 1

2

Here's a few things that need checking:

  1. Your Geoserver url looks odd. See the documentation on making a wfs request. Try url: http://localhost:8080/geoserver/wfs
  2. check your featureNS. That also looks strange. Is that what you set it as?
  3. Is there any reason you are using version 1.1.0 in ol3 and 1.0.0 in ol2
2
  • i have changed url, featurens and version still layer is not displaying wfslayer = new OpenLayers.Layer.Vector("WFS", { strategies: [new OpenLayers.Strategy.BBOX()], protocol: new OpenLayers.Protocol.WFS({ url: 'localhost:8080/geoserver/wfs', featureType: 'AMBALA_sma', featureNS: 'localhost:8080/cite', srsName: 'EPSG:3857', geometryName: 'the_geom', version: '1.1.0 }) });
    – iit
    Mar 10, 2017 at 4:03
  • i have changed featureNS: "opengeospatial.net/cite", then it is displaying
    – iit
    Mar 10, 2017 at 4:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.