8

I have tried with different setups and formats, but no success.

With firebug, I can see that the json data is loaded, but nothing shows up on the map.

Have anyone experience with geoserver and wfs in openlayers 3?

var layer_ojd_vector = new ol.layer.Vector({
 source: new ol.source.Vector({
  parser: new ol.parser.GeoJSON(),
  url: http://SERVER:8080/geoserver/NS/ows?service=WFS&version=1.0.0&request=GetFeature&typeName=NS:LAYER&maxFeatures=50&outputFormat=json
 }),
 style: new ol.style.Style({rules: [
  new ol.style.Rule({
   filter: 'geometryType("point")',
   symbolizers: [
     new ol.style.Shape({
       fillColor: '#013',
       size: 40
     })
   ]
 })
]})  
});
0

3 Answers 3

3

I've seen this answered quite a bit on here.

You must run the HTML file from a webserver and access by:

SERVER:8080/geoserver/index.html

or however yours is setup.

You can't simply double click the HTML file and view the WFS layer.

4
  • The file with this javascript is accessed via a web server. Commented Aug 7, 2013 at 7:29
  • OK! Now I understand: I can't access the wfs data from another web server, I have to have the html file on the geoserver web server. Commented Aug 7, 2013 at 9:39
  • 4
    @GISer "I've seen this answered quite a bit on here." Really? This is the only post I've seen that specifically targets OL3. Wouldn't mind seeing some better documentation on this as the OL3 documentation is still very much a work in progress.
    – Kyle
    Commented Jan 13, 2014 at 18:36
  • 1
    This does not make sense. Are you saying if you have remote GeoJSON data that it has to run on the same server that serves the map? If you see some of the OpenLayers examples on their website, the spatial data does not have to reside on the same server as the map server displaying the data. Commented Sep 9, 2014 at 20:35
3

I agree with Kyle. Even a year later it took me a while to find good examples with explanation which can be easily reproduced.

I do like the examples from the 'the book of openlayers 3'. Unfortunately I do not have access to the book itself but I believe it to be well written judging from the examples.

This example is for ol 3.4

http://acanimal.github.io/thebookofopenlayers3/chapter03_07_query_wfs.html

I had some problems replicating the ol 3.5 vector-wfs master example from the openlayers examples page. These problems are probably fixed by now.

http://openlayers.org/en/master/examples/vector-wfs.html

I created three jsfiddle to demonstrate ol 3.5.0 calls via AJAX for ol.format.GeoJSON (JSON and JSONP) as well as ol.format.WFS.

WFS (CORS access has to enabled on the web server, e.g. for Apache Tomcat)

http://jsfiddle.net/goldrydigital/9d3jzpna/

JSON (CORS access has to enabled on the web server, e.g. for Apache Tomcat)

http://jsfiddle.net/goldrydigital/ucspgvx0/

JSONP (JSONP needs to be enabled in Geoserver)

http://jsfiddle.net/goldrydigital/08zzh9n9/

1
  • Well, the answer did come two years after the accepted answer, and the accepted answer was correct as far as it went. But this is much more useful.
    – Auspex
    Commented Jan 26, 2017 at 15:23
0

I think what you need is this:
REST configuration API reference
With REST you can call data between servers (or between e.g. Apache on port 80 and geoserver in port 8080 if it's the same server).

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.