0

I am trying to put a WFS layer on top of a openlayer's template I found in openlayers examples. This is the link for the untouched version. And this is the pen I am working on. I am actually only changing the url defined in function extent and the center of coordinates to be zoomed. I think I do something wrong with getfeature link formation. Or maybe something about the coordinate systems.

<!DOCTYPE html>
<html>
<head>
</head>
<body>
<div id="map" class="map"></div>

<script>
var vectorSource = new ol.source.Vector({
  format: new ol.format.GeoJSON(),
  url: function(extent) {
    return 'http://52.42.3.28:8080/geoserver/county/ows?service=WFS&' +
        'version=1.0.0&request=GetFeature&typeName=county:taxlots&' +
        'outputFormat=application%2Fjson&srsname=EPSG:4326' +
        'bbox=' + extent.join(',') + ',EPSG:4326';
  },
  strategy: ol.loadingstrategy.bbox
});


var vector = new ol.layer.Vector({
  source: vectorSource,
  style: new ol.style.Style({
    stroke: new ol.style.Stroke({
      color: 'rgba(0, 0, 255, 1.0)',
      width: 2
    })
  })
});

var raster = new ol.layer.Tile({
  source: new ol.source.OSM()
});

var map = new ol.Map({
  layers: [raster, vector],
  target: document.getElementById('map'),
  view: new ol.View({
    center: [-13679410,5217562],
    maxZoom: 21,
    zoom: 14
  })
});
</script>
</body>
</html>
2

You seem to have switched your extent and GetFeature request to use lat/lon (EPSG:4326) while your map and centre are still in meters(?) probably using EPSG:3857. So your data is drawn just very small and on Null Island.

So either switch back to using metres throughout or transform your data to match the map or switch the map to match the data.

1
  • Thanks. I have changed the coordinate system accordinlgy. But still, I could not find a way to properly call the WFS layer. – Sam Jan 30 '18 at 20:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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