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

Hook up hillshade style layers, raster DEM sources to iOS/macOS #11036

Merged
merged 5 commits into from
Jan 25, 2018

Conversation

1ec5
Copy link
Contributor

@1ec5 1ec5 commented Jan 24, 2018

This PR adds the MGLHillshadeStyleLayer class implemented in #10642 to the iOS and macOS map SDKs and implements a new MGLRasterDEMSource class to provide the data used by hillshade style layers. Along the way, the runtime styling code generation script had to be modified to treat hillshade style layers like raster style layers. Now MGLHillshadeStyleLayer is a subclass of MGLForegroundStyleLayer, just like MGLRasterStyleLayer.

Finally, a Debug ‣ Enhance Terrain menu item has been added to macosapp so that you can swap out any style’s Mapbox Terrain–based hillshading layers with a single Mapbox Terrain-RGB–based hillshading layer. The new layers are inserted in the same place as the old ones, though no effort is made to match the new layer’s appearance to the old layers’ appearance. That would be an interesting research project.

before after
Enhance!

Bloopers terraformed

The Mapbox Outdoors style has a single source that composites Mapbox Terrain with Mapbox Streets. So every layer is technically based on Mapbox Terrain. The Enhance Terrain command needed to remove only those based on the hillshade layer in Terrain.

Fixes #10991.

/cc @mollymerp @friedbunny

@1ec5 1ec5 added feature iOS Mapbox Maps SDK for iOS macOS Mapbox Maps SDK for macOS runtime styling labels Jan 24, 2018
@1ec5 1ec5 added this to the ios-v4.0.0 milestone Jan 24, 2018
@1ec5 1ec5 self-assigned this Jan 24, 2018
@1ec5 1ec5 requested review from friedbunny and mollymerp January 24, 2018 22:28
@lbud
Copy link
Contributor

lbud commented Jan 24, 2018

Finally, a Debug ‣ Enhance Terrain menu item has been added to macosapp so that you can swap out any style’s Mapbox Terrain–based hillshading layers with a single Mapbox Terrain-RGB–based hillshading layer.

😄

Copy link
Contributor

@mollymerp mollymerp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for taking this on @1ec5 – this looks good overall (but I do not have experience reading/writing ObjC) just left a few comments about the docs. not "approving" bc of my lack of familiarity w ObjC + iOS dev, so I'll leave the official ✅ to someone on the iOS team but the macoss debug app "enhance terrain" works great ✨

implementation only supports Mapbox Terrain RGB tiles
An `MGLHillshadeStyleLayer` is a style layer that renders raster <a
href="https://en.wikipedia.org/wiki/Digital_elevation_model">digital elevation
model</a> (DEM) tiles on the map.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that currently it only supports the mapbox terrain.rgb dem encoding scheme, but we plan to add support for other like Mapzen Terrarium?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From that Wikipedia article, I gathered that digital elevation model is a generic term, encompassing other formats like USGS DEM. Would Terrarium be considered a DEM format?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should avoid being overly broad here, especially if it’s suggesting something we don’t currently support.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It’s true that we should avoid overpromising, but I think it’s also important to draw a connection to the MGLRasterDEMSource class, which does use the same terminology, since the type system doesn’t otherwise guide the developer towards using MGLHillshadeStyleLayer with MGLRasterDEMSource.

### Example

```swift
let source = MGLRasterDEMSource(identifier: "hills", tileURLTemplates: ["https://example.com/raster-rgb/{z}/{x}/{y}.png"], options: [
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we use mapbox://mapbox.terrain-rgb url here so the example actually works if copied and pasted?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Few if any of these in-header examples work when copy-pasted. But since this one was so close to working, and since specifying a configuration URL is so much easier than specifying all the TileJSON parameters manually, I went ahead and implemented your suggestion.

let source = MGLRasterDEMSource(identifier: "hills", tileURLTemplates: ["https://example.com/raster-rgb/{z}/{x}/{y}.png"], options: [
.minimumZoomLevel: 9,
.maximumZoomLevel: 16,
.tileSize: 512,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this assuming devicePixelRatio of 2? otherwise tilesize should be 256px

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch. I blindly copied this from the raster source example without thinking about tile sizes.

@1ec5 1ec5 force-pushed the 1ec5-hillshade-10991 branch from 328b984 to 38d7753 Compare January 25, 2018 01:17
@1ec5 1ec5 force-pushed the 1ec5-hillshade-10991 branch from 38d7753 to 84cabd9 Compare January 25, 2018 01:26
implementation only supports Mapbox Terrain RGB tiles
An `MGLHillshadeStyleLayer` is a style layer that renders raster <a
href="https://en.wikipedia.org/wiki/Digital_elevation_model">digital elevation
model</a> (DEM) tiles on the map.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should avoid being overly broad here, especially if it’s suggesting something we don’t currently support.

}

// Find and remove all the style layers using those sources.
NSUInteger hillshadeIndex = NSNotFound;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

version="1.1"
inkscape:version="0.92.2 5c3e80d, 2017-08-06"
sodipodi:docname="hillshade.svg"
inkscape:export-filename="/Users/mxn/Desktop/symbol.png"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a big deal, but Inkscape sure does toss a lot of cruft into SVGs. There are a variety of SVG optimizers/minifiers out there, if you felt so inclined.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would be good tail work, since all the SVGs in the platform/macos/app/resources/ folder are in Inkscape SVG format.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@1ec5 1ec5 mentioned this pull request Jan 25, 2018
@1ec5 1ec5 merged commit b6747a8 into master Jan 25, 2018
@1ec5 1ec5 deleted the 1ec5-hillshade-10991 branch January 25, 2018 18:46
@1ec5 1ec5 mentioned this pull request Jan 27, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
feature iOS Mapbox Maps SDK for iOS macOS Mapbox Maps SDK for macOS runtime styling
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants