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

legacy raster mapID API #1844

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions include/mbgl/ios/MGLMapView.h
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,10 @@ IB_DESIGNABLE
* To display the default style, set this property to `nil`. */
@property (nonatomic, null_resettable) NSURL *styleURL;

/** Compatibility API to use legacy raster-only tile sources. Expected format is e.g. `examples.map-pgygbwdm`.
* @param mapID A legacy Mapbox raster-only map ID. */
- (void)setRasterMapID:(NSString *)mapID;

/** Currently active style classes, represented as an array of string identifiers. */
@property (nonatomic) NS_ARRAY_OF(NSString *) *styleClasses;

Expand Down
23 changes: 23 additions & 0 deletions platform/ios/MGLMapView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,29 @@ - (void)setStyleURL:(nullable NSURL *)styleURL
_mbglMap->setStyleURL([[styleURL absoluteString] UTF8String]);
}

- (void)setRasterMapID:(NSString *)mapID
{
NSMutableString *templateJSON = [[[NSString alloc] initWithContentsOfFile:
[MGLMapView pathForBundleResourceNamed:@"raster-v7"
ofType:@"json"
inDirectory:nil]
encoding:NSUTF8StringEncoding
error:nil] mutableCopy];

[templateJSON replaceOccurrencesOfString:@"mapbox://xxxxxx"
withString:[NSString stringWithFormat:@"mapbox://%@", mapID]
options:0
range:NSMakeRange(0, templateJSON.length)];

NSString *tempFile = [[NSTemporaryDirectory()
stringByAppendingString:@"/"]
stringByAppendingString:[[NSUUID UUID] UUIDString]];

[templateJSON writeToFile:tempFile atomically:YES encoding:NSUTF8StringEncoding error:nil];

_mbglMap->setStyleURL([[@"asset://" stringByAppendingString:tempFile] UTF8String]);
}

- (void)commonInit
{
_isTargetingInterfaceBuilder = NSProcessInfo.processInfo.mgl_isInterfaceBuilderDesignablesAgent;
Expand Down
25 changes: 25 additions & 0 deletions platform/ios/resources/raster-v7.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"version": 7,
"name": "Raster",
"sources": {
"raster": {
"type": "raster",
"url": "mapbox://xxxxxx",
"tileSize": 256
}
},
"layers": [{
"id": "background",
"type": "background",
"paint": {
"background-color": "#666"
}
}, {
"id": "raster",
"type": "raster",
"source": "raster",
"paint": {
"raster-fade-duration": 100
}
}]
}
2 changes: 1 addition & 1 deletion src/mbgl/map/map_context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ void MapContext::updateAnnotationTiles(const std::unordered_set<TileID, TileID::
shapeLayer->type = (shapeStyle.is<LineProperties>() ? StyleLayerType::Line : StyleLayerType::Fill);

// add to end of other shape layers just before (last) point layer
style->layers.emplace((style->layers.end() - 2), shapeLayer);
style->layers.emplace((style->layers.end() - 1), shapeLayer);

// create shape bucket & connect to source
util::ptr<StyleBucket> shapeBucket = std::make_shared<StyleBucket>(shapeLayer->type);
Expand Down