Skip to content
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

Supporting Non GeoJSON Shapes via Custom Shapes #761

Open
mcwhittemore opened this issue Apr 1, 2018 · 3 comments
Open

Supporting Non GeoJSON Shapes via Custom Shapes #761

mcwhittemore opened this issue Apr 1, 2018 · 3 comments
Labels

Comments

@mcwhittemore
Copy link
Contributor

Currently Draw is tightly coupled with the GeoJSON spec. I've long defended this decision because I think it helps reduce bugs by limiting the surface area Draw needs to manage to the GeoJSON spec. That said, a few months back @flippmoke, @sgillies and myself had a conversation about the vector tile spec that made me start to question if the job of Draw is to create good GeoJSON or if its to create data to be rendered to the map which could be any content type than can be turned in the vector tiles.

Anyway, while time has not given me clarity on how Draw might change to create VT rather than GeoJSON, considering the consequences of such a shift has convinced me that user defined Custom Shapes should be a thing in Draw just like Custom Modes.

Some custom shapes that I have in mind are:

  • Square
  • Triangle
  • Hexagon
  • Circle

You know, simple things people have asked for for a long time but I've said no to because they aren't in the GeoJSON spec.

Why custom

The main problem I've long had with the out of spec shape suggestions is that they all depend on adding a magic property to a Feature. While this is a great idea (really) the fact is that much of the GeoJSON users drop into Draw wasn't created by them and thus might use said magic property for different reasons.

That said, as a developer, you should have the power to create great software despite the above problem and, the best way I see to do that well, is custom shapes.

How would these work

Like we did with modes when creating the custom modes, the Draw API would need to expose a way to change the list of shapes by passing your own JS objects into Draw. For modes we let you drop the core modes if you wanted to, for shapes we'd continue to require Point, LineString, Polygon and their Multi* counterparts to stay.

Part of the Custom Shape interface would be a function that takes a GeoJSON Feature and returns true or false to indicate if this GeoJSON matches the Custom Shapes convention like the code below.

var square = {};

customShape.featureIsShape = function(feature) {
  // This would be a pretty poor check
  return feature.properties.type === 'square';
}

Would draw_polygon make my shape?

Nope. Custom Shape creators would likely want to create a Custom Mode to draw their shapes.

Next Steps

Does this sound like a good idea to other users out in the wild? If not, please explain what your concerns are below. If so, do you have any time to put into helping make this happen either via PRs or brainstorming?

@e-n-f
Copy link

e-n-f commented Apr 2, 2018

Are these more like polygons or more like icons?

If they're more like icons, there is some perhaps-relevant discussion in the gridded-data ticket for the vector tile spec: mapbox/vector-tile-spec#50 (comment)

Instead of having the magic in properties it might be better to have another set of feature characteristics at the top level of the Feature object, maybe a mapbox object where we contain whatever GeoJSON extensions Mapbox products might need. I feel like properties ought to belong to the user, not the implementation.

@mcwhittemore
Copy link
Contributor Author

I assume that there are more like polygons. The key thing here though would be creating a module interface so users can bring their own ideas into Draw.

Instead of having the magic in properties it might be better to have another set of feature characteristics at the top level of the Feature object

This is a great suggestion and if we run out Custom Shapes would be a nice thing to put in the docs/examples for how to make them.

@iamanvesh
Copy link
Contributor

#767 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants