ncssar / caltopo_python

Python interface to unofficial CalTopo API
GNU General Public License v3.0
1 stars 1 forks source link

Any way to assign marker IDs from client side? #20

Closed petered closed 1 month ago

petered commented 1 month ago

Hey all.

I've noticed that if you add a marker through the v1/map/[MAP_ID]/Marker endpoint, if you provide a pre-specified id in your marker (as a UUID like 5990b8bf-5592-4123-90b1-6337e23453dd), the marker returned in the result has a different ID.

This is inconvenient if you want to sync caltopo with a local database - because if you create a point locally, you need to wait for a response from CalTopo servers to get its "final" id.

Has anyone found a way to submit Markers (or general geoJSON objects) to CalTopo and have CalTopo accept the ID they're submitted with?

caver456 commented 1 month ago

Hello @petered - interesting question, I've never looked into the interaction between a CTD (CalTopo Desktop) feature's ID before sync vs after sync. Either way, I'm guessing it's not user-controllable at all, and any feature ID passed at creation time is completely ignored if it doesn't match an existing feature ID - but you'd probably need to ask the caltopo folks directly (help@caltopo.com).

Note this line from the docs at the start of .editFeature() explanation:

This is a convenience method that calls the appropriate .add… method with existingId specified.

Basically as far as the caltopo API goes, here's my understanding, and the way caltopo_python is built: there is no separate 'edit' request - the same request is used whether adding or editing; the only difference is whether a feature ID is specified in the request. Case 1: If an ID is specified and it matches an existing feature, the request is used to edit that feature. Case 2: If no ID is specified, the request is used by the servers to add a feature. I never checked to see what happens if (Case 3) an ID is specified that doesn't match any existing feature, but from what you observed, sounds like the ID is ignored and the request is used to add a feature, just as if no ID was specified at all.

If you find out otherwise please do post it here!

petered commented 1 month ago

Hey @caver456 , figured it out - and thanks for the hint to look into how editing works - that was what revealed it. You CAN assign marker ids from the client side.

Instead of calling the v1/map/[MAP_ID]/Marker endpoint, you call the v1/map/[MAP_ID]/Marker/[MARKER_ID] endpoint, eg.

v1/map/D0RBMRR/Marker/7c789929-96eb-4656-bf3a-0764ca975b87

... Passing the geoJSON object in the payload - which itself contains the marker id. Haven't checked which of those 2 marker ids matters.