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

Replace bundled styles with mapbox: style URLs #2746

Merged
merged 3 commits into from
Oct 30, 2015
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
4 changes: 0 additions & 4 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@
path = .mason
url = https://github.com/mapbox/mason.git

[submodule "styles"]
path = styles
url = https://github.com/mapbox/mapbox-gl-styles.git

[submodule "test/ios/KIF"]
path = test/ios/KIF
url = https://github.com/kif-framework/KIF.git
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## iOS master

- The `styleID` property has been removed from MGLMapView. Instead, set the `styleURL` property to an NSURL in the form `mapbox://styles/STYLE_ID`. If you previously set the style ID in Interface Builder’s Attributes inspector, delete the `styleID` entry from the User Defined Runtime Attributes section of the Identity inspector, then set the new “Style URL” inspectable to a value in the form `mapbox://styles/STYLE_ID`. ([#2632](https://github.com/mapbox/mapbox-gl-native/pull/2632))
- Default styles such as Streets are no longer bundled with the SDK; instead, they are loaded at runtime from the style API on mapbox.com. As always, you can use these default styles with any valid access token, and Streets continues to be `MGLMapView`’s initial style. The `bundledStyleURLs` property on `MGLMapView` has been deprecated in favor of several class methods on `MGLStyle` that provide direct access to the default styles. ([#2746](https://github.com/mapbox/mapbox-gl-native/pull/2746))
- The SDK now builds with Bitcode enabled. ([#2332](https://github.com/mapbox/mapbox-gl-native/issues/2332))
- The double-tap-drag gesture for zooming in and out is now consistent with the Google Maps SDK. ([#2153](https://github.com/mapbox/mapbox-gl-native/pull/2153))
- A new `MGLAnnotationImage.enabled` property allows you to disable touch events on individual annotations. ([#2501](https://github.com/mapbox/mapbox-gl-native/pull/2501))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,27 +28,27 @@ public class Style {
/**
* Mapbox Streets: A complete basemap, perfect for incorporating your own data.
*/
public static final String MAPBOX_STREETS = "asset://styles/streets-v8.json";
public static final String MAPBOX_STREETS = "mapbox://styles/mapbox/streets-v8";
/**
* Emerald: A versatile style, with emphasis on road networks and public transit.
*/
public static final String EMERALD = "asset://styles/emerald-v8.json";
public static final String EMERALD = "mapbox://styles/mapbox/emerald-v8";
/**
* Light: Subtle light backdrop for data visualizations.
*/
public static final String LIGHT = "asset://styles/light-v8.json";
public static final String LIGHT = "mapbox://styles/mapbox/light-v8";
/**
* Dark: Subtle dark backdrop for data visualizations.
*/
public static final String DARK = "asset://styles/dark-v8.json";
public static final String DARK = "mapbox://styles/mapbox/dark-v8";
/**
* Satellite: A beautiful global satellite and aerial imagery layer.
*/
public static final String SATELLITE = "asset://styles/satellite-v8.json";
public static final String SATELLITE = "mapbox://styles/mapbox/satellite-v8";

/**
* Satellite Streets: Global satellite and aerial imagery with unobtrusive labels.
*/
public static final String SATELLITE_STREETS = "asset://styles/satellite-hybrid-v8.json";
public static final String SATELLITE_STREETS = "mapbox://styles/mapbox/satellite-hybrid-v8";

}
12 changes: 6 additions & 6 deletions android/MapboxGLAndroidSDK/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
<string name="infoWindowAddress">Address</string>

<!-- these are public -->
<string name="style_mapbox_streets">asset://styles/streets-v8.json</string>
<string name="style_emerald">asset://styles/emerald-v8.json</string>
<string name="style_light">asset://styles/light-v8.json</string>
<string name="style_dark">asset://styles/dark-v8.json</string>
<string name="style_satellite">asset://styles/satellite-v8.json</string>
<string name="style_satellite_streets">asset://styles/satellite-hybrid-v8.json</string>
<string name="style_mapbox_streets">mapbox://styles/mapbox/streets-v8</string>
<string name="style_emerald">mapbox://styles/mapbox/emerald-v8</string>
<string name="style_light">mapbox://styles/mapbox/light-v8</string>
<string name="style_dark">mapbox://styles/mapbox/dark-v8</string>
<string name="style_satellite">mapbox://styles/mapbox/satellite-v8</string>
<string name="style_satellite_streets">mapbox://styles/mapbox/satellite-hybrid-v8</string>
</resources>
2 changes: 2 additions & 0 deletions gyp/platform-ios.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@
'../platform/ios/MGLShape.m',
'../include/mbgl/ios/MGLAnnotationImage.h',
'../platform/ios/MGLAnnotationImage.m',
'../include/mbgl/ios/MGLStyle.h',
'../platform/ios/MGLStyle.mm',
'../platform/ios/NSBundle+MGLAdditions.h',
'../platform/ios/NSBundle+MGLAdditions.m',
'../platform/ios/NSException+MGLAdditions.h',
Expand Down
35 changes: 0 additions & 35 deletions gyp/styles.gypi

This file was deleted.

5 changes: 3 additions & 2 deletions include/mbgl/ios/MGLMapView.h
Original file line number Diff line number Diff line change
Expand Up @@ -217,8 +217,9 @@ IB_DESIGNABLE

@property (nonatomic, nullable) NSString *styleID __attribute__((unavailable("Set styleURL to an NSURL of the form <mapbox://styles/STYLE_ID>, where STYLE_ID would have been the value of this property.")));

/** URLs of the styles bundled with the library. */
@property (nonatomic, readonly) NS_ARRAY_OF(NSURL *) *bundledStyleURLs;
/** URLs of the styles bundled with the library.
@deprecated Call the relevant class method of `MGLStyle` for the URL of a particular default style. */
@property (nonatomic, readonly) NS_ARRAY_OF(NSURL *) *bundledStyleURLs __attribute__((deprecated("Call the relevant class method of MGLStyle for the URL of a particular default style.")));

/** URL of the style currently displayed in the receiver.
*
Expand Down
36 changes: 36 additions & 0 deletions include/mbgl/ios/MGLStyle.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#import "Mapbox.h"

NS_ASSUME_NONNULL_BEGIN

/** A collection of convenience methods for creating style URLs of default styles provided by Mapbox. These instances of NSURL are cached. */
@interface MGLStyle : NSObject

/** Returns the Streets style URL.
* Mapbox Streets is a complete base map, perfect for incorporating your own data. */
+ (NSURL *)streetsStyleURL;

/** Returns the Emerald style URL.
* Emerald is a versatile style with emphasis on road networks and public transportation. */
+ (NSURL *)emeraldStyleURL;

/** Returns the Light style URL.
* Light is a subtle, light-colored backdrop for data visualizations. */
+ (NSURL *)lightStyleURL;

/** Returns the Dark style URL.
* Dark is a subtle, dark-colored backdrop for data visualizations. */
+ (NSURL *)darkStyleURL;

/** Returns the Satellite style URL.
* Mapbox Satellite is a beautiful global satellite and aerial imagery layer. */
+ (NSURL *)satelliteStyleURL;

/** Returns the Hybrid style URL.
* Hybrid combines the global satellite and aerial imagery of Mapbox Satellite with unobtrusive labels. */
+ (NSURL *)hybridStyleURL;

- (instancetype)init NS_UNAVAILABLE;

@end

NS_ASSUME_NONNULL_END
1 change: 1 addition & 0 deletions include/mbgl/ios/Mapbox.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@
#import "MGLPolygon.h"
#import "MGLPolyline.h"
#import "MGLShape.h"
#import "MGLStyle.h"
#import "MGLTypes.h"
#import "MGLUserLocation.h"
32 changes: 32 additions & 0 deletions include/mbgl/util/default_styles.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#ifndef MBGL_PLATFORM_DEFAULT_STYLES
#define MBGL_PLATFORM_DEFAULT_STYLES

#include <vector>
#include <string>

namespace mbgl {
namespace util {
namespace default_styles {

struct DefaultStyle {
const char* url;
const char* name;
};

extern const DefaultStyle streets;
extern const DefaultStyle emerald;
extern const DefaultStyle light;
extern const DefaultStyle dark;
extern const DefaultStyle satellite;
extern const DefaultStyle hybrid;

const DefaultStyle orderedStyles[] = {
streets, emerald, light, dark, satellite, hybrid,
};
const size_t numOrderedStyles = sizeof(orderedStyles) / sizeof(DefaultStyle);

} // end namespace default_styles
} // end namespace util
} // end namespace mbgl

#endif
26 changes: 5 additions & 21 deletions ios/app/MBXViewController.mm
Original file line number Diff line number Diff line change
@@ -1,25 +1,12 @@
#import "MBXViewController.h"

#import <mbgl/ios/Mapbox.h>
#import <mbgl/util/default_styles.hpp>

#import <CoreLocation/CoreLocation.h>

static UIColor *const kTintColor = [UIColor colorWithRed:0.120 green:0.550 blue:0.670 alpha:1.000];

static struct MBXStyle {
NSString *name;
NSString *displayName;
} MBXAvailableStyles[] = {
{@"streets", @"Streets"},
{@"emerald", @"Emerald"},
{@"light", @"Light"},
{@"dark", @"Dark"},
{@"satellite", @"Satellite"},
{@"satellite-hybrid", @"Hybrid"},
};

static NSUInteger const kStyleVersion = 8;

@interface MBXViewController () <UIActionSheetDelegate, MGLMapViewDelegate>

@property (nonatomic) MGLMapView *mapView;
Expand Down Expand Up @@ -79,7 +66,7 @@ - (void)viewDidLoad

UIButton *titleButton = [UIButton buttonWithType:UIButtonTypeCustom];
[titleButton setFrame:CGRectMake(0, 0, 150, 40)];
[titleButton setTitle:MBXAvailableStyles[self.styleIndex].displayName forState:UIControlStateNormal];
[titleButton setTitle:@(mbgl::util::default_styles::orderedStyles[self.styleIndex].name) forState:UIControlStateNormal];
[titleButton setTitleColor:kTintColor forState:UIControlStateNormal];
[titleButton addTarget:self action:@selector(cycleStyles) forControlEvents:UIControlEventTouchUpInside];
self.navigationItem.titleView = titleButton;
Expand Down Expand Up @@ -323,14 +310,11 @@ - (void)cycleStyles
{
UIButton *titleButton = (UIButton *)self.navigationItem.titleView;

self.styleIndex = (self.styleIndex + 1) % (sizeof(MBXAvailableStyles) / sizeof(MBXAvailableStyles[0]));
self.styleIndex = (self.styleIndex + 1) % mbgl::util::default_styles::numOrderedStyles;

self.mapView.styleURL = [NSURL URLWithString:
[NSString stringWithFormat:@"asset://styles/%@-v%lu.json",
MBXAvailableStyles[self.styleIndex].name,
(unsigned long)kStyleVersion]];
self.mapView.styleURL = [NSURL URLWithString:@(mbgl::util::default_styles::orderedStyles[self.styleIndex].url)];

[titleButton setTitle:MBXAvailableStyles[self.styleIndex].displayName forState:UIControlStateNormal];
[titleButton setTitle:@(mbgl::util::default_styles::orderedStyles[self.styleIndex].name) forState:UIControlStateNormal];
}

- (void)locateUser
Expand Down
1 change: 0 additions & 1 deletion ios/app/mapboxgl-app.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
],

'dependencies': [
'../mbgl.gyp:bundle_styles',
'../mbgl.gyp:core',
'../mbgl.gyp:platform-<(platform_lib)',
'../mbgl.gyp:http-<(http_lib)',
Expand Down
2 changes: 1 addition & 1 deletion ios/benchmark/MBXBenchViewController.mm
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ - (void)viewDidLoad
{
[super viewDidLoad];

NSURL* url = [[NSURL alloc] initWithString:@"asset://styles/streets-v8.json"];
NSURL* url = [[NSURL alloc] initWithString:@"mapbox://styles/mapbox/streets-v8.json"];
self.mapView = [[MGLMapView alloc] initWithFrame:self.view.bounds styleURL:url];
self.mapView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
self.mapView.delegate = self;
Expand Down
1 change: 0 additions & 1 deletion ios/benchmark/benchmark-ios.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
'<!@(find ../ios/benchmark/img -type f)',
'assets/glyphs',
'assets/sprites',
'assets/styles',
'assets/tiles',
],

Expand Down
18 changes: 9 additions & 9 deletions linux/main.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include <mbgl/mbgl.hpp>
#include "../platform/default/default_styles.hpp"
#include <mbgl/util/default_styles.hpp>
#include <mbgl/util/uv.hpp>
#include <mbgl/platform/log.hpp>
#include <mbgl/platform/platform.hpp>
Expand Down Expand Up @@ -131,22 +131,22 @@ int main(int argc, char *argv[]) {
view->setChangeStyleCallback([&map] () {
static uint8_t currentStyleIndex;

if (++currentStyleIndex == mbgl::util::defaultStyles.size()) {
if (++currentStyleIndex == mbgl::util::default_styles::numOrderedStyles) {
currentStyleIndex = 0;
}

const auto& newStyle = mbgl::util::defaultStyles[currentStyleIndex];
map.setStyleURL(newStyle.first);
view->setWindowTitle(newStyle.second);
mbgl::util::default_styles::DefaultStyle newStyle = mbgl::util::default_styles::orderedStyles[currentStyleIndex];
map.setStyleURL(newStyle.url);
view->setWindowTitle(newStyle.name);

mbgl::Log::Info(mbgl::Event::Setup, std::string("Changed style to: ") + newStyle.first);
mbgl::Log::Info(mbgl::Event::Setup, std::string("Changed style to: ") + newStyle.name);
});

// Load style
if (style.empty()) {
const auto& newStyle = mbgl::util::defaultStyles.front();
style = newStyle.first;
view->setWindowTitle(newStyle.second);
mbgl::util::default_styles::DefaultStyle newStyle = mbgl::util::default_styles::orderedStyles[0];
style = newStyle.url;
view->setWindowTitle(newStyle.name);
}

map.setStyleURL(style);
Expand Down
3 changes: 0 additions & 3 deletions linux/mapboxgl-app.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
'../mbgl.gyp:http-<(http_lib)',
'../mbgl.gyp:asset-<(asset_lib)',
'../mbgl.gyp:cache-<(cache_lib)',
'../mbgl.gyp:copy_styles',
'../mbgl.gyp:copy_certificate_bundle',
],

Expand All @@ -23,8 +22,6 @@
'../platform/default/glfw_view.hpp',
'../platform/default/glfw_view.cpp',
'../platform/default/log_stderr.cpp',
'../platform/default/default_styles.hpp',
'../platform/default/default_styles.cpp',
],

'variables' : {
Expand Down
18 changes: 9 additions & 9 deletions macosx/main.mm
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#include <mbgl/platform/log.hpp>
#include "../platform/default/default_styles.hpp"
#include <mbgl/platform/platform.hpp>
#include <mbgl/platform/darwin/settings_nsuserdefaults.hpp>
#include <mbgl/platform/darwin/reachability.h>
Expand All @@ -9,6 +8,7 @@
#include <mbgl/storage/network_status.hpp>

#include <mbgl/util/geo.hpp>
#include <mbgl/util/default_styles.hpp>

#import <Foundation/Foundation.h>

Expand Down Expand Up @@ -172,23 +172,23 @@ int main(int argc, char* argv[]) {
view.setChangeStyleCallback([&map, &view] () {
static uint8_t currentStyleIndex;

if (++currentStyleIndex == mbgl::util::defaultStyles.size()) {
if (++currentStyleIndex == mbgl::util::default_styles::numOrderedStyles) {
currentStyleIndex = 0;
}

const auto& newStyle = mbgl::util::defaultStyles[currentStyleIndex];
map.setStyleURL(newStyle.first);
view.setWindowTitle(newStyle.second);
mbgl::util::default_styles::DefaultStyle newStyle = mbgl::util::default_styles::orderedStyles[currentStyleIndex];
map.setStyleURL(newStyle.url);
view.setWindowTitle(newStyle.name);

mbgl::Log::Info(mbgl::Event::Setup, std::string("Changed style to: ") + newStyle.first);
mbgl::Log::Info(mbgl::Event::Setup, std::string("Changed style to: ") + newStyle.name);
});


// Load style
if (style.empty()) {
const auto& newStyle = mbgl::util::defaultStyles.front();
style = newStyle.first;
view.setWindowTitle(newStyle.second);
mbgl::util::default_styles::DefaultStyle newStyle = mbgl::util::default_styles::orderedStyles[0];
style = newStyle.url;
view.setWindowTitle(newStyle.name);
}

map.setStyleURL(style);
Expand Down
Loading