Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Add Circle (with radius expressed in physical units) #4312

Closed
tobrun opened this issue Mar 14, 2016 · 14 comments · Fixed by #14429
Closed

Add Circle (with radius expressed in physical units) #4312

tobrun opened this issue Mar 14, 2016 · 14 comments · Fixed by #14429
Labels
Android Mapbox Maps SDK for Android Google Maps parity For feature parity with the Google Maps SDK for Android or iOS

Comments

@tobrun
Copy link
Member

tobrun commented Mar 14, 2016

A circle on the earth's surface on a specific LatLng as center.
iOS equivalent: #2167

@tobrun tobrun added the Android Mapbox Maps SDK for Android label Mar 14, 2016
@tmcw
Copy link
Contributor

tmcw commented Mar 14, 2016

Given that there are circles defined from

  • Pixel radius
  • Meter radius, but always a circle in mercator
  • Meter radius, and actually a spherical cap, so sometimes oblong on mercator

We should have a solid vocabulary that helps differentiate from the beginning.

@tobrun
Copy link
Member Author

tobrun commented Mar 14, 2016

I created this issue for parity with gmaps. There they define this circle as sperical cap.

@zugaldia
Copy link
Member

We're in a good position now to add this API. Meanwhile, we currently have three workarounds:

@1ec5
Copy link
Contributor

1ec5 commented Sep 15, 2016

Note the differences between the three approaches: the polygon approach in #2167 (comment) is for a circle whose radius corresponds to a physical ground distance, whereas the MarkerView and CircleLayerActivity approaches are for circles whose radii correspond to fixed screen distances, regardless of the zoom level or latitude.

@tobrun tobrun added the Google Maps parity For feature parity with the Google Maps SDK for Android or iOS label Aug 11, 2017
@bilthon
Copy link

bilthon commented Aug 18, 2017

Using a polygon feels like a hackish workaround. This feature should really be supported at the native level.

@tobrun
Copy link
Member Author

tobrun commented Aug 18, 2017

Circles are supported through CircleLayer, we do not expose an annotation API for it atm.

@bilthon
Copy link

bilthon commented Aug 18, 2017

The problem I have with the CircleLayer right now is that the only way I found of creating a circle with dynamic in-app data is using a geoJSON source. But geojson doesn't seem to allow us to specify a circle. https://stackoverflow.com/questions/16942697/geojson-circles-supported-or-not

@zugaldia
Copy link
Member

The problem I have with the CircleLayer right now is that the only way I found of creating a circle with dynamic in-app data is using a geoJSON source. But geojson doesn't seem to allow us to specify a circle.

For a CircleLayer is enough if you set a point to indicate the center of the circle. For example, you could create a GeoJsonSource with:

GeoJsonSource geoJsonSource = new GeoJsonSource("circle-source",
    Point.fromCoordinates(Position.fromLngLat(-0.07520, 51.50550)));
mapboxMap.addSource(geoJsonSource);

And then use the CircleLayer to visualize it:

CircleLayer circleLayer = new CircleLayer("circle-layer", "circle-source");
circleLayer.setProperties(
    PropertyFactory.visibility(Property.VISIBLE),
    PropertyFactory.circleRadius(25f),
    PropertyFactory.circleColor(Color.argb(1, 55, 148, 179)));
mapboxMap.addLayer(circleLayer);

If you need more control over the circle, another option you might want to look into is the SymbolLayer. The LocationLayer plugin is a good example of it.

@1ec5
Copy link
Contributor

1ec5 commented Aug 21, 2017

@tobrun @zugaldia, please note that there’s a fundamental difference between the kind of circle drawn by CircleLayer (whose radius is expressed in screen units) and the kind of circle that’s tracked in this ticket (whose radius corresponds to a physical distance). Please refer to #4312 (comment). This is still a valid feature request, although there’s a tension between implementing this very useful feature while at the same time conforming to the Simple Features specification and GeoJSON.

@1ec5 1ec5 changed the title Add Circle Add Circle (with radius expressed in physical units) Aug 21, 2017
@stale stale bot added the archived Archived because of inactivity label Nov 4, 2018
@stale
Copy link

stale bot commented Dec 1, 2018

This issue has been automatically detected as stale because it has not had recent activity and will be archived. Thank you for your contributions.

@stale stale bot closed this as completed Dec 1, 2018
@LukasPaczos LukasPaczos reopened this Feb 14, 2019
@stale stale bot removed the archived Archived because of inactivity label Feb 14, 2019
@jrgonzalezg
Copy link

Now there seems to be annotation support for circles using CircleOptions and CircleManager. And the CircleOptions seem quite similar to the Google Maps version, but unlike the behavior on Google Maps it seems that the radius here is using screen pixels instead of meters and the circle does not properly scale with zoom. Workarounds like sampling the circumference and using a polygon with FillManager work but require quite a bit of boilerplate. Also I don't really understand what's the purpose of CircleManager / CircleOptions working that way with radius in device pixels and ignoring zoom changes. Will it be possible to fix this to work as Google Maps (if there aren't any valid use cases for the current behavior) or to provide a variant that works like in Google Maps?

@androideveloper
Copy link

Coming from Google Maps and found the same issue. Any updates on this?

@tobrun
Copy link
Member Author

tobrun commented Apr 15, 2019

First step to implement this feature is supporting http://turfjs.org/docs/#circle in the java port of turf. This is ticketed in mapbox/mapbox-java#1002.

edit: that functionality is already implemented so this should already be possible today. Will create a small example around this.

edit: ezgif com-video-to-gif (58)

@miladsalimiiii
Copy link

The problem I have with the CircleLayer right now is that the only way I found of creating a circle with dynamic in-app data is using a geoJSON source. But geojson doesn't seem to allow us to specify a circle.

For a CircleLayer is enough if you set a point to indicate the center of the circle. For example, you could create a GeoJsonSource with:

GeoJsonSource geoJsonSource = new GeoJsonSource("circle-source",
    Point.fromCoordinates(Position.fromLngLat(-0.07520, 51.50550)));
mapboxMap.addSource(geoJsonSource);

And then use the CircleLayer to visualize it:

CircleLayer circleLayer = new CircleLayer("circle-layer", "circle-source");
circleLayer.setProperties(
    PropertyFactory.visibility(Property.VISIBLE),
    PropertyFactory.circleRadius(25f),
    PropertyFactory.circleColor(Color.argb(1, 55, 148, 179)));
mapboxMap.addLayer(circleLayer);

If you need more control over the circle, another option you might want to look into is the SymbolLayer. The LocationLayer plugin is a good example of it.

Did you try this ?! for draw circle

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Android Mapbox Maps SDK for Android Google Maps parity For feature parity with the Google Maps SDK for Android or iOS
Projects
None yet
Development

Successfully merging a pull request may close this issue.

9 participants