You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Aug 8, 2023. It is now read-only.
Repository navigation
This repository was archived by the owner on Aug 8, 2023. It is now read-only.
Add MGLCircle (with radius expressed in physical units) #2167
@incanus is there a roadmap plan for when MGLCircle will be implemented? Trying to update from the old "RMMapView" based SDK and the lack of replacement for an RMCircle is blocking me.
Thanks for the ping on this @cowgp. It hasn't been on the roadmap, but thinking this was relatively straightforward, I took a look today in 2167-MGLCircle.
The Cocoa side was pretty easy, but as it turns out, even though we have support for circles in the renderer and styles as of 0451aca, we don't have support for circle annotations in that API.
It's an interesting bind, since circles seems like shapes (have alpha & color) but behave like points (have a single coordinate and a scalar icon-like property radius). So the going has been a little more than I expected there, but I think I'm close.
@cowgp Sorry, I'm gonna have to say we're going to push this out a ways right now — too many higher priorities. If it was as easy as I had initially guessed, with pure Cocoa API, it would have been easy to rationalize, but increasing the surface area of our annotations API right now is not ideal given the other things we're integrating them with.
Stay tuned; I'd love to get this in, but it's not a priority roadmap right now.
@incanus - Thanks so much for looking into it, I appreciate the effort. I do hope it can remain a priority, seems like an important feature from my perspective. That said, totally understand that this update is all new underpinnings and thus there's a lot to build up.
@cowgp Depending on if your needs are truly at runtime, you could possibly use the existing support in the style spec for rendering circles in the meantime? mapbox/mapbox-gl-js#1446 shows an example of how this looks in the style. You could also consider mutating the style JSON and custom setting it at runtime as a workaround.
@incanus - I looked into the style spec you linked, but no it doesn't seem to be a viable solve for our needs. We have ~45k active users each with one or more geofences that they can set/modify at will. This is accomplished in the existing deprecated SDK by adding an annotation at the center point of the geofence and then in the layerForAnnotation delegate method returning an RMCircle with the correct radius in meters for the fence. It seems to me a clear case where an MGLCircle is necessary to have in the new SDK.
What I meant about mutating the style, though, could be a workaround here. The idea would be that you'd have a parsed representation of the style JSON (as, say, an NSMutableDictionary) to which you could add/modify items in the layers array using the circle primitive. Then, you'd send this out to JSON data with NSJSONSerialization and use it to set the styleJSON in the library.
Admittedly more work than just having MGLCircle, but an idea.
@jlubeck@KaneCheshire - After some internal discussions we are currently planning a major refactor to how shapes are generated to be added to a map. The current plan is to wait until that work is done before proceeding to address this issue. I know this is not ideal, but we believe the upcoming refactoring we’re working on will make adding all sorts of shapes to a map much easier for everyone in the long run. We’ll be sure to post back here as soon as we have more updates.
If you're looking for a workaround right now, one possibility would be to implement this with turf-swift. There are limitations to this approach though - this is not a true circle, but rather a an n-sided polygon (I just used the default 64 from the Turf.js documentation. Here is an example of my implementation. In addition, you can also update the shape of this circle on-the-fly using an MGLMapViewDelegate method that responds to map position changes.
Reacted by Julian Rex, Roland Egiazaryan, Antonio Zugaldia and Chloe Krawczyk
All, thanks for following this ticket. Our refactor is going well, and we are nearing a go/no-go decision on merging #14534 sometime this year after we resolve the remaining considerations.
Please upvote this comment if #14534 would work for your use case and solve your needs.
Per its description, the PR implements a new MGLCircle class, analogous to MapKit’s MKCircle or the Google Map SDK’s GMSCircle, which allows the developer to add spherical caps to the map view as overlays or to a shape source as polygons.
Reacted by Jan Lübeck, Josh Ferrara, Rihards, Steve, Denis Chagin, Alevtina Anishchenko, Egor Fedorov, Igor Vereninov and Rémi Thaunay
Any news on this issue? Looks like it was on good track back in August... And Github is returning a 500 error on the pull request so I can't see if there is progress there... Weird thing is that is the only PR that is returning an error, the others work just fine
Inspired by @incanus's answer in 2017, I came up with another solution, which doesn't requires usage of MGLCircleStyleLayer, but uses mapView(_:viewFor annotation:) -> MGLAnnotationView? delegate method.
Code below is written in Swift 5, using Mapbox-iOS-SDK 6.1.0, The performance seems ok on a simulator.
// Code below only covers 1 annotation use case for demo purpose, make changes if you need to support multiple annotations
classMyMapBoxViewController:UIViewController,MGLMapViewDelegate{/// Use this stored property to track my circleprivatevarcircleAnnotationView:MGLAnnotationView?privateletradiusMeters:Double=200privateletdivisor:Double=2.../// Return a clear image instead of default pin image, so the annotation will be invisible./// if you do not want to hide annotation, comment this method outfuncmapView(_mapView:MGLMapView,imageForannotation:MGLAnnotation)->MGLAnnotationImage?{letclearImage=mapView.dequeueReusableAnnotationImage(withIdentifier:"clear")??.init(image:UIImage(color:.clear)!,reuseIdentifier:"clear")returnclearImage}/// Return a circular `MGLAnnotationView` for the annotation, use ViewController's stored property `circleAnnotationView` to track itfuncmapView(_mapView:MGLMapView,viewForannotation:MGLAnnotation)->MGLAnnotationView?{
// use lng, lat to create a unique reuse identifier
letreuseIdentifier="\(annotation.coordinate.longitude)-\(annotation.coordinate.latitude)"
// reuse or create a circle view around the annotation
circleAnnotationView=mapView.dequeueReusableAnnotationView(withIdentifier:reuseIdentifier)??CustomAnnotationView(reuseIdentifier:reuseIdentifier)varradiusPoints=radiusMeters/mapView.metersPerPoint(atLatitude:annotation.coordinate.latitude)radiusPoints/=divisor // divide by (2) here so circle doesn't fill the entire screen, please choose your own divisor
circleAnnotationView?.bounds=.init(origin:.zero,size:.init(width:radiusPoints,height:radiusPoints))circleAnnotationView?.backgroundColor=UIColor.blue.withAlphaComponent(0.5)returncircleAnnotationView}/// When map zooms, rescale `circleAnnotationView` based on zoom levelfuncmapViewRegionIsChanging(_mapView:MGLMapView){guardcircleAnnotationView!=nilelse{return}varradiusPoints=radiusMeters/mapView.metersPerPoint(atLatitude:mapView.centerCoordinate.latitude)radiusPoints/=divisor // divide by (2) here so circle doesn't fill the entire screen, please choose your own divisor
circleAnnotationView?.bounds=.init(origin:.zero,size:.init(width:radiusPoints,height:radiusPoints))}}
Some subclass and extension used in code above
classCustomAnnotationView:MGLAnnotationView{overridefunclayoutSubviews(){super.layoutSubviews()
// Use CALayer’s corner radius to turn this view into a circle.
layer.cornerRadius=bounds.width/2layer.borderWidth=2layer.borderColor=UIColor.textBlue.cgColor}}extensionUIImage{/// Use color to init an `UIImage`convenienceinit?(color:UIColor,size:CGSize=CGSize(width:1,height:1)){letrect=CGRect(origin:.zero,size:size)UIGraphicsBeginImageContextWithOptions(rect.size,false,0.0)color.setFill()UIRectFill(rect)letimage=UIGraphicsGetImageFromCurrentImageContext()UIGraphicsEndImageContext()guardletcgImage=image?.cgImageelse{returnnil}self.init(cgImage:cgImage)}}
Activity
1ec5 commentedon Aug 24, 2015
ref #1740
cowgp commentedon Oct 27, 2015
@incanus is there a roadmap plan for when MGLCircle will be implemented? Trying to update from the old "RMMapView" based SDK and the lack of replacement for an RMCircle is blocking me.
incanus commentedon Oct 28, 2015
Thanks for the ping on this @cowgp. It hasn't been on the roadmap, but thinking this was relatively straightforward, I took a look today in
2167-MGLCircle.The Cocoa side was pretty easy, but as it turns out, even though we have support for circles in the renderer and styles as of 0451aca, we don't have support for circle annotations in that API.
It's an interesting bind, since circles seems like shapes (have alpha & color) but behave like points (have a single coordinate and a scalar
icon-like propertyradius). So the going has been a little more than I expected there, but I think I'm close.Stay tuned — will try to push this through soon.
/cc @friedbunny @jfirebaugh
incanus commentedon Oct 28, 2015
@cowgp Sorry, I'm gonna have to say we're going to push this out a ways right now — too many higher priorities. If it was as easy as I had initially guessed, with pure Cocoa API, it would have been easy to rationalize, but increasing the surface area of our annotations API right now is not ideal given the other things we're integrating them with.
Stay tuned; I'd love to get this in, but it's not a priority roadmap right now.
cowgp commentedon Oct 28, 2015
@incanus - Thanks so much for looking into it, I appreciate the effort. I do hope it can remain a priority, seems like an important feature from my perspective. That said, totally understand that this update is all new underpinnings and thus there's a lot to build up.
incanus commentedon Oct 28, 2015
@cowgp Depending on if your needs are truly at runtime, you could possibly use the existing support in the style spec for rendering circles in the meantime? mapbox/mapbox-gl-js#1446 shows an example of how this looks in the style. You could also consider mutating the style JSON and custom setting it at runtime as a workaround.
cowgp commentedon Nov 9, 2015
@incanus - I looked into the style spec you linked, but no it doesn't seem to be a viable solve for our needs. We have ~45k active users each with one or more geofences that they can set/modify at will. This is accomplished in the existing deprecated SDK by adding an annotation at the center point of the geofence and then in the layerForAnnotation delegate method returning an RMCircle with the correct radius in meters for the fence. It seems to me a clear case where an MGLCircle is necessary to have in the new SDK.
incanus commentedon Nov 9, 2015
What I meant about mutating the style, though, could be a workaround here. The idea would be that you'd have a parsed representation of the style JSON (as, say, an
NSMutableDictionary) to which you could add/modify items in thelayersarray using thecircleprimitive. Then, you'd send this out to JSON data withNSJSONSerializationand use it to set thestyleJSONin the library.Admittedly more work than just having
MGLCircle, but an idea.EasyAsABC123 commentedon Nov 19, 2015
Is this still not available with the new release of mapbox studio?
incanus commentedon Nov 19, 2015
Nope, no further movement here just yet. Workaround is to code circle primitives into your style and/or add them to the style JSON at runtime for now.
42 remaining items
jlubeck commentedon Feb 7, 2019
Any news on this front? (trying to get the bot not to close it again)
KaneCheshire commentedon Feb 7, 2019
Given it’s 3 years old, would be nice to have some sort of update on the issue for sure.
julianrex commentedon Mar 6, 2019
@jlubeck @KaneCheshire just wanted to assure you that this is on our list - and you should start seeing some movement on this issue soon.
KaneCheshire commentedon Mar 6, 2019
Thanks for the update @julianrex
jlubeck commentedon Mar 6, 2019
Great to hear that @julianrex !
captainbarbosa commentedon Apr 24, 2019
@jlubeck @KaneCheshire - After some internal discussions we are currently planning a major refactor to how shapes are generated to be added to a map. The current plan is to wait until that work is done before proceeding to address this issue. I know this is not ideal, but we believe the upcoming refactoring we’re working on will make adding all sorts of shapes to a map much easier for everyone in the long run. We’ll be sure to post back here as soon as we have more updates.
If you're looking for a workaround right now, one possibility would be to implement this with turf-swift. There are limitations to this approach though - this is not a true circle, but rather a an
n-sidedpolygon (I just used the default64from the Turf.js documentation. Here is an example of my implementation. In addition, you can also update the shape of this circle on-the-fly using anMGLMapViewDelegatemethod that responds to map position changes.jlubeck commentedon Apr 24, 2019
Thanks for the heads up @captainbarbosa
KaneCheshire commentedon Jul 17, 2019
How's the refactoring going? This issue will be 4 years old in just over a month :/
chloekraw commentedon Aug 7, 2019
All, thanks for following this ticket. Our refactor is going well, and we are nearing a go/no-go decision on merging #14534 sometime this year after we resolve the remaining considerations.
Please upvote this comment if #14534 would work for your use case and solve your needs.
Per its description, the PR implements a new
MGLCircleclass, analogous to MapKit’sMKCircleor the Google Map SDK’sGMSCircle, which allows the developer to add spherical caps to the map view as overlays or to a shape source as polygons.jlubeck commentedon Feb 10, 2020
Any news on this issue? Looks like it was on good track back in August... And Github is returning a 500 error on the pull request so I can't see if there is progress there... Weird thing is that is the only PR that is returning an error, the others work just fine
Thanks!
hdmdhr commentedon Mar 8, 2021
Inspired by @incanus's answer in 2017, I came up with another solution, which doesn't requires usage of
MGLCircleStyleLayer, but usesmapView(_:viewFor annotation:) -> MGLAnnotationView?delegate method.Code below is written in Swift 5, using Mapbox-iOS-SDK 6.1.0, The performance seems ok on a simulator.
Some subclass and extension used in code above