2

I have been trying to load some point data from geojson into openlayers 3. Eventually I would like to load the features from a url with the data, But I cannot get a single point to show from a hardcoded object.

Do I need to inform openlayers 3 about epsg:27700 in some way? Or what am I missing.

Loading the same layer from a WMS seems to work fine, but I would like to get a WFS to work as well.

var geojson = {
"type":"FeatureCollection",
"totalFeatures":1,
"features":[
    {
        "type":"Feature",
        "id":"schools",
        "geometry":{
            "type":"Point",
            "coordinates":[315850.99712308607,176054.0042378275]
        },
        "geometry_name":"geometry",
        "properties":{
            "ID":1,"Name":"High School","POINT_X":315850.997098,"POINT_Y":176054.004321
        }
    }
],"crs":{"type":"name","properties":{"name":"urn:ogc:def:crs:EPSG::27700"}}}

var layer = new ol.layer.Vector({
title: 'Schools',
source: new ol.source.Vector({
    features: (new ol.format.GeoJSON()).readFeatures(geojson, { dataProjection: 'EPSG:27700', featureProjection: 'EPSG:3286' })
}),
style: new ol.style.Style({
    image: new ol.style.Circle({
        radius: 10,
        fill: new ol.style.Fill({color: 'rgba(255, 0, 0, 0.1)'}),
        stroke: new ol.style.Stroke({color: 'red', width: 1})
    })
})

});

  • 1
    Could you expand on what exactly is going wrong? What type of browser are you using? Is the basemap displaying? ect – AvidDabbler Mar 8 '17 at 14:18
  • The base map is loading fine, using a variety of them and a custom layer switcher and that all works. The I have a plethora of layers I am requesting from my geoserver setup and they all work a charm in said layer switcher. I though I was doing really well with this and then thought I will load in some geojson data, from the same layer on on the geoserver and nothing displays, no errors and I am unsure how to move forward. The above hardcoded var is just a sample feature of the layer, picked out from the geojson string geoserver returns. – Ryan Mar 8 '17 at 14:25
1

Trying to load WFS data in place of a WMS map image, now seems so wrong.

If I had gotten this working, I would have had to re-specify styles for it in openlayers 3, rendering any Geoserver-side SLD styling pointless.

If you are asking Geoserver for WFS data for a layer, simply to display, lets say a whole country's worth of data in Openlayers, like I was - it is most likely you want to rethink where you are going.

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.