Skip to content
This repository was archived by the owner on Aug 8, 2023. It is now read-only.
This repository was 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

Description

@friedbunny

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

Activity

  1. added
    iOS
    on Sep 14, 2015
  2. incanus commented on Sep 14, 2015

    @incanus
    Contributor

    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.

  3. friedbunny commented on Sep 14, 2015

    @friedbunny
    ContributorAuthor

    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.

  4. self-assigned this
    on Sep 24, 2015
  5. added a commit that references this issue on Nov 6, 2015
    eb9fcd8
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugiOS

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions