-
-
Notifications
You must be signed in to change notification settings - Fork 58
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unclear requirements for GeoJSON to be provided in addFeatures #177
Comments
Hey @nerik thanks for raising this, appreciate the feedback about this! Agree these requirements could be made a little bit clearer. I was thinking about it yesterday and wondered if maybe we could make the There are some considerations around this however - imagine a user adds a series of Polygons to their Terra Draw instance, we don't necessarily know if that should be associated with This being said I agree it's not super user friendly and maybe there's a 'sensible default' that would work for 80% of peoples use cases, which I imagine would just be adding and associating Polygons to the TerraDrawPolygonMode in the example describe above. I might experiment with this today and see if there's an approach that feels right! |
Hey @nerik - I was looking into this more deeply today. I noticed the first point about IDs will fail if there is an existing id provided - which made me think you probably have IDs which are not UUIDv4. I have raised a PR which opens up the types of IDs that you can use with Terra Draw, so if users have features that have a different ID strategy then you can bring your own. Here's an example if you wanted to use incrementing integers: const draw = new TerraDraw({
adapter,
modes,
idStrategy: {
isValidId: (id) => typeof id === "number" && Number.isInteger(id),
getId: (function () {
let id = 0;
return function () {
return ++id;
};
})() // Returns a function that returns incrementing integer ids
},
}); This way you can provide features with any id type the user likes, and it will also generate new ids using the draw.addFeatures([
{
type: "Feature",
geometry: {
type: "Point",
coordinates: [-1.825859, 51.178867],
},
properties: {
mode: "point",
},
},
]); The PR also exposes a This gives the developer more control over ids and id validation which was in your first point. With regards to the second point, I think at least for now making users explicitly provide the mode they want to assign the feature to feels right, given the many ways users could choose to use Terra Draw. Hopefully the documentation around this is clear enough and if not would totally welcome feedback on improving it. I appreciate this is slightly more long winded, but I think the trade off is worth it to make sure features end up associate with their correct modes. |
Ah, awesome, thanks. Shorter ids are definitely a win in scenarios when data is stored in the URL 🎉 |
Hey @nerik - we recently merged some PRs that don't explicitly throw an error on adding features with the Please see the following PRs for more details: |
Using
addFeatures
, validation fails if features:id
set with a proper UUID stringmode
set in the feature's properties.This behavior might be problematic for a few different reasons:
it's unclear from the docs what is requiredmissed that bit in the docs, sorry https://github.com/JamesLMilner/terra-draw/blob/main/guides/4.MODES.md#loading-featurestype GeoJSONStoreFeatures = Feature<GeoJSONStoreGeometries, DefinedProperties>;
)Not sure if/how you want to see these things address but happy to give a hand. Cheers!
The text was updated successfully, but these errors were encountered: