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

Adding MGLRasterStyleLayer on map is not refreshing until we pan the map. #10160

Closed
ThiyagarajanShivSankaran opened this issue Oct 9, 2017 · 10 comments
Labels
bug Core The cross-platform C++ core, aka mbgl iOS Mapbox Maps SDK for iOS release blocker Blocks the next final release

Comments

@ThiyagarajanShivSankaran
Copy link

ThiyagarajanShivSankaran commented Oct 9, 2017

Platform: IOS
Mapbox SDK version: ios-v3.7.0-beta.1

Steps to trigger behavior

  1. Create a button called "Add Raster".
  2. Open map, wait to load all the layer's on map.
  3. Now tap on the button to add the MGLRasterStyleLayer.
  4. Adding MGLRasterStyleLayer on map is not refreshing until we pan the map.

Expected behavior

  1. MGLRasterStyleLayer should add on map.

Actual behavior

  1. But it's not adding on map, until the map is panned.

Here is how I am adding MGLRasterStyleLayer on map,

let source = MGLRasterSource(identifier: "custom-raster-source", tileURLTemplates: [basemapURL], options: [ .tileSize: 256 ])
let rasterLayer = MGLRasterStyleLayer(identifier: "custom-raster-layer", source: source)
rasterLayer.isVisible = true
mapView?.style?.addSource(source)
if let water = mapView?.style?.layer(withIdentifier: "water") {
      mapView?.style?.insertLayer(rasterLayer, below: water)
}

The same is working in older version of SDK.

@tobrun tobrun added the iOS Mapbox Maps SDK for iOS label Oct 9, 2017
@fabian-guerra fabian-guerra added this to the ios-v3.7.0 milestone Oct 9, 2017
@fabian-guerra
Copy link
Contributor

Hi, @ThiyagarajanShivSankaran. Thank you for using Mapbox. Looking at the source code you provided I realized that the source is added but raster layer.

If you add this line it will work:
mapView?.style?.addLayer(rasterLayer)

The full example should be:

let source = MGLRasterSource(identifier: "custom-raster-source", tileURLTemplates: [basemapURL], options: [ .tileSize: 256 ])
let rasterLayer = MGLRasterStyleLayer(identifier: "custom-raster-layer", source: source)
rasterLayer.isVisible = true
mapView?.style?.addSource(source)
mapView?.style?.addLayer(rasterLayer)

I tried this code with 3.6.4 and 3.7.0-beta.1 and works as expected.

3.6.4 3.7.0-beta.1
simulator screen shot - iphone 7 - 2017-10-09 at 10 58 47 simulator screen shot - iphone 7 - 2017-10-09 at 11 03 14

Let me know if this helps.

@fabian-guerra fabian-guerra added support and removed bug labels Oct 9, 2017
@fabian-guerra fabian-guerra removed this from the ios-v3.7.0 milestone Oct 9, 2017
@ThiyagarajanShivSankaran
Copy link
Author

ThiyagarajanShivSankaran commented Oct 11, 2017

Hi @fabian-guerra thank you for the reply , Actually I have missed the line while copying and pasting. Now edited the above code snippet. Also, updated the steps to reinvent the issue can you look at that, Thanks,

@ThiyagarajanShivSankaran ThiyagarajanShivSankaran changed the title Adding MGLRasterStyleLayer on map is not rendering until we pan the map. Adding MGLRasterStyleLayer on map is not refreshing until we pan the map. Oct 11, 2017
@fabian-guerra
Copy link
Contributor

Hi, @ThiyagarajanShivSankaran. Thank you for updating the example. I tried the sample code you provided and I still don't get any problem.

3.6.4 3.7.0-beta.1
3 6 4 3 7 0

I'm loading the style in:
func mapView(_ mapView: MGLMapView, didFinishLoading style: MGLStyle)

@ThiyagarajanShivSankaran
Copy link
Author

Hi @fabian-guerra adding raster style in:
func mapView(_ mapView: MGLMapView, didFinishLoading style: MGLStyle) is working for me as well.

Look at the below steps to reinvent,

  1. Open map view .
  2. Wait to load all the layer's on map.
  3. Create a button called Add Raster Style
  4. Now, tap on that button to add the style on map.
  5. It's not loading at the time of tap event, but if you pan map little it's loading.

If you are unable to reinvent just reply me. I will try to upload a video, Thanks.

@fabian-guerra fabian-guerra added bug and removed support labels Oct 12, 2017
@fabian-guerra
Copy link
Contributor

Hi, @ThiyagarajanShivSankaran. Thank you for providing the steps to reproduce the error. Now I see what is happening. I am going to track down the problem.

@fabian-guerra fabian-guerra added the Core The cross-platform C++ core, aka mbgl label Oct 12, 2017
@fabian-guerra
Copy link
Contributor

@jfirebaugh could you please take a look.

@fabian-guerra fabian-guerra added this to the ios-v3.7.0 milestone Oct 12, 2017
@fabian-guerra fabian-guerra added the release blocker Blocks the next final release label Oct 12, 2017
@fabian-guerra
Copy link
Contributor

@jfirebaugh this is the code sample to reproduce the problem.

    MGLRasterSource *source = [[MGLRasterSource alloc] initWithIdentifier:@"stamen-watercolor" tileURLTemplates:@[@"https://stamen-tiles.a.ssl.fastly.net/watercolor/{z}/{x}/{y}.jpg"] options:@{MGLTileSourceOptionTileSize:@256}];
    
    MGLRasterStyleLayer *rasterLayer = [[MGLRasterStyleLayer alloc] initWithIdentifier:@"custom-stamen-watercolor" source:source];
    
    rasterLayer.rasterOpacity = [MGLStyleValue valueWithRawValue:@0.4];
    rasterLayer.visible = YES;
    
    [self.mapView.style addSource:source];
    
    MGLStyleLayer *water = [self.mapView.style layerWithIdentifier:@"water"];
    if (water) {
        [self.mapView.style insertLayer:rasterLayer belowLayer:water];
    }

This must be called outside mapView:didFinishLoadingStyle:.

@jfirebaugh
Copy link
Contributor

@fabian-guerra Sure -- can you please push a branch with the code that reproduces the issue?

@jfirebaugh
Copy link
Contributor

Oops, didn't see your latest comment!

@fabian-guerra
Copy link
Contributor

@jfirebaugh no worries if it's more useful I made this branch that reproduces the problem. https://github.com/mapbox/mapbox-gl-native/tree/fabian-load-style-10160 Tap on Add Style and pan the map.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Core The cross-platform C++ core, aka mbgl iOS Mapbox Maps SDK for iOS release blocker Blocks the next final release
Projects
None yet
Development

No branches or pull requests

4 participants