You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Basically in every project I have been, get some data from server side via some kind of (REST) API, that return data in some kind of JSON formatted structure. Generally as plain array of objects or object where array of objects are obtained as (nested) property.
{
"data": [...]
}
In only very few cases API return GeoJSON-formatted data that can be directly used by Openlayers. But usually it is not the case and usually we don't get opportunity to develop also server side API to return data in some spatial format. If we are lucky, we get geometry encoded in some spatial format (GeoJSON geometry, WKT geometry) as property of object.
Or in case of points - separate fields for x and y coordinates.
My last couple of projects were based on Directus backend, which do have some kind of spatial functionality, but very limited and it returns data in format:
As there was requirement that layers for ol map should come from Directus presets (and therefore all should be dynamic), I needed to create Vector layers with just url. So I created PlainJSON format for that. Not a big deal, but I was quite suprised, that I didn't find this kind of generic solution (or there is but I just didn't found it?). At first I was quite sure I can just extend GeoJSON format, but it was not the case, as basically all functionality isn't exported. So I kind of did a wrapper for GeoJSON format:
const format = new FlatJSON({
dataPrefix: 'data', // Input data prefix, string from root to array of data items. Use dot notation when nested object.
dataGeometryName: 'geometry', // Geometry name to use when reading geometry or array of coordinate fields (x, y, z, m)
})
It is quick hack and only targeted (and tested) to one use case so far. But it should be generic enough to cover most API responses that are not formatted some spatial format.
Do we need this kind of generic and usable format in Openlayers? Should now abstract JSONFeature format be something alike and usable?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
Basically in every project I have been, get some data from server side via some kind of (REST) API, that return data in some kind of JSON formatted structure. Generally as plain array of objects or object where array of objects are obtained as (nested) property.
In only very few cases API return GeoJSON-formatted data that can be directly used by Openlayers. But usually it is not the case and usually we don't get opportunity to develop also server side API to return data in some spatial format. If we are lucky, we get geometry encoded in some spatial format (GeoJSON geometry, WKT geometry) as property of object.
Or in case of points - separate fields for x and y coordinates.
My last couple of projects were based on Directus backend, which do have some kind of spatial functionality, but very limited and it returns data in format:
As there was requirement that layers for ol map should come from Directus presets (and therefore all should be dynamic), I needed to create Vector layers with just url. So I created PlainJSON format for that. Not a big deal, but I was quite suprised, that I didn't find this kind of generic solution (or there is but I just didn't found it?). At first I was quite sure I can just extend GeoJSON format, but it was not the case, as basically all functionality isn't exported. So I kind of did a wrapper for GeoJSON format:
https://github.com/sookoll/olly/blob/main/src/format/FlatJSON.mjs
Usage:
It is quick hack and only targeted (and tested) to one use case so far. But it should be generic enough to cover most API responses that are not formatted some spatial format.
Do we need this kind of generic and usable format in Openlayers? Should now abstract JSONFeature format be something alike and usable?
Beta Was this translation helpful? Give feedback.
All reactions