0

The guys from guide4you did a great job making this lib opensource!!

I've succeeded in having a working demo guide4you sample.

How adjustable is the lib? For instance how can I add layers with GeoJSON instead of KML. Can the layers be added dynamically (with own javascript) instead of predefined?

Take this as example: https://openlayers.org/en/latest/examples/geojson.html

To be more specific: how can that example work together with guide4you ?

Kind regards,

Sam

Simon Zyx
  • 6,503
  • 1
  • 25
  • 37
Sam
  • 23
  • 4

1 Answers1

0

To use a GeoJSON layer in guide4you you can just specify the type "GeoJSON" in the layerconfig.

{ "id": "3", "type": "GeoJSON", "source": { "url": "path/to/geojson" } }

See also https://github.com/KlausBenndorf/guide4you/blob/master/conf/full/layers.commented.json for some examples

If you like to add a layer on the fly with javascript you can use this api function:

map.get('api').addFeatureLayer({ "id": "3", "type": "GeoJSON", "source": { "url": "path/to/geojson" }, "visible": true })

the possible options are the same as in the layer config.

If you like to add only new features you can create a layer with type "Intern" and add the features with openlayers functionalities. The source of a feature layer is a subclass of ol.source.Vector. In the example below I am assuming that geojsonObject is of the same kind as in the geojson example of openlayers. var layer = map.get('api').addFeatureLayer({ "id": "3", "type": "Intern", "source": { "features": [] }, "visible": true }); layer.getSource().addFeatures((new ol.format.GeoJSON()).readFeatures(geojsonObject));

And last but not least you can use a simplified api to define features inside a layerConfig object like this:

{ "id": "3", "type": "Intern", "source": { "features": [{ "id": 6, "name": "Some feature", "description: "Some description", "style": "#defaultStyle", "geometryWKT": "... any wkt string here ..." },{ "geometryWKT": "... any wkt string here ..." }] } }

this can be used either in a layerConfig file or in the addFeatureLayer api method.

Simon Zyx
  • 6,503
  • 1
  • 25
  • 37
  • Hi Simon. Thanks for the fast answer!! When I place the code in index.html inside the script block I get "ReferenceError: map is not defined" – Sam May 09 '17 at 12:19
  • You can use createG4U('#g4u-map').then(function (map) { ... here map is defined ... }) – Simon Zyx May 09 '17 at 12:22
  • I tried this myself, it does not work because the map is not ready at this point. This should work: createG4U('#g4u-map').then(function (map) { map.asSoonAs('ready', true, function () { ... here ... }) }) – Simon Zyx May 09 '17 at 12:33