mapbox / mapbox-gl-js

Interactive, thoroughly customizable maps in the browser, powered by vector tiles and WebGL
https://docs.mapbox.com/mapbox-gl-js/
Other
11.18k stars 2.22k forks source link

Ellipse / Circle Support #8160

Closed pwilczynski closed 5 years ago

pwilczynski commented 5 years ago

Motivation

We have a lot of situations in which data comes with error bounds / confidence windows - these often come in a format of either an ellipse or a circle expressed in terms of a centerpoint in lat,lng space and then either a radius (for a circle) or a major and minor axis + rotation angle for an ellipse.

However, the GeoJSON specification does not support this type of polygon natively, and as such there isn't a way to support this naturally in MBGL.

Design Alternatives

Currently, our frontend application creates GeoJSON Polgyons on the fly by incrementing the azimuth angle in a for loop - this causes the circle to be overly detailed when zoomed out or too chunky when zoomed in; additionally, it makes it very challenging to move the radius around because moving the centerpoint requires recomputing the projected circle.

Design

I suspect that this may not be a common case, but if you were interested, it might be interesting to support an extension of the GeoJSON spec via a custom layer which could also have ellipse and circles on it, and which would correctly project them into the EPSG:3857 space without clients needing to do this manually

Overall, I appreciate that this probably isn't the right direction for MBGLJS but I figured I'd provide the feedback - thanks as always for all of your help!

cs09g commented 5 years ago

For the alternative approach, there's a library for circle https://github.com/smithmicro/mapbox-gl-circle

pwilczynski commented 5 years ago

Yeah, we build that out using some of our own internal libraries, and we actually serialize the metadata into the polygon in order to reconstruct it if a user wants to make an edit to the radius, it's just more of an annoyance that there isn't a native GeoJSON representation for something like the Google Maps Circle.

cs09g commented 5 years ago

I think, this should be discussed on GeoJSON WG first as MBGL follows its standards. https://github.com/geojson

mourner commented 5 years ago

Yeah, I think we'll have to continue rely on conversion to polygons for these use cases in the nearest years since there's no defined standard for it, either in vector tiles or in GeoJSON.