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

Cannot move MGLCircleStyleLayer with draggable MGLAnnotationView #8964

Closed
evgzor opened this issue May 11, 2017 · 5 comments
Closed

Cannot move MGLCircleStyleLayer with draggable MGLAnnotationView #8964

evgzor opened this issue May 11, 2017 · 5 comments
Labels
annotations Annotations on iOS and macOS or markers on Android archived Archived because of inactivity feature iOS Mapbox Maps SDK for iOS runtime styling

Comments

@evgzor
Copy link

evgzor commented May 11, 2017

iOS
3.5.4:

Steps to trigger behavior

  1. Create MGLAnnotation with MGLCircleStyleLayer
  2. Make MGLAnnotation draggable
  3. Move annotation by dragging

Expected behavior

MGLCircleStyleLayer can move with MGLCircleStyleLayer

Actual behavior

MGLCircleStyleLayer is static and no API referenced to it. Only reloadStyle: reload all styles - and flash the screen
screenshot_ios_2 14 0 7 1
code:

func mapView(_ mapView: MGLMapView, didFinishLoading style: MGLStyle) {
        guard let annotations = mapView.annotations else {
            return
        }
        if !annotations.isEmpty {
            let point = MGLPointAnnotation()
            guard let coordinate = mapView.annotations?.first?.coordinate else {
                return
            }
            point.coordinate = coordinate
            let source = MGLShapeSource(identifier: "circle", shape: point, options: nil)
            style.addSource(source)

            let layer = MGLCircleStyleLayer(identifier: "circle", source: source)
            let radiusPoints = 80.0
            layer.circleRadius = MGLStyleValue(rawValue: NSNumber(value: radiusPoints))
            layer.circleColor = MGLStyleValue(rawValue: UIColor.gray)
            layer.circleOpacity = MGLStyleValue(rawValue: 0.5)
            style.addLayer(layer)
        }
    }
@friedbunny friedbunny added the iOS Mapbox Maps SDK for iOS label May 11, 2017
@boundsj boundsj added support annotations Annotations on iOS and macOS or markers on Android runtime styling feature and removed support labels May 11, 2017
@boundsj
Copy link
Contributor

boundsj commented May 11, 2017

Hi @evgzor. It sounds like you would like the changes that a draggable MGLAnnotationView makes to the coordinate in the MGLPointAnnotation it represents to automatically cause the shape in the source to be updated to reflect the latest value of the annotation's coordinate.

The code you provided suggests how one might think this ought to work. Since the MGLPointAnnotation is passed directly to the MGLShapeSource, the source seems like it could keep a reference to and monitor the annotation (shape) and make the internal calls to the gl system that would actually update the shape on the map automatically.

#7458 tracks making the shape property of a source mutable. I don't think we were already discussing the feature you've described but I think we should keep this ticket open as a feature request. This does seem like it might be convenient for single points and maybe also other kinds of more complex shapes.

In the meantime, you should already be able to do what you are asking for here by observing the coordinate of the annotation that the MGLAnnotationView represents and mutating the shape property of the MGLShapeSource when the coordinate changes. You will need to set the source's shape property to a new MGLPointAnnotation each time the annotation coordinate is updated. Also, since it appears you are using annotation views (MGLAnnotationView is the only class that has a draggable API) you might consider using a more complex MGLAnnotationView to get the effect you are looking for if doing the extra work to connect the native view and the style layer seems like too much.

@staticdreams
Copy link

@boundsj , I'm trying to implement what you're suggesting by observing MGLPointAnnotation coordinate changes and setting the MGLShapeSource shape coordinate to a new coordinate, but it seem to be read-only. Any suggestions?

screen shot 2017-07-16 at 08 44 17

@boundsj
Copy link
Contributor

boundsj commented Jul 18, 2017

Hi @staticdreams, I think I suggested setting the shape property itself. Have you tried that?

@staticdreams
Copy link

@boundsj Thank you Jesse, it seem to work :)

@stale stale bot added the archived Archived because of inactivity label Nov 5, 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
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
annotations Annotations on iOS and macOS or markers on Android archived Archived because of inactivity feature iOS Mapbox Maps SDK for iOS runtime styling
Projects
None yet
Development

No branches or pull requests

4 participants