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

Add option to restrict tile source to bounds #11141

Merged
merged 1 commit into from
Feb 8, 2018
Merged
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
2 changes: 2 additions & 0 deletions platform/darwin/docs/guides/For Style Authors.md.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ the following terms for concepts defined in the style specification:

In the style specification | In the SDK
---------------------------|---------
bounds | coordinate bounds
filter | predicate
function type | interpolation mode
id | identifier
Expand Down Expand Up @@ -200,6 +201,7 @@ In style JSON | In TileJSON | In the SDK
`tiles` | `tiles` | `tileURLTemplates` parameter in `-[MGLTileSource initWithIdentifier:tileURLTemplates:options:]`
`minzoom` | `minzoom` | `MGLTileSourceOptionMinimumZoomLevel`
`maxzoom` | `maxzoom` | `MGLTileSourceOptionMaximumZoomLevel`
`bounds` | `bounds` | `MGLTileSourceOptionCoordinateBounds`
`tileSize` | — | `MGLTileSourceOptionTileSize`
`attribution` | `attribution` | `MGLTileSourceOptionAttributionHTMLString` (but consider specifying `MGLTileSourceOptionAttributionInfos` instead for improved security)
`scheme` | `scheme` | `MGLTileSourceOptionTileCoordinateSystem`
Expand Down
14 changes: 14 additions & 0 deletions platform/darwin/src/MGLTileSource.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,20 @@ extern MGL_EXPORT const MGLTileSourceOption MGLTileSourceOptionMinimumZoomLevel;
*/
extern MGL_EXPORT const MGLTileSourceOption MGLTileSourceOptionMaximumZoomLevel;

/**
An `NSValue` object containing an `MGLCoordinateBounds` struct that specifies
the geographic extent of the source.

If this option is specified, the SDK avoids requesting any tile that falls
outside of the coordinate bounds. Otherwise, the SDK requests any tile needed
to cover the viewport, as it does by default.

This option corresponds to the `bounds` key in the
<a href="https://github.com/mapbox/tilejson-spec/tree/master/2.1.0">TileJSON</a>
specification.
*/
extern MGL_EXPORT const MGLTileSourceOption MGLTileSourceOptionCoordinateBounds;

#if TARGET_OS_IPHONE
/**
An HTML string defining the buttons to be displayed in an action sheet when the
Expand Down
12 changes: 12 additions & 0 deletions platform/darwin/src/MGLTileSource.mm
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#import "MGLTileSource_Private.h"

#import "MGLAttributionInfo_Private.h"
#import "MGLGeometry_Private.h"
#import "NSString+MGLAdditions.h"
#import "NSValue+MGLAdditions.h"

#if TARGET_OS_IPHONE
#import <UIKit/UIKit.h>
Expand All @@ -13,6 +15,7 @@

const MGLTileSourceOption MGLTileSourceOptionMinimumZoomLevel = @"MGLTileSourceOptionMinimumZoomLevel";
const MGLTileSourceOption MGLTileSourceOptionMaximumZoomLevel = @"MGLTileSourceOptionMaximumZoomLevel";
const MGLTileSourceOption MGLTileSourceOptionCoordinateBounds = @"MGLTileSourceOptionCoordinateBounds";
const MGLTileSourceOption MGLTileSourceOptionAttributionHTMLString = @"MGLTileSourceOptionAttributionHTMLString";
const MGLTileSourceOption MGLTileSourceOptionAttributionInfos = @"MGLTileSourceOptionAttributionInfos";
const MGLTileSourceOption MGLTileSourceOptionTileCoordinateSystem = @"MGLTileSourceOptionTileCoordinateSystem";
Expand Down Expand Up @@ -70,6 +73,15 @@ - (NSString *)attributionHTMLString {
[NSException raise:NSInvalidArgumentException
format:@"MGLTileSourceOptionMinimumZoomLevel must be less than MGLTileSourceOptionMaximumZoomLevel."];
}

if (NSValue *coordinateBounds = options[MGLTileSourceOptionCoordinateBounds]) {
if (![coordinateBounds isKindOfClass:[NSValue class]]
&& strcmp(coordinateBounds.objCType, @encode(MGLCoordinateBounds)) == 0) {
[NSException raise:NSInvalidArgumentException
format:@"MGLTileSourceOptionCoordinateBounds must be set to an NSValue containing an MGLCoordinateBounds."];
}
tileSet.bounds = MGLLatLngBoundsFromCoordinateBounds(coordinateBounds.MGLCoordinateBoundsValue);
}

if (NSString *attribution = options[MGLTileSourceOptionAttributionHTMLString]) {
if (![attribution isKindOfClass:[NSString class]]) {
Expand Down
14 changes: 14 additions & 0 deletions platform/darwin/test/MGLTileSetTests.mm
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#import <Mapbox/Mapbox.h>
#import "MGLTileSource_Private.h"
#import "MGLGeometry_Private.h"

#include <mbgl/util/tileset.hpp>

Expand Down Expand Up @@ -40,6 +41,19 @@ - (void)testTileSetFromTileURLTemplates {
XCTAssertEqual(tileSet.zoomRange.min, 1);
XCTAssertEqual(tileSet.zoomRange.max, 2);

// when the tile set has a bounds set
MGLCoordinateBounds bounds = MGLCoordinateBoundsMake(CLLocationCoordinate2DMake(12, 34), CLLocationCoordinate2DMake(56, 78));
tileSet = MGLTileSetFromTileURLTemplates(@[@"tile.1"], @{
MGLTileSourceOptionCoordinateBounds: @(bounds),
});

// the mbgl object reflects the set values for the bounds
XCTAssert(!!tileSet.bounds, @"The bounds are set after setting the bounds");
if (tileSet.bounds) {
MGLCoordinateBounds actual = MGLCoordinateBoundsFromLatLngBounds(*tileSet.bounds);
XCTAssert(MGLCoordinateBoundsEqualToCoordinateBounds(bounds, actual), @"The bounds round-trip");
}

// when the tile set has an attribution
NSString *attribution = @"my tileset © ©️🎈";
tileSet = MGLTileSetFromTileURLTemplates(tileURLTemplates, @{
Expand Down
1 change: 1 addition & 0 deletions platform/ios/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Mapbox welcomes participation and contributions from everyone. Please read [CONT
* Properties such as `MGLSymbolStyleLayer.iconAllowsOverlap` and `MGLSymbolStyleLayer.iconIgnoresPlacement` now account for symbols in other sources. ([#10436](https://github.com/mapbox/mapbox-gl-native/pull/10436))
* Improved the reliability of collision detection between symbols near the edges of tiles, as well as between symbols when the map is tilted. It is no longer necessary to enable `MGLSymbolStyleLayer.symbolAvoidsEdges` to prevent symbols in adjacent tiles from overlapping with each other. ([#10436](https://github.com/mapbox/mapbox-gl-native/pull/10436))
* Symbols can fade in and out as the map pans, rotates, or tilts. ([#10436](https://github.com/mapbox/mapbox-gl-native/pull/10436))
* Added the `MGLTileSourceOptionTileCoordinateBounds` option to create an `MGLTileSource` that only supplies tiles within a specific geographic bounding box. ([#11141](https://github.com/mapbox/mapbox-gl-native/pull/11141))
* Fixed an issue preventing a dynamically-added `MGLRasterStyleLayer` from drawing until the map pans. ([#10270](https://github.com/mapbox/mapbox-gl-native/pull/10270))
* Fixed an issue preventing `MGLImageSource`s from drawing on the map when the map is zoomed in and tilted. ([#10677](https://github.com/mapbox/mapbox-gl-native/pull/10677))

Expand Down
2 changes: 2 additions & 0 deletions platform/ios/docs/guides/For Style Authors.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ the following terms for concepts defined in the style specification:

In the style specification | In the SDK
---------------------------|---------
bounds | coordinate bounds
filter | predicate
function type | interpolation mode
id | identifier
Expand Down Expand Up @@ -149,6 +150,7 @@ In style JSON | In TileJSON | In the SDK
`tiles` | `tiles` | `tileURLTemplates` parameter in `-[MGLTileSource initWithIdentifier:tileURLTemplates:options:]`
`minzoom` | `minzoom` | `MGLTileSourceOptionMinimumZoomLevel`
`maxzoom` | `maxzoom` | `MGLTileSourceOptionMaximumZoomLevel`
`bounds` | `bounds` | `MGLTileSourceOptionCoordinateBounds`
`tileSize` | — | `MGLTileSourceOptionTileSize`
`attribution` | `attribution` | `MGLTileSourceOptionAttributionHTMLString` (but consider specifying `MGLTileSourceOptionAttributionInfos` instead for improved security)
`scheme` | `scheme` | `MGLTileSourceOptionTileCoordinateSystem`
Expand Down
1 change: 1 addition & 0 deletions platform/macos/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
* Properties such as `MGLSymbolStyleLayer.iconAllowsOverlap` and `MGLSymbolStyleLayer.iconIgnoresPlacement` now account for symbols in other sources. ([#10436](https://github.com/mapbox/mapbox-gl-native/pull/10436))
* Improved the reliability of collision detection between symbols near the edges of tiles, as well as between symbols when the map is tilted. It is no longer necessary to enable `MGLSymbolStyleLayer.symbolAvoidsEdges` to prevent symbols in adjacent tiles from overlapping with each other. ([#10436](https://github.com/mapbox/mapbox-gl-native/pull/10436))
* Symbols can fade in and out as the map pans, rotates, or tilts. ([#10436](https://github.com/mapbox/mapbox-gl-native/pull/10436))
* Added the `MGLTileSourceOptionTileCoordinateBounds` option to create an `MGLTileSource` that only supplies tiles within a specific geographic bounding box. ([#11141](https://github.com/mapbox/mapbox-gl-native/pull/11141))
* Fixed an issue preventing a dynamically-added `MGLRasterStyleLayer` from drawing until the map pans. ([#10270](https://github.com/mapbox/mapbox-gl-native/pull/10270))
* Fixed an issue preventing `MGLImageSource`s from drawing on the map when the map is zoomed in and tilted. ([#10677](https://github.com/mapbox/mapbox-gl-native/pull/10677))

Expand Down
2 changes: 2 additions & 0 deletions platform/macos/docs/guides/For Style Authors.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ the following terms for concepts defined in the style specification:

In the style specification | In the SDK
---------------------------|---------
bounds | coordinate bounds
filter | predicate
function type | interpolation mode
id | identifier
Expand Down Expand Up @@ -136,6 +137,7 @@ In style JSON | In TileJSON | In the SDK
`tiles` | `tiles` | `tileURLTemplates` parameter in `-[MGLTileSource initWithIdentifier:tileURLTemplates:options:]`
`minzoom` | `minzoom` | `MGLTileSourceOptionMinimumZoomLevel`
`maxzoom` | `maxzoom` | `MGLTileSourceOptionMaximumZoomLevel`
`bounds` | `bounds` | `MGLTileSourceOptionCoordinateBounds`
`tileSize` | — | `MGLTileSourceOptionTileSize`
`attribution` | `attribution` | `MGLTileSourceOptionAttributionHTMLString` (but consider specifying `MGLTileSourceOptionAttributionInfos` instead for improved security)
`scheme` | `scheme` | `MGLTileSourceOptionTileCoordinateSystem`
Expand Down