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

Simple polylines & polygons don't appear if initialized with map #2322

Closed
friedbunny opened this issue Sep 14, 2015 · 2 comments · Fixed by #2420
Closed

Simple polylines & polygons don't appear if initialized with map #2322

friedbunny opened this issue Sep 14, 2015 · 2 comments · Fixed by #2420
Assignees
Labels
bug iOS Mapbox Maps SDK for iOS

Comments

@friedbunny
Copy link
Contributor

Polylines and polygons that don't require much processing before being added to the map fail to ever appear, if initialized concurrently with the map. Adding the slightest delay or drawing the shapes in viewDidAppear causes them to appear as expected.

The GeoJSON example works when drawn directly in viewDidLoad.
#2289 fixed this problem for markers and complex shapes, but I clearly must have missed the simple case during testing.

Demo (based on this):

import Mapbox

class ViewController: UIViewController, MGLMapViewDelegate {

    var mapView: MGLMapView!

    override func viewDidLoad() {
        super.viewDidLoad()

        mapView = MGLMapView(frame: view.bounds)
        mapView.autoresizingMask = .FlexibleWidth | .FlexibleHeight

        mapView.setCenterCoordinate(CLLocationCoordinate2D(latitude: 45.520486,
                                                           longitude: -122.673541),
                                    zoomLevel: 11, animated: false)
        view.addSubview(mapView)

        mapView.delegate = self

        // this works
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0), dispatch_get_main_queue(), {
            self.drawShape()
        })

        // this does not work
        drawShape()
    }

    override func viewDidAppear(animated: Bool) {
        // this works
        drawShape()
    }

    func drawShape() {
        // Create a coordinates array to hold all of the coordinates for our shape.
        var coordinates = [
            CLLocationCoordinate2D(latitude: 45.522585, longitude: -122.685699),
            CLLocationCoordinate2D(latitude: 45.534611, longitude: -122.708873),
            CLLocationCoordinate2D(latitude: 45.530883, longitude: -122.678833),
            CLLocationCoordinate2D(latitude: 45.547115, longitude: -122.667503),
            CLLocationCoordinate2D(latitude: 45.530643, longitude: -122.660121),
            CLLocationCoordinate2D(latitude: 45.533529, longitude: -122.636260),
            CLLocationCoordinate2D(latitude: 45.521743, longitude: -122.659091),
            CLLocationCoordinate2D(latitude: 45.510677, longitude: -122.648792),
            CLLocationCoordinate2D(latitude: 45.515008, longitude: -122.664070),
            CLLocationCoordinate2D(latitude: 45.502496, longitude: -122.669048),
            CLLocationCoordinate2D(latitude: 45.515369, longitude: -122.678489),
            CLLocationCoordinate2D(latitude: 45.506346, longitude: -122.702007),
            CLLocationCoordinate2D(latitude: 45.522585, longitude: -122.685699),
        ]

        let shape = MGLPolygon(coordinates: &coordinates, count: UInt(coordinates.count))

        mapView.addAnnotation(shape)
    }
}

/cc @incanus

@friedbunny friedbunny added bug iOS Mapbox Maps SDK for iOS labels Sep 14, 2015
@incanus
Copy link
Contributor

incanus commented Sep 14, 2015

Hmm, this shouldn't be related to #1675 / #2289 as shapes aren't dependent upon the sprite or sprite store initialization the way marker images are.

@friedbunny
Copy link
Contributor Author

shapes aren't dependent upon the sprite or sprite store initialization the way marker images are.

Totally. Something definitely improved the timing issue that did exist, in any case, as dispatch_after zero seconds didn't previously work.

@jfirebaugh jfirebaugh self-assigned this Sep 24, 2015
jfirebaugh added a commit that referenced this issue Sep 25, 2015
First, move style mutation code out of StyleParser and into AnnotationManager,
coalescing it with the mutation code for shape layers.

Second, allow AnnotationManager to keep track of stale tiles entirely
internally. There's no reason to pass sets of TileIDs around.

Third, correct the logic for invalidating the shape source. Since
AnnotationManager does not track shape invalidations on a tile-by-tile basis,
don't try to invalidate the shape source tile-by-tile.

Fixes #1675
Fixes #2322
Fixes #2095
jfirebaugh added a commit that referenced this issue Sep 28, 2015
First, move style mutation code out of StyleParser and into AnnotationManager,
coalescing it with the mutation code for shape layers.

Second, allow AnnotationManager to keep track of stale tiles entirely
internally. There's no reason to pass sets of TileIDs around.

Third, correct the logic for invalidating the shape source. Since
AnnotationManager does not track shape invalidations on a tile-by-tile basis,
don't try to invalidate the shape source tile-by-tile.

Fixes #1675
Fixes #2322
Fixes #2095
AndwareSsj pushed a commit to AndwareSsj/mapbox-gl-native that referenced this issue Nov 6, 2015
First, move style mutation code out of StyleParser and into AnnotationManager,
coalescing it with the mutation code for shape layers.

Second, allow AnnotationManager to keep track of stale tiles entirely
internally. There's no reason to pass sets of TileIDs around.

Third, correct the logic for invalidating the shape source. Since
AnnotationManager does not track shape invalidations on a tile-by-tile basis,
don't try to invalidate the shape source tile-by-tile.

Fixes mapbox#1675
Fixes mapbox#2322
Fixes mapbox#2095
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug iOS Mapbox Maps SDK for iOS
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants