Is there anyway you can allow users to edit the geometry of shapes (e.g. move an existing point) using the CartoDB.js or CartDB SQL API libraries.
I realise you can do this directly in the CartoDB app but I don't want to give the client access to the CartoDB app and would rather them edit the data through a separate web app.
The only thought I have had so far is to convert the features to GeoJSON and use available leaflet functions to move the data and then update the location via the SQL API.
1 Answer 1
I'm not aware of a plugin that lets you do this right now, but it could be handy! In the meantime, I'd recommend looking into using Leaflet and Leaflet.draw.
My process for doing this would be:
- Load the geometry that a user is editing into the Leaflet.draw layer. P
- Listen for
draw:created
,draw:edited
, anddraw:deleted
. - Push changes to CartoDB as GeoJSON using the SQL API (
UPDATE
orDELETE
, as appropriate) as you suggest.
(3) gets a little complicated because you need to authenticate with CartoDB to change your table, and you likely won't want to use your API key in the client (then anyone would be able to edit your tables). So you'll probably either want to:
- proxy the SQL API requests through your server, using the API key on your server, or
- use OAuth, which you could potentially use client-side.