orb
orb copied to clipboard
copy the original mvt.Layers for reuse
Hi there,
I am trying to build a tileserver that reads geojson and serve tiles
I started by reading the json file:
geojsonData, err := ioutil.ReadFile("./data/large_data.geojson")
then I unmarshal the file to go object:
r = map[string]*geojson.FeatureCollection{}
err = json.Unmarshal(geojsonData, &r)
layers := mvt.NewLayers(r)
when serving the tiles the original values of the layers gets mutated, which force me to read and unmarshal the geojson again,
I tried to copy layers so I don't modify the original layers, but still changing one changes the other.
How I can copy the layers by value?
full example can be found here: playground
The answer for your tool it to load the file for every request.
The layers.ProjectToTile
, layers.Clip
and layers.Simplify
commands modify the layer data. This is by design for performance reasons. It's expected the feature collection/layers are loaded newly from a database on every request.
It possible we could add a Clone
method to geojson features and feature collections so you could do that instead for just reloading the file.
I have wrote a function that's deep copy the features collections, but I am not sure about the performance.
If you will do it at your end that would be great.