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.

MGLImageSource doesn't overlay an image #10138

Closed

Description

@fousa

Platform: iPhone iOS 11.0.1
Mapbox SDK version: Mapbox-iOS-SDK 3.7.0-beta.1

Steps to trigger behavior

Here is a small code snippet to render the radar.gif on the map as done in the example:

I added the MGLMapView as an outlet to my controller and this works fine until I want to display an overlay.

func mapView(_ mapView: MGLMapView, didFinishLoading style: MGLStyle) {
    let coordinates = MGLCoordinateQuad(
        topLeft: CLLocationCoordinate2D(latitude: 46.437, longitude: -80.425),
        bottomLeft: CLLocationCoordinate2D(latitude: 37.936, longitude: -80.425),
        bottomRight: CLLocationCoordinate2D(latitude: 37.936, longitude: -71.516),
        topRight: CLLocationCoordinate2D(latitude: 46.437, longitude: -71.516)
    )
    let source = MGLImageSource(identifier: "radar", coordinateQuad: coordinates, url: URL(string: "https://www.mapbox.com/mapbox-gl-js/assets/radar.gif")!)
    style.addSource(source)
}

Expected behavior

It should render the rain overlay on the map.

Actual behavior

It renders no image...

Activity

  1. added
    iOS
    on Oct 6, 2017
  2. jmkiley commented on Oct 6, 2017

    @jmkiley
    Contributor

    Hi @fousa -

    You will want to use the MGLImageSource to create a MGLRasterStyleLayer. The radar image should appear once you add that layer to your map's style.

    For example:

    func mapView(_ mapView: MGLMapView, didFinishLoading style: MGLStyle) {
            let coordinates = MGLCoordinateQuad(
                topLeft: CLLocationCoordinate2D(latitude: 46.437, longitude: -80.425),
                bottomLeft: CLLocationCoordinate2D(latitude: 37.936, longitude: -80.425),
                bottomRight: CLLocationCoordinate2D(latitude: 37.936, longitude: -71.516),
                topRight: CLLocationCoordinate2D(latitude: 46.437, longitude: -71.516))
            let source = MGLImageSource(identifier: "radar", coordinateQuad: coordinates, url: URL(string: "https://www.mapbox.com/mapbox-gl-js/assets/radar.gif")!)
            style.addSource(source)
            
            let layer = MGLRasterStyleLayer(identifier: "radar-layer", source: source)
            layer.rasterOpacity = MGLStyleValue(rawValue: 0.5)
            style.addLayer(layer)
    }
  3. fabian-guerra commented on Oct 6, 2017

    @fabian-guerra
    Contributor

    The example in MGLImageSource documentation does not mention creating a raster style. We should update the example clarifying it's usage.

    /cc @jmkiley

  4. fousa commented on Oct 6, 2017

    @fousa
    Author

    That makes sense. Now it works! Thanks for your quick response @jmkiley!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugdocumentationiOS

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions