summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CHANGELOG.md15
-rw-r--r--bin/offline.cpp52
-rw-r--r--bin/offline.gypi5
-rw-r--r--include/mbgl/map/camera.hpp2
-rw-r--r--include/mbgl/map/map.hpp18
-rw-r--r--include/mbgl/util/constants.hpp2
-rw-r--r--include/mbgl/util/geo.hpp36
-rw-r--r--include/mbgl/util/mat4.hpp8
-rw-r--r--include/mbgl/util/string.hpp5
-rw-r--r--include/mbgl/util/vec.hpp4
-rw-r--r--platform/android/MapboxGLAndroidSDK/build.gradle2
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/MarkerOptions.java22
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/camera/CameraPosition.java56
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/camera/CameraUpdateFactory.java20
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/http/HTTPContext.java2
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapFragment.java1
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapView.java132
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapboxMap.java10
-rwxr-xr-xplatform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/NativeMapView.java6
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/SupportMapFragment.java1
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/widgets/UserLocationView.java6
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/offline/OfflineManager.java4
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/offline/OfflineRegion.java10
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/offline/OfflineRegionMetadata.java40
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/telemetry/MapboxEventManager.java36
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/telemetry/TelemetryService.java8
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/CameraActivity.java1
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/CoordinateChangeActivity.java1
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/DoubleMapActivity.java5
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/DynamicMarkerChangeActivity.java1
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/GeocoderActivity.java84
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/InfoWindowActivity.java9
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/LatLngBoundsActivity.java1
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/MainActivity.java14
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/ManualZoomActivity.java2
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/MapFragmentActivity.java2
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/MapPaddingActivity.java22
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/MapboxMapActivity.java6
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/MaxMinZoomActivity.java2
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/OfflineActivity.java16
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/PressForMarkerActivity.java6
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/ScrollByActivity.java3
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/TiltActivity.java4
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/offline/CustomMetadata.java20
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/main/res/drawable/ic_droppin_24dp.xml4
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/maps/MapboxMapTest.java16
-rwxr-xr-xplatform/android/src/jni.cpp136
-rw-r--r--platform/android/src/jni.hpp4
-rw-r--r--platform/default/glfw_view.cpp4
-rw-r--r--platform/ios/framework/Mapbox-static.h (renamed from ios/framework/Mapbox-static.h)0
-rw-r--r--platform/ios/src/MGLMapView.mm8
-rw-r--r--platform/osx/src/MGLMapView.mm10
-rw-r--r--src/mbgl/annotation/annotation_tile.hpp1
-rw-r--r--src/mbgl/annotation/point_annotation_impl.cpp13
-rw-r--r--src/mbgl/annotation/shape_annotation_impl.cpp5
-rw-r--r--src/mbgl/layer/custom_layer.cpp2
-rw-r--r--src/mbgl/layer/line_layer.cpp2
-rw-r--r--src/mbgl/layer/symbol_layer.cpp2
-rw-r--r--src/mbgl/map/map.cpp45
-rw-r--r--src/mbgl/map/map_context.cpp2
-rw-r--r--src/mbgl/map/tile_id.cpp4
-rw-r--r--src/mbgl/map/tile_id.hpp28
-rw-r--r--src/mbgl/map/transform.cpp92
-rw-r--r--src/mbgl/map/transform.hpp22
-rw-r--r--src/mbgl/map/transform_state.cpp168
-rw-r--r--src/mbgl/map/transform_state.hpp29
-rw-r--r--src/mbgl/renderer/line_bucket.cpp22
-rw-r--r--src/mbgl/renderer/line_bucket.hpp6
-rw-r--r--src/mbgl/renderer/painter.cpp18
-rw-r--r--src/mbgl/renderer/painter_fill.cpp12
-rw-r--r--src/mbgl/renderer/painter_line.cpp6
-rw-r--r--src/mbgl/renderer/painter_raster.cpp2
-rw-r--r--src/mbgl/renderer/painter_symbol.cpp4
-rw-r--r--src/mbgl/renderer/symbol_bucket.cpp13
-rw-r--r--src/mbgl/renderer/symbol_bucket.hpp6
-rw-r--r--src/mbgl/source/source.cpp2
-rw-r--r--src/mbgl/source/source_info.hpp10
-rw-r--r--src/mbgl/style/style.cpp1
-rw-r--r--src/mbgl/style/style_parser.cpp19
-rw-r--r--src/mbgl/text/check_max_angle.cpp9
-rw-r--r--src/mbgl/text/check_max_angle.hpp7
-rw-r--r--src/mbgl/text/collision_feature.cpp12
-rw-r--r--src/mbgl/text/collision_feature.hpp10
-rw-r--r--src/mbgl/text/get_anchors.cpp8
-rw-r--r--src/mbgl/text/get_anchors.hpp3
-rw-r--r--src/mbgl/text/quads.cpp16
-rw-r--r--src/mbgl/text/quads.hpp5
-rw-r--r--src/mbgl/tile/geojson_tile.cpp2
-rw-r--r--src/mbgl/tile/geojson_tile.hpp1
-rw-r--r--src/mbgl/tile/geometry_tile.hpp11
-rw-r--r--src/mbgl/tile/vector_tile.cpp2
-rw-r--r--src/mbgl/util/clip_lines.cpp8
-rw-r--r--src/mbgl/util/clip_lines.hpp2
-rw-r--r--src/mbgl/util/constants.cpp4
-rw-r--r--src/mbgl/util/geo.cpp12
-rw-r--r--src/mbgl/util/mapbox.cpp3
-rw-r--r--src/mbgl/util/mat4.cpp38
-rw-r--r--src/mbgl/util/merge_lines.cpp10
-rw-r--r--src/mbgl/util/merge_lines.hpp4
-rw-r--r--src/mbgl/util/tile_coordinate.hpp17
-rw-r--r--src/mbgl/util/tile_cover.cpp77
-rw-r--r--src/mbgl/util/vec.cpp11
-rw-r--r--src/mbgl/util/vec4.cpp33
-rw-r--r--src/mbgl/util/vec4.hpp40
-rw-r--r--test/map/transform.cpp74
-rw-r--r--test/util/geo.cpp31
106 files changed, 964 insertions, 906 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 9076565c42..05f3cdb4c8 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -49,16 +49,17 @@ Known issues:
- Black Screen On Ice Cream Sandwich and Jelly Bean devices ([#2802](https://github.com/mapbox/mapbox-gl-native/issues/2802))
- Resolved in 2.2.0
-## iOS Master
+## iOS master
-- An icon laid out along a line no longer appears if it would extend past the end of the line. Some one-way arrows no longer point the wrong way. (https://github.com/mapbox/mapbox-gl-native/pull/3839)
-- Fixed a formatting issue in the documentation for `MGLCoordinateBoundsIsEmpty()`. (https://github.com/mapbox/mapbox-gl-native/pull/3958)
-- Push a turnstile event whenever a map view event is queued in each session so that an accounts MAU will only get triggered if a map is shown. (https://github.com/mapbox/mapbox-gl-native/pull/3713)
-- Reduce slanted segments in dashed lines near corners (https://github.com/mapbox/mapbox-gl-native/pull/3914)
-- Updated documentation to reflect the requirement that you must embed the framework in the “Embedded Binaries” section in Xcode. (discussed in https://github.com/mapbox/mapbox-gl-native/issues/4011)
+- An icon laid out along a line no longer appears if it would extend past the end of the line. Some one-way arrows no longer point the wrong way. ([#3839](https://github.com/mapbox/mapbox-gl-native/pull/3839))
+- Reduce slanted segments in dashed lines near corners. ([#3914](https://github.com/mapbox/mapbox-gl-native/pull/3914))
+- Telemetry location gathering now only occurs when the device is in motion. ([#4115](https://github.com/mapbox/mapbox-gl-native/pull/4115))
+- An account’s monthly active users metric only counts a user once a map view is displayed to that user. ([#3713](https://github.com/mapbox/mapbox-gl-native/pull/3713))
+- Updated documentation to reflect the requirement that you must embed the framework in the “Embedded Binaries” section in Xcode. ([#4011](https://github.com/mapbox/mapbox-gl-native/issues/4011))
- Telemetry location gathering now only occurs when the device is in motion (https://github.com/mapbox/mapbox-gl-native/pull/4115)
-- Polygons and polylines now default to using the map view's tint color. ([#4028](https://github.com/mapbox/mapbox-gl-native/pull/4028))
+- Polygons and polylines now default to using the map view’s tint color. ([#4028](https://github.com/mapbox/mapbox-gl-native/pull/4028))
- The Improve This Map tool now uses the same zoom level that is currently being shown in the map view. ([#4068](https://github.com/mapbox/mapbox-gl-native/pull/4068))
+- Fixed a formatting issue in the documentation for `MGLCoordinateBoundsIsEmpty()`. ([#3958](https://github.com/mapbox/mapbox-gl-native/pull/3958))
## iOS 3.1.2
diff --git a/bin/offline.cpp b/bin/offline.cpp
index 7d69273b51..c03149d2f5 100644
--- a/bin/offline.cpp
+++ b/bin/offline.cpp
@@ -1,3 +1,4 @@
+#include <mbgl/util/default_styles.hpp>
#include <mbgl/util/run_loop.hpp>
#include <mbgl/util/string.hpp>
#include <mbgl/util/io.hpp>
@@ -7,20 +8,57 @@
#include <cstdlib>
#include <iostream>
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wunknown-pragmas"
+#pragma GCC diagnostic ignored "-Wunused-local-typedefs"
+#pragma GCC diagnostic ignored "-Wshadow"
+#include <boost/program_options.hpp>
+#pragma GCC diagnostic pop
+
+namespace po = boost::program_options;
using namespace std::literals::chrono_literals;
-int main(int, char * []) {
- using namespace mbgl;
+int main(int argc, char *argv[]) {
+ std::string style = mbgl::util::default_styles::streets.url;
+ double north = 37.2, west = -122.8, south = 38.1, east = -121.7; // Bay area
+ double minZoom = 0.0, maxZoom = 15.0, pixelRatio = 1.0;
+ std::string output = "offline.db";
+
+ const char* tokenEnv = getenv("MAPBOX_ACCESS_TOKEN");
+ std::string token = tokenEnv ? tokenEnv : std::string();
+
+ po::options_description desc("Allowed options");
+ desc.add_options()
+ ("style,s", po::value(&style)->value_name("URL"), "Map stylesheet")
+ ("north", po::value(&north)->value_name("degrees")->default_value(north), "North latitude")
+ ("west", po::value(&west)->value_name("degrees")->default_value(west), "West longitude")
+ ("south", po::value(&south)->value_name("degrees")->default_value(south), "South latitude")
+ ("east", po::value(&east)->value_name("degrees")->default_value(east), "East longitude")
+ ("minZoom", po::value(&minZoom)->value_name("number")->default_value(minZoom), "Min zoom level")
+ ("maxZoom", po::value(&maxZoom)->value_name("number")->default_value(maxZoom), "Max zoom level")
+ ("pixelRatio", po::value(&pixelRatio)->value_name("number")->default_value(pixelRatio), "Pixel ratio")
+ ("token,t", po::value(&token)->value_name("key")->default_value(token), "Mapbox access token")
+ ("output,o", po::value(&output)->value_name("file")->default_value(output), "Output database file name")
+ ;
+
+ try {
+ po::variables_map vm;
+ po::store(po::parse_command_line(argc, argv, desc), vm);
+ po::notify(vm);
+ } catch(std::exception& e) {
+ std::cout << "Error: " << e.what() << std::endl << desc;
+ exit(1);
+ }
- unlink("offline.db");
+ using namespace mbgl;
util::RunLoop loop;
- DefaultFileSource fileSource("offline.db", ".");
- fileSource.setAccessToken(getenv("MAPBOX_ACCESS_TOKEN"));
+ DefaultFileSource fileSource(output, ".");
+ fileSource.setAccessToken(token);
- LatLngBounds bayArea = LatLngBounds::hull(LatLng(37.2, -122.8), LatLng(38.1, -121.7));
- OfflineTilePyramidRegionDefinition definition("mapbox://styles/mapbox/streets-v8", bayArea, 0, 15, 1.0);
+ LatLngBounds boundingBox = LatLngBounds::hull(LatLng(north, west), LatLng(south, east));
+ OfflineTilePyramidRegionDefinition definition(style, boundingBox, minZoom, maxZoom, pixelRatio);
OfflineRegionMetadata metadata;
class Observer : public OfflineRegionObserver {
diff --git a/bin/offline.gypi b/bin/offline.gypi
index b5980ae76d..885a199b36 100644
--- a/bin/offline.gypi
+++ b/bin/offline.gypi
@@ -28,15 +28,20 @@
'cflags_cc': [
'<@(boost_cflags)',
],
+ 'libraries': [
+ '<@(boost_libprogram_options_static_libs)'
+ ],
},
'conditions': [
['OS == "mac"', {
+ 'libraries': [ '<@(libraries)' ],
'xcode_settings': {
'OTHER_CPLUSPLUSFLAGS': [ '<@(cflags_cc)' ],
}
}, {
'cflags_cc': [ '<@(cflags_cc)' ],
+ 'libraries': [ '<@(libraries)' ],
}]
],
},
diff --git a/include/mbgl/map/camera.hpp b/include/mbgl/map/camera.hpp
index a1b9bfe691..2e20a6386f 100644
--- a/include/mbgl/map/camera.hpp
+++ b/include/mbgl/map/camera.hpp
@@ -22,7 +22,7 @@ struct CameraOptions {
/** Point of reference for `zoom` and `angle`, assuming an origin at the
top-left corner of the view. */
- optional<PrecisionPoint> anchor;
+ optional<ScreenCoordinate> anchor;
/** Zero-based zoom level. Constrained to the minimum and maximum zoom
levels. */
diff --git a/include/mbgl/map/map.hpp b/include/mbgl/map/map.hpp
index 688565fecb..463bee7938 100644
--- a/include/mbgl/map/map.hpp
+++ b/include/mbgl/map/map.hpp
@@ -97,16 +97,16 @@ public:
void flyTo(const CameraOptions&, const AnimationOptions&);
// Position
- void moveBy(const PrecisionPoint&, const Duration& = Duration::zero());
- void setLatLng(const LatLng&, const PrecisionPoint&, const Duration& = Duration::zero());
+ void moveBy(const ScreenCoordinate&, const Duration& = Duration::zero());
+ void setLatLng(const LatLng&, const ScreenCoordinate&, const Duration& = Duration::zero());
void setLatLng(const LatLng&, const EdgeInsets&, const Duration& = Duration::zero());
void setLatLng(const LatLng&, const Duration& = Duration::zero());
LatLng getLatLng(const EdgeInsets& = {}) const;
void resetPosition(const EdgeInsets& = {});
// Scale
- void scaleBy(double ds, const PrecisionPoint& = { NAN, NAN }, const Duration& = Duration::zero());
- void setScale(double scale, const PrecisionPoint& = { NAN, NAN }, const Duration& = Duration::zero());
+ void scaleBy(double ds, const ScreenCoordinate& = { NAN, NAN }, const Duration& = Duration::zero());
+ void setScale(double scale, const ScreenCoordinate& = { NAN, NAN }, const Duration& = Duration::zero());
double getScale() const;
void setZoom(double zoom, const Duration& = Duration::zero());
void setZoom(double zoom, const EdgeInsets&, const Duration& = Duration::zero());
@@ -122,9 +122,9 @@ public:
double getMaxZoom() const;
// Rotation
- void rotateBy(const PrecisionPoint& first, const PrecisionPoint& second, const Duration& = Duration::zero());
+ void rotateBy(const ScreenCoordinate& first, const ScreenCoordinate& second, const Duration& = Duration::zero());
void setBearing(double degrees, const Duration& = Duration::zero());
- void setBearing(double degrees, const PrecisionPoint&, const Duration& = Duration::zero());
+ void setBearing(double degrees, const ScreenCoordinate&, const Duration& = Duration::zero());
void setBearing(double degrees, const EdgeInsets&, const Duration& = Duration::zero());
double getBearing() const;
void resetNorth(const Duration& = Milliseconds(500));
@@ -132,7 +132,7 @@ public:
// Pitch
void setPitch(double pitch, const Duration& = Duration::zero());
- void setPitch(double pitch, const PrecisionPoint&, const Duration& = Duration::zero());
+ void setPitch(double pitch, const ScreenCoordinate&, const Duration& = Duration::zero());
double getPitch() const;
// North Orientation
@@ -151,8 +151,8 @@ public:
double getMetersPerPixelAtLatitude(double lat, double zoom) const;
ProjectedMeters projectedMetersForLatLng(const LatLng&) const;
LatLng latLngForProjectedMeters(const ProjectedMeters&) const;
- PrecisionPoint pixelForLatLng(const LatLng&) const;
- LatLng latLngForPixel(const PrecisionPoint&) const;
+ ScreenCoordinate pixelForLatLng(const LatLng&) const;
+ LatLng latLngForPixel(const ScreenCoordinate&) const;
// Annotations
void addAnnotationIcon(const std::string&, std::shared_ptr<const SpriteImage>);
diff --git a/include/mbgl/util/constants.hpp b/include/mbgl/util/constants.hpp
index fef68fcf8c..5bfb252bce 100644
--- a/include/mbgl/util/constants.hpp
+++ b/include/mbgl/util/constants.hpp
@@ -19,6 +19,8 @@ extern const double RAD2DEG;
extern const double M2PI;
extern const double EARTH_RADIUS_M;
extern const double LATITUDE_MAX;
+extern const double LONGITUDE_MAX;
+extern const double DEGREES_MAX;
extern const double PITCH_MAX;
extern const double MIN_ZOOM;
extern const double MAX_ZOOM;
diff --git a/include/mbgl/util/geo.hpp b/include/mbgl/util/geo.hpp
index 86bc586cba..56d575ceaa 100644
--- a/include/mbgl/util/geo.hpp
+++ b/include/mbgl/util/geo.hpp
@@ -2,6 +2,7 @@
#define MBGL_UTIL_GEO
#include <mbgl/util/vec.hpp>
+#include <mbgl/util/constants.hpp>
#include <cmath>
@@ -9,15 +10,36 @@ namespace mbgl {
class TileID;
-using PrecisionPoint = vec2<double>;
+using ScreenCoordinate = vec2<double>;
class LatLng {
public:
- double latitude = 0;
- double longitude = 0;
+ double latitude;
+ double longitude;
- LatLng(double lat = 0, double lon = 0)
- : latitude(lat), longitude(lon) {}
+ enum WrapMode : bool { Unwrapped, Wrapped };
+
+ LatLng(double lat = 0, double lon = 0, WrapMode mode = Unwrapped)
+ : latitude(lat), longitude(lon) { if (mode == Wrapped) wrap(); }
+
+ LatLng wrapped() const { return { latitude, longitude, Wrapped }; }
+
+ void wrap() {
+ if (longitude < -util::LONGITUDE_MAX) longitude = std::fmod(longitude, util::LONGITUDE_MAX * 2);
+ if (longitude > util::LONGITUDE_MAX) longitude = -util::LONGITUDE_MAX + std::fmod(longitude, util::LONGITUDE_MAX);
+ }
+
+ /** If a path crossing the antemeridian would be shorter, extend the final
+ coordinate so that interpolating between the two endpoints will cross it. */
+ void unwrapForShortestPath(const LatLng& start) {
+ if (std::abs(start.longitude) + std::abs(longitude) > util::LONGITUDE_MAX) {
+ if (start.longitude > 0 && longitude < 0) {
+ longitude += util::DEGREES_MAX;
+ } else if (start.longitude < 0 && longitude > 0) {
+ longitude -= util::DEGREES_MAX;
+ }
+ }
+ }
explicit operator bool() const {
return !(std::isnan(latitude) || std::isnan(longitude));
@@ -26,7 +48,7 @@ public:
// Constructs a LatLng object with the top left position of the specified tile.
LatLng(const TileID& id);
- PrecisionPoint project() const;
+ ScreenCoordinate project() const;
};
inline bool operator==(const LatLng& a, const LatLng& b) {
@@ -195,7 +217,7 @@ public:
};
}
- PrecisionPoint getCenter(uint16_t width, uint16_t height) const;
+ ScreenCoordinate getCenter(uint16_t width, uint16_t height) const;
};
} // namespace mbgl
diff --git a/include/mbgl/util/mat4.hpp b/include/mbgl/util/mat4.hpp
index 59f6e3ee00..ff8e65224c 100644
--- a/include/mbgl/util/mat4.hpp
+++ b/include/mbgl/util/mat4.hpp
@@ -23,11 +23,13 @@
#ifndef MBGL_UTIL_MAT4
#define MBGL_UTIL_MAT4
+#include <mbgl/util/vec.hpp>
+
#include <array>
namespace mbgl {
-typedef std::array<double, 16> mat4;
+using mat4 = std::array<double, 16>;
namespace matrix {
@@ -43,7 +45,9 @@ void rotate_z(mat4& out, const mat4& a, double rad);
void scale(mat4& out, const mat4& a, double x, double y, double z);
void multiply(mat4& out, const mat4& a, const mat4& b);
+void transformMat4(vec4<double>& out, vec4<double>& a, mat4& m);
+
} // namespace matrix
} // namespace mbgl
-#endif
+#endif // MBGL_UTIL_MAT4
diff --git a/include/mbgl/util/string.hpp b/include/mbgl/util/string.hpp
index bc6b3b1eff..6c2433534e 100644
--- a/include/mbgl/util/string.hpp
+++ b/include/mbgl/util/string.hpp
@@ -22,6 +22,11 @@ inline std::string toString(int8_t num) {
return boost::lexical_cast<std::string>(int(num));
}
+// boost::lexical_cast() treats this as a character, but we are using it as number types.
+inline std::string toString(uint8_t num) {
+ return boost::lexical_cast<std::string>(unsigned(num));
+}
+
inline std::string toString(std::exception_ptr error) {
try {
std::rethrow_exception(error);
diff --git a/include/mbgl/util/vec.hpp b/include/mbgl/util/vec.hpp
index a59a4162f9..83530a1798 100644
--- a/include/mbgl/util/vec.hpp
+++ b/include/mbgl/util/vec.hpp
@@ -120,8 +120,6 @@ struct vec4 {
};
-using Coordinate = vec2<int16_t>;
-
} // namespace mbgl
-#endif
+#endif // MBGL_UTIL_VEC
diff --git a/platform/android/MapboxGLAndroidSDK/build.gradle b/platform/android/MapboxGLAndroidSDK/build.gradle
index 75e41035f1..cc06995df6 100644
--- a/platform/android/MapboxGLAndroidSDK/build.gradle
+++ b/platform/android/MapboxGLAndroidSDK/build.gradle
@@ -25,7 +25,7 @@ dependencies {
compile "com.android.support:support-annotations:${supportLibVersion}"
compile "com.android.support:support-v4:${supportLibVersion}"
compile "com.android.support:design:${supportLibVersion}"
- compile 'com.squareup.okhttp3:okhttp:3.1.2'
+ compile 'com.squareup.okhttp3:okhttp:3.2.0'
compile 'com.mapzen.android:lost:1.0.1'
}
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/MarkerOptions.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/MarkerOptions.java
index 5cc54cd1ca..a3df23d96f 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/MarkerOptions.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/MarkerOptions.java
@@ -39,10 +39,14 @@ public final class MarkerOptions extends BaseMarkerOptions<Marker, MarkerOptions
marker = new Marker();
position((LatLng) in.readParcelable(LatLng.class.getClassLoader()));
snippet(in.readString());
- String iconId = in.readString();
- Bitmap iconBitmap = in.readParcelable(Bitmap.class.getClassLoader());
- Icon icon = new Icon(iconId, iconBitmap);
- icon(icon);
+
+ if(in.readByte()!=0){
+ // this means we have an icon
+ String iconId = in.readString();
+ Bitmap iconBitmap = in.readParcelable(Bitmap.class.getClassLoader());
+ Icon icon = new Icon(iconId, iconBitmap);
+ icon(icon);
+ }
title(in.readString());
}
@@ -53,15 +57,19 @@ public final class MarkerOptions extends BaseMarkerOptions<Marker, MarkerOptions
@Override
public int describeContents() {
- return 0;
+ return hashCode();
}
@Override
public void writeToParcel(Parcel out, int flags) {
out.writeParcelable(getPosition(), flags);
out.writeString(getSnippet());
- out.writeString(getIcon().getId());
- out.writeParcelable(getIcon().getBitmap(), flags);
+ Icon icon = getIcon();
+ out.writeByte((byte) (icon != null ? 1 : 0));
+ if (icon != null) {
+ out.writeString(getIcon().getId());
+ out.writeParcelable(getIcon().getBitmap(), flags);
+ }
out.writeString(getTitle());
}
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/camera/CameraPosition.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/camera/CameraPosition.java
index ec2f0eb316..e66c9ee572 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/camera/CameraPosition.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/camera/CameraPosition.java
@@ -16,10 +16,10 @@ public final class CameraPosition implements Parcelable {
public static final Parcelable.Creator<CameraPosition> CREATOR
= new Parcelable.Creator<CameraPosition>() {
public CameraPosition createFromParcel(Parcel in) {
- float bearing = in.readFloat();
+ double bearing = in.readDouble();
LatLng target = in.readParcelable(LatLng.class.getClassLoader());
- float tilt = in.readFloat();
- float zoom = in.readFloat();
+ double tilt = in.readDouble();
+ double zoom = in.readDouble();
return new CameraPosition(target, zoom, tilt, bearing);
}
@@ -32,7 +32,7 @@ public final class CameraPosition implements Parcelable {
/**
* Direction that the camera is pointing in, in degrees clockwise from north.
*/
- public final float bearing;
+ public final double bearing;
/**
* The location that the camera is pointing at.
@@ -42,12 +42,12 @@ public final class CameraPosition implements Parcelable {
/**
* The angle, in degrees, of the camera angle from the nadir (directly facing the Earth). See tilt(float) for details of restrictions on the range of values.
*/
- public final float tilt;
+ public final double tilt;
/**
* Zoom level near the center of the screen. See zoom(float) for the definition of the camera's zoom level.
*/
- public final float zoom;
+ public final double zoom;
/**
* Constructs a CameraPosition.
@@ -59,7 +59,7 @@ public final class CameraPosition implements Parcelable {
* @throws NullPointerException if target is null
* @throws IllegalArgumentException if tilt is outside the range of 0 to 90 degrees inclusive.
*/
- CameraPosition(LatLng target, float zoom, float tilt, float bearing) {
+ CameraPosition(LatLng target, double zoom, double tilt, double bearing) {
this.target = target;
this.bearing = bearing;
this.tilt = tilt;
@@ -73,10 +73,10 @@ public final class CameraPosition implements Parcelable {
@Override
public void writeToParcel(Parcel out, int flags) {
- out.writeFloat(bearing);
+ out.writeDouble(bearing);
out.writeParcelable(target, flags);
- out.writeFloat(tilt);
- out.writeFloat(zoom);
+ out.writeDouble(tilt);
+ out.writeDouble(zoom);
}
@Override
@@ -119,10 +119,10 @@ public final class CameraPosition implements Parcelable {
*/
public static final class Builder {
- private float bearing = -1;
+ private double bearing = -1;
private LatLng target = null;
- private float tilt = -1;
- private float zoom = -1;
+ private double tilt = -1;
+ private double zoom = -1;
private boolean isRadiant;
/**
@@ -201,15 +201,31 @@ public final class CameraPosition implements Parcelable {
}
/**
+ * Create Builder from an exisiting array of doubles.
+ *
+ * @param values Values containing target, bearing, tilt and zoom
+ */
+ public Builder(double[] values) {
+ super();
+ if (values != null && values.length == 5) {
+ this.target = new LatLng(values[0], values[1]);
+ this.bearing = (float) values[2];
+ this.tilt = (float) values[3];
+ this.zoom = (float) values[4];
+ }
+ }
+
+
+ /**
* Sets the direction that the camera is pointing in, in degrees clockwise from north.
*
* @param bearing Bearing
* @return Builder
*/
- public Builder bearing(float bearing) {
- if(isRadiant){
+ public Builder bearing(double bearing) {
+ if (isRadiant) {
this.bearing = bearing;
- }else{
+ } else {
// converting degrees to radiant
this.bearing = (float) (-bearing * MathConstants.DEG2RAD);
}
@@ -243,10 +259,10 @@ public final class CameraPosition implements Parcelable {
* @return Builder
*/
@FloatRange(from = 0.0, to = 60.0)
- public Builder tilt(float tilt) {
- if(isRadiant){
+ public Builder tilt(double tilt) {
+ if (isRadiant) {
this.tilt = tilt;
- }else {
+ } else {
// converting degrees to radiant
this.tilt = (float) (MathUtils.clamp(tilt, MapboxConstants.MINIMUM_TILT, MapboxConstants.MAXIMUM_TILT) * MathConstants.DEG2RAD);
}
@@ -259,7 +275,7 @@ public final class CameraPosition implements Parcelable {
* @param zoom Zoom value
* @return Builder
*/
- public Builder zoom(float zoom) {
+ public Builder zoom(double zoom) {
this.zoom = zoom;
return this;
}
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/camera/CameraUpdateFactory.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/camera/CameraUpdateFactory.java
index df156961a0..93d1cd2e66 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/camera/CameraUpdateFactory.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/camera/CameraUpdateFactory.java
@@ -148,12 +148,12 @@ public final class CameraUpdateFactory {
static final class CameraPositionUpdate implements CameraUpdate {
- private final float bearing;
+ private final double bearing;
private final LatLng target;
- private final float tilt;
- private final float zoom;
+ private final double tilt;
+ private final double zoom;
- CameraPositionUpdate(float bearing, LatLng target, float tilt, float zoom) {
+ CameraPositionUpdate(double bearing, LatLng target, double tilt, double zoom) {
this.bearing = bearing;
this.target = target;
this.tilt = tilt;
@@ -164,15 +164,15 @@ public final class CameraUpdateFactory {
return target;
}
- public float getBearing() {
+ public double getBearing() {
return bearing;
}
- public float getTilt() {
+ public double getTilt() {
return tilt;
}
- public float getZoom() {
+ public double getZoom() {
return zoom;
}
@@ -311,7 +311,7 @@ public final class CameraUpdateFactory {
@Type
private final int type;
- private final float zoom;
+ private final double zoom;
private float x;
private float y;
@@ -332,7 +332,7 @@ public final class CameraUpdateFactory {
this.y = y;
}
- public float getZoom() {
+ public double getZoom() {
return zoom;
}
@@ -349,7 +349,7 @@ public final class CameraUpdateFactory {
return y;
}
- public float transformZoom(float currentZoom) {
+ public double transformZoom(double currentZoom) {
switch (getType()) {
case CameraUpdateFactory.ZoomUpdate.ZOOM_IN:
currentZoom++;
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/http/HTTPContext.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/http/HTTPContext.java
index b9d1d1ba18..7132f8ead6 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/http/HTTPContext.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/http/HTTPContext.java
@@ -83,7 +83,7 @@ class HTTPContext {
@Override
public void onResponse(Call call, Response response) throws IOException {
if (response.isSuccessful()) {
- Log.d(LOG_TAG, String.format("[HTTP] Request was successful (code = %d).", response.code()));
+ Log.v(LOG_TAG, String.format("[HTTP] Request was successful (code = %d).", response.code()));
} else {
// We don't want to call this unsuccessful because a 304 isn't really an error
String message = !TextUtils.isEmpty(response.message()) ? response.message() : "No additional information";
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapFragment.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapFragment.java
index 3d103f6f8c..61d4af51cd 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapFragment.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapFragment.java
@@ -9,6 +9,7 @@ import android.view.View;
import android.view.ViewGroup;
import com.mapbox.mapboxsdk.R;
+import com.mapbox.mapboxsdk.constants.Style;
import com.mapbox.mapboxsdk.utils.ApiAccess;
/**
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapView.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapView.java
index 3a689ac97b..483099a387 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapView.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapView.java
@@ -55,6 +55,7 @@ import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.ZoomButtonsController;
+
import com.almeros.android.multitouch.gesturedetectors.RotateGestureDetector;
import com.almeros.android.multitouch.gesturedetectors.ShoveGestureDetector;
import com.almeros.android.multitouch.gesturedetectors.TwoFingerGestureDetector;
@@ -71,6 +72,7 @@ import com.mapbox.mapboxsdk.camera.CameraUpdateFactory;
import com.mapbox.mapboxsdk.constants.MapboxConstants;
import com.mapbox.mapboxsdk.constants.MyBearingTracking;
import com.mapbox.mapboxsdk.constants.MyLocationTracking;
+import com.mapbox.mapboxsdk.constants.Style;
import com.mapbox.mapboxsdk.exceptions.IconBitmapChangedException;
import com.mapbox.mapboxsdk.exceptions.InvalidAccessTokenException;
import com.mapbox.mapboxsdk.exceptions.TelemetryServiceNotConfiguredException;
@@ -82,6 +84,7 @@ import com.mapbox.mapboxsdk.maps.widgets.UserLocationView;
import com.mapbox.mapboxsdk.telemetry.MapboxEvent;
import com.mapbox.mapboxsdk.telemetry.MapboxEventManager;
import com.mapbox.mapboxsdk.utils.ApiAccess;
+
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.nio.ByteBuffer;
@@ -145,6 +148,10 @@ public class MapView extends FrameLayout {
private int mContentPaddingRight;
private int mContentPaddingBottom;
+ private OnMapReadyCallback mMapReadyCallback;
+ private String mStyleUrl;
+ private boolean mInitialLoad;
+
@UiThread
public MapView(@NonNull Context context) {
super(context);
@@ -164,6 +171,7 @@ public class MapView extends FrameLayout {
}
private void initialize(@NonNull Context context, @Nullable AttributeSet attrs) {
+ mInitialLoad = true;
mOnMapChangedListener = new CopyOnWriteArrayList<>();
mMapboxMap = new MapboxMap(this);
mIcons = new ArrayList<>();
@@ -307,6 +315,9 @@ public class MapView extends FrameLayout {
*/
@UiThread
public void onCreate(@Nullable Bundle savedInstanceState) {
+ // Force a check for an access token
+ validateAccessToken(getAccessToken());
+
if (savedInstanceState != null && savedInstanceState.getBoolean(MapboxConstants.STATE_HAS_SAVED_STATE)) {
// Get previous camera position
@@ -370,16 +381,10 @@ public class MapView extends FrameLayout {
// Force a check for Telemetry
validateTelemetryServiceConfigured();
- // Force a check for an access token
- validateAccessToken(getAccessToken());
-
// Start Telemetry (authorization determined in initial MapboxEventManager constructor)
MapboxEventManager.configureAndStartMapboxEventManager(getContext(), getAccessToken());
}
- // Force a check for an access token
- validateAccessToken(getAccessToken());
-
// Initialize EGL
mNativeMapView.initializeDisplay();
mNativeMapView.initializeContext();
@@ -392,6 +397,12 @@ public class MapView extends FrameLayout {
reloadIcons();
reloadMarkers();
adjustTopOffsetPixels();
+ if (mInitialLoad) {
+ mInitialLoad = false;
+ if (mMapReadyCallback != null) {
+ mMapReadyCallback.onMapReady(mMapboxMap);
+ }
+ }
}
}
});
@@ -417,7 +428,7 @@ public class MapView extends FrameLayout {
outState.putBoolean(MapboxConstants.STATE_HAS_SAVED_STATE, true);
outState.putParcelable(MapboxConstants.STATE_CAMERA_POSITION, mMapboxMap.getCameraPosition());
outState.putBoolean(MapboxConstants.STATE_DEBUG_ACTIVE, mMapboxMap.isDebugActive());
- outState.putString(MapboxConstants.STATE_STYLE_URL, mMapboxMap.getStyleUrl());
+ outState.putString(MapboxConstants.STATE_STYLE_URL, mStyleUrl);
outState.putString(MapboxConstants.STATE_ACCESS_TOKEN, mMapboxMap.getAccessToken());
outState.putLong(MapboxConstants.STATE_DEFAULT_TRANSITION_DURATION, mNativeMapView.getDefaultTransitionDuration());
outState.putBoolean(MapboxConstants.STATE_MY_LOCATION_ENABLED, mMapboxMap.isMyLocationEnabled());
@@ -514,6 +525,11 @@ public class MapView extends FrameLayout {
mNativeMapView.resume();
mNativeMapView.update();
mUserLocationView.resume();
+
+ if (mStyleUrl == null) {
+ // user has failed to supply a style url
+ setStyleUrl(Style.MAPBOX_STREETS);
+ }
}
/**
@@ -676,10 +692,72 @@ public class MapView extends FrameLayout {
// Styling
//
- void setStyleUrl(@NonNull String url) {
+ /**
+ * <p>
+ * Loads a new map style from the specified URL.
+ * </p>
+ * {@code url} can take the following forms:
+ * <ul>
+ * <li>{@code Style.*}: load one of the bundled styles in {@link Style}.</li>
+ * <li>{@code mapbox://styles/<user>/<style>}:
+ * retrieves the style from a <a href="https://www.mapbox.com/account/">Mapbox account.</a>
+ * {@code user} is your username. {@code style} is the ID of your custom
+ * style created in <a href="https://www.mapbox.com/studio">Mapbox Studio</a>.</li>
+ * <li>{@code http://...} or {@code https://...}:
+ * retrieves the style over the Internet from any web server.</li>
+ * <li>{@code asset://...}:
+ * reads the style from the APK {@code assets/} directory.
+ * This is used to load a style bundled with your app.</li>
+ * <li>{@code null}: loads the default {@link Style#MAPBOX_STREETS} style.</li>
+ * </ul>
+ * <p>
+ * This method is asynchronous and will return immediately before the style finishes loading.
+ * If you wish to wait for the map to finish loading listen for the {@link MapView#DID_FINISH_LOADING_MAP} event.
+ * </p>
+ * If the style fails to load or an invalid style URL is set, the map view will become blank.
+ * An error message will be logged in the Android logcat and {@link MapView#DID_FAIL_LOADING_MAP} event will be sent.
+ *
+ * @param url The URL of the map style
+ * @see Style
+ */
+ public void setStyleUrl(@NonNull String url) {
+ mStyleUrl = url;
mNativeMapView.setStyleUrl(url);
}
+ /**
+ * <p>
+ * Loads a new map style from the specified bundled style.
+ * </p>
+ * <p>
+ * This method is asynchronous and will return immediately before the style finishes loading.
+ * If you wish to wait for the map to finish loading listen for the {@link MapView#DID_FINISH_LOADING_MAP} event.
+ * </p>
+ * If the style fails to load or an invalid style URL is set, the map view will become blank.
+ * An error message will be logged in the Android logcat and {@link MapView#DID_FAIL_LOADING_MAP} event will be sent.
+ *
+ * @param style The bundled style. Accepts one of the values from {@link Style}.
+ * @see Style
+ */
+ @UiThread
+ public void setStyle(@Style.StyleUrl String style) {
+ setStyleUrl(style);
+ }
+
+ /**
+ * <p>
+ * Returns the map style currently displayed in the map view.
+ * </p>
+ * If the default style is currently displayed, a URL will be returned instead of null.
+ *
+ * @return The URL of the map style.
+ */
+ @UiThread
+ @NonNull
+ public String getStyleUrl() {
+ return mStyleUrl;
+ }
+
//
// Access token
//
@@ -855,9 +933,6 @@ public class MapView extends FrameLayout {
}
long addMarker(@NonNull Marker marker) {
- if (mNativeMapView == null) {
- return 0l;
- }
return mNativeMapView.addMarker(marker);
}
@@ -1118,32 +1193,18 @@ public class MapView extends FrameLayout {
}
}
- /**
- * Get Bearing in degrees
- *
- * @return Bearing in degrees
- */
+ CameraPosition invalidateCameraPosition() {
+ return new CameraPosition.Builder(mNativeMapView.getCameraValues()).build();
+ }
+
double getBearing() {
return mNativeMapView.getBearing();
}
- /**
- * Set Bearing in degrees
- *
- * @param bearing Bearing in degrees
- */
void setBearing(float bearing) {
mNativeMapView.setBearing(bearing);
}
- /**
- * Sets Bearing in degrees
- * <p/>
- * NOTE: Used by UserLocationView
- *
- * @param bearing Bearing in degrees
- * @param duration Length of time to rotate
- */
void setBearing(float bearing, long duration) {
mNativeMapView.setBearing(bearing, duration);
}
@@ -1204,6 +1265,7 @@ public class MapView extends FrameLayout {
/**
* Helper method for tracking DragEnd gesture event
* See {@see MapboxEvent#TYPE_MAP_DRAGEND}
+ *
* @param xCoordinate Original x screen coordinate at end of drag
* @param yCoordinate Orginal y screen coordinate at end of drag
*/
@@ -2231,14 +2293,10 @@ public class MapView extends FrameLayout {
*/
@UiThread
public void getMapAsync(@NonNull final OnMapReadyCallback callback) {
-
- // We need to put our callback on the message queue
- post(new Runnable() {
- @Override
- public void run() {
- callback.onMapReady(mMapboxMap);
- }
- });
+ if (mMapReadyCallback == null && !mInitialLoad) {
+ callback.onMapReady(mMapboxMap);
+ }
+ mMapReadyCallback = callback;
}
MapboxMap getMapboxMap() {
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapboxMap.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapboxMap.java
index 9530096131..93ef6a8299 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapboxMap.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapboxMap.java
@@ -323,12 +323,7 @@ public class MapboxMap {
*/
private void invalidateCameraPosition() {
mInvalidCameraPosition = false;
- mCameraPosition = new CameraPosition.Builder(true)
- .bearing((float) mMapView.getBearing())
- .target(mMapView.getLatLng())
- .tilt((float) mMapView.getTilt())
- .zoom((float) mMapView.getZoom())
- .build();
+ mCameraPosition = mMapView.invalidateCameraPosition();
if (mOnCameraChangeListener != null) {
mOnCameraChangeListener.onCameraChange(mCameraPosition);
}
@@ -420,7 +415,6 @@ public class MapboxMap {
*/
@UiThread
public void setStyleUrl(@NonNull String url) {
- mStyleUrl = url;
mMapView.setStyleUrl(url);
}
@@ -454,7 +448,7 @@ public class MapboxMap {
@UiThread
@NonNull
public String getStyleUrl() {
- return mStyleUrl;
+ return mMapView.getStyleUrl();
}
//
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/NativeMapView.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/NativeMapView.java
index b7f583e943..7948097ec7 100755
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/NativeMapView.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/NativeMapView.java
@@ -487,6 +487,10 @@ final class NativeMapView {
nativeRemoveCustomLayer(mNativeMapViewPtr, id);
}
+ public double[] getCameraValues(){
+ return nativeGetCameraValues(mNativeMapViewPtr);
+ }
+
//
// Callbacks
//
@@ -680,4 +684,6 @@ final class NativeMapView {
private native void nativeAddCustomLayer(long nativeMapViewPtr, CustomLayer customLayer, String before);
private native void nativeRemoveCustomLayer(long nativeMapViewPtr, String id);
+
+ private native double[] nativeGetCameraValues(long mNativeMapViewPtr);
}
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/SupportMapFragment.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/SupportMapFragment.java
index 60d9320ee6..ff587ca4d2 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/SupportMapFragment.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/SupportMapFragment.java
@@ -9,6 +9,7 @@ import android.view.View;
import android.view.ViewGroup;
import com.mapbox.mapboxsdk.R;
+import com.mapbox.mapboxsdk.constants.Style;
import com.mapbox.mapboxsdk.utils.ApiAccess;
/**
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/widgets/UserLocationView.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/widgets/UserLocationView.java
index b2364dc042..dcc440dd1c 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/widgets/UserLocationView.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/widgets/UserLocationView.java
@@ -278,7 +278,7 @@ public final class UserLocationView extends View {
mMarkerScreenPoint.y);
} else if (mMyLocationTrackingMode == MyLocationTracking.TRACKING_FOLLOW) {
- float bearing;
+ double bearing;
if (mShowDirection) {
bearing = mMyBearingTrackingMode == MyBearingTracking.COMPASS ? mBearingChangeListener.getCompassBearing() : mUserLocation.getBearing();
} else {
@@ -309,10 +309,10 @@ public final class UserLocationView extends View {
// rotate so arrow in points to bearing
if (mShowDirection) {
if (mMyBearingTrackingMode == MyBearingTracking.COMPASS && mMyLocationTrackingMode == MyLocationTracking.TRACKING_NONE) {
- mMarkerScreenMatrix.preRotate(mCompassMarkerDirection + mMapboxMap.getCameraPosition().bearing);
+ mMarkerScreenMatrix.preRotate((float)(mCompassMarkerDirection + mMapboxMap.getCameraPosition().bearing));
} else if (mMyBearingTrackingMode == MyBearingTracking.GPS) {
if (mMyLocationTrackingMode == MyLocationTracking.TRACKING_NONE) {
- mMarkerScreenMatrix.preRotate(mGpsMarkerDirection + mMapboxMap.getCameraPosition().bearing);
+ mMarkerScreenMatrix.preRotate((float)(mGpsMarkerDirection + mMapboxMap.getCameraPosition().bearing));
} else {
mMarkerScreenMatrix.preRotate(mGpsMarkerDirection);
}
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/offline/OfflineManager.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/offline/OfflineManager.java
index b56ecfc057..e632bcd765 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/offline/OfflineManager.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/offline/OfflineManager.java
@@ -126,7 +126,7 @@ public class OfflineManager {
*/
public void createOfflineRegion(
@NonNull OfflineRegionDefinition definition,
- @NonNull OfflineRegionMetadata metadata,
+ @NonNull byte[] metadata,
@NonNull final CreateOfflineRegionCallback callback) {
createOfflineRegion(mDefaultFileSourcePtr, definition, metadata, new CreateOfflineRegionCallback() {
@@ -176,7 +176,7 @@ public class OfflineManager {
private native void createOfflineRegion(
long defaultFileSourcePtr, OfflineRegionDefinition definition,
- OfflineRegionMetadata metadata, CreateOfflineRegionCallback callback);
+ byte[] metadata, CreateOfflineRegionCallback callback);
private native void setOfflineMapboxTileCountLimit(
long defaultFileSourcePtr, long limit);
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/offline/OfflineRegion.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/offline/OfflineRegion.java
index 9e518f1e6a..0f05549338 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/offline/OfflineRegion.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/offline/OfflineRegion.java
@@ -23,7 +23,13 @@ public class OfflineRegion {
// Members
private long mId = 0;
private OfflineRegionDefinition mDefinition = null;
- private OfflineRegionMetadata mMetadata = null;
+
+ /**
+ * Arbitrary binary region metadata. The contents are opaque to the SDK implementation;
+ * it just stores and retrieves a byte[]. Check the `OfflineActivity` in the TestApp
+ * for a sample implementation that uses JSON to store an offline region name.
+ */
+ private byte[] mMetadata = null;
// Holds the pointer to JNI OfflineRegion
private long mOfflineRegionPtr = 0;
@@ -122,7 +128,7 @@ public class OfflineRegion {
return mDefinition;
}
- public OfflineRegionMetadata getMetadata() {
+ public byte[] getMetadata() {
return mMetadata;
}
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/offline/OfflineRegionMetadata.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/offline/OfflineRegionMetadata.java
deleted file mode 100644
index d4445ca037..0000000000
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/offline/OfflineRegionMetadata.java
+++ /dev/null
@@ -1,40 +0,0 @@
-package com.mapbox.mapboxsdk.offline;
-
-/**
- * Arbitrary binary region metadata. The contents are opaque to the SDK implementation;
- * it just stores and retrieves a byte[].
- */
-public class OfflineRegionMetadata {
-
- private byte[] metadata;
-
- /*
- * Constructor
- */
-
- public OfflineRegionMetadata(byte[] metadata) {
- this.metadata = metadata;
- }
-
- /*
- * Getters and setters
- */
-
- public byte[] getMetadata() {
- return metadata;
- }
-
- public void setMetadata(byte[] metadata) {
- this.metadata = metadata;
- }
-
- /*
- * Overrides
- */
-
- @Override
- public String toString() {
- return "OfflineRegionMetadata{metadata=" + metadata + "}";
- }
-
-}
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/telemetry/MapboxEventManager.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/telemetry/MapboxEventManager.java
index 1d8b75f6dc..5a74c841cf 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/telemetry/MapboxEventManager.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/telemetry/MapboxEventManager.java
@@ -598,31 +598,19 @@ public class MapboxEventManager {
}
// Based on http://square.github.io/okhttp/3.x/okhttp/okhttp3/CertificatePinner.html
-
- // SHA256 Values for Certs when OkHttp 3.2.0 Is Released
- // Staging - Geotrust
-// .add("cloudfront-staging.tilestream.net", "sha256/kR9ysyN/lzBl/ecearDERV7qO7xqSN4jt6XuQjIVL0I=")
-// .add("cloudfront-staging.tilestream.net", "sha256/sPbNCVpVasMJxps3IqFfLTRKkVnRCLrTlZVc5kspqlkw=")
-// .add("cloudfront-staging.tilestream.net", "sha256/h6801m+z8v3zbgkRHpq6L29Esgfzhj89C1SyUCOQmqU=")
- // Prod - Geotrust
-// .add("api.mapbox.com", "sha256/svaiYM/ZVIfxC+CMDe4kj1KsviQmzyZ9To8nQqUJwFI=")
-// .add("api.mapbox.com", "sha256/owrR9U9FWDWtrFF+myoRIu75JwU4sJwzvhCNLZoY37g=")
-// .add("api.mapbox.com", "sha256/SQVGZiOrQXi+kqxcvWWE96HhfydlLVqFr4lQTqI5qqo=")
- // Prod - DigiCert
-// .add("api.mapbox.com", "sha256/JL+uwAwpA2U1UVl/AFdZy1ZnvkZJ1P1hRfmfPaPVSLU=")
-// .add("api.mapbox.com", "sha256/RRM1dGqnDFsCJXBTHky16vi1obOlCgFFn/yOhI/y+ho=")
-// .add("api.mapbox.com", "sha256/WoiWRyIOVNa9ihaBciRSC7XHjliYS9VwUGOIud4PB18=")
-
CertificatePinner certificatePinner = new CertificatePinner.Builder()
- // Staging - Geotrust SHA1
- .add("cloudfront-staging.tilestream.net", "sha1/KcdiTca54HxWTV8VuAd67x8I=")
- .add("cloudfront-staging.tilestream.net", "sha1//KDE76PP0DQBDcTnMFBv+efp4eg=")
- // Prod - Geotrust SHA1
- .add("api.mapbox.com", "sha1/Uv71ooi32pyba+oLD7egnXm7/GQ=")
- .add("api.mapbox.com", "sha1/hOP0d37/ZTSGgCSseE3DIZ1uSg0=")
- // Prod - DigiCert SHA1
- .add("api.mapbox.com", "sha1/EoBG4XgG0B1cTNYJbFJDlNuxpII=")
- .add("api.mapbox.com", "sha1/LHspp8BlMzJeqfRrY/MmhzxEa3Q=")
+ // Staging - Geotrust
+ .add("cloudfront-staging.tilestream.net", "sha256/kR9ysyN/lzBl/ecearDERV7qO7xqSN4jt6XuQjIVL0I=")
+ .add("cloudfront-staging.tilestream.net", "sha256/sPbNCVpVasMJxps3IqFfLTRKkVnRCLrTlZVc5kspqlkw=")
+ .add("cloudfront-staging.tilestream.net", "sha256/h6801m+z8v3zbgkRHpq6L29Esgfzhj89C1SyUCOQmqU=")
+ // Prod - Geotrust
+ .add("api.mapbox.com", "sha256/svaiYM/ZVIfxC+CMDe4kj1KsviQmzyZ9To8nQqUJwFI=")
+ .add("api.mapbox.com", "sha256/owrR9U9FWDWtrFF+myoRIu75JwU4sJwzvhCNLZoY37g=")
+ .add("api.mapbox.com", "sha256/SQVGZiOrQXi+kqxcvWWE96HhfydlLVqFr4lQTqI5qqo=")
+ // Prod - DigiCert
+ .add("api.mapbox.com", "sha256/JL+uwAwpA2U1UVl/AFdZy1ZnvkZJ1P1hRfmfPaPVSLU=")
+ .add("api.mapbox.com", "sha256/RRM1dGqnDFsCJXBTHky16vi1obOlCgFFn/yOhI/y+ho=")
+ .add("api.mapbox.com", "sha256/WoiWRyIOVNa9ihaBciRSC7XHjliYS9VwUGOIud4PB18=")
.build();
OkHttpClient client = new OkHttpClient.Builder().certificatePinner(certificatePinner).build();
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/telemetry/TelemetryService.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/telemetry/TelemetryService.java
index 0640620814..820502db64 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/telemetry/TelemetryService.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/telemetry/TelemetryService.java
@@ -6,7 +6,6 @@ import android.content.IntentFilter;
import android.content.pm.ServiceInfo;
import android.os.AsyncTask;
import android.os.IBinder;
-import android.os.PowerManager;
import android.support.annotation.Nullable;
import android.util.Log;
@@ -15,7 +14,6 @@ public class TelemetryService extends Service {
private static final String TAG = "TelemetryService";
private TelemetryLocationReceiver telemetryLocationReceiver = null;
- private PowerManager.WakeLock telemetryWakeLock;
/**
* Return the communication channel to the service. May return null if
@@ -130,11 +128,6 @@ public class TelemetryService extends Service {
Log.i(TAG, "onStartCommand() called");
- // Start WakeLock to keep Location Data working when device sleeps
- PowerManager mgr = (PowerManager)getSystemService(Context.POWER_SERVICE);
- telemetryWakeLock = mgr.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "TelemetryWakeLock");
- telemetryWakeLock.acquire();
-
return START_NOT_STICKY;
}
@@ -151,6 +144,5 @@ public class TelemetryService extends Service {
}
unregisterReceiver(telemetryLocationReceiver);
- telemetryWakeLock.release();
}
}
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/CameraActivity.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/CameraActivity.java
index 50c3c3e42e..a9c98b5d3d 100644
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/CameraActivity.java
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/CameraActivity.java
@@ -47,7 +47,6 @@ public class CameraActivity extends AppCompatActivity {
@Override
public void onMapReady(@NonNull final MapboxMap mapboxMap) {
// set a style
- mapboxMap.setStyle(Style.MAPBOX_STREETS);
mapboxMap.setOnCameraChangeListener(new MapboxMap.OnCameraChangeListener() {
@Override
public void onCameraChange(CameraPosition position) {
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/CoordinateChangeActivity.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/CoordinateChangeActivity.java
index 615b3388c3..88b3887cdf 100644
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/CoordinateChangeActivity.java
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/CoordinateChangeActivity.java
@@ -46,7 +46,6 @@ public class CoordinateChangeActivity extends AppCompatActivity {
@Override
public void onMapReady(@NonNull MapboxMap mapboxMap) {
mMapboxMap = mapboxMap;
- mapboxMap.setStyle(Style.MAPBOX_STREETS);
mapboxMap.moveCamera(CameraUpdateFactory.newLatLngZoom(getNextLatLng(), 16));
UiSettings uiSettings = mapboxMap.getUiSettings();
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/DoubleMapActivity.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/DoubleMapActivity.java
index 7af3790443..4452b03ff1 100644
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/DoubleMapActivity.java
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/DoubleMapActivity.java
@@ -65,12 +65,11 @@ public class DoubleMapActivity extends AppCompatActivity {
// MapView large
mMapView = (MapView) view.findViewById(R.id.mapView);
+ mMapView.setStyleUrl(Style.DARK);
mMapView.onCreate(savedInstanceState);
mMapView.getMapAsync(new OnMapReadyCallback() {
@Override
public void onMapReady(@NonNull MapboxMap mapboxMap) {
- mapboxMap.setStyle(Style.DARK);
-
mapboxMap.moveCamera(CameraUpdateFactory.zoomTo(18));
try {
TrackingSettings settings = mapboxMap.getTrackingSettings();
@@ -84,11 +83,11 @@ public class DoubleMapActivity extends AppCompatActivity {
// MapView mini
mMapViewMini = (MapView) view.findViewById(R.id.mini_map);
+ mMapViewMini.setStyle(Style.LIGHT);
mMapViewMini.onCreate(savedInstanceState);
mMapViewMini.getMapAsync(new OnMapReadyCallback() {
@Override
public void onMapReady(@NonNull MapboxMap mapboxMap) {
- mapboxMap.setStyle(Style.LIGHT);
mapboxMap.moveCamera(CameraUpdateFactory.zoomTo(4));
UiSettings uiSettings = mapboxMap.getUiSettings();
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/DynamicMarkerChangeActivity.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/DynamicMarkerChangeActivity.java
index 89aff8169b..58fc2c1603 100644
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/DynamicMarkerChangeActivity.java
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/DynamicMarkerChangeActivity.java
@@ -55,7 +55,6 @@ public class DynamicMarkerChangeActivity extends AppCompatActivity {
@Override
public void onMapReady(@NonNull MapboxMap mapboxMap) {
mMapboxMap = mapboxMap;
- mapboxMap.setStyle(Style.MAPBOX_STREETS);
mapboxMap.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(51.506675, -0.128699), 10));
// Create marker
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/GeocoderActivity.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/GeocoderActivity.java
index 5594348be7..5cc9b0da68 100644
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/GeocoderActivity.java
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/GeocoderActivity.java
@@ -1,12 +1,18 @@
package com.mapbox.mapboxsdk.testapp;
+import android.graphics.PointF;
+import android.os.AsyncTask;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.util.Log;
+import android.view.Gravity;
import android.view.MenuItem;
+import android.view.ViewGroup;
+import android.widget.FrameLayout;
+import android.widget.ImageView;
import android.widget.TextView;
import com.mapbox.geocoder.GeocoderCriteria;
@@ -19,6 +25,7 @@ import com.mapbox.mapboxsdk.annotations.MarkerOptions;
import com.mapbox.mapboxsdk.constants.Style;
import com.mapbox.mapboxsdk.geometry.LatLng;
import com.mapbox.mapboxsdk.maps.OnMapReadyCallback;
+import com.mapbox.mapboxsdk.maps.Projection;
import com.mapbox.mapboxsdk.utils.ApiAccess;
import com.mapbox.mapboxsdk.maps.MapView;
@@ -55,13 +62,21 @@ public class GeocoderActivity extends AppCompatActivity {
mapView = (MapView) findViewById(R.id.mapView);
mapView.setAccessToken(ApiAccess.getToken(this));
+ mapView.setStyle(Style.MAPBOX_STREETS);
mapView.onCreate(savedInstanceState);
+
+ final ImageView dropPinView = new ImageView(this);
+ dropPinView.setImageResource(R.drawable.ic_droppin_24dp);
+ FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT, Gravity.CENTER);
+ dropPinView.setLayoutParams(params);
+ mapView.addView(dropPinView);
+
mapView.getMapAsync(new OnMapReadyCallback() {
@Override
public void onMapReady(@NonNull final MapboxMap mapboxMap) {
-
- // Style
- mapboxMap.setStyle(Style.EMERALD);
+ final Projection projection = mapboxMap.getProjection();
+ final int width = mapView.getMeasuredWidth();
+ final int height = mapView.getMeasuredHeight();
// Camera position
mapboxMap.setCameraPosition(
@@ -77,12 +92,15 @@ public class GeocoderActivity extends AppCompatActivity {
mapboxMap.setOnMapClickListener(new MapboxMap.OnMapClickListener() {
@Override
public void onMapClick(@NonNull LatLng point) {
+ PointF centerPoint = new PointF(width / 2, (height + dropPinView.getHeight()) / 2);
+ LatLng centerLatLng = new LatLng(projection.fromScreenLocation(centerPoint));
+
setMessage("Geocoding...");
+
mapboxMap.removeAnnotations();
- mapboxMap.addMarker(new MarkerOptions()
- .position(point)
- .title("Your finger is here"));
- geocode(point);
+ mapboxMap.addMarker(new MarkerOptions().position(centerLatLng));
+
+ geocode(centerLatLng);
}
});
}
@@ -129,31 +147,41 @@ public class GeocoderActivity extends AppCompatActivity {
* Forward geocoding
*/
- private void geocode(LatLng point) {
- MapboxGeocoder client = new MapboxGeocoder.Builder()
- .setAccessToken(ApiAccess.getToken(this))
- .setCoordinates(point.getLongitude(), point.getLatitude())
- .setType(GeocoderCriteria.TYPE_POI)
- .build();
+ private void geocode(final LatLng point) {
+ new AsyncTask<Void, Void, Void>() {
- client.enqueue(new Callback<GeocoderResponse>() {
@Override
- public void onResponse(Response<GeocoderResponse> response, Retrofit retrofit) {
- List<GeocoderFeature> results = response.body().getFeatures();
- if (results.size() > 0) {
- String placeName = results.get(0).getPlaceName();
- setSuccess(placeName);
- } else {
- setMessage("No results.");
- }
- }
+ protected Void doInBackground(Void... params) {
+ MapboxGeocoder client = new MapboxGeocoder.Builder()
+ .setAccessToken(ApiAccess.getToken(GeocoderActivity.this))
+ .setCoordinates(point.getLongitude(), point.getLatitude())
+ .setType(GeocoderCriteria.TYPE_POI)
+ .build();
+
+ client.enqueue(new Callback<GeocoderResponse>()
+
+ {
+ @Override
+ public void onResponse(Response<GeocoderResponse> response, Retrofit retrofit) {
+ List<GeocoderFeature> results = response.body().getFeatures();
+ if (results.size() > 0) {
+ String placeName = results.get(0).getPlaceName();
+ setSuccess(placeName);
+ } else {
+ setMessage("No results.");
+ }
+ }
+
+ @Override
+ public void onFailure(Throwable t) {
+ setError(t.getMessage());
+ }
+ }
- @Override
- public void onFailure(Throwable t) {
- setError(t.getMessage());
+ );
+ return null;
}
- });
-
+ }.execute();
}
/*
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/InfoWindowActivity.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/InfoWindowActivity.java
index f12a183563..b002d41f7b 100644
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/InfoWindowActivity.java
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/InfoWindowActivity.java
@@ -49,11 +49,14 @@ public class InfoWindowActivity extends AppCompatActivity {
.snippet("H St NW with 15th St NW")
.position(new LatLng(38.9002073, -77.03364419)));
- mapboxMap.addMarker(new MarkerOptions()
+ Marker marker = mapboxMap.addMarker(new MarkerOptions()
.title("White House")
.snippet("The official residence and principal workplace of the President of the United States, located at 1600 Pennsylvania Avenue NW in Washington, D.C. It has been the residence of every U.S. president since John Adams in 1800.")
.position(new LatLng(38.897705003219784, -77.03655168667463)));
+ // open InfoWindow at startup!
+ mapboxMap.selectMarker(marker);
+
mapboxMap.addMarker(new MarkerOptions().title("Intersection")
.snippet("E St NW with 17th St NW")
.position(new LatLng(38.8954236, -77.0394623)));
@@ -61,7 +64,7 @@ public class InfoWindowActivity extends AppCompatActivity {
mapboxMap.setOnInfoWindowCloseListener(new MapboxMap.OnInfoWindowCloseListener() {
@Override
public void onInfoWindowClose(Marker marker) {
- Toast.makeText(getApplicationContext(),"OnClose: "+marker.getTitle(),Toast.LENGTH_LONG).show();
+ Toast.makeText(getApplicationContext(), "OnClose: " + marker.getTitle(), Toast.LENGTH_LONG).show();
}
});
@@ -97,7 +100,7 @@ public class InfoWindowActivity extends AppCompatActivity {
mapboxMap.setOnInfoWindowLongClickListener(new MapboxMap.OnInfoWindowLongClickListener() {
@Override
public void onInfoWindowLongClick(Marker marker) {
- Toast.makeText(getApplicationContext(),"OnLongClick: "+marker.getTitle(),Toast.LENGTH_LONG).show();
+ Toast.makeText(getApplicationContext(), "OnLongClick: " + marker.getTitle(), Toast.LENGTH_LONG).show();
}
});
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/LatLngBoundsActivity.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/LatLngBoundsActivity.java
index 3246807f89..0e66981e13 100644
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/LatLngBoundsActivity.java
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/LatLngBoundsActivity.java
@@ -43,6 +43,7 @@ public class LatLngBoundsActivity extends AppCompatActivity {
mMapView = (MapView) findViewById(R.id.mapView);
mMapView.setAccessToken(ApiAccess.getToken(this));
+ mMapView.setStyle(Style.DARK);
mMapView.onCreate(savedInstanceState);
mMapView.getMapAsync(new OnMapReadyCallback() {
@Override
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/MainActivity.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/MainActivity.java
index 451876e39b..9545b929a4 100644
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/MainActivity.java
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/MainActivity.java
@@ -136,6 +136,7 @@ public class MainActivity extends AppCompatActivity {
mMapView = (MapView) findViewById(R.id.mainMapView);
mMapView.setAccessToken(ApiAccess.getToken(this));
+ changeMapStyle(mSelectedStyle);
mMapView.onCreate(savedInstanceState);
mMapView.getMapAsync(new OnMapReadyCallback() {
@Override
@@ -229,7 +230,6 @@ public class MainActivity extends AppCompatActivity {
}
});
- changeMapStyle(mSelectedStyle);
}
});
}
@@ -496,32 +496,32 @@ public class MainActivity extends AppCompatActivity {
private boolean changeMapStyle(int id) {
switch (id) {
case R.id.actionStyleMapboxStreets:
- mMapboxMap.setStyle(Style.MAPBOX_STREETS);
+ mMapView.setStyleUrl(Style.MAPBOX_STREETS);
mSelectedStyle = id;
return true;
case R.id.actionStyleEmerald:
- mMapboxMap.setStyle(Style.EMERALD);
+ mMapView.setStyleUrl(Style.EMERALD);
mSelectedStyle = id;
return true;
case R.id.actionStyleLight:
- mMapboxMap.setStyle(Style.LIGHT);
+ mMapView.setStyleUrl(Style.LIGHT);
mSelectedStyle = id;
return true;
case R.id.actionStyleDark:
- mMapboxMap.setStyle(Style.DARK);
+ mMapView.setStyleUrl(Style.DARK);
mSelectedStyle = id;
return true;
case R.id.actionStyleSatellite:
- mMapboxMap.setStyle(Style.SATELLITE);
+ mMapView.setStyleUrl(Style.SATELLITE);
mSelectedStyle = id;
return true;
case R.id.actionStyleSatelliteStreets:
- mMapboxMap.setStyle(Style.SATELLITE_STREETS);
+ mMapView.setStyleUrl(Style.SATELLITE_STREETS);
mSelectedStyle = id;
return true;
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/ManualZoomActivity.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/ManualZoomActivity.java
index 1f74d1e7f8..17cc194253 100644
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/ManualZoomActivity.java
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/ManualZoomActivity.java
@@ -39,12 +39,12 @@ public class ManualZoomActivity extends AppCompatActivity {
mMapView = (MapView) findViewById(R.id.manualZoomMapView);
mMapView.setAccessToken(ApiAccess.getToken(this));
+ mMapView.setStyleUrl(Style.SATELLITE_STREETS);
mMapView.onCreate(savedInstanceState);
mMapView.getMapAsync(new OnMapReadyCallback() {
@Override
public void onMapReady(@NonNull final MapboxMap mapboxMap) {
mMapboxMap = mapboxMap;
- mMapboxMap.setStyle(Style.SATELLITE_STREETS);
UiSettings uiSettings = mMapboxMap.getUiSettings();
uiSettings.setAllGesturesEnabled(false);
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/MapFragmentActivity.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/MapFragmentActivity.java
index 4615d35e33..5fbc2f64ba 100644
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/MapFragmentActivity.java
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/MapFragmentActivity.java
@@ -49,8 +49,6 @@ public class MapFragmentActivity extends AppCompatActivity {
new CameraPosition.Builder()
.target(new LatLng(48.861431, 2.334166))
.zoom(10)
- .bearing(0)
- .tilt(0)
.build()));
}
});
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/MapPaddingActivity.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/MapPaddingActivity.java
index 524925d51b..d0ccd1ddbf 100644
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/MapPaddingActivity.java
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/MapPaddingActivity.java
@@ -43,18 +43,18 @@ public class MapPaddingActivity extends AppCompatActivity {
mMapView.setTag(true);
mMapView.setAccessToken(ApiAccess.getToken(this));
mMapView.onCreate(savedInstanceState);
+
mMapView.getMapAsync(new OnMapReadyCallback() {
@Override
public void onMapReady(@NonNull MapboxMap mapboxMap) {
mMapboxMap = mapboxMap;
- mapboxMap.setStyle(Style.MAPBOX_STREETS);
-
- moveToBangalore();
int paddingLeft = (int) getResources().getDimension(R.dimen.map_padding_left);
int paddingBottom = (int) getResources().getDimension(R.dimen.map_padding_bottom);
int paddingRight = (int) getResources().getDimension(R.dimen.map_padding_right);
mapboxMap.setPadding(paddingLeft, toolbar.getHeight(), paddingRight, paddingBottom);
+
+ moveToBangalore();
}
});
}
@@ -123,14 +123,16 @@ public class MapPaddingActivity extends AppCompatActivity {
private void moveToBangalore() {
toggleGps(false);
+
LatLng bangalore = new LatLng(12.9810816, 77.6368034);
- mMapboxMap.moveCamera(CameraUpdateFactory.newCameraPosition(
- new CameraPosition.Builder()
- .zoom(16)
- .target(bangalore)
- .bearing(40)
- .tilt(45)
- .build()));
+ CameraPosition cameraPosition = new CameraPosition.Builder()
+ .zoom(16)
+ .target(bangalore)
+ .bearing(40)
+ .tilt(45)
+ .build();
+
+ mMapboxMap.moveCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));
mMapboxMap.addMarker(new MarkerOptions().title("Center map").position(bangalore));
}
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/MapboxMapActivity.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/MapboxMapActivity.java
index 16160a2fc6..a7d7e0b18a 100644
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/MapboxMapActivity.java
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/MapboxMapActivity.java
@@ -37,24 +37,22 @@ public class MapboxMapActivity extends AppCompatActivity {
mMapView = (MapView) findViewById(R.id.mapView);
mMapView.setAccessToken(ApiAccess.getToken(this));
+ mMapView.setStyle(Style.SATELLITE_STREETS);
mMapView.onCreate(savedInstanceState);
mMapView.getMapAsync(new OnMapReadyCallback() {
@Override
public void onMapReady(@NonNull MapboxMap mapboxMap) {
- mapboxMap.setStyle(Style.SATELLITE_STREETS);
mapboxMap.moveCamera(CameraUpdateFactory.newCameraPosition(
new CameraPosition.Builder()
.target(new LatLng(43.876550, -103.454791))
.zoom(14)
- .bearing(0)
- .tilt(0)
.build()));
}
});
Snackbar.make(findViewById(android.R.id.content),
- "Demo MapboxMap API.",
+ "Demo MapboxMap API",
Snackbar.LENGTH_INDEFINITE).show();
}
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/MaxMinZoomActivity.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/MaxMinZoomActivity.java
index 19c2578db2..7fbb18e981 100644
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/MaxMinZoomActivity.java
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/MaxMinZoomActivity.java
@@ -39,12 +39,12 @@ public class MaxMinZoomActivity extends AppCompatActivity {
mMapView = (MapView) findViewById(R.id.manualZoomMapView);
mMapView.setAccessToken(ApiAccess.getToken(this));
+ mMapView.setStyle(Style.SATELLITE_STREETS);
mMapView.onCreate(savedInstanceState);
mMapView.getMapAsync(new OnMapReadyCallback() {
@Override
public void onMapReady(@NonNull final MapboxMap mapboxMap) {
mMapboxMap = mapboxMap;
- mMapboxMap.setStyle(Style.SATELLITE_STREETS);
UiSettings uiSettings = mapboxMap.getUiSettings();
uiSettings.setMinZoom(3);
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/OfflineActivity.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/OfflineActivity.java
index 23a8be54a7..c48bec1a90 100644
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/OfflineActivity.java
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/OfflineActivity.java
@@ -13,7 +13,6 @@ import android.widget.Button;
import android.widget.ProgressBar;
import android.widget.Toast;
-import com.google.gson.Gson;
import com.mapbox.mapboxsdk.camera.CameraPosition;
import com.mapbox.mapboxsdk.camera.CameraUpdateFactory;
import com.mapbox.mapboxsdk.constants.Style;
@@ -24,7 +23,6 @@ import com.mapbox.mapboxsdk.maps.MapboxMap;
import com.mapbox.mapboxsdk.maps.OnMapReadyCallback;
import com.mapbox.mapboxsdk.offline.OfflineManager;
import com.mapbox.mapboxsdk.offline.OfflineRegion;
-import com.mapbox.mapboxsdk.offline.OfflineRegionMetadata;
import com.mapbox.mapboxsdk.offline.OfflineTilePyramidRegionDefinition;
import com.mapbox.mapboxsdk.offline.OfflineRegionError;
import com.mapbox.mapboxsdk.offline.OfflineRegionStatus;
@@ -75,6 +73,7 @@ public class OfflineActivity extends AppCompatActivity
// Set up map
mMapView = (MapView) findViewById(R.id.mapView);
mMapView.setAccessToken(ApiAccess.getToken(this));
+ mMapView.setStyle(Style.MAPBOX_STREETS);
mMapView.onCreate(savedInstanceState);
mMapView.getMapAsync(new OnMapReadyCallback() {
@Override
@@ -82,9 +81,6 @@ public class OfflineActivity extends AppCompatActivity
Log.d(LOG_TAG, "Map is ready");
mMapboxMap = mapboxMap;
- // Set style
- mapboxMap.setStyle(Style.MAPBOX_STREETS);
-
// Set initial position to UNHQ in NYC
mapboxMap.moveCamera(CameraUpdateFactory.newCameraPosition(
new CameraPosition.Builder()
@@ -224,8 +220,7 @@ public class OfflineActivity extends AppCompatActivity
String regionName;
try {
- String json = new String(offlineRegion.getMetadata().getMetadata(), CustomMetadata.CHARSET);
- CustomMetadata customMetadata = new Gson().fromJson(json, CustomMetadata.class);
+ CustomMetadata customMetadata = CustomMetadata.decode(offlineRegion.getMetadata());
regionName = customMetadata.getRegionName();
} catch (UnsupportedEncodingException e) {
Log.e(LOG_TAG, "Failed to decode metadata: " + e.getMessage());
@@ -262,13 +257,10 @@ public class OfflineActivity extends AppCompatActivity
styleURL, bounds, minZoom, maxZoom, pixelRatio);
// Sample way of encoding metadata
- OfflineRegionMetadata metadata;
+ byte[] metadata;
try {
CustomMetadata customMetadata = new CustomMetadata(regionName);
- byte[] encoded = new Gson()
- .toJson(customMetadata, CustomMetadata.class)
- .getBytes(CustomMetadata.CHARSET);
- metadata = new OfflineRegionMetadata(encoded);
+ metadata = customMetadata.encode();
} catch (UnsupportedEncodingException e) {
Log.e(LOG_TAG, "Failed to encode metadata: " + e.getMessage());
metadata = null;
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/PressForMarkerActivity.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/PressForMarkerActivity.java
index 3ffab596ca..9a4201e9d7 100644
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/PressForMarkerActivity.java
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/PressForMarkerActivity.java
@@ -47,6 +47,7 @@ public class PressForMarkerActivity extends AppCompatActivity implements MapboxM
// Adding MapView programmatically
mMapView = new MapView(this);
mMapView.setAccessToken(ApiAccess.getToken(this));
+ mMapView.setStyle(Style.EMERALD);
mMapView.onCreate(savedInstanceState);
((ViewGroup) findViewById(R.id.activity_container)).addView(mMapView);
@@ -61,15 +62,10 @@ public class PressForMarkerActivity extends AppCompatActivity implements MapboxM
public void onMapReady(@NonNull MapboxMap mapboxMap) {
mMapboxMap = mapboxMap;
- // select style
- mapboxMap.setStyle(Style.EMERALD);
-
// set camera
mapboxMap.setCameraPosition(new CameraPosition.Builder()
.target(new LatLng(45.1855569, 5.7215506))
.zoom(11)
- .bearing(0)
- .tilt(0)
.build());
// add markers
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/ScrollByActivity.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/ScrollByActivity.java
index 2e0e741677..35b9cd32d6 100644
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/ScrollByActivity.java
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/ScrollByActivity.java
@@ -53,12 +53,11 @@ public class ScrollByActivity extends AppCompatActivity {
mMapView = (MapView) findViewById(R.id.mapView);
mMapView.setTag(true);
mMapView.setAccessToken(ApiAccess.getToken(this));
+ mMapView.setStyleUrl(Style.MAPBOX_STREETS);
mMapView.onCreate(savedInstanceState);
mMapView.getMapAsync(new OnMapReadyCallback() {
@Override
public void onMapReady(@NonNull final MapboxMap mapboxMap) {
- mapboxMap.setStyle(Style.MAPBOX_STREETS);
-
UiSettings uiSettings = mapboxMap.getUiSettings();
uiSettings.setLogoEnabled(false);
uiSettings.setAttributionEnabled(false);
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/TiltActivity.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/TiltActivity.java
index 1713673129..1576c7fc98 100644
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/TiltActivity.java
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/TiltActivity.java
@@ -43,14 +43,11 @@ public class TiltActivity extends AppCompatActivity {
mMapView.getMapAsync(new OnMapReadyCallback() {
@Override
public void onMapReady(@NonNull MapboxMap mapboxMap) {
- mapboxMap.setStyle(Style.MAPBOX_STREETS);
// Move camera to Washington DC
CameraPosition normalCameraPosition = new CameraPosition.Builder()
.target(WASHINGTON_DC)
.zoom(11)
- .bearing(0)
- .tilt(0)
.build();
mapboxMap.moveCamera(CameraUpdateFactory.newCameraPosition(normalCameraPosition));
@@ -58,7 +55,6 @@ public class TiltActivity extends AppCompatActivity {
CameraPosition tiltedCameraPosition = new CameraPosition.Builder()
.target(WASHINGTON_DC)
.zoom(11)
- .bearing(0)
.tilt(45.0f)
.build();
mapboxMap.animateCamera(CameraUpdateFactory.newCameraPosition(tiltedCameraPosition), 10000);
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/offline/CustomMetadata.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/offline/CustomMetadata.java
index 27bdef6312..75c5f719f5 100644
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/offline/CustomMetadata.java
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/offline/CustomMetadata.java
@@ -1,5 +1,9 @@
package com.mapbox.mapboxsdk.testapp.offline;
+import com.google.gson.Gson;
+
+import java.io.UnsupportedEncodingException;
+
/**
* A custom metadata class
*/
@@ -33,4 +37,20 @@ public class CustomMetadata {
this.regionName = regionName;
}
+ /*
+ * Helper methods to encode/decode metadata into/from byte[]
+ */
+
+ public byte[] encode() throws UnsupportedEncodingException {
+ return new Gson()
+ .toJson(this, CustomMetadata.class)
+ .getBytes(CustomMetadata.CHARSET);
+ }
+
+ public static CustomMetadata decode(byte[] metadata) throws UnsupportedEncodingException {
+ String json = new String(metadata, CustomMetadata.CHARSET);
+ return new Gson()
+ .fromJson(json, CustomMetadata.class);
+ }
+
}
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/drawable/ic_droppin_24dp.xml b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/drawable/ic_droppin_24dp.xml
new file mode 100644
index 0000000000..a25e7884cd
--- /dev/null
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/drawable/ic_droppin_24dp.xml
@@ -0,0 +1,4 @@
+<vector android:height="32dp" android:viewportHeight="24.0"
+ android:viewportWidth="24.0" android:width="32dp" xmlns:android="http://schemas.android.com/apk/res/android">
+ <path android:fillColor="#FF000000" android:pathData="M12,2C8.13,2 5,5.13 5,9c0,5.25 7,13 7,13s7,-7.75 7,-13c0,-3.87 -3.13,-7 -7,-7zm0,9.5c-1.38,0 -2.5,-1.12 -2.5,-2.5s1.12,-2.5 2.5,-2.5 2.5,1.12 2.5,2.5 -1.12,2.5 -2.5,2.5z"/>
+</vector>
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/maps/MapboxMapTest.java b/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/maps/MapboxMapTest.java
index 2fac586da1..1bf49823c8 100644
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/maps/MapboxMapTest.java
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/maps/MapboxMapTest.java
@@ -231,22 +231,6 @@ public class MapboxMapTest {
mMapboxMap.setOnMyLocationTrackingModeChangeListener(mMyLocationTrackingModeChangeListener);
assertEquals("MyLocationTrackigChangeListener should match",mMyLocationTrackingModeChangeListener, mMapboxMap.getOnMyLocationTrackingModeChangeListener());
}
-
- //
- // Style
- //
-
- @Test
- public void testStyleUrl() {
- mMapboxMap.setStyleUrl("somestyle");
- assertEquals("StyleUrl should be same", "somestyle", mMapboxMap.getStyleUrl());
- }
-
- @Test
- public void testStyle() {
- mMapboxMap.setStyle(Style.MAPBOX_STREETS);
- assertEquals("Style should be same", Style.MAPBOX_STREETS, mMapboxMap.getStyleUrl());
- }
//
// CameraPosition
diff --git a/platform/android/src/jni.cpp b/platform/android/src/jni.cpp
index 9855529c66..69c0740b45 100755
--- a/platform/android/src/jni.cpp
+++ b/platform/android/src/jni.cpp
@@ -141,10 +141,6 @@ jfieldID offlineRegionDefinitionMinZoomId = nullptr;
jfieldID offlineRegionDefinitionMaxZoomId = nullptr;
jfieldID offlineRegionDefinitionPixelRatioId = nullptr;
-jclass offlineRegionMetadataClass = nullptr;
-jmethodID offlineRegionMetadataConstructorId = nullptr;
-jfieldID offlineRegionMetadataMetadataId = nullptr;
-
jclass createOfflineRegionCallbackClass = nullptr;
jmethodID createOnCreateMethodId = nullptr;
jmethodID createOnErrorMethodId = nullptr;
@@ -488,6 +484,18 @@ static mbgl::LatLngBounds latlngbounds_from_java(JNIEnv *env, jobject latLngBoun
return result;
}
+static jobject latlngbounds_from_native(JNIEnv *env, mbgl::LatLngBounds bounds) {
+ double northLatitude = bounds.north();
+ double eastLongitude = bounds.east();
+ double southLatitude = bounds.south();
+ double westLongitude = bounds.west();
+
+ jobject jbounds = env->NewObject(latLngBoundsClass, latLngBoundsConstructorId,
+ northLatitude, eastLongitude, southLatitude, westLongitude);
+
+ return jbounds;
+}
+
}
}
@@ -736,7 +744,7 @@ void JNICALL nativeMoveBy(JNIEnv *env, jobject obj, jlong nativeMapViewPtr, jdou
mbgl::Log::Debug(mbgl::Event::JNI, "nativeMoveBy");
assert(nativeMapViewPtr != 0);
NativeMapView *nativeMapView = reinterpret_cast<NativeMapView *>(nativeMapViewPtr);
- mbgl::PrecisionPoint center(dx, dy);
+ mbgl::ScreenCoordinate center(dx, dy);
nativeMapView->getMap().moveBy(center, mbgl::Milliseconds(duration));
}
@@ -776,6 +784,30 @@ jobject JNICALL nativeGetLatLng(JNIEnv *env, jobject obj, jlong nativeMapViewPtr
return ret;
}
+jdoubleArray JNICALL nativeGetCameraValues(JNIEnv *env, jobject obj, jlong nativeMapViewPtr) {
+ mbgl::Log::Debug(mbgl::Event::JNI, "nativeGetCameraValues");
+ assert(nativeMapViewPtr != 0);
+ NativeMapView *nativeMapView = reinterpret_cast<NativeMapView *>(nativeMapViewPtr);
+ mbgl::LatLng latLng = nativeMapView->getMap().getLatLng(nativeMapView->getInsets());
+ jdoubleArray output = env->NewDoubleArray(5);
+ jsize start = 0;
+ jsize leng = 5;
+ jdouble buf[5];
+ buf[0] = latLng.latitude;
+ buf[1] = latLng.longitude;
+ buf[2] = nativeMapView->getMap().getBearing();
+ buf[3] = nativeMapView->getMap().getPitch();
+ buf[4] = nativeMapView->getMap().getZoom();
+ env->SetDoubleArrayRegion(output, start, leng, buf);
+
+ if (output == nullptr) {
+ env->ExceptionDescribe();
+ return nullptr;
+ }
+
+ return output;
+}
+
void JNICALL nativeResetPosition(JNIEnv *env, jobject obj, jlong nativeMapViewPtr) {
mbgl::Log::Debug(mbgl::Event::JNI, "nativeResetPosition");
assert(nativeMapViewPtr != 0);
@@ -803,7 +835,7 @@ void JNICALL nativeScaleBy(JNIEnv *env, jobject obj, jlong nativeMapViewPtr, jdo
mbgl::Log::Debug(mbgl::Event::JNI, "nativeScaleBy");
assert(nativeMapViewPtr != 0);
NativeMapView *nativeMapView = reinterpret_cast<NativeMapView *>(nativeMapViewPtr);
- mbgl::PrecisionPoint center(cx, cy);
+ mbgl::ScreenCoordinate center(cx, cy);
nativeMapView->getMap().scaleBy(ds, center, mbgl::Milliseconds(duration));
}
@@ -812,7 +844,7 @@ void JNICALL nativeSetScale(JNIEnv *env, jobject obj, jlong nativeMapViewPtr, jd
mbgl::Log::Debug(mbgl::Event::JNI, "nativeSetScale");
assert(nativeMapViewPtr != 0);
NativeMapView *nativeMapView = reinterpret_cast<NativeMapView *>(nativeMapViewPtr);
- mbgl::PrecisionPoint center(cx, cy);
+ mbgl::ScreenCoordinate center(cx, cy);
nativeMapView->getMap().setScale(scale, center, mbgl::Milliseconds(duration));
}
@@ -877,8 +909,8 @@ void JNICALL nativeRotateBy(JNIEnv *env, jobject obj, jlong nativeMapViewPtr, jd
mbgl::Log::Debug(mbgl::Event::JNI, "nativeRotateBy");
assert(nativeMapViewPtr != 0);
NativeMapView *nativeMapView = reinterpret_cast<NativeMapView *>(nativeMapViewPtr);
- mbgl::PrecisionPoint first(sx, sy);
- mbgl::PrecisionPoint second(ex, ey);
+ mbgl::ScreenCoordinate first(sx, sy);
+ mbgl::ScreenCoordinate second(ex, ey);
nativeMapView->getMap().rotateBy(first, second, mbgl::Milliseconds(duration));
}
@@ -896,7 +928,7 @@ void JNICALL nativeSetBearing(JNIEnv *env, jobject obj, jlong nativeMapViewPtr,
mbgl::Log::Debug(mbgl::Event::JNI, "nativeSetBearing");
assert(nativeMapViewPtr != 0);
NativeMapView *nativeMapView = reinterpret_cast<NativeMapView *>(nativeMapViewPtr);
- mbgl::PrecisionPoint center(cx, cy);
+ mbgl::ScreenCoordinate center(cx, cy);
nativeMapView->getMap().setBearing(degrees, center);
}
@@ -1535,7 +1567,7 @@ jobject JNICALL nativePixelForLatLng(JNIEnv *env, jobject obj, jlong nativeMapVi
return nullptr;
}
- mbgl::vec2<double> pixel = nativeMapView->getMap().pixelForLatLng(mbgl::LatLng(latitude, longitude));
+ mbgl::ScreenCoordinate pixel = nativeMapView->getMap().pixelForLatLng(mbgl::LatLng(latitude, longitude));
jobject ret = env->NewObject(pointFClass, pointFConstructorId, static_cast<jfloat>(pixel.x), static_cast<jfloat>(pixel.y));
if (ret == nullptr) {
@@ -1563,7 +1595,7 @@ jobject JNICALL nativeLatLngForPixel(JNIEnv *env, jobject obj, jlong nativeMapVi
return nullptr;
}
- mbgl::LatLng latLng = nativeMapView->getMap().latLngForPixel(mbgl::PrecisionPoint(x, y));
+ mbgl::LatLng latLng = nativeMapView->getMap().latLngForPixel(mbgl::ScreenCoordinate(x, y));
jobject ret = env->NewObject(latLngClass, latLngConstructorId, latLng.latitude, latLng.longitude);
if (ret == nullptr) {
@@ -1776,11 +1808,20 @@ void JNICALL listOfflineRegions(JNIEnv *env, jobject obj, jlong defaultFileSourc
jobject jregion = env2->NewObject(offlineRegionClass, offlineRegionConstructorId);
env2->SetObjectField(jregion, offlineRegionOfflineManagerId, obj);
env2->SetLongField(jregion, offlineRegionIdId, region.getID());
+
+ // Definition object
+ mbgl::OfflineTilePyramidRegionDefinition definition = region.getDefinition();
+ jobject jdefinition = env2->NewObject(offlineRegionDefinitionClass, offlineRegionDefinitionConstructorId);
+ env2->SetObjectField(jdefinition, offlineRegionDefinitionStyleURLId, std_string_to_jstring(env2, definition.styleURL));
+ env2->SetObjectField(jdefinition, offlineRegionDefinitionBoundsId, latlngbounds_from_native(env2, definition.bounds));
+ env2->SetDoubleField(jdefinition, offlineRegionDefinitionMinZoomId, definition.minZoom);
+ env2->SetDoubleField(jdefinition, offlineRegionDefinitionMaxZoomId, definition.maxZoom);
+ env2->SetFloatField(jdefinition, offlineRegionDefinitionPixelRatioId, definition.pixelRatio);
+ env2->SetObjectField(jregion, offlineRegionDefinitionId, jdefinition);
// Metadata object
jbyteArray metadata = metadata_from_native(env2, region.getMetadata());
- jobject jmetadata = env2->NewObject(offlineRegionMetadataClass, offlineRegionMetadataConstructorId, metadata);
- env2->SetObjectField(jregion, offlineRegionMetadataId, jmetadata);
+ env2->SetObjectField(jregion, offlineRegionMetadataId, metadata);
// Moves the region on the stack into a heap-allocated one
env2->SetLongField(jregion, offlineRegionPtrId,
@@ -1801,7 +1842,7 @@ void JNICALL listOfflineRegions(JNIEnv *env, jobject obj, jlong defaultFileSourc
});
}
-void JNICALL createOfflineRegion(JNIEnv *env, jobject obj, jlong defaultFileSourcePtr, jobject definition_, jobject metadata_, jobject createCallback) {
+void JNICALL createOfflineRegion(JNIEnv *env, jobject obj, jlong defaultFileSourcePtr, jobject definition_, jbyteArray metadata_, jobject createCallback) {
mbgl::Log::Debug(mbgl::Event::JNI, "createOfflineRegion");
// Checks
@@ -1827,9 +1868,8 @@ void JNICALL createOfflineRegion(JNIEnv *env, jobject obj, jlong defaultFileSour
// Metadata
mbgl::OfflineRegionMetadata metadata;
- jbyteArray jmetadata = (jbyteArray)env->GetObjectField(metadata_, offlineRegionMetadataMetadataId);
- if (jmetadata != nullptr) {
- metadata = metadata_from_java(env, jmetadata);
+ if (metadata_ != nullptr) {
+ metadata = metadata_from_java(env, metadata_);
}
// Makes sure the objects don't get GC'ed
@@ -1857,9 +1897,8 @@ void JNICALL createOfflineRegion(JNIEnv *env, jobject obj, jlong defaultFileSour
env2->SetLongField(jregion, offlineRegionIdId, region->getID());
// Metadata object
- jbyteArray xmetadata = metadata_from_native(env2, region->getMetadata());
- jobject xjmetadata = env2->NewObject(offlineRegionMetadataClass, offlineRegionMetadataConstructorId, xmetadata);
- env2->SetObjectField(jregion, offlineRegionMetadataId, xjmetadata);
+ jbyteArray jmetadata = metadata_from_native(env2, region->getMetadata());
+ env2->SetObjectField(jregion, offlineRegionMetadataId, jmetadata);
// Moves the region on the stack into a heap-allocated one
env2->SetLongField(jregion, offlineRegionPtrId,
@@ -2582,7 +2621,7 @@ extern "C" JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved) {
return JNI_ERR;
}
- offlineRegionMetadataId = env->GetFieldID(offlineRegionClass, "mMetadata", "Lcom/mapbox/mapboxsdk/offline/OfflineRegionMetadata;");
+ offlineRegionMetadataId = env->GetFieldID(offlineRegionClass, "mMetadata", "[B");
if (offlineRegionMetadataId == nullptr) {
env->ExceptionDescribe();
return JNI_ERR;
@@ -2637,24 +2676,6 @@ extern "C" JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved) {
return JNI_ERR;
}
- offlineRegionMetadataClass = env->FindClass("com/mapbox/mapboxsdk/offline/OfflineRegionMetadata");
- if (offlineRegionMetadataClass == nullptr) {
- env->ExceptionDescribe();
- return JNI_ERR;
- }
-
- offlineRegionMetadataConstructorId = env->GetMethodID(offlineRegionMetadataClass, "<init>", "([B)V");
- if (offlineRegionMetadataConstructorId == nullptr) {
- env->ExceptionDescribe();
- return JNI_ERR;
- }
-
- offlineRegionMetadataMetadataId = env->GetFieldID(offlineRegionMetadataClass, "metadata", "[B");
- if (offlineRegionMetadataMetadataId == nullptr) {
- env->ExceptionDescribe();
- return JNI_ERR;
- }
-
createOfflineRegionCallbackClass = env->FindClass("com/mapbox/mapboxsdk/offline/OfflineManager$CreateOfflineRegionCallback");
if (createOfflineRegionCallbackClass == nullptr) {
env->ExceptionDescribe();
@@ -2855,6 +2876,7 @@ extern "C" JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved) {
{"nativeGetLatLng", "(J)Lcom/mapbox/mapboxsdk/geometry/LatLng;",
reinterpret_cast<void *>(&nativeGetLatLng)},
{"nativeResetPosition", "(J)V", reinterpret_cast<void *>(&nativeResetPosition)},
+ {"nativeGetCameraValues","(J)[D", reinterpret_cast<void *>(&nativeGetCameraValues)},
{"nativeGetPitch", "(J)D", reinterpret_cast<void *>(&nativeGetPitch)},
{"nativeSetPitch", "(JDJ)V", reinterpret_cast<void *>(&nativeSetPitch)},
{"nativeScaleBy", "(JDDDJ)V", reinterpret_cast<void *>(&nativeScaleBy)},
@@ -2944,7 +2966,7 @@ extern "C" JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved) {
{"setAccessToken", "(JLjava/lang/String;)V", reinterpret_cast<void *>(&setAccessToken)},
{"getAccessToken", "(J)Ljava/lang/String;", reinterpret_cast<void *>(&getAccessToken)},
{"listOfflineRegions", "(JLcom/mapbox/mapboxsdk/offline/OfflineManager$ListOfflineRegionsCallback;)V", reinterpret_cast<void *>(&listOfflineRegions)},
- {"createOfflineRegion", "(JLcom/mapbox/mapboxsdk/offline/OfflineRegionDefinition;Lcom/mapbox/mapboxsdk/offline/OfflineRegionMetadata;Lcom/mapbox/mapboxsdk/offline/OfflineManager$CreateOfflineRegionCallback;)V", reinterpret_cast<void *>(&createOfflineRegion)},
+ {"createOfflineRegion", "(JLcom/mapbox/mapboxsdk/offline/OfflineRegionDefinition;[BLcom/mapbox/mapboxsdk/offline/OfflineManager$CreateOfflineRegionCallback;)V", reinterpret_cast<void *>(&createOfflineRegion)},
{"setOfflineMapboxTileCountLimit", "(JJ)V", reinterpret_cast<void *>(&setOfflineMapboxTileCountLimit)}
};
@@ -3223,28 +3245,6 @@ extern "C" JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved) {
env->DeleteGlobalRef(offlineRegionClass);
}
- offlineRegionMetadataClass = reinterpret_cast<jclass>(env->NewGlobalRef(offlineRegionMetadataClass));
- if (offlineRegionMetadataClass == nullptr) {
- env->ExceptionDescribe();
- env->DeleteGlobalRef(latLngClass);
- env->DeleteGlobalRef(latLngBoundsClass);
- env->DeleteGlobalRef(iconClass);
- env->DeleteGlobalRef(markerClass);
- env->DeleteGlobalRef(polylineClass);
- env->DeleteGlobalRef(polygonClass);
- env->DeleteGlobalRef(runtimeExceptionClass);
- env->DeleteGlobalRef(nullPointerExceptionClass);
- env->DeleteGlobalRef(arrayListClass);
- env->DeleteGlobalRef(projectedMetersClass);
- env->DeleteGlobalRef(pointFClass);
- env->DeleteGlobalRef(rectFClass);
- env->DeleteGlobalRef(httpContextClass);
- env->DeleteGlobalRef(offlineManagerClass);
- env->DeleteGlobalRef(listOfflineRegionsCallbackClass);
- env->DeleteGlobalRef(offlineRegionClass);
- env->DeleteGlobalRef(offlineRegionDefinitionClass);
- }
-
createOfflineRegionCallbackClass = reinterpret_cast<jclass>(env->NewGlobalRef(createOfflineRegionCallbackClass));
if (createOfflineRegionCallbackClass == nullptr) {
env->ExceptionDescribe();
@@ -3265,7 +3265,6 @@ extern "C" JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved) {
env->DeleteGlobalRef(listOfflineRegionsCallbackClass);
env->DeleteGlobalRef(offlineRegionClass);
env->DeleteGlobalRef(offlineRegionDefinitionClass);
- env->DeleteGlobalRef(offlineRegionMetadataClass);
}
offlineRegionObserverClass = reinterpret_cast<jclass>(env->NewGlobalRef(offlineRegionObserverClass));
@@ -3288,7 +3287,6 @@ extern "C" JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved) {
env->DeleteGlobalRef(listOfflineRegionsCallbackClass);
env->DeleteGlobalRef(offlineRegionClass);
env->DeleteGlobalRef(offlineRegionDefinitionClass);
- env->DeleteGlobalRef(offlineRegionMetadataClass);
env->DeleteGlobalRef(createOfflineRegionCallbackClass);
}
@@ -3312,7 +3310,6 @@ extern "C" JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved) {
env->DeleteGlobalRef(listOfflineRegionsCallbackClass);
env->DeleteGlobalRef(offlineRegionClass);
env->DeleteGlobalRef(offlineRegionDefinitionClass);
- env->DeleteGlobalRef(offlineRegionMetadataClass);
env->DeleteGlobalRef(createOfflineRegionCallbackClass);
env->DeleteGlobalRef(offlineRegionObserverClass);
}
@@ -3337,7 +3334,6 @@ extern "C" JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved) {
env->DeleteGlobalRef(listOfflineRegionsCallbackClass);
env->DeleteGlobalRef(offlineRegionClass);
env->DeleteGlobalRef(offlineRegionDefinitionClass);
- env->DeleteGlobalRef(offlineRegionMetadataClass);
env->DeleteGlobalRef(createOfflineRegionCallbackClass);
env->DeleteGlobalRef(offlineRegionObserverClass);
env->DeleteGlobalRef(offlineRegionStatusClass);
@@ -3363,7 +3359,6 @@ extern "C" JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved) {
env->DeleteGlobalRef(listOfflineRegionsCallbackClass);
env->DeleteGlobalRef(offlineRegionClass);
env->DeleteGlobalRef(offlineRegionDefinitionClass);
- env->DeleteGlobalRef(offlineRegionMetadataClass);
env->DeleteGlobalRef(createOfflineRegionCallbackClass);
env->DeleteGlobalRef(offlineRegionObserverClass);
env->DeleteGlobalRef(offlineRegionStatusClass);
@@ -3390,7 +3385,6 @@ extern "C" JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved) {
env->DeleteGlobalRef(listOfflineRegionsCallbackClass);
env->DeleteGlobalRef(offlineRegionClass);
env->DeleteGlobalRef(offlineRegionDefinitionClass);
- env->DeleteGlobalRef(offlineRegionMetadataClass);
env->DeleteGlobalRef(createOfflineRegionCallbackClass);
env->DeleteGlobalRef(offlineRegionObserverClass);
env->DeleteGlobalRef(offlineRegionStatusClass);
@@ -3528,10 +3522,6 @@ extern "C" JNIEXPORT void JNICALL JNI_OnUnload(JavaVM *vm, void *reserved) {
offlineRegionDefinitionMaxZoomId = nullptr;
offlineRegionDefinitionPixelRatioId = nullptr;
- env->DeleteGlobalRef(offlineRegionMetadataClass);
- offlineRegionMetadataConstructorId = nullptr;
- offlineRegionMetadataMetadataId = nullptr;
-
env->DeleteGlobalRef(createOfflineRegionCallbackClass);
createOnCreateMethodId = nullptr;
createOnErrorMethodId = nullptr;
diff --git a/platform/android/src/jni.hpp b/platform/android/src/jni.hpp
index 2995ea0b35..6a3c248373 100644
--- a/platform/android/src/jni.hpp
+++ b/platform/android/src/jni.hpp
@@ -127,10 +127,6 @@ extern jfieldID offlineRegionDefinitionMinZoomId;
extern jfieldID offlineRegionDefinitionMaxZoomId;
extern jfieldID offlineRegionDefinitionPixelRatioId;
-extern jclass offlineRegionMetadataClass;
-extern jmethodID offlineRegionMetadataConstructorId;
-extern jfieldID offlineRegionMetadataMetadataId;
-
extern jclass createOfflineRegionCallbackClass;
extern jmethodID createOnCreateMethodId;
extern jmethodID createOnErrorMethodId;
diff --git a/platform/default/glfw_view.cpp b/platform/default/glfw_view.cpp
index a4e8d7059f..790b0a4dd7 100644
--- a/platform/default/glfw_view.cpp
+++ b/platform/default/glfw_view.cpp
@@ -380,8 +380,8 @@ void GLFWView::onMouseMove(GLFWwindow *window, double x, double y) {
double dy = y - view->lastY;
if (dx || dy) {
view->map->setLatLng(
- view->map->latLngForPixel(mbgl::PrecisionPoint(x - dx, y - dy)),
- mbgl::PrecisionPoint(x, y));
+ view->map->latLngForPixel(mbgl::ScreenCoordinate(x - dx, y - dy)),
+ mbgl::ScreenCoordinate(x, y));
}
} else if (view->rotating) {
view->map->rotateBy({ view->lastX, view->lastY }, { x, y });
diff --git a/ios/framework/Mapbox-static.h b/platform/ios/framework/Mapbox-static.h
index d3674b0b61..d3674b0b61 100644
--- a/ios/framework/Mapbox-static.h
+++ b/platform/ios/framework/Mapbox-static.h
diff --git a/platform/ios/src/MGLMapView.mm b/platform/ios/src/MGLMapView.mm
index 458221fd69..ccf8a7bc3d 100644
--- a/platform/ios/src/MGLMapView.mm
+++ b/platform/ios/src/MGLMapView.mm
@@ -1333,7 +1333,7 @@ mbgl::Duration MGLDurationInSeconds(NSTimeInterval duration)
gesturePoint = self.userLocationAnnotationViewCenter;
}
- mbgl::PrecisionPoint center(gesturePoint.x, gesturePoint.y);
+ mbgl::ScreenCoordinate center(gesturePoint.x, gesturePoint.y);
_mbglMap->scaleBy(2, center, MGLDurationInSeconds(MGLAnimationDuration));
__weak MGLMapView *weakSelf = self;
@@ -1365,7 +1365,7 @@ mbgl::Duration MGLDurationInSeconds(NSTimeInterval duration)
gesturePoint = self.userLocationAnnotationViewCenter;
}
- mbgl::PrecisionPoint center(gesturePoint.x, gesturePoint.y);
+ mbgl::ScreenCoordinate center(gesturePoint.x, gesturePoint.y);
_mbglMap->scaleBy(0.5, center, MGLDurationInSeconds(MGLAnimationDuration));
__weak MGLMapView *weakSelf = self;
@@ -2166,7 +2166,7 @@ mbgl::Duration MGLDurationInSeconds(NSTimeInterval duration)
- (mbgl::LatLng)convertPoint:(CGPoint)point toLatLngFromView:(nullable UIView *)view
{
CGPoint convertedPoint = [self convertPoint:point fromView:view];
- return _mbglMap->latLngForPixel(mbgl::PrecisionPoint(convertedPoint.x, convertedPoint.y));
+ return _mbglMap->latLngForPixel(mbgl::ScreenCoordinate(convertedPoint.x, convertedPoint.y));
}
- (CGPoint)convertCoordinate:(CLLocationCoordinate2D)coordinate toPointToView:(nullable UIView *)view
@@ -2177,7 +2177,7 @@ mbgl::Duration MGLDurationInSeconds(NSTimeInterval duration)
/// Converts a geographic coordinate to a point in the view’s coordinate system.
- (CGPoint)convertLatLng:(mbgl::LatLng)latLng toPointToView:(nullable UIView *)view
{
- mbgl::vec2<double> pixel = _mbglMap->pixelForLatLng(latLng);
+ mbgl::ScreenCoordinate pixel = _mbglMap->pixelForLatLng(latLng);
return [self convertPoint:CGPointMake(pixel.x, pixel.y) toView:view];
}
diff --git a/platform/osx/src/MGLMapView.mm b/platform/osx/src/MGLMapView.mm
index cd8cd45265..9c903484e4 100644
--- a/platform/osx/src/MGLMapView.mm
+++ b/platform/osx/src/MGLMapView.mm
@@ -899,7 +899,7 @@ public:
- (void)scaleBy:(double)scaleFactor atPoint:(NSPoint)point animated:(BOOL)animated {
[self willChangeValueForKey:@"centerCoordinate"];
[self willChangeValueForKey:@"zoomLevel"];
- mbgl::PrecisionPoint center(point.x, self.bounds.size.height - point.y);
+ mbgl::ScreenCoordinate center(point.x, self.bounds.size.height - point.y);
_mbglMap->scaleBy(scaleFactor, center, MGLDurationInSeconds(animated ? MGLAnimationDuration : 0));
[self didChangeValueForKey:@"zoomLevel"];
[self didChangeValueForKey:@"centerCoordinate"];
@@ -1214,7 +1214,7 @@ public:
_directionAtBeginningOfGesture = self.direction;
_pitchAtBeginningOfGesture = _mbglMap->getPitch();
} else if (gestureRecognizer.state == NSGestureRecognizerStateChanged) {
- mbgl::PrecisionPoint center(startPoint.x, self.bounds.size.height - startPoint.y);
+ mbgl::ScreenCoordinate center(startPoint.x, self.bounds.size.height - startPoint.y);
if (self.rotateEnabled) {
CLLocationDirection newDirection = _directionAtBeginningOfGesture - delta.x / 10;
[self willChangeValueForKey:@"direction"];
@@ -1258,7 +1258,7 @@ public:
_scaleAtBeginningOfGesture = _mbglMap->getScale();
} else if (gestureRecognizer.state == NSGestureRecognizerStateChanged) {
NSPoint zoomInPoint = [gestureRecognizer locationInView:self];
- mbgl::PrecisionPoint center(zoomInPoint.x, self.bounds.size.height - zoomInPoint.y);
+ mbgl::ScreenCoordinate center(zoomInPoint.x, self.bounds.size.height - zoomInPoint.y);
if (gestureRecognizer.magnification > -1) {
[self willChangeValueForKey:@"zoomLevel"];
[self willChangeValueForKey:@"centerCoordinate"];
@@ -1339,7 +1339,7 @@ public:
_directionAtBeginningOfGesture = self.direction;
} else if (gestureRecognizer.state == NSGestureRecognizerStateChanged) {
NSPoint rotationPoint = [gestureRecognizer locationInView:self];
- mbgl::PrecisionPoint center(rotationPoint.x, self.bounds.size.height - rotationPoint.y);
+ mbgl::ScreenCoordinate center(rotationPoint.x, self.bounds.size.height - rotationPoint.y);
_mbglMap->setBearing(_directionAtBeginningOfGesture + gestureRecognizer.rotationInDegrees, center);
} else if (gestureRecognizer.state == NSGestureRecognizerStateEnded
|| gestureRecognizer.state == NSGestureRecognizerStateCancelled) {
@@ -2165,7 +2165,7 @@ public:
/// Converts a geographic coordinate to a point in the view’s coordinate system.
- (NSPoint)convertLatLng:(mbgl::LatLng)latLng toPointToView:(nullable NSView *)view {
- mbgl::vec2<double> pixel = _mbglMap->pixelForLatLng(latLng);
+ mbgl::ScreenCoordinate pixel = _mbglMap->pixelForLatLng(latLng);
// Cocoa origin is at the lower-left corner.
pixel.y = NSHeight(self.bounds) - pixel.y;
return [self convertPoint:NSMakePoint(pixel.x, pixel.y) toView:view];
diff --git a/src/mbgl/annotation/annotation_tile.hpp b/src/mbgl/annotation/annotation_tile.hpp
index b2d98c6a3b..8d0804d7f9 100644
--- a/src/mbgl/annotation/annotation_tile.hpp
+++ b/src/mbgl/annotation/annotation_tile.hpp
@@ -17,7 +17,6 @@ public:
FeatureType getType() const override { return type; }
optional<Value> getValue(const std::string&) const override;
GeometryCollection getGeometries() const override { return geometries; }
- uint32_t getExtent() const override { return 4096; }
const FeatureType type;
const std::unordered_map<std::string, std::string> properties;
diff --git a/src/mbgl/annotation/point_annotation_impl.cpp b/src/mbgl/annotation/point_annotation_impl.cpp
index 8e1aab2edf..b54995bfdd 100644
--- a/src/mbgl/annotation/point_annotation_impl.cpp
+++ b/src/mbgl/annotation/point_annotation_impl.cpp
@@ -12,16 +12,15 @@ void PointAnnotationImpl::updateLayer(const TileID& tileID, AnnotationTileLayer&
std::unordered_map<std::string, std::string> featureProperties;
featureProperties.emplace("sprite", point.icon.empty() ? std::string("default_marker") : point.icon);
- const uint16_t extent = 4096;
- const mbgl::PrecisionPoint pp = point.position.project();
- const uint32_t z2 = 1 << tileID.z;
- const uint32_t x = pp.x * z2;
- const uint32_t y = pp.y * z2;
- const Coordinate coordinate(extent * (pp.x * z2 - x), extent * (pp.y * z2 - y));
+ mbgl::ScreenCoordinate projected = point.position.project();
+ projected *= 1 << tileID.z;
+ projected.x -= int16_t(projected.x);
+ projected.y -= int16_t(projected.y);
+ projected *= GeometryTileFeature::defaultExtent;
layer.features.emplace_back(
std::make_shared<const AnnotationTileFeature>(FeatureType::Point,
- GeometryCollection {{ {{ coordinate }} }},
+ GeometryCollection {{ {{ GeometryCoordinate { projected } }} }},
featureProperties));
}
diff --git a/src/mbgl/annotation/shape_annotation_impl.cpp b/src/mbgl/annotation/shape_annotation_impl.cpp
index 418d3adaed..a9277ee0a7 100644
--- a/src/mbgl/annotation/shape_annotation_impl.cpp
+++ b/src/mbgl/annotation/shape_annotation_impl.cpp
@@ -81,11 +81,10 @@ void ShapeAnnotationImpl::updateStyle(Style& style) {
void ShapeAnnotationImpl::updateTile(const TileID& tileID, AnnotationTile& tile) {
static const double baseTolerance = 4;
- static const uint16_t extent = 4096;
if (!shapeTiler) {
const uint64_t maxAmountOfTiles = 1 << maxZoom;
- const double tolerance = baseTolerance / (maxAmountOfTiles * extent);
+ const double tolerance = baseTolerance / (maxAmountOfTiles * GeometryTileFeature::defaultExtent);
geojsonvt::ProjectedRings rings;
std::vector<geojsonvt::LonLat> points;
@@ -133,7 +132,7 @@ void ShapeAnnotationImpl::updateTile(const TileID& tileID, AnnotationTile& tile)
GeometryCollection renderGeometry;
for (auto& shapeRing : shapeFeature.tileGeometry.get<geojsonvt::TileRings>()) {
- std::vector<Coordinate> renderLine;
+ GeometryCoordinates renderLine;
for (auto& shapePoint : shapeRing) {
renderLine.emplace_back(shapePoint.x, shapePoint.y);
diff --git a/src/mbgl/layer/custom_layer.cpp b/src/mbgl/layer/custom_layer.cpp
index 0b6de51e67..3b683bf833 100644
--- a/src/mbgl/layer/custom_layer.cpp
+++ b/src/mbgl/layer/custom_layer.cpp
@@ -44,7 +44,7 @@ void CustomLayer::render(const TransformState& state) const {
parameters.latitude = state.getLatLng().latitude;
parameters.longitude = state.getLatLng().longitude;
parameters.zoom = state.getZoom();
- parameters.bearing = -state.getAngle() / M_PI * 180;
+ parameters.bearing = -state.getAngle() * util::RAD2DEG;
parameters.pitch = state.getPitch();
parameters.altitude = state.getAltitude();
diff --git a/src/mbgl/layer/line_layer.cpp b/src/mbgl/layer/line_layer.cpp
index edf128fd35..c6ddaee37d 100644
--- a/src/mbgl/layer/line_layer.cpp
+++ b/src/mbgl/layer/line_layer.cpp
@@ -69,7 +69,7 @@ bool LineLayer::recalculate(const StyleCalculationParameters& parameters) {
}
std::unique_ptr<Bucket> LineLayer::createBucket(StyleBucketParameters& parameters) const {
- auto bucket = std::make_unique<LineBucket>(parameters.tileID.overscaling);
+ auto bucket = std::make_unique<LineBucket>(parameters.tileID.overscaling());
bucket->layout = layout;
diff --git a/src/mbgl/layer/symbol_layer.cpp b/src/mbgl/layer/symbol_layer.cpp
index 77254d6f2b..f8a21a4782 100644
--- a/src/mbgl/layer/symbol_layer.cpp
+++ b/src/mbgl/layer/symbol_layer.cpp
@@ -113,7 +113,7 @@ bool SymbolLayer::recalculate(const StyleCalculationParameters& parameters) {
}
std::unique_ptr<Bucket> SymbolLayer::createBucket(StyleBucketParameters& parameters) const {
- auto bucket = std::make_unique<SymbolBucket>(parameters.tileID.overscaling,
+ auto bucket = std::make_unique<SymbolBucket>(parameters.tileID.overscaling(),
parameters.tileID.z,
parameters.mode);
diff --git a/src/mbgl/map/map.cpp b/src/mbgl/map/map.cpp
index c3123fb3be..374e3fe615 100644
--- a/src/mbgl/map/map.cpp
+++ b/src/mbgl/map/map.cpp
@@ -166,7 +166,7 @@ void Map::flyTo(const CameraOptions& camera, const AnimationOptions& animation)
#pragma mark - Position
-void Map::moveBy(const PrecisionPoint& point, const Duration& duration) {
+void Map::moveBy(const ScreenCoordinate& point, const Duration& duration) {
transform->moveBy(point, duration);
update(Update::Repaint);
}
@@ -180,7 +180,7 @@ void Map::setLatLng(const LatLng& latLng, const EdgeInsets& padding, const Durat
update(Update::Repaint);
}
-void Map::setLatLng(const LatLng& latLng, const PrecisionPoint& point, const Duration& duration) {
+void Map::setLatLng(const LatLng& latLng, const ScreenCoordinate& point, const Duration& duration) {
transform->setLatLng(latLng, point, duration);
update(Update::Repaint);
}
@@ -192,6 +192,7 @@ LatLng Map::getLatLng(const EdgeInsets& padding) const {
void Map::resetPosition(const EdgeInsets& padding) {
CameraOptions camera;
camera.angle = 0;
+ camera.pitch = 0;
camera.center = LatLng(0, 0);
if (padding) {
camera.padding = padding;
@@ -204,12 +205,12 @@ void Map::resetPosition(const EdgeInsets& padding) {
#pragma mark - Scale
-void Map::scaleBy(double ds, const PrecisionPoint& point, const Duration& duration) {
+void Map::scaleBy(double ds, const ScreenCoordinate& point, const Duration& duration) {
transform->scaleBy(ds, point, duration);
update(Update::Zoom);
}
-void Map::setScale(double scale, const PrecisionPoint& point, const Duration& duration) {
+void Map::setScale(double scale, const ScreenCoordinate& point, const Duration& duration) {
transform->setScale(scale, point, duration);
update(Update::Zoom);
}
@@ -257,11 +258,11 @@ CameraOptions Map::cameraForLatLngs(const std::vector<LatLng>& latLngs, const Ed
}
// Calculate the bounds of the possibly rotated shape with respect to the viewport.
- PrecisionPoint nePixel = {-INFINITY, -INFINITY};
- PrecisionPoint swPixel = {INFINITY, INFINITY};
+ ScreenCoordinate nePixel = {-INFINITY, -INFINITY};
+ ScreenCoordinate swPixel = {INFINITY, INFINITY};
double viewportHeight = getHeight();
for (LatLng latLng : latLngs) {
- PrecisionPoint pixel = pixelForLatLng(latLng);
+ ScreenCoordinate pixel = pixelForLatLng(latLng);
swPixel.x = std::min(swPixel.x, pixel.x);
nePixel.x = std::max(nePixel.x, pixel.x);
swPixel.y = std::min(swPixel.y, viewportHeight - pixel.y);
@@ -278,15 +279,15 @@ CameraOptions Map::cameraForLatLngs(const std::vector<LatLng>& latLngs, const Ed
zoom = util::clamp(zoom, getMinZoom(), getMaxZoom());
// Calculate the center point of a virtual bounds that is extended in all directions by padding.
- PrecisionPoint paddedNEPixel = {
+ ScreenCoordinate paddedNEPixel = {
nePixel.x + padding.right / minScale,
nePixel.y + padding.top / minScale,
};
- PrecisionPoint paddedSWPixel = {
+ ScreenCoordinate paddedSWPixel = {
swPixel.x - padding.left / minScale,
swPixel.y - padding.bottom / minScale,
};
- PrecisionPoint centerPixel = {
+ ScreenCoordinate centerPixel = {
(paddedNEPixel.x + paddedSWPixel.x) / 2,
(paddedNEPixel.y + paddedSWPixel.y) / 2,
};
@@ -339,7 +340,7 @@ uint16_t Map::getHeight() const {
#pragma mark - Rotation
-void Map::rotateBy(const PrecisionPoint& first, const PrecisionPoint& second, const Duration& duration) {
+void Map::rotateBy(const ScreenCoordinate& first, const ScreenCoordinate& second, const Duration& duration) {
transform->rotateBy(first, second, duration);
update(Update::Repaint);
}
@@ -348,18 +349,18 @@ void Map::setBearing(double degrees, const Duration& duration) {
setBearing(degrees, EdgeInsets(), duration);
}
-void Map::setBearing(double degrees, const PrecisionPoint& center, const Duration& duration) {
- transform->setAngle(-degrees * M_PI / 180, center, duration);
+void Map::setBearing(double degrees, const ScreenCoordinate& center, const Duration& duration) {
+ transform->setAngle(-degrees * util::DEG2RAD, center, duration);
update(Update::Repaint);
}
void Map::setBearing(double degrees, const EdgeInsets& padding, const Duration& duration) {
- transform->setAngle(-degrees * M_PI / 180, padding, duration);
+ transform->setAngle(-degrees * util::DEG2RAD, padding, duration);
update(Update::Repaint);
}
double Map::getBearing() const {
- return -transform->getAngle() / M_PI * 180;
+ return -transform->getAngle() * util::RAD2DEG;
}
void Map::resetNorth(const Duration& duration) {
@@ -374,13 +375,13 @@ void Map::setPitch(double pitch, const Duration& duration) {
setPitch(pitch, {NAN, NAN}, duration);
}
-void Map::setPitch(double pitch, const PrecisionPoint& anchor, const Duration& duration) {
- transform->setPitch(pitch * M_PI / 180, anchor, duration);
+void Map::setPitch(double pitch, const ScreenCoordinate& anchor, const Duration& duration) {
+ transform->setPitch(pitch * util::DEG2RAD, anchor, duration);
update(Update::Repaint);
}
double Map::getPitch() const {
- return transform->getPitch() / M_PI * 180;
+ return transform->getPitch() * util::RAD2DEG;
}
@@ -420,12 +421,12 @@ LatLng Map::latLngForProjectedMeters(const ProjectedMeters& projectedMeters) con
return Projection::latLngForProjectedMeters(projectedMeters);
}
-PrecisionPoint Map::pixelForLatLng(const LatLng& latLng) const {
- return transform->latLngToPoint(latLng);
+ScreenCoordinate Map::pixelForLatLng(const LatLng& latLng) const {
+ return transform->latLngToScreenCoordinate(latLng);
}
-LatLng Map::latLngForPixel(const PrecisionPoint& pixel) const {
- return transform->pointToLatLng(pixel);
+LatLng Map::latLngForPixel(const ScreenCoordinate& pixel) const {
+ return transform->screenCoordinateToLatLng(pixel);
}
#pragma mark - Annotations
diff --git a/src/mbgl/map/map_context.cpp b/src/mbgl/map/map_context.cpp
index f9397d4f78..e6d8b389e4 100644
--- a/src/mbgl/map/map_context.cpp
+++ b/src/mbgl/map/map_context.cpp
@@ -247,7 +247,7 @@ bool MapContext::renderSync(const TransformState& state, const FrameData& frame)
view.afterRender();
if (style->hasTransitions()) {
- updateFlags |= Update::Classes;
+ updateFlags |= Update::Zoom;
asyncUpdate.send();
} else if (painter->needsAnimation()) {
updateFlags |= Update::Repaint;
diff --git a/src/mbgl/map/tile_id.cpp b/src/mbgl/map/tile_id.cpp
index 3058125a20..fe6f2b8eb7 100644
--- a/src/mbgl/map/tile_id.cpp
+++ b/src/mbgl/map/tile_id.cpp
@@ -5,7 +5,7 @@
namespace mbgl {
-TileID TileID::parent(int8_t parent_z, int8_t sourceMaxZoom) const {
+TileID TileID::parent(uint8_t parent_z, uint8_t sourceMaxZoom) const {
assert(parent_z < z);
auto newX = x;
auto newY = y;
@@ -22,7 +22,7 @@ TileID TileID::parent(int8_t parent_z, int8_t sourceMaxZoom) const {
return TileID{parent_z, newX, newY, parent_z > sourceMaxZoom ? sourceMaxZoom : parent_z};
}
-std::forward_list<TileID> TileID::children(int8_t sourceMaxZoom) const {
+std::forward_list<TileID> TileID::children(uint8_t sourceMaxZoom) const {
auto childZ = z + 1;
std::forward_list<TileID> child_ids;
diff --git a/src/mbgl/map/tile_id.hpp b/src/mbgl/map/tile_id.hpp
index a193b63392..5fa5e45433 100644
--- a/src/mbgl/map/tile_id.hpp
+++ b/src/mbgl/map/tile_id.hpp
@@ -13,38 +13,42 @@ namespace mbgl {
class TileID {
public:
const int16_t w = 0;
- const int8_t z = 0;
- const int32_t x = 0, y = 0;
- const int8_t sourceZ;
- const float overscaling;
+ const uint8_t z;
+ const int32_t x;
+ const int32_t y;
+ const uint8_t sourceZ;
- inline explicit TileID(int8_t z_, int32_t x_, int32_t y_, int8_t sourceZ_)
+ explicit TileID(uint8_t z_, int32_t x_, int32_t y_, uint8_t sourceZ_)
: w((x_ < 0 ? x_ - (1 << z_) + 1 : x_) / (1 << z_)), z(z_), x(x_), y(y_),
- sourceZ(sourceZ_), overscaling(std::pow(2, z_ - sourceZ_)) {}
+ sourceZ(sourceZ_) {}
- inline uint64_t to_uint64() const {
+ uint64_t to_uint64() const {
return ((std::pow(2, z) * y + x) * 32) + z;
}
- inline bool operator==(const TileID& rhs) const {
+ float overscaling() const {
+ return std::pow(2, z - sourceZ);
+ }
+
+ bool operator==(const TileID& rhs) const {
return w == rhs.w && z == rhs.z && x == rhs.x && y == rhs.y;
}
- inline bool operator!=(const TileID& rhs) const {
+ bool operator!=(const TileID& rhs) const {
return !operator==(rhs);
}
- inline bool operator<(const TileID& rhs) const {
+ bool operator<(const TileID& rhs) const {
if (w != rhs.w) return w < rhs.w;
if (z != rhs.z) return z < rhs.z;
if (x != rhs.x) return x < rhs.x;
return y < rhs.y;
}
- TileID parent(int8_t z, int8_t sourceMaxZoom) const;
+ TileID parent(uint8_t z, uint8_t sourceMaxZoom) const;
TileID normalized() const;
std::forward_list<TileID>
- children(int8_t sourceMaxZoom = std::numeric_limits<int8_t>::max()) const;
+ children(uint8_t sourceMaxZoom = std::numeric_limits<uint8_t>::max()) const;
bool isChildOf(const TileID&) const;
operator std::string() const;
};
diff --git a/src/mbgl/map/transform.cpp b/src/mbgl/map/transform.cpp
index 0f7af8c9e9..74e43a62fe 100644
--- a/src/mbgl/map/transform.cpp
+++ b/src/mbgl/map/transform.cpp
@@ -6,7 +6,6 @@
#include <mbgl/util/math.hpp>
#include <mbgl/util/unitbezier.hpp>
#include <mbgl/util/interpolate.hpp>
-#include <mbgl/util/tile_coordinate.hpp>
#include <mbgl/platform/log.hpp>
#include <mbgl/platform/platform.hpp>
#include <mbgl/util/chrono.hpp>
@@ -36,7 +35,7 @@ static double _normalizeAngle(double angle, double anchorAngle)
return angle;
}
-inline bool _validPoint(const PrecisionPoint& point) {
+inline bool _validPoint(const ScreenCoordinate& point) {
return !std::isnan(point.x) && !std::isnan(point.y);
}
@@ -97,16 +96,16 @@ void Transform::easeTo(const CameraOptions& camera, const AnimationOptions& anim
padding = *camera.padding;
}
const LatLng startLatLng = getLatLng(padding);
- const PrecisionPoint startPoint = {
+ const ScreenCoordinate startPoint = {
state.lngX(startLatLng.longitude),
state.latY(startLatLng.latitude),
};
- unwrapLatLng(latLng);
- const PrecisionPoint endPoint = {
+ latLng.unwrapForShortestPath(getLatLng());
+ const ScreenCoordinate endPoint = {
state.lngX(latLng.longitude),
state.latY(latLng.latitude),
};
- PrecisionPoint center = padding.getCenter(state.width, state.height);
+ ScreenCoordinate center = padding.getCenter(state.width, state.height);
center.y = state.height - center.y;
// Constrain camera options.
@@ -123,7 +122,7 @@ void Transform::easeTo(const CameraOptions& camera, const AnimationOptions& anim
Duration duration = animation.duration ? *animation.duration : Duration::zero();
const double startWorldSize = state.worldSize();
- state.Bc = startWorldSize / 360;
+ state.Bc = startWorldSize / util::DEGREES_MAX;
state.Cc = startWorldSize / util::M2PI;
const double startScale = state.scale;
@@ -134,7 +133,7 @@ void Transform::easeTo(const CameraOptions& camera, const AnimationOptions& anim
state.rotating = angle != startAngle;
startTransition(camera, animation, [=](double t) {
- PrecisionPoint framePoint = util::interpolate(startPoint, endPoint, t);
+ ScreenCoordinate framePoint = util::interpolate(startPoint, endPoint, t);
LatLng frameLatLng = {
state.yLat(framePoint.y, startWorldSize),
state.xLng(framePoint.x, startWorldSize),
@@ -180,16 +179,16 @@ void Transform::flyTo(const CameraOptions &camera, const AnimationOptions &anima
padding = *camera.padding;
}
const LatLng startLatLng = getLatLng(padding);
- const PrecisionPoint startPoint = {
+ const ScreenCoordinate startPoint = {
state.lngX(startLatLng.longitude),
state.latY(startLatLng.latitude),
};
- unwrapLatLng(latLng);
- const PrecisionPoint endPoint = {
+ latLng.unwrapForShortestPath(getLatLng());
+ const ScreenCoordinate endPoint = {
state.lngX(latLng.longitude),
state.latY(latLng.latitude),
};
- PrecisionPoint center = padding.getCenter(state.width, state.height);
+ ScreenCoordinate center = padding.getCenter(state.width, state.height);
center.y = state.height - center.y;
// Constrain camera options.
@@ -291,7 +290,7 @@ void Transform::flyTo(const CameraOptions &camera, const AnimationOptions &anima
}
const double startWorldSize = state.worldSize();
- state.Bc = startWorldSize / 360;
+ state.Bc = startWorldSize / util::DEGREES_MAX;
state.Cc = startWorldSize / util::M2PI;
state.panning = true;
@@ -305,7 +304,7 @@ void Transform::flyTo(const CameraOptions &camera, const AnimationOptions &anima
double us = u(s);
// Calculate the current point and zoom level along the flight path.
- PrecisionPoint framePoint = util::interpolate(startPoint, endPoint, us);
+ ScreenCoordinate framePoint = util::interpolate(startPoint, endPoint, us);
double frameZoom = startZoom + state.scaleZoom(1 / w(s));
// Convert to geographic coordinates and set the new viewpoint.
@@ -329,34 +328,21 @@ void Transform::flyTo(const CameraOptions &camera, const AnimationOptions &anima
}, duration);
}
-/** If a path crossing the antemeridian would be shorter, extend the final
- coordinate so that interpolating between the two endpoints will cross it. */
-void Transform::unwrapLatLng(LatLng& latLng) {
- LatLng startLatLng = getLatLng();
- if (std::abs(startLatLng.longitude) + std::abs(latLng.longitude) > 180) {
- if (startLatLng.longitude > 0 && latLng.longitude < 0) {
- latLng.longitude += 360;
- } else if (startLatLng.longitude < 0 && latLng.longitude > 0) {
- latLng.longitude -= 360;
- }
- }
-}
-
#pragma mark - Position
-void Transform::moveBy(const PrecisionPoint& offset, const Duration& duration) {
+void Transform::moveBy(const ScreenCoordinate& offset, const Duration& duration) {
if (!_validPoint(offset)) {
return;
}
- PrecisionPoint centerOffset = {
+ ScreenCoordinate centerOffset = {
offset.x,
-offset.y,
};
- PrecisionPoint centerPoint = state.latLngToPoint(state.getLatLng()) - centerOffset;
+ ScreenCoordinate centerPoint = state.latLngToScreenCoordinate(state.getLatLng()) - centerOffset;
CameraOptions camera;
- camera.center = state.pointToLatLng(centerPoint);
+ camera.center = state.screenCoordinateToLatLng(centerPoint);
easeTo(camera, duration);
}
@@ -377,7 +363,7 @@ void Transform::setLatLng(const LatLng& latLng, const EdgeInsets& padding, const
easeTo(camera, duration);
}
-void Transform::setLatLng(const LatLng& latLng, const PrecisionPoint& point, const Duration& duration) {
+void Transform::setLatLng(const LatLng& latLng, const ScreenCoordinate& point, const Duration& duration) {
if (!latLng || !point) {
return;
}
@@ -414,7 +400,7 @@ void Transform::setLatLngZoom(const LatLng& latLng, double zoom, const EdgeInset
LatLng Transform::getLatLng(const EdgeInsets& padding) const {
if (padding) {
- return pointToLatLng(padding.getCenter(state.width, state.height));
+ return screenCoordinateToLatLng(padding.getCenter(state.width, state.height));
} else {
return state.getLatLng();
}
@@ -423,7 +409,7 @@ LatLng Transform::getLatLng(const EdgeInsets& padding) const {
#pragma mark - Zoom
-void Transform::scaleBy(double ds, const PrecisionPoint& center, const Duration& duration) {
+void Transform::scaleBy(double ds, const ScreenCoordinate& center, const Duration& duration) {
if (std::isnan(ds)) {
return;
}
@@ -432,12 +418,12 @@ void Transform::scaleBy(double ds, const PrecisionPoint& center, const Duration&
setScale(scale, center, duration);
}
-void Transform::setZoom(double zoom, const PrecisionPoint& anchor, const Duration& duration) {
+void Transform::setZoom(double zoom, const ScreenCoordinate& anchor, const Duration& duration) {
setScale(state.zoomScale(zoom), anchor, duration);
}
void Transform::setZoom(double zoom, const EdgeInsets& padding, const Duration& duration) {
- const PrecisionPoint center = padding.getCenter(state.width, state.height);
+ const ScreenCoordinate center = padding.getCenter(state.width, state.height);
setZoom(zoom, center, duration);
}
@@ -449,7 +435,7 @@ double Transform::getScale() const {
return state.scale;
}
-void Transform::setScale(double scale, const PrecisionPoint& anchor, const Duration& duration) {
+void Transform::setScale(double scale, const ScreenCoordinate& anchor, const Duration& duration) {
if (std::isnan(scale)) {
return;
}
@@ -461,7 +447,7 @@ void Transform::setScale(double scale, const PrecisionPoint& anchor, const Durat
}
void Transform::setScale(double scale, const EdgeInsets& padding, const Duration& duration) {
- const PrecisionPoint center = padding.getCenter(state.width, state.height);
+ const ScreenCoordinate center = padding.getCenter(state.width, state.height);
setScale(scale, center, duration);
}
@@ -475,15 +461,15 @@ void Transform::setMaxZoom(const double maxZoom) {
#pragma mark - Angle
-void Transform::rotateBy(const PrecisionPoint& first, const PrecisionPoint& second, const Duration& duration) {
+void Transform::rotateBy(const ScreenCoordinate& first, const ScreenCoordinate& second, const Duration& duration) {
if (!first || !second) {
return;
}
- PrecisionPoint center(state.width, state.height);
+ ScreenCoordinate center(state.width, state.height);
center /= 2;
- const PrecisionPoint offset = first - center;
+ const ScreenCoordinate offset = first - center;
const double distance = std::sqrt(std::pow(2, offset.x) + std::pow(2, offset.y));
// If the first click was too close to the center, move the center of rotation by 200 pixels
@@ -495,8 +481,8 @@ void Transform::rotateBy(const PrecisionPoint& first, const PrecisionPoint& seco
center.y = first.y + std::sin(rotateAngle) * heightOffset;
}
- const PrecisionPoint newFirst = first - center;
- const PrecisionPoint newSecond = second - center;
+ const ScreenCoordinate newFirst = first - center;
+ const ScreenCoordinate newSecond = second - center;
const double ang = state.angle + util::angle_between(newFirst.x, newFirst.y, newSecond.x, newSecond.y);
CameraOptions camera;
@@ -508,7 +494,7 @@ void Transform::setAngle(double angle, const Duration& duration) {
setAngle(angle, {NAN, NAN}, duration);
}
-void Transform::setAngle(double angle, const PrecisionPoint& anchor, const Duration& duration) {
+void Transform::setAngle(double angle, const ScreenCoordinate& anchor, const Duration& duration) {
if (std::isnan(angle)) {
return;
}
@@ -520,7 +506,7 @@ void Transform::setAngle(double angle, const PrecisionPoint& anchor, const Durat
}
void Transform::setAngle(double angle, const EdgeInsets& padding, const Duration& duration) {
- const PrecisionPoint center = padding.getCenter(state.width, state.height);
+ const ScreenCoordinate center = padding.getCenter(state.width, state.height);
setAngle(angle, center, duration);
}
@@ -534,7 +520,7 @@ void Transform::setPitch(double pitch, const Duration& duration) {
setPitch(pitch, {NAN, NAN}, duration);
}
-void Transform::setPitch(double pitch, const PrecisionPoint& anchor, const Duration& duration) {
+void Transform::setPitch(double pitch, const ScreenCoordinate& anchor, const Duration& duration) {
if (std::isnan(pitch)) {
return;
}
@@ -585,11 +571,11 @@ void Transform::startTransition(const CameraOptions& camera,
view.notifyMapChange(isAnimated ? MapChangeRegionWillChangeAnimated : MapChangeRegionWillChange);
// Associate the anchor, if given, with a coordinate.
- PrecisionPoint anchor = camera.anchor ? *camera.anchor : PrecisionPoint(NAN, NAN);
+ ScreenCoordinate anchor = camera.anchor ? *camera.anchor : ScreenCoordinate(NAN, NAN);
LatLng anchorLatLng;
if (_validPoint(anchor)) {
anchor.y = state.getHeight() - anchor.y;
- anchorLatLng = state.pointToLatLng(anchor);
+ anchorLatLng = state.screenCoordinateToLatLng(anchor);
}
transitionStart = Clock::now();
@@ -664,14 +650,14 @@ void Transform::setGestureInProgress(bool inProgress) {
#pragma mark Conversion and projection
-PrecisionPoint Transform::latLngToPoint(const LatLng& latLng) const {
- PrecisionPoint point = state.latLngToPoint(latLng);
+ScreenCoordinate Transform::latLngToScreenCoordinate(const LatLng& latLng) const {
+ ScreenCoordinate point = state.latLngToScreenCoordinate(latLng);
point.y = state.height - point.y;
return point;
}
-LatLng Transform::pointToLatLng(const PrecisionPoint& point) const {
- PrecisionPoint flippedPoint = point;
+LatLng Transform::screenCoordinateToLatLng(const ScreenCoordinate& point) const {
+ ScreenCoordinate flippedPoint = point;
flippedPoint.y = state.height - flippedPoint.y;
- return state.pointToLatLng(flippedPoint);
+ return state.screenCoordinateToLatLng(flippedPoint);
}
diff --git a/src/mbgl/map/transform.hpp b/src/mbgl/map/transform.hpp
index 48615421fe..638eead5f1 100644
--- a/src/mbgl/map/transform.hpp
+++ b/src/mbgl/map/transform.hpp
@@ -41,10 +41,10 @@ public:
/** Pans the map by the given amount.
@param offset The distance to pan the map by, measured in pixels from
top to bottom and from left to right. */
- void moveBy(const PrecisionPoint& offset, const Duration& = Duration::zero());
+ void moveBy(const ScreenCoordinate& offset, const Duration& = Duration::zero());
void setLatLng(const LatLng&, const Duration& = Duration::zero());
void setLatLng(const LatLng&, const EdgeInsets&, const Duration& = Duration::zero());
- void setLatLng(const LatLng&, const PrecisionPoint&, const Duration& = Duration::zero());
+ void setLatLng(const LatLng&, const ScreenCoordinate&, const Duration& = Duration::zero());
void setLatLngZoom(const LatLng&, double zoom, const Duration& = Duration::zero());
void setLatLngZoom(const LatLng&, double zoom, const EdgeInsets&, const Duration& = Duration::zero());
LatLng getLatLng(const EdgeInsets& = {}) const;
@@ -55,12 +55,12 @@ public:
@param ds The difference in scale factors to scale the map by.
@param anchor A point relative to the top-left corner of the view.
If unspecified, the center point is fixed within the view. */
- void scaleBy(double ds, const PrecisionPoint& anchor = {NAN, NAN}, const Duration& = Duration::zero());
+ void scaleBy(double ds, const ScreenCoordinate& anchor = {NAN, NAN}, const Duration& = Duration::zero());
/** Sets the scale factor, keeping the given point fixed within the view.
@param scale The new scale factor.
@param anchor A point relative to the top-left corner of the view.
If unspecified, the center point is fixed within the view. */
- void setScale(double scale, const PrecisionPoint& anchor = {NAN, NAN}, const Duration& = Duration::zero());
+ void setScale(double scale, const ScreenCoordinate& anchor = {NAN, NAN}, const Duration& = Duration::zero());
/** Sets the scale factor, keeping the center point fixed within the inset view.
@param scale The new scale factor.
@param padding The viewport padding that affects the fixed center point. */
@@ -69,7 +69,7 @@ public:
@param zoom The new zoom level.
@param anchor A point relative to the top-left corner of the view.
If unspecified, the center point is fixed within the view. */
- void setZoom(double zoom, const PrecisionPoint& anchor = {NAN, NAN}, const Duration& = Duration::zero());
+ void setZoom(double zoom, const ScreenCoordinate& anchor = {NAN, NAN}, const Duration& = Duration::zero());
/** Sets the zoom level, keeping the center point fixed within the inset view.
@param zoom The new zoom level.
@param padding The viewport padding that affects the fixed center point. */
@@ -84,7 +84,7 @@ public:
// Angle
- void rotateBy(const PrecisionPoint& first, const PrecisionPoint& second, const Duration& = Duration::zero());
+ void rotateBy(const ScreenCoordinate& first, const ScreenCoordinate& second, const Duration& = Duration::zero());
/** Sets the angle of rotation.
@param angle The new angle of rotation, measured in radians
counterclockwise from true north. */
@@ -93,7 +93,7 @@ public:
@param angle The new angle of rotation, measured in radians
counterclockwise from true north.
@param anchor A point relative to the top-left corner of the view. */
- void setAngle(double angle, const PrecisionPoint& anchor, const Duration& = Duration::zero());
+ void setAngle(double angle, const ScreenCoordinate& anchor, const Duration& = Duration::zero());
/** Sets the angle of rotation, keeping the center point fixed within the inset view.
@param angle The new angle of rotation, measured in radians
counterclockwise from true north.
@@ -113,7 +113,7 @@ public:
@param angle The new pitch angle, measured in radians toward the
horizon.
@param anchor A point relative to the top-left corner of the view. */
- void setPitch(double pitch, const PrecisionPoint& anchor, const Duration& = Duration::zero());
+ void setPitch(double pitch, const ScreenCoordinate& anchor, const Duration& = Duration::zero());
double getPitch() const;
// North Orientation
@@ -140,12 +140,10 @@ public:
bool isPanning() const { return state.isPanning(); }
// Conversion and projection
- PrecisionPoint latLngToPoint(const LatLng&) const;
- LatLng pointToLatLng(const PrecisionPoint&) const;
+ ScreenCoordinate latLngToScreenCoordinate(const LatLng&) const;
+ LatLng screenCoordinateToLatLng(const ScreenCoordinate&) const;
private:
- void unwrapLatLng(LatLng&);
-
View &view;
TransformState state;
diff --git a/src/mbgl/map/transform_state.cpp b/src/mbgl/map/transform_state.cpp
index 087defabda..006a8d5d3a 100644
--- a/src/mbgl/map/transform_state.cpp
+++ b/src/mbgl/map/transform_state.cpp
@@ -1,11 +1,10 @@
#include <mbgl/map/transform_state.hpp>
#include <mbgl/map/tile_id.hpp>
#include <mbgl/util/constants.hpp>
-#include <mbgl/util/tile_coordinate.hpp>
#include <mbgl/util/interpolate.hpp>
#include <mbgl/util/math.hpp>
-using namespace mbgl;
+namespace mbgl {
TransformState::TransformState(ConstrainMode constrainMode_)
: constrainMode(constrainMode_)
@@ -16,7 +15,7 @@ TransformState::TransformState(ConstrainMode constrainMode_)
void TransformState::matrixFor(mat4& matrix, const TileID& id, const int8_t z) const {
const double tile_scale = std::pow(2, z);
- double s = util::tileSize * scale / tile_scale;
+ double s = worldSize() / tile_scale;
matrix::identity(matrix);
matrix::translate(matrix, matrix, id.x * s, id.y * s, 0);
@@ -89,35 +88,34 @@ ConstrainMode TransformState::getConstrainMode() const {
#pragma mark - Position
-LatLng TransformState::getLatLng() const {
- LatLng ll;
-
- ll.longitude = -x / Bc;
- ll.latitude = util::RAD2DEG * (2 * std::atan(std::exp(y / Cc)) - 0.5 * M_PI);
+LatLng TransformState::getLatLng(LatLng::WrapMode wrapMode) const {
+ LatLng ll {
+ util::RAD2DEG * (2 * std::atan(std::exp(y / Cc)) - 0.5 * M_PI),
+ -x / Bc,
+ wrapMode
+ };
- // adjust for world wrap
- while (ll.longitude > 180) ll.longitude -= 180;
- while (ll.longitude < -180) ll.longitude += 180;
+ if (wrapMode == LatLng::Unwrapped) return ll;
// adjust for date line
- double w = util::tileSize * scale / 2;
+ double w = worldSize() / 2;
double x_ = x;
if (x_ > w) {
while (x_ > w) {
x_ -= w;
if (ll.longitude < 0) {
- ll.longitude += 180;
+ ll.longitude += util::LONGITUDE_MAX;
} else if (ll.longitude > 0) {
- ll.longitude -= 180;
+ ll.longitude -= util::LONGITUDE_MAX;
}
}
} else if (x_ < -w) {
while (x_ < -w) {
x_ += w;
if (ll.longitude < 0) {
- ll.longitude -= 180;
+ ll.longitude -= util::LONGITUDE_MAX;
} else if (ll.longitude > 0) {
- ll.longitude -= 180;
+ ll.longitude -= util::LONGITUDE_MAX;
}
}
}
@@ -126,12 +124,12 @@ LatLng TransformState::getLatLng() const {
}
double TransformState::pixel_x() const {
- const double center = (width - scale * util::tileSize) / 2;
+ const double center = (width - worldSize()) / 2;
return center + x;
}
double TransformState::pixel_y() const {
- const double center = (height - scale * util::tileSize) / 2;
+ const double center = (height - worldSize()) / 2;
return center + y;
}
@@ -220,21 +218,21 @@ bool TransformState::isGestureInProgress() const {
#pragma mark - Projection
double TransformState::lngX(double lng) const {
- return (180.0f + lng) * worldSize() / 360.0f;
+ return (util::LONGITUDE_MAX + lng) * worldSize() / util::DEGREES_MAX;
}
double TransformState::latY(double lat) const {
- double y_ = 180.0f / M_PI * std::log(std::tan(M_PI / 4 + lat * M_PI / 360.0f));
- return (180.0f - y_) * worldSize() / 360.0f;
+ double y_ = util::RAD2DEG * std::log(std::tan(M_PI / 4 + lat * M_PI / util::DEGREES_MAX));
+ return (util::LONGITUDE_MAX - y_) * worldSize() / util::DEGREES_MAX;
}
double TransformState::xLng(double x_, double worldSize_) const {
- return x_ * 360.0f / worldSize_ - 180.0f;
+ return x_ * util::DEGREES_MAX / worldSize_ - util::LONGITUDE_MAX;
}
double TransformState::yLat(double y_, double worldSize_) const {
- double y2 = 180.0f - y_ * 360.0f / worldSize_;
- return 360.0f / M_PI * std::atan(std::exp(y2 * M_PI / 180.0f)) - 90.0f;
+ double y2 = util::LONGITUDE_MAX - y_ * util::DEGREES_MAX / worldSize_;
+ return util::DEGREES_MAX / M_PI * std::atan(std::exp(y2 * util::DEG2RAD)) - 90.0f;
}
double TransformState::zoomScale(double zoom) const {
@@ -249,47 +247,17 @@ double TransformState::worldSize() const {
return scale * util::tileSize;
}
-PrecisionPoint TransformState::latLngToPoint(const LatLng& latLng) const {
- return coordinateToPoint(latLngToCoordinate(latLng));
-}
-
-LatLng TransformState::pointToLatLng(const PrecisionPoint& point) const {
- return coordinateToLatLng(pointToCoordinate(point));
-}
-
-TileCoordinate TransformState::latLngToCoordinate(const LatLng& latLng) const {
- return {
- lngX(latLng.longitude) / util::tileSize,
- latY(latLng.latitude) / util::tileSize,
- getZoom()
- };
-}
-
-LatLng TransformState::coordinateToLatLng(const TileCoordinate& coord) const {
- const double worldSize_ = zoomScale(coord.zoom);
- LatLng latLng = {
- yLat(coord.row, worldSize_),
- xLng(coord.column, worldSize_)
- };
- while (latLng.longitude < -180.0f) latLng.longitude += 360.0f;
- while (latLng.longitude > 180.0f) latLng.longitude -= 360.0f;
- return latLng;
-}
-
-PrecisionPoint TransformState::coordinateToPoint(const TileCoordinate& coord) const {
- mat4 mat = coordinatePointMatrix(coord.zoom);
- matrix::vec4 p;
- matrix::vec4 c = {{ coord.column, coord.row, 0, 1 }};
+ScreenCoordinate TransformState::latLngToScreenCoordinate(const LatLng& latLng) const {
+ mat4 mat = coordinatePointMatrix(getZoom());
+ vec4<double> p;
+ vec4<double> c = { lngX(latLng.longitude) / util::tileSize, latY(latLng.latitude) / util::tileSize, 0, 1 };
matrix::transformMat4(p, c, mat);
- return { p[0] / p[3], height - p[1] / p[3] };
+ return { p.x / p.w, height - p.y / p.w };
}
-TileCoordinate TransformState::pointToCoordinate(const PrecisionPoint& point) const {
-
+LatLng TransformState::screenCoordinateToLatLng(const ScreenCoordinate& point, LatLng::WrapMode wrapMode) const {
float targetZ = 0;
- const double tileZoom = getZoom();
-
- mat4 mat = coordinatePointMatrix(tileZoom);
+ mat4 mat = coordinatePointMatrix(getZoom());
mat4 inverted;
bool err = matrix::invert(inverted, mat);
@@ -302,31 +270,34 @@ TileCoordinate TransformState::pointToCoordinate(const PrecisionPoint& point) co
// unproject two points to get a line and then find the point on that
// line with z=0
- matrix::vec4 coord0;
- matrix::vec4 coord1;
- matrix::vec4 point0 = {{ point.x, flippedY, 0, 1 }};
- matrix::vec4 point1 = {{ point.x, flippedY, 1, 1 }};
+ vec4<double> coord0;
+ vec4<double> coord1;
+ vec4<double> point0 = { point.x, flippedY, 0, 1 };
+ vec4<double> point1 = { point.x, flippedY, 1, 1 };
matrix::transformMat4(coord0, point0, inverted);
matrix::transformMat4(coord1, point1, inverted);
- double w0 = coord0[3];
- double w1 = coord1[3];
- double x0 = coord0[0] / w0;
- double x1 = coord1[0] / w1;
- double y0 = coord0[1] / w0;
- double y1 = coord1[1] / w1;
- double z0 = coord0[2] / w0;
- double z1 = coord1[2] / w1;
+ double w0 = coord0.w;
+ double w1 = coord1.w;
+ double x0 = coord0.x / w0;
+ double x1 = coord1.x / w1;
+ double y0 = coord0.y / w0;
+ double y1 = coord1.y / w1;
+ double z0 = coord0.z / w0;
+ double z1 = coord1.z / w1;
double t = z0 == z1 ? 0 : (targetZ - z0) / (z1 - z0);
-
- return { util::interpolate(x0, x1, t), util::interpolate(y0, y1, t), tileZoom };
+ return {
+ yLat(util::interpolate(y0, y1, t), scale),
+ xLng(util::interpolate(x0, x1, t), scale),
+ wrapMode
+ };
}
mat4 TransformState::coordinatePointMatrix(double z) const {
mat4 proj;
getProjMatrix(proj);
- float s = util::tileSize * scale / std::pow(2, z);
+ float s = worldSize() / std::pow(2, z);
matrix::scale(proj, proj, s, s, 1);
matrix::multiply(proj, getPixelMatrix(), proj);
return proj;
@@ -366,50 +337,49 @@ void TransformState::constrain(double& scale_, double& x_, double& y_) const {
}
}
-void TransformState::moveLatLng(const LatLng& latLng, const PrecisionPoint& anchor) {
- if (!latLng || !anchor) {
- return;
- }
-
- auto coord = latLngToCoordinate(latLng);
- auto coordAtPoint = pointToCoordinate(anchor);
- auto coordCenter = pointToCoordinate({ width / 2.0f, height / 2.0f });
-
- float columnDiff = coordAtPoint.column - coord.column;
- float rowDiff = coordAtPoint.row - coord.row;
-
- auto newLatLng = coordinateToLatLng({
- coordCenter.column - columnDiff,
- coordCenter.row - rowDiff,
- coordCenter.zoom
- });
- setLatLngZoom(newLatLng, coordCenter.zoom);
+void TransformState::moveLatLng(const LatLng& latLng, const ScreenCoordinate& anchor) {
+ if (!latLng || !anchor) return;
+
+ auto latLngToTileCoord = [&](const LatLng& ll) -> vec2<double> {
+ return { lngX(ll.longitude), latY(ll.latitude) };
+ };
+
+ auto tileCoordToLatLng = [&](const vec2<double> coord) -> LatLng {
+ return { yLat(coord.y, worldSize()), xLng(coord.x, worldSize()) };
+ };
+
+ auto centerCoord = latLngToTileCoord(getLatLng(LatLng::Unwrapped));
+ auto latLngCoord = latLngToTileCoord(latLng);
+ auto anchorCoord = latLngToTileCoord(screenCoordinateToLatLng(anchor, LatLng::Unwrapped));
+ setLatLngZoom(tileCoordToLatLng(centerCoord + latLngCoord - anchorCoord), getZoom());
}
void TransformState::setLatLngZoom(const LatLng &latLng, double zoom) {
double newScale = zoomScale(zoom);
const double newWorldSize = newScale * util::tileSize;
- Bc = newWorldSize / 360;
+ Bc = newWorldSize / util::DEGREES_MAX;
Cc = newWorldSize / util::M2PI;
const double m = 1 - 1e-15;
const double f = util::clamp(std::sin(util::DEG2RAD * latLng.latitude), -m, m);
- PrecisionPoint point = {
+ ScreenCoordinate point = {
-latLng.longitude * Bc,
0.5 * Cc * std::log((1 + f) / (1 - f)),
};
setScalePoint(newScale, point);
}
-void TransformState::setScalePoint(const double newScale, const PrecisionPoint &point) {
+void TransformState::setScalePoint(const double newScale, const ScreenCoordinate &point) {
double constrainedScale = newScale;
- PrecisionPoint constrainedPoint = point;
+ ScreenCoordinate constrainedPoint = point;
constrain(constrainedScale, constrainedPoint.x, constrainedPoint.y);
scale = constrainedScale;
x = constrainedPoint.x;
y = constrainedPoint.y;
- Bc = worldSize() / 360;
+ Bc = worldSize() / util::DEGREES_MAX;
Cc = worldSize() / util::M2PI;
}
+
+} // namespace mbgl
diff --git a/src/mbgl/map/transform_state.hpp b/src/mbgl/map/transform_state.hpp
index 0fb1f2304b..797a28692e 100644
--- a/src/mbgl/map/transform_state.hpp
+++ b/src/mbgl/map/transform_state.hpp
@@ -6,7 +6,6 @@
#include <mbgl/util/constants.hpp>
#include <mbgl/util/vec.hpp>
#include <mbgl/util/mat4.hpp>
-#include <mbgl/util/vec4.hpp>
#include <cstdint>
#include <array>
@@ -15,7 +14,6 @@
namespace mbgl {
class TileID;
-class TileCoordinate;
class TransformState {
friend class Transform;
@@ -39,7 +37,7 @@ public:
ConstrainMode getConstrainMode() const;
// Position
- LatLng getLatLng() const;
+ LatLng getLatLng(LatLng::WrapMode = LatLng::Wrapped) const;
double pixel_x() const;
double pixel_y() const;
@@ -66,14 +64,13 @@ public:
bool isGestureInProgress() const;
// Conversion and projection
- PrecisionPoint latLngToPoint(const LatLng&) const;
- LatLng pointToLatLng(const PrecisionPoint&) const;
+ ScreenCoordinate latLngToScreenCoordinate(const LatLng&) const;
+ LatLng screenCoordinateToLatLng(const ScreenCoordinate&, LatLng::WrapMode = LatLng::Wrapped) const;
- TileCoordinate latLngToCoordinate(const LatLng&) const;
- LatLng coordinateToLatLng(const TileCoordinate&) const;
-
- PrecisionPoint coordinateToPoint(const TileCoordinate&) const;
- TileCoordinate pointToCoordinate(const PrecisionPoint&) const;
+ double xLng(double x, double worldSize) const;
+ double yLat(double y, double worldSize) const;
+ double lngX(double lon) const;
+ double latY(double lat) const;
private:
bool rotatedNorth() const;
@@ -88,10 +85,6 @@ private:
// logical dimensions
uint16_t width = 0, height = 0;
- double xLng(double x, double worldSize) const;
- double yLat(double y, double worldSize) const;
- double lngX(double lon) const;
- double latY(double lat) const;
double zoomScale(double zoom) const;
double scaleZoom(double scale) const;
double worldSize() const;
@@ -101,9 +94,9 @@ private:
/** Recenter the map so that the given coordinate is located at the given
point on screen. */
- void moveLatLng(const LatLng&, const PrecisionPoint&);
+ void moveLatLng(const LatLng&, const ScreenCoordinate&);
void setLatLngZoom(const LatLng &latLng, double zoom);
- void setScalePoint(const double scale, const PrecisionPoint& point);
+ void setScalePoint(const double scale, const ScreenCoordinate& point);
private:
ConstrainMode constrainMode;
@@ -122,8 +115,8 @@ private:
double pitch = 0.0;
// cache values for spherical mercator math
- double Bc = (scale * util::tileSize) / 360;
- double Cc = (scale * util::tileSize) / util::M2PI;
+ double Bc = worldSize() / util::DEGREES_MAX;
+ double Cc = worldSize() / util::M2PI;
};
} // namespace mbgl
diff --git a/src/mbgl/renderer/line_bucket.cpp b/src/mbgl/renderer/line_bucket.cpp
index ba50e6b1f0..e05f00c288 100644
--- a/src/mbgl/renderer/line_bucket.cpp
+++ b/src/mbgl/renderer/line_bucket.cpp
@@ -41,7 +41,7 @@ void LineBucket::addGeometry(const GeometryCollection& geometryCollection) {
const float COS_HALF_SHARP_CORNER = std::cos(75.0 / 2.0 * (M_PI / 180.0));
const float SHARP_CORNER_OFFSET = 15.0f;
-void LineBucket::addGeometry(const std::vector<Coordinate>& vertices) {
+void LineBucket::addGeometry(const GeometryCoordinates& vertices) {
const GLsizei len = [&vertices] {
GLsizei l = static_cast<GLsizei>(vertices.size());
// If the line has duplicate vertices at the end, adjust length to remove them.
@@ -58,10 +58,10 @@ void LineBucket::addGeometry(const std::vector<Coordinate>& vertices) {
const float miterLimit = layout.join == JoinType::Bevel ? 1.05f : float(layout.miterLimit);
- const double sharpCornerOffset = SHARP_CORNER_OFFSET * (util::EXTENT / (512.0 * overscaling));
+ const double sharpCornerOffset = SHARP_CORNER_OFFSET * (util::EXTENT / (util::tileSize * overscaling));
- const Coordinate firstVertex = vertices.front();
- const Coordinate lastVertex = vertices[len - 1];
+ const GeometryCoordinate firstVertex = vertices.front();
+ const GeometryCoordinate lastVertex = vertices[len - 1];
const bool closed = firstVertex == lastVertex;
if (len == 2 && closed) {
@@ -75,8 +75,8 @@ void LineBucket::addGeometry(const std::vector<Coordinate>& vertices) {
int8_t flip = 1;
double distance = 0;
bool startOfLine = true;
- Coordinate currentVertex = Coordinate::null(), prevVertex = Coordinate::null(),
- nextVertex = Coordinate::null();
+ GeometryCoordinate currentVertex = GeometryCoordinate::null(), prevVertex = GeometryCoordinate::null(),
+ nextVertex = GeometryCoordinate::null();
vec2<double> prevNormal = vec2<double>::null(), nextNormal = vec2<double>::null();
// the last three vertices added
@@ -99,7 +99,7 @@ void LineBucket::addGeometry(const std::vector<Coordinate>& vertices) {
nextVertex = vertices[i + 1];
} else {
// there is no next vertex
- nextVertex = Coordinate::null();
+ nextVertex = GeometryCoordinate::null();
}
// if two consecutive vertices exist, skip the current one
@@ -153,7 +153,7 @@ void LineBucket::addGeometry(const std::vector<Coordinate>& vertices) {
if (isSharpCorner && i > 0) {
const double prevSegmentLength = util::dist<double>(currentVertex, prevVertex);
if (prevSegmentLength > 2.0 * sharpCornerOffset) {
- Coordinate newPrevVertex = currentVertex - (util::round(vec2<double>(currentVertex - prevVertex) * (sharpCornerOffset / prevSegmentLength)));
+ GeometryCoordinate newPrevVertex = currentVertex - (util::round(vec2<double>(currentVertex - prevVertex) * (sharpCornerOffset / prevSegmentLength)));
distance += util::dist<double>(newPrevVertex, prevVertex);
addCurrentVertex(newPrevVertex, flip, distance, prevNormal, 0, 0, false, startVertex, triangleStore);
prevVertex = newPrevVertex;
@@ -328,7 +328,7 @@ void LineBucket::addGeometry(const std::vector<Coordinate>& vertices) {
if (isSharpCorner && i < len - 1) {
const double nextSegmentLength = util::dist<double>(currentVertex, nextVertex);
if (nextSegmentLength > 2 * sharpCornerOffset) {
- Coordinate newCurrentVertex = currentVertex + util::round(vec2<double>(nextVertex - currentVertex) * (sharpCornerOffset / nextSegmentLength));
+ GeometryCoordinate newCurrentVertex = currentVertex + util::round(vec2<double>(nextVertex - currentVertex) * (sharpCornerOffset / nextSegmentLength));
distance += util::dist<double>(newCurrentVertex, currentVertex);
addCurrentVertex(newCurrentVertex, flip, distance, nextNormal, 0, 0, false, startVertex, triangleStore);
currentVertex = newCurrentVertex;
@@ -361,7 +361,7 @@ void LineBucket::addGeometry(const std::vector<Coordinate>& vertices) {
}
}
-void LineBucket::addCurrentVertex(const Coordinate& currentVertex,
+void LineBucket::addCurrentVertex(const GeometryCoordinate& currentVertex,
float flip,
double distance,
const vec2<double>& normal,
@@ -395,7 +395,7 @@ void LineBucket::addCurrentVertex(const Coordinate& currentVertex,
e2 = e3;
}
-void LineBucket::addPieSliceVertex(const Coordinate& currentVertex,
+void LineBucket::addPieSliceVertex(const GeometryCoordinate& currentVertex,
float flip,
double distance,
const vec2<double>& extrude,
diff --git a/src/mbgl/renderer/line_bucket.hpp b/src/mbgl/renderer/line_bucket.hpp
index dd0ce4ff29..f02293c873 100644
--- a/src/mbgl/renderer/line_bucket.hpp
+++ b/src/mbgl/renderer/line_bucket.hpp
@@ -32,7 +32,7 @@ public:
bool hasData() const override;
void addGeometry(const GeometryCollection&);
- void addGeometry(const std::vector<Coordinate>& line);
+ void addGeometry(const GeometryCoordinates& line);
void drawLines(LineShader&, gl::GLObjectStore&);
void drawLineSDF(LineSDFShader&, gl::GLObjectStore&);
@@ -43,10 +43,10 @@ private:
TriangleElement(uint16_t a_, uint16_t b_, uint16_t c_) : a(a_), b(b_), c(c_) {}
uint16_t a, b, c;
};
- void addCurrentVertex(const Coordinate& currentVertex, float flip, double distance,
+ void addCurrentVertex(const GeometryCoordinate& currentVertex, float flip, double distance,
const vec2<double>& normal, float endLeft, float endRight, bool round,
GLint startVertex, std::vector<LineBucket::TriangleElement>& triangleStore);
- void addPieSliceVertex(const Coordinate& currentVertex, float flip, double distance,
+ void addPieSliceVertex(const GeometryCoordinate& currentVertex, float flip, double distance,
const vec2<double>& extrude, bool lineTurnsLeft, GLint startVertex,
std::vector<TriangleElement>& triangleStore);
diff --git a/src/mbgl/renderer/painter.cpp b/src/mbgl/renderer/painter.cpp
index da3551aa74..6cf2afc228 100644
--- a/src/mbgl/renderer/painter.cpp
+++ b/src/mbgl/renderer/painter.cpp
@@ -34,7 +34,6 @@
#include <mbgl/util/constants.hpp>
#include <mbgl/util/mat3.hpp>
-#include <mbgl/util/tile_coordinate.hpp>
#if defined(DEBUG)
#include <mbgl/util/stopwatch.hpp>
@@ -270,8 +269,6 @@ void Painter::renderBackground(const BackgroundLayer& layer) {
if (!imagePosA || !imagePosB)
return;
- float zoomFraction = state.getZoomFraction();
-
config.program = patternShader->getID();
patternShader->u_matrix = identityMatrix;
patternShader->u_pattern_tl_a = (*imagePosA).tl;
@@ -282,8 +279,9 @@ void Painter::renderBackground(const BackgroundLayer& layer) {
patternShader->u_opacity = properties.opacity;
LatLng latLng = state.getLatLng();
- TileCoordinate center = state.latLngToCoordinate(latLng);
- float scale = 1 / std::pow(2, zoomFraction);
+ double centerX = state.lngX(latLng.longitude);
+ double centerY = state.latY(latLng.latitude);
+ float scale = 1 / std::pow(2, state.getZoomFraction());
std::array<float, 2> sizeA = (*imagePosA).size;
mat3 matrixA;
@@ -292,8 +290,8 @@ void Painter::renderBackground(const BackgroundLayer& layer) {
1.0f / (sizeA[0] * properties.pattern.value.fromScale),
1.0f / (sizeA[1] * properties.pattern.value.fromScale));
matrix::translate(matrixA, matrixA,
- std::fmod(center.column * util::tileSize, sizeA[0] * properties.pattern.value.fromScale),
- std::fmod(center.row * util::tileSize, sizeA[1] * properties.pattern.value.fromScale));
+ std::fmod(centerX, sizeA[0] * properties.pattern.value.fromScale),
+ std::fmod(centerY, sizeA[1] * properties.pattern.value.fromScale));
matrix::rotate(matrixA, matrixA, -state.getAngle());
matrix::scale(matrixA, matrixA,
scale * state.getWidth() / 2,
@@ -306,8 +304,8 @@ void Painter::renderBackground(const BackgroundLayer& layer) {
1.0f / (sizeB[0] * properties.pattern.value.toScale),
1.0f / (sizeB[1] * properties.pattern.value.toScale));
matrix::translate(matrixB, matrixB,
- std::fmod(center.column * util::tileSize, sizeB[0] * properties.pattern.value.toScale),
- std::fmod(center.row * util::tileSize, sizeB[1] * properties.pattern.value.toScale));
+ std::fmod(centerX, sizeB[0] * properties.pattern.value.toScale),
+ std::fmod(centerY, sizeB[1] * properties.pattern.value.toScale));
matrix::rotate(matrixB, matrixB, -state.getAngle());
matrix::scale(matrixB, matrixB,
scale * state.getWidth() / 2,
@@ -346,7 +344,7 @@ mat4 Painter::translatedMatrix(const mat4& matrix, const std::array<float, 2> &t
if (translation[0] == 0 && translation[1] == 0) {
return matrix;
} else {
- const double factor = ((double)(1 << id.z)) / state.getScale() * (util::EXTENT / util::tileSize / id.overscaling);
+ const double factor = ((double)(1 << id.z)) / state.getScale() * (util::EXTENT / util::tileSize / id.overscaling());
mat4 vtxMatrix;
if (anchor == TranslateAnchorType::Viewport) {
diff --git a/src/mbgl/renderer/painter_fill.cpp b/src/mbgl/renderer/painter_fill.cpp
index cd54645c2b..6e7700702a 100644
--- a/src/mbgl/renderer/painter_fill.cpp
+++ b/src/mbgl/renderer/painter_fill.cpp
@@ -65,7 +65,7 @@ void Painter::renderFill(FillBucket& bucket, const FillLayer& layer, const TileI
// Image fill.
if (pass == RenderPass::Translucent && posA && posB) {
- float factor = (util::EXTENT / util::tileSize / std::pow(2, state.getIntegerZoom() - id.z)) / id.overscaling;
+ float factor = (util::EXTENT / util::tileSize / std::pow(2, state.getIntegerZoom() - id.z)) / id.overscaling();
mat3 patternMatrixA;
matrix::identity(patternMatrixA);
@@ -99,13 +99,11 @@ void Painter::renderFill(FillBucket& bucket, const FillLayer& layer, const TileI
(int)((*posB).size[1] * properties.pattern.value.toScale)
}};
- int tileSize = 512;
+ float offsetAx = (std::fmod(util::tileSize, imageSizeScaledA[0]) * id.x) / (float)imageSizeScaledA[0];
+ float offsetAy = (std::fmod(util::tileSize, imageSizeScaledA[1]) * id.y) / (float)imageSizeScaledA[1];
- float offsetAx = ((tileSize % imageSizeScaledA[0]) * id.x) / (float)imageSizeScaledA[0];
- float offsetAy = ((tileSize % imageSizeScaledA[1]) * id.y) / (float)imageSizeScaledA[1];
-
- float offsetBx = ((tileSize % imageSizeScaledB[0]) * id.x) / (float)imageSizeScaledB[0];
- float offsetBy = ((tileSize % imageSizeScaledB[1]) * id.y) / (float)imageSizeScaledB[1];
+ float offsetBx = (std::fmod(util::tileSize, imageSizeScaledB[0]) * id.x) / (float)imageSizeScaledB[0];
+ float offsetBy = (std::fmod(util::tileSize, imageSizeScaledB[1]) * id.y) / (float)imageSizeScaledB[1];
patternShader->u_offset_a = std::array<float, 2>{{offsetAx, offsetAy}};
patternShader->u_offset_b = std::array<float, 2>{{offsetBx, offsetBy}};
diff --git a/src/mbgl/renderer/painter_line.cpp b/src/mbgl/renderer/painter_line.cpp
index 5fc5ee0221..dfa19c43b0 100644
--- a/src/mbgl/renderer/painter_line.cpp
+++ b/src/mbgl/renderer/painter_line.cpp
@@ -51,7 +51,7 @@ void Painter::renderLine(LineBucket& bucket, const LineLayer& layer, const TileI
color[2] *= properties.opacity;
color[3] *= properties.opacity;
- float ratio = state.getScale() / std::pow(2, id.z) / (util::EXTENT / (512.0 * id.overscaling));
+ float ratio = state.getScale() / std::pow(2, id.z) / (util::EXTENT / (util::tileSize * id.overscaling()));
mat2 antialiasingMatrix;
matrix::identity(antialiasingMatrix);
@@ -85,7 +85,7 @@ void Painter::renderLine(LineBucket& bucket, const LineLayer& layer, const TileI
const float widthA = posA.width * properties.dasharray.value.fromScale;
const float widthB = posB.width * properties.dasharray.value.toScale;
- float patternratio = std::pow(2.0, std::floor(::log2(state.getScale())) - id.z) / (util::EXTENT / util::tileSize) * id.overscaling;
+ float patternratio = std::pow(2.0, std::floor(::log2(state.getScale())) - id.z) / (util::EXTENT / util::tileSize) * id.overscaling();
float scaleXA = patternratio / widthA / properties.dashLineWidth;
float scaleYA = -posA.height / 2.0;
float scaleXB = patternratio / widthB / properties.dashLineWidth;
@@ -111,7 +111,7 @@ void Painter::renderLine(LineBucket& bucket, const LineLayer& layer, const TileI
if (!imagePosA || !imagePosB)
return;
- float factor = util::EXTENT / (512 * id.overscaling) / std::pow(2, state.getIntegerZoom() - id.z);
+ float factor = util::EXTENT / (util::tileSize * id.overscaling()) / std::pow(2, state.getIntegerZoom() - id.z);
config.program = linepatternShader->getID();
diff --git a/src/mbgl/renderer/painter_raster.cpp b/src/mbgl/renderer/painter_raster.cpp
index 377b2c005c..827229d3a5 100644
--- a/src/mbgl/renderer/painter_raster.cpp
+++ b/src/mbgl/renderer/painter_raster.cpp
@@ -49,7 +49,7 @@ float Painter::contrastFactor(float contrast) {
}
std::array<float, 3> Painter::spinWeights(float spin) {
- spin *= M_PI / 180;
+ spin *= util::DEG2RAD;
float s = std::sin(spin);
float c = std::cos(spin);
std::array<float, 3> spin_weights = {{
diff --git a/src/mbgl/renderer/painter_symbol.cpp b/src/mbgl/renderer/painter_symbol.cpp
index 5f59d6a8a6..a460af400b 100644
--- a/src/mbgl/renderer/painter_symbol.cpp
+++ b/src/mbgl/renderer/painter_symbol.cpp
@@ -34,7 +34,7 @@ void Painter::renderSDF(SymbolBucket &bucket,
if (skewed) {
matrix::identity(exMatrix);
- s = util::EXTENT / util::tileSize / id.overscaling / std::pow(2, state.getZoom() - id.z);
+ s = util::EXTENT / util::tileSize / id.overscaling() / std::pow(2, state.getZoom() - id.z);
gammaScale = 1.0f / std::cos(state.getPitch());
} else {
exMatrix = extrudeMatrix;
@@ -195,7 +195,7 @@ void Painter::renderSymbol(SymbolBucket& bucket, const SymbolLayer& layer, const
if (skewed) {
matrix::identity(exMatrix);
- s = util::EXTENT / util::tileSize / id.overscaling / std::pow(2, state.getZoom() - id.z);
+ s = util::EXTENT / util::tileSize / id.overscaling() / std::pow(2, state.getZoom() - id.z);
} else {
exMatrix = extrudeMatrix;
matrix::rotate_z(exMatrix, exMatrix, state.getNorthOrientationAngle());
diff --git a/src/mbgl/renderer/symbol_bucket.cpp b/src/mbgl/renderer/symbol_bucket.cpp
index 683a6f4b11..ca6f455de6 100644
--- a/src/mbgl/renderer/symbol_bucket.cpp
+++ b/src/mbgl/renderer/symbol_bucket.cpp
@@ -29,7 +29,7 @@
namespace mbgl {
-SymbolInstance::SymbolInstance(Anchor& anchor, const std::vector<Coordinate>& line,
+SymbolInstance::SymbolInstance(Anchor& anchor, const GeometryCoordinates& line,
const Shaping& shapedText, const PositionedIcon& shapedIcon,
const SymbolLayoutProperties& layout, const bool addToBuffers, const uint32_t index_,
const float textBoxScale, const float textPadding, const float textAlongLine,
@@ -57,8 +57,11 @@ SymbolInstance::SymbolInstance(Anchor& anchor, const std::vector<Coordinate>& li
SymbolBucket::SymbolBucket(float overscaling_, float zoom_, const MapMode mode_)
- : overscaling(overscaling_), zoom(zoom_), tileSize(512 * overscaling_), tilePixelRatio(util::EXTENT / tileSize), mode(mode_) {
-}
+ : overscaling(overscaling_),
+ zoom(zoom_),
+ tileSize(util::tileSize * overscaling_),
+ tilePixelRatio(util::EXTENT / tileSize),
+ mode(mode_) {}
SymbolBucket::~SymbolBucket() {
// Do not remove. header file only contains forward definitions to unique pointers.
@@ -271,7 +274,7 @@ void SymbolBucket::addFeatures(uintptr_t tileUID,
}
-void SymbolBucket::addFeature(const std::vector<std::vector<Coordinate>> &lines,
+void SymbolBucket::addFeature(const GeometryCollection &lines,
const Shaping &shapedText, const PositionedIcon &shapedIcon, const GlyphPositions &face) {
const float minScale = 0.5f;
@@ -285,7 +288,7 @@ void SymbolBucket::addFeature(const std::vector<std::vector<Coordinate>> &lines,
const bool avoidEdges = layout.avoidEdges && layout.placement != PlacementType::Line;
const float textPadding = layout.text.padding * tilePixelRatio;
const float iconPadding = layout.icon.padding * tilePixelRatio;
- const float textMaxAngle = layout.text.maxAngle * M_PI / 180;
+ const float textMaxAngle = layout.text.maxAngle * util::DEG2RAD;
const bool textAlongLine =
layout.text.rotationAlignment == RotationAlignmentType::Map &&
layout.placement == PlacementType::Line;
diff --git a/src/mbgl/renderer/symbol_bucket.hpp b/src/mbgl/renderer/symbol_bucket.hpp
index cebb7e5dbe..0b1e4e5cf3 100644
--- a/src/mbgl/renderer/symbol_bucket.hpp
+++ b/src/mbgl/renderer/symbol_bucket.hpp
@@ -35,7 +35,7 @@ class GlyphStore;
class SymbolFeature {
public:
- std::vector<std::vector<Coordinate>> geometry;
+ GeometryCollection geometry;
std::u32string label;
std::string sprite;
};
@@ -44,7 +44,7 @@ struct Anchor;
class SymbolInstance {
public:
- explicit SymbolInstance(Anchor& anchor, const std::vector<Coordinate>& line,
+ explicit SymbolInstance(Anchor& anchor, const GeometryCoordinates& line,
const Shaping& shapedText, const PositionedIcon& shapedIcon,
const SymbolLayoutProperties& layout, const bool inside, const uint32_t index,
const float textBoxScale, const float textPadding, const float textAlongLine,
@@ -93,7 +93,7 @@ public:
void placeFeatures(CollisionTile&) override;
private:
- void addFeature(const std::vector<std::vector<Coordinate>> &lines,
+ void addFeature(const GeometryCollection &lines,
const Shaping &shapedText, const PositionedIcon &shapedIcon,
const GlyphPositions &face);
bool anchorIsTooClose(const std::u32string &text, const float repeatDistance, Anchor &anchor);
diff --git a/src/mbgl/source/source.cpp b/src/mbgl/source/source.cpp
index 8947e4f988..967a829ee9 100644
--- a/src/mbgl/source/source.cpp
+++ b/src/mbgl/source/source.cpp
@@ -160,7 +160,7 @@ void Source::load(FileSource& fileSource) {
void Source::updateMatrices(const mat4 &projMatrix, const TransformState &transform) {
for (const auto& pair : tiles) {
Tile &tile = *pair.second;
- transform.matrixFor(tile.matrix, tile.id, std::min(static_cast<int8_t>(info->maxZoom), tile.id.z));
+ transform.matrixFor(tile.matrix, tile.id, std::min(static_cast<uint8_t>(info->maxZoom), tile.id.z));
matrix::multiply(tile.matrix, projMatrix, tile.matrix);
}
}
diff --git a/src/mbgl/source/source_info.hpp b/src/mbgl/source/source_info.hpp
index 2fb5c2466d..ceae8ef8a3 100644
--- a/src/mbgl/source/source_info.hpp
+++ b/src/mbgl/source/source_info.hpp
@@ -3,6 +3,7 @@
#include <mbgl/style/types.hpp>
#include <mbgl/util/constants.hpp>
+#include <mbgl/util/geo.hpp>
#include <array>
#include <vector>
@@ -16,11 +17,12 @@ class TileID;
class SourceInfo {
public:
std::vector<std::string> tiles;
- uint16_t minZoom = 0;
- uint16_t maxZoom = 22;
+ uint8_t minZoom = 0;
+ uint8_t maxZoom = 22;
std::string attribution;
- std::array<float, 3> center = { { 0, 0, 0 } };
- std::array<float, 4> bounds = { { -180, -90, 180, 90 } };
+ LatLng center;
+ double zoom = 0;
+ LatLngBounds bounds = LatLngBounds::world();
};
} // namespace mbgl
diff --git a/src/mbgl/style/style.cpp b/src/mbgl/style/style.cpp
index e5ba08e57f..fcdddb6415 100644
--- a/src/mbgl/style/style.cpp
+++ b/src/mbgl/style/style.cpp
@@ -176,6 +176,7 @@ void Style::recalculate(float z) {
zoomHistory,
data.getDefaultFadeDuration());
+ hasPendingTransitions = false;
for (const auto& layer : layers) {
hasPendingTransitions |= layer->recalculate(parameters);
diff --git a/src/mbgl/style/style_parser.cpp b/src/mbgl/style/style_parser.cpp
index 7c2a94b206..ca0fe94056 100644
--- a/src/mbgl/style/style_parser.cpp
+++ b/src/mbgl/style/style_parser.cpp
@@ -59,7 +59,7 @@ void parseTileJSONMember(const JSValue& value, std::string& target, const char*
target = { property.GetString(), property.GetStringLength() };
}
-void parseTileJSONMember(const JSValue& value, uint16_t& target, const char* name) {
+void parseTileJSONMember(const JSValue& value, uint8_t& target, const char* name) {
if (!value.HasMember(name)) {
return;
}
@@ -70,21 +70,20 @@ void parseTileJSONMember(const JSValue& value, uint16_t& target, const char* nam
}
unsigned int uint = property.GetUint();
- if (uint > std::numeric_limits<uint16_t>::max()) {
+ if (uint > std::numeric_limits<uint8_t>::max()) {
return;
}
target = uint;
}
-template <size_t N>
-void parseTileJSONMember(const JSValue& value, std::array<float, N>& target, const char* name) {
+void parseTileJSONMember(const JSValue& value, std::array<double, 4>& target, const char* name) {
if (!value.HasMember(name)) {
return;
}
const JSValue& property = value[name];
- if (!property.IsArray() || property.Size() != N) {
+ if (!property.IsArray() || property.Size() > 4) {
return;
}
@@ -284,8 +283,14 @@ std::unique_ptr<SourceInfo> StyleParser::parseTileJSON(const JSValue& value) {
parseTileJSONMember(value, info->minZoom, "minzoom");
parseTileJSONMember(value, info->maxZoom, "maxzoom");
parseTileJSONMember(value, info->attribution, "attribution");
- parseTileJSONMember(value, info->center, "center");
- parseTileJSONMember(value, info->bounds, "bounds");
+
+ std::array<double, 4> array;
+ parseTileJSONMember(value, array, "center");
+ info->center = { array[0], array[1] };
+ info->zoom = array[2];
+ parseTileJSONMember(value, array, "bounds");
+ info->bounds = LatLngBounds::hull({ array[0], array[1] }, { array[2], array[3] });
+
return info;
}
diff --git a/src/mbgl/text/check_max_angle.cpp b/src/mbgl/text/check_max_angle.cpp
index bb32e4235e..4777f66a23 100644
--- a/src/mbgl/text/check_max_angle.cpp
+++ b/src/mbgl/text/check_max_angle.cpp
@@ -1,4 +1,7 @@
#include <mbgl/text/check_max_angle.hpp>
+#include <mbgl/geometry/anchor.hpp>
+#include <mbgl/util/math.hpp>
+
#include <queue>
namespace mbgl{
@@ -10,14 +13,14 @@ struct Corner {
float angleDelta;
};
-bool checkMaxAngle(const std::vector<Coordinate> &line, Anchor &anchor, const float labelLength,
+bool checkMaxAngle(const GeometryCoordinates &line, Anchor &anchor, const float labelLength,
const float windowSize, const float maxAngle) {
// horizontal labels always pass
if (anchor.segment < 0) return true;
- Coordinate anchorPoint = Coordinate{ (int16_t)anchor.x, (int16_t)anchor.y };
- Coordinate &p = anchorPoint;
+ GeometryCoordinate anchorPoint = { (int16_t)anchor.x, (int16_t)anchor.y };
+ GeometryCoordinate &p = anchorPoint;
int index = anchor.segment + 1;
float anchorDistance = 0;
diff --git a/src/mbgl/text/check_max_angle.hpp b/src/mbgl/text/check_max_angle.hpp
index 1354abe95e..0fb8a715a9 100644
--- a/src/mbgl/text/check_max_angle.hpp
+++ b/src/mbgl/text/check_max_angle.hpp
@@ -1,12 +1,13 @@
#ifndef MBGL_TEXT_CHECK_MAX_ANGLE
#define MBGL_TEXT_CHECK_MAX_ANGLE
-#include <mbgl/geometry/anchor.hpp>
-#include <mbgl/util/math.hpp>
+#include <mbgl/tile/geometry_tile.hpp>
namespace mbgl {
-bool checkMaxAngle(const std::vector<Coordinate> &line, Anchor &anchor, const float labelLength,
+struct Anchor;
+
+bool checkMaxAngle(const GeometryCoordinates &line, Anchor &anchor, const float labelLength,
const float windowSize, const float maxAngle);
} // namespace mbgl
diff --git a/src/mbgl/text/collision_feature.cpp b/src/mbgl/text/collision_feature.cpp
index 186fb39b5d..42f1119b33 100644
--- a/src/mbgl/text/collision_feature.cpp
+++ b/src/mbgl/text/collision_feature.cpp
@@ -3,7 +3,7 @@
namespace mbgl {
-CollisionFeature::CollisionFeature(const std::vector<Coordinate> &line, const Anchor &anchor,
+CollisionFeature::CollisionFeature(const GeometryCoordinates &line, const Anchor &anchor,
const float top, const float bottom, const float left, const float right,
const float boxScale, const float padding, const bool alongLine, const bool straight) {
@@ -22,12 +22,12 @@ CollisionFeature::CollisionFeature(const std::vector<Coordinate> &line, const An
height = std::max(10.0f * boxScale, height);
- Coordinate anchorPoint(int16_t(anchor.x), int16_t(anchor.y));
+ GeometryCoordinate anchorPoint(int16_t(anchor.x), int16_t(anchor.y));
if (straight) {
// used for icon labels that are aligned with the line, but don't curve along it
const vec2<double> vector = util::unit(vec2<double>(line[anchor.segment + 1] - line[anchor.segment])) * length;
- const std::vector<Coordinate> newLine({ anchorPoint - vector, anchorPoint + vector });
+ const GeometryCoordinates newLine({ anchorPoint - vector, anchorPoint + vector });
bboxifyLabel(newLine, anchorPoint, 0, length, height);
} else {
// used for text labels that curve along a line
@@ -38,8 +38,8 @@ CollisionFeature::CollisionFeature(const std::vector<Coordinate> &line, const An
}
}
-void CollisionFeature::bboxifyLabel(const std::vector<Coordinate> &line,
- Coordinate &anchorPoint, const int segment, const float labelLength, const float boxSize) {
+void CollisionFeature::bboxifyLabel(const GeometryCoordinates &line,
+ GeometryCoordinate &anchorPoint, const int segment, const float labelLength, const float boxSize) {
const float step = boxSize / 2;
const unsigned int nBoxes = std::floor(labelLength / step);
@@ -48,7 +48,7 @@ void CollisionFeature::bboxifyLabel(const std::vector<Coordinate> &line,
// box is at the edge of the label.
const float firstBoxOffset = -boxSize / 2;
- Coordinate &p = anchorPoint;
+ GeometryCoordinate &p = anchorPoint;
int index = segment + 1;
float anchorDistance = firstBoxOffset;
diff --git a/src/mbgl/text/collision_feature.hpp b/src/mbgl/text/collision_feature.hpp
index a9d227de1b..fcfb8e9ae9 100644
--- a/src/mbgl/text/collision_feature.hpp
+++ b/src/mbgl/text/collision_feature.hpp
@@ -4,6 +4,8 @@
#include <mbgl/util/vec.hpp>
#include <mbgl/geometry/anchor.hpp>
#include <mbgl/text/shaping.hpp>
+#include <mbgl/tile/geometry_tile.hpp>
+
#include <vector>
namespace mbgl {
@@ -32,7 +34,7 @@ namespace mbgl {
class CollisionFeature {
public:
// for text
- inline explicit CollisionFeature(const std::vector<Coordinate> &line, const Anchor &anchor,
+ inline explicit CollisionFeature(const GeometryCoordinates &line, const Anchor &anchor,
const Shaping &shapedText,
const float boxScale, const float padding, const bool alongLine)
: CollisionFeature(line, anchor,
@@ -40,14 +42,14 @@ namespace mbgl {
boxScale, padding, alongLine, false) {}
// for icons
- inline explicit CollisionFeature(const std::vector<Coordinate> &line, const Anchor &anchor,
+ inline explicit CollisionFeature(const GeometryCoordinates &line, const Anchor &anchor,
const PositionedIcon &shapedIcon,
const float boxScale, const float padding, const bool alongLine)
: CollisionFeature(line, anchor,
shapedIcon.top, shapedIcon.bottom, shapedIcon.left, shapedIcon.right,
boxScale, padding, alongLine, true) {}
- explicit CollisionFeature(const std::vector<Coordinate> &line, const Anchor &anchor,
+ explicit CollisionFeature(const GeometryCoordinates &line, const Anchor &anchor,
const float top, const float bottom, const float left, const float right,
const float boxScale, const float padding, const bool alongLine, const bool straight);
@@ -55,7 +57,7 @@ namespace mbgl {
std::vector<CollisionBox> boxes;
private:
- void bboxifyLabel(const std::vector<Coordinate> &line, Coordinate &anchorPoint, const int segment, const float length, const float height);
+ void bboxifyLabel(const GeometryCoordinates &line, GeometryCoordinate &anchorPoint, const int segment, const float length, const float height);
};
} // namespace mbgl
diff --git a/src/mbgl/text/get_anchors.cpp b/src/mbgl/text/get_anchors.cpp
index 7a129d692c..740ec288b3 100644
--- a/src/mbgl/text/get_anchors.cpp
+++ b/src/mbgl/text/get_anchors.cpp
@@ -7,7 +7,7 @@
namespace mbgl {
-Anchors resample(const std::vector<Coordinate> &line, const float offset, const float spacing,
+Anchors resample(const GeometryCoordinates &line, const float offset, const float spacing,
const float angleWindowSize, const float maxAngle, const float labelLength, const bool continuedLine, const bool placeAtMiddle) {
const float halfLabelLength = labelLength / 2.0f;
@@ -23,8 +23,8 @@ Anchors resample(const std::vector<Coordinate> &line, const float offset, const
int i = 0;
for (auto it = line.begin(), end = line.end() - 1; it != end; it++, i++) {
- const Coordinate &a = *(it);
- const Coordinate &b = *(it + 1);
+ const GeometryCoordinate &a = *(it);
+ const GeometryCoordinate &b = *(it + 1);
const float segmentDist = util::dist<float>(a, b);
const float angle = util::angle_to(b, a);
@@ -65,7 +65,7 @@ Anchors resample(const std::vector<Coordinate> &line, const float offset, const
return anchors;
}
-Anchors getAnchors(const std::vector<Coordinate> &line, float spacing,
+Anchors getAnchors(const GeometryCoordinates &line, float spacing,
const float maxAngle, const float textLeft, const float textRight,
const float iconLeft, const float iconRight,
const float glyphSize, const float boxScale, const float overscaling) {
diff --git a/src/mbgl/text/get_anchors.hpp b/src/mbgl/text/get_anchors.hpp
index fcb0578d5b..1f76685f9a 100644
--- a/src/mbgl/text/get_anchors.hpp
+++ b/src/mbgl/text/get_anchors.hpp
@@ -2,11 +2,12 @@
#define MBGL_TEXT_GETANCHORS
#include <mbgl/geometry/anchor.hpp>
+#include <mbgl/tile/geometry_tile.hpp>
#include <mbgl/util/math.hpp>
namespace mbgl {
-Anchors getAnchors(const std::vector<Coordinate> &line, float spacing,
+Anchors getAnchors(const GeometryCoordinates &line, float spacing,
const float maxAngle, const float textLeft, const float textRight,
const float iconLeft, const float iconRight,
const float glyphSize, const float boxScale, const float overscaling);
diff --git a/src/mbgl/text/quads.cpp b/src/mbgl/text/quads.cpp
index 92866566d8..2117538232 100644
--- a/src/mbgl/text/quads.cpp
+++ b/src/mbgl/text/quads.cpp
@@ -1,8 +1,10 @@
#include <mbgl/text/quads.hpp>
#include <mbgl/text/shaping.hpp>
+#include <mbgl/tile/geometry_tile.hpp>
#include <mbgl/geometry/anchor.hpp>
#include <mbgl/layer/symbol_layer.hpp>
#include <mbgl/util/math.hpp>
+#include <mbgl/util/constants.hpp>
#include <cassert>
namespace mbgl {
@@ -10,7 +12,7 @@ namespace mbgl {
const float globalMinScale = 0.5f; // underscale by 1 zoom level
SymbolQuads getIconQuads(Anchor& anchor, const PositionedIcon& shapedIcon,
- const std::vector<Coordinate>& line, const SymbolLayoutProperties& layout,
+ const GeometryCoordinates& line, const SymbolLayoutProperties& layout,
const bool alongLine) {
auto image = *(shapedIcon.image);
@@ -26,13 +28,13 @@ SymbolQuads getIconQuads(Anchor& anchor, const PositionedIcon& shapedIcon,
vec2<float> bl{left, bottom};
- float angle = layout.icon.rotate * M_PI / 180.0f;
+ float angle = layout.icon.rotate * util::DEG2RAD;
if (alongLine) {
assert(static_cast<unsigned int>(anchor.segment) < line.size());
- const Coordinate &prev= line[anchor.segment];
+ const GeometryCoordinate &prev= line[anchor.segment];
if (anchor.y == prev.y && anchor.x == prev.x &&
static_cast<unsigned int>(anchor.segment + 1) < line.size()) {
- const Coordinate &next= line[anchor.segment + 1];
+ const GeometryCoordinate &next= line[anchor.segment + 1];
angle += std::atan2(anchor.y - next.y, anchor.x - next.x) + M_PI;
} else {
angle += std::atan2(anchor.y - prev.y, anchor.x - prev.x);
@@ -73,7 +75,7 @@ struct GlyphInstance {
typedef std::vector<GlyphInstance> GlyphInstances;
void getSegmentGlyphs(std::back_insert_iterator<GlyphInstances> glyphs, Anchor &anchor,
- float offset, const std::vector<Coordinate> &line, int segment, bool forward) {
+ float offset, const GeometryCoordinates &line, int segment, bool forward) {
const bool upsideDown = !forward;
@@ -131,10 +133,10 @@ void getSegmentGlyphs(std::back_insert_iterator<GlyphInstances> glyphs, Anchor &
}
SymbolQuads getGlyphQuads(Anchor& anchor, const Shaping& shapedText,
- const float boxScale, const std::vector<Coordinate>& line, const SymbolLayoutProperties& layout,
+ const float boxScale, const GeometryCoordinates& line, const SymbolLayoutProperties& layout,
const bool alongLine, const GlyphPositions& face) {
- const float textRotate = layout.text.rotate * M_PI / 180;
+ const float textRotate = layout.text.rotate * util::DEG2RAD;
const bool keepUpright = layout.text.keepUpright;
SymbolQuads quads;
diff --git a/src/mbgl/text/quads.hpp b/src/mbgl/text/quads.hpp
index cdf7c23627..12b8893503 100644
--- a/src/mbgl/text/quads.hpp
+++ b/src/mbgl/text/quads.hpp
@@ -2,6 +2,7 @@
#define MBGL_TEXT_QUADS
#include <mbgl/text/glyph.hpp>
+#include <mbgl/tile/geometry_tile.hpp>
#include <mbgl/util/vec.hpp>
#include <vector>
@@ -37,11 +38,11 @@ namespace mbgl {
class PositionedIcon;
SymbolQuads getIconQuads(Anchor& anchor, const PositionedIcon& shapedIcon,
- const std::vector<Coordinate>& line, const SymbolLayoutProperties& layout,
+ const GeometryCoordinates& line, const SymbolLayoutProperties& layout,
const bool alongLine);
SymbolQuads getGlyphQuads(Anchor& anchor, const Shaping& shapedText,
- const float boxScale, const std::vector<Coordinate>& line, const SymbolLayoutProperties& layout,
+ const float boxScale, const GeometryCoordinates& line, const SymbolLayoutProperties& layout,
const bool alongLine, const GlyphPositions& face);
} // namespace mbgl
diff --git a/src/mbgl/tile/geojson_tile.cpp b/src/mbgl/tile/geojson_tile.cpp
index d8eabf00a2..fceae19619 100644
--- a/src/mbgl/tile/geojson_tile.cpp
+++ b/src/mbgl/tile/geojson_tile.cpp
@@ -51,7 +51,7 @@ std::unique_ptr<GeoJSONTile> convertTile(const mapbox::geojsonvt::Tile& tile) {
if (tile) {
std::vector<std::shared_ptr<const GeoJSONTileFeature>> features;
- std::vector<Coordinate> line;
+ GeometryCoordinates line;
for (auto& feature : tile.features) {
const FeatureType featureType =
diff --git a/src/mbgl/tile/geojson_tile.hpp b/src/mbgl/tile/geojson_tile.hpp
index 6f3cbc10d1..ce9c643de2 100644
--- a/src/mbgl/tile/geojson_tile.hpp
+++ b/src/mbgl/tile/geojson_tile.hpp
@@ -25,7 +25,6 @@ public:
FeatureType getType() const override;
optional<Value> getValue(const std::string&) const override;
GeometryCollection getGeometries() const override;
- uint32_t getExtent() const override { return 4096; }
private:
const FeatureType type;
diff --git a/src/mbgl/tile/geometry_tile.hpp b/src/mbgl/tile/geometry_tile.hpp
index 5cb2f96fdc..6236e4e889 100644
--- a/src/mbgl/tile/geometry_tile.hpp
+++ b/src/mbgl/tile/geometry_tile.hpp
@@ -24,15 +24,22 @@ enum class FeatureType : uint8_t {
Polygon = 3
};
-typedef std::vector<std::vector<Coordinate>> GeometryCollection;
+// Normalized vector tile coordinates.
+// Each geometry coordinate represents a point in a bidimensional space,
+// varying from -V...0...+V, where V is the maximum extent applicable.
+using GeometryCoordinate = vec2<int16_t>;
+using GeometryCoordinates = std::vector<GeometryCoordinate>;
+using GeometryCollection = std::vector<GeometryCoordinates>;
class GeometryTileFeature : private util::noncopyable {
public:
+ static const uint32_t defaultExtent = 4096;
+
virtual ~GeometryTileFeature() = default;
virtual FeatureType getType() const = 0;
virtual optional<Value> getValue(const std::string& key) const = 0;
virtual GeometryCollection getGeometries() const = 0;
- virtual uint32_t getExtent() const = 0;
+ virtual uint32_t getExtent() const { return defaultExtent; }
};
class GeometryTileLayer : private util::noncopyable {
diff --git a/src/mbgl/tile/vector_tile.cpp b/src/mbgl/tile/vector_tile.cpp
index 9e35debbff..8b58ade169 100644
--- a/src/mbgl/tile/vector_tile.cpp
+++ b/src/mbgl/tile/vector_tile.cpp
@@ -94,7 +94,7 @@ GeometryCollection VectorTileFeature::getGeometries() const {
GeometryCollection lines;
lines.emplace_back();
- std::vector<Coordinate>* line = &lines.back();
+ GeometryCoordinates* line = &lines.back();
while (data.data < data.end) {
if (length == 0) {
diff --git a/src/mbgl/util/clip_lines.cpp b/src/mbgl/util/clip_lines.cpp
index 071e9d09bd..41965876cb 100644
--- a/src/mbgl/util/clip_lines.cpp
+++ b/src/mbgl/util/clip_lines.cpp
@@ -3,10 +3,10 @@
namespace mbgl {
namespace util {
-std::vector<std::vector<Coordinate>> clipLines(const std::vector<std::vector<Coordinate>> &lines,
+GeometryCollection clipLines(const GeometryCollection &lines,
const int16_t x1, const int16_t y1, const int16_t x2, const int16_t y2) {
- std::vector<std::vector<Coordinate>> clippedLines;
+ GeometryCollection clippedLines;
for (auto& line : lines) {
@@ -15,8 +15,8 @@ std::vector<std::vector<Coordinate>> clipLines(const std::vector<std::vector<Coo
auto end = line.end() - 1;
for (auto it = line.begin(); it != end; it++) {
- Coordinate p0 = *(it);
- Coordinate p1 = *(it + 1);
+ GeometryCoordinate p0 = *(it);
+ GeometryCoordinate p1 = *(it + 1);
if (p0.x < x1 && p1.x < x1) {
continue;
diff --git a/src/mbgl/util/clip_lines.hpp b/src/mbgl/util/clip_lines.hpp
index 6e49b48085..a4a5c5fb8a 100644
--- a/src/mbgl/util/clip_lines.hpp
+++ b/src/mbgl/util/clip_lines.hpp
@@ -10,7 +10,7 @@ namespace mbgl {
namespace util {
-std::vector<std::vector<Coordinate>> clipLines(const std::vector<std::vector<Coordinate>> &lines,
+GeometryCollection clipLines(const GeometryCollection &lines,
const int16_t x1, const int16_t y1, const int16_t x2, const int16_t y2);
} // end namespace util
diff --git a/src/mbgl/util/constants.cpp b/src/mbgl/util/constants.cpp
index 85f9856a3a..7ff00800ae 100644
--- a/src/mbgl/util/constants.cpp
+++ b/src/mbgl/util/constants.cpp
@@ -24,7 +24,9 @@ const double DEG2RAD = M_PI / 180.0;
const double RAD2DEG = 180.0 / M_PI;
const double M2PI = 2 * M_PI;
const double EARTH_RADIUS_M = 6378137;
-const double LATITUDE_MAX = 85.05112878;
+const double LATITUDE_MAX = 85.051128779806604;
+const double LONGITUDE_MAX = 180;
+const double DEGREES_MAX = 360;
const double PITCH_MAX = M_PI / 3;
const double MIN_ZOOM = 0.0;
const double MAX_ZOOM = 25.5;
diff --git a/src/mbgl/util/geo.cpp b/src/mbgl/util/geo.cpp
index 25e795e4ef..bf7cf38117 100644
--- a/src/mbgl/util/geo.cpp
+++ b/src/mbgl/util/geo.cpp
@@ -7,18 +7,18 @@
namespace mbgl {
LatLng::LatLng(const TileID& id) {
- longitude = id.x / std::pow(2.0, id.z) * 360.0 - 180;
+ longitude = id.x / std::pow(2.0, id.z) * util::DEGREES_MAX - util::LONGITUDE_MAX;
const double n = M_PI - 2.0 * M_PI * id.y / std::pow(2.0, id.z);
- latitude = 180.0 / M_PI * std::atan(0.5 * (std::exp(n) - std::exp(-n)));
+ latitude = util::RAD2DEG * std::atan(0.5 * (std::exp(n) - std::exp(-n)));
}
-PrecisionPoint LatLng::project() const {
+ScreenCoordinate LatLng::project() const {
// Clamp to the latitude limits of Mercator.
const double constrainedLatitude = ::fmin(::fmax(latitude, -util::LATITUDE_MAX), util::LATITUDE_MAX);
// Project a coordinate into unit space in a square map.
- const double sine = std::sin(constrainedLatitude * M_PI / 180.0);
- const double x = longitude / 360.0 + 0.5;
+ const double sine = std::sin(constrainedLatitude * util::DEG2RAD);
+ const double x = longitude / util::DEGREES_MAX + 0.5;
const double y = 0.5 - 0.25 * std::log((1.0 + sine) / (1.0 - sine)) / M_PI;
return { x, y };
}
@@ -28,7 +28,7 @@ LatLngBounds::LatLngBounds(const TileID& id)
ne(TileID{ id.z, id.x + 1, id.y, id.sourceZ }) {
}
-PrecisionPoint EdgeInsets::getCenter(uint16_t width, uint16_t height) const {
+ScreenCoordinate EdgeInsets::getCenter(uint16_t width, uint16_t height) const {
return {
(width - left - right) / 2.0f + left,
(height - top - bottom) / 2.0f + top,
diff --git a/src/mbgl/util/mapbox.cpp b/src/mbgl/util/mapbox.cpp
index a3d886f673..170b05ee68 100644
--- a/src/mbgl/util/mapbox.cpp
+++ b/src/mbgl/util/mapbox.cpp
@@ -1,4 +1,5 @@
#include <mbgl/util/mapbox.hpp>
+#include <mbgl/util/constants.hpp>
#include <mbgl/platform/log.hpp>
#include <stdexcept>
@@ -162,7 +163,7 @@ std::string canonicalizeTileURL(const std::string& url, SourceType type, uint16_
std::string result = "mapbox://tiles/" + tileset + "/{z}/{x}/{y}";
if (type == SourceType::Raster) {
- result += tileSize == 512 ? "@2x" : "{ratio}";
+ result += tileSize == util::tileSize ? "@2x" : "{ratio}";
}
result += "." + extension;
diff --git a/src/mbgl/util/mat4.cpp b/src/mbgl/util/mat4.cpp
index 5f6f9d1b4c..bf8252595d 100644
--- a/src/mbgl/util/mat4.cpp
+++ b/src/mbgl/util/mat4.cpp
@@ -21,12 +21,15 @@
// 3. This notice may not be removed or altered from any source distribution.
#include <mbgl/util/mat4.hpp>
+#include <mbgl/util/vec.hpp>
#include <cmath>
-using namespace mbgl;
+namespace mbgl {
-void matrix::identity(mat4& out) {
+namespace matrix {
+
+void identity(mat4& out) {
out[0] = 1.0f;
out[1] = 0.0f;
out[2] = 0.0f;
@@ -45,7 +48,7 @@ void matrix::identity(mat4& out) {
out[15] = 1.0f;
}
-bool matrix::invert(mat4& out, mat4& a) {
+bool invert(mat4& out, mat4& a) {
double a00 = a[0], a01 = a[1], a02 = a[2], a03 = a[3],
a10 = a[4], a11 = a[5], a12 = a[6], a13 = a[7],
a20 = a[8], a21 = a[9], a22 = a[10], a23 = a[11],
@@ -92,7 +95,7 @@ bool matrix::invert(mat4& out, mat4& a) {
return false;
}
-void matrix::ortho(mat4& out, double left, double right, double bottom, double top, double near, double far) {
+void ortho(mat4& out, double left, double right, double bottom, double top, double near, double far) {
double lr = 1.0f / (left - right),
bt = 1.0f / (bottom - top),
nf = 1.0f / (near - far);
@@ -114,7 +117,7 @@ void matrix::ortho(mat4& out, double left, double right, double bottom, double t
out[15] = 1.0f;
}
-void matrix::perspective(mat4& out, double fovy, double aspect, double near, double far) {
+void perspective(mat4& out, double fovy, double aspect, double near, double far) {
double f = 1.0f / std::tan(fovy / 2.0f),
nf = 1.0f / (near - far);
out[0] = f / aspect;
@@ -135,7 +138,7 @@ void matrix::perspective(mat4& out, double fovy, double aspect, double near, dou
out[15] = 0.0f;
}
-void matrix::copy(mat4& out, const mat4& a) {
+void copy(mat4& out, const mat4& a) {
out[0] = a[0];
out[1] = a[1];
out[2] = a[2];
@@ -154,7 +157,7 @@ void matrix::copy(mat4& out, const mat4& a) {
out[15] = a[15];
}
-void matrix::translate(mat4& out, const mat4& a, double x, double y, double z) {
+void translate(mat4& out, const mat4& a, double x, double y, double z) {
if (&a == &out) {
out[12] = a[0] * x + a[4] * y + a[8] * z + a[12];
out[13] = a[1] * x + a[5] * y + a[9] * z + a[13];
@@ -180,7 +183,7 @@ void matrix::translate(mat4& out, const mat4& a, double x, double y, double z) {
}
}
-void matrix::rotate_x(mat4& out, const mat4& a, double rad) {
+void rotate_x(mat4& out, const mat4& a, double rad) {
double s = std::sin(rad),
c = std::cos(rad),
a10 = a[4],
@@ -214,7 +217,7 @@ void matrix::rotate_x(mat4& out, const mat4& a, double rad) {
out[11] = a23 * c - a13 * s;
}
-void matrix::rotate_y(mat4& out, const mat4& a, double rad) {
+void rotate_y(mat4& out, const mat4& a, double rad) {
double s = std::sin(rad),
c = std::cos(rad),
a00 = a[0],
@@ -248,7 +251,7 @@ void matrix::rotate_y(mat4& out, const mat4& a, double rad) {
out[11] = a03 * s + a23 * c;
}
-void matrix::rotate_z(mat4& out, const mat4& a, double rad) {
+void rotate_z(mat4& out, const mat4& a, double rad) {
double s = std::sin(rad),
c = std::cos(rad),
a00 = a[0],
@@ -282,7 +285,7 @@ void matrix::rotate_z(mat4& out, const mat4& a, double rad) {
out[7] = a13 * c - a03 * s;
}
-void matrix::scale(mat4& out, const mat4& a, double x, double y, double z) {
+void scale(mat4& out, const mat4& a, double x, double y, double z) {
out[0] = a[0] * x;
out[1] = a[1] * x;
out[2] = a[2] * x;
@@ -301,7 +304,7 @@ void matrix::scale(mat4& out, const mat4& a, double x, double y, double z) {
out[15] = a[15];
}
-void matrix::multiply(mat4& out, const mat4& a, const mat4& b) {
+void multiply(mat4& out, const mat4& a, const mat4& b) {
double a00 = a[0], a01 = a[1], a02 = a[2], a03 = a[3],
a10 = a[4], a11 = a[5], a12 = a[6], a13 = a[7],
a20 = a[8], a21 = a[9], a22 = a[10], a23 = a[11],
@@ -332,3 +335,14 @@ void matrix::multiply(mat4& out, const mat4& a, const mat4& b) {
out[14] = b0 * a02 + b1 * a12 + b2 * a22 + b3 * a32;
out[15] = b0 * a03 + b1 * a13 + b2 * a23 + b3 * a33;
}
+
+void transformMat4(vec4<double>& out, vec4<double>& a, mat4& m) {
+ out.x = m[0] * a.x + m[4] * a.y + m[8] * a.z + m[12] * a.w;
+ out.y = m[1] * a.x + m[5] * a.y + m[9] * a.z + m[13] * a.w;
+ out.z = m[2] * a.x + m[6] * a.y + m[10] * a.z + m[14] * a.w;
+ out.w = m[3] * a.x + m[7] * a.y + m[11] * a.z + m[15] * a.w;
+}
+
+} // namespace matrix
+
+} // namespace mbgl
diff --git a/src/mbgl/util/merge_lines.cpp b/src/mbgl/util/merge_lines.cpp
index 4ff1caaf76..ee930c113e 100644
--- a/src/mbgl/util/merge_lines.cpp
+++ b/src/mbgl/util/merge_lines.cpp
@@ -11,7 +11,7 @@ unsigned int mergeFromRight(std::vector<SymbolFeature> &features,
Index &rightIndex,
Index::iterator left,
size_t rightKey,
- std::vector<std::vector<Coordinate>> &geom) {
+ GeometryCollection &geom) {
unsigned int index = left->second;
rightIndex.erase(left);
@@ -27,7 +27,7 @@ unsigned int mergeFromLeft(std::vector<SymbolFeature> &features,
Index &leftIndex,
size_t leftKey,
Index::iterator right,
- std::vector<std::vector<Coordinate>> &geom) {
+ GeometryCollection &geom) {
unsigned int index = right->second;
leftIndex.erase(right);
@@ -41,8 +41,8 @@ unsigned int mergeFromLeft(std::vector<SymbolFeature> &features,
}
size_t
-getKey(const std::u32string& text, const std::vector<std::vector<Coordinate>>& geom, bool onRight) {
- const Coordinate& coord = onRight ? geom[0].back() : geom[0].front();
+getKey(const std::u32string& text, const GeometryCollection& geom, bool onRight) {
+ const GeometryCoordinate& coord = onRight ? geom[0].back() : geom[0].front();
auto hash = std::hash<std::u32string>()(text);
boost::hash_combine(hash, coord.x);
@@ -57,7 +57,7 @@ void mergeLines(std::vector<SymbolFeature> &features) {
for (unsigned int k = 0; k < features.size(); k++) {
SymbolFeature &feature = features[k];
- std::vector<std::vector<Coordinate>> &geometry = feature.geometry;
+ GeometryCollection &geometry = feature.geometry;
if (!feature.label.length()) {
continue;
diff --git a/src/mbgl/util/merge_lines.hpp b/src/mbgl/util/merge_lines.hpp
index 4460a0bcea..55ad79036e 100644
--- a/src/mbgl/util/merge_lines.hpp
+++ b/src/mbgl/util/merge_lines.hpp
@@ -13,13 +13,13 @@ unsigned int mergeFromRight(std::vector<SymbolFeature> &features,
std::map<std::string, unsigned int> &rightIndex,
std::map<std::string, unsigned int>::iterator left,
std::string &rightKey,
- std::vector<std::vector<Coordinate>> &geom);
+ GeometryCollection &geom);
unsigned int mergeFromLeft(std::vector<SymbolFeature> &features,
std::map<std::string, unsigned int> &leftIndex,
std::string &leftKey,
std::map<std::string, unsigned int>::iterator right,
- std::vector<std::vector<Coordinate>> &geom);
+ GeometryCollection &geom);
void mergeLines(std::vector<SymbolFeature> &features);
diff --git a/src/mbgl/util/tile_coordinate.hpp b/src/mbgl/util/tile_coordinate.hpp
deleted file mode 100644
index a989bef0c9..0000000000
--- a/src/mbgl/util/tile_coordinate.hpp
+++ /dev/null
@@ -1,17 +0,0 @@
-#ifndef MBGL_UTIL_TILE_COORDINATE
-#define MBGL_UTIL_TILE_COORDINATE
-
-#include <mbgl/util/vec.hpp>
-
-namespace mbgl {
-
-class TileCoordinate {
-public:
- double column;
- double row;
- double zoom;
-};
-
-} // namespace mbgl
-
-#endif
diff --git a/src/mbgl/util/tile_cover.cpp b/src/mbgl/util/tile_cover.cpp
index e77ea469a7..0fae940271 100644
--- a/src/mbgl/util/tile_cover.cpp
+++ b/src/mbgl/util/tile_cover.cpp
@@ -1,21 +1,41 @@
#include <mbgl/util/tile_cover.hpp>
#include <mbgl/util/vec.hpp>
-#include <mbgl/util/tile_coordinate.hpp>
#include <mbgl/util/constants.hpp>
+#include <mbgl/util/interpolate.hpp>
#include <mbgl/map/transform_state.hpp>
namespace mbgl {
+namespace {
+
+// Has floating point x/y coordinates.
+// Used for computing the tiles that need to be visible in the viewport.
+class TileCoordinate {
+public:
+ double x, y;
+
+ static TileCoordinate fromLatLng(const TransformState& state, double zoom, const LatLng& latLng) {
+ const double scale = std::pow(2, zoom - state.getZoom());
+ return {
+ state.lngX(latLng.longitude) * scale / util::tileSize,
+ state.latY(latLng.latitude) * scale / util::tileSize,
+ };
+ }
+
+ static TileCoordinate fromScreenCoordinate(const TransformState& state, double zoom, const ScreenCoordinate& point) {
+ return fromLatLng(state, zoom, state.screenCoordinateToLatLng(point, LatLng::Unwrapped));
+ }
+};
+
// Taken from polymaps src/Layer.js
// https://github.com/simplegeo/polymaps/blob/master/src/Layer.js#L333-L383
-
struct edge {
double x0 = 0, y0 = 0;
double x1 = 0, y1 = 0;
double dx = 0, dy = 0;
- edge(vec2<double> a, vec2<double> b) {
- if (a.y > b.y) { std::swap(a, b); }
+ edge(TileCoordinate a, TileCoordinate b) {
+ if (a.y > b.y) std::swap(a, b);
x0 = a.x;
y0 = a.y;
x1 = b.x;
@@ -25,7 +45,7 @@ struct edge {
}
};
-typedef const std::function<void(int32_t x0, int32_t x1, int32_t y)> ScanLine;
+using ScanLine = const std::function<void(int32_t x0, int32_t x1, int32_t y)>;
// scan-line conversion
static void scanSpans(edge e0, edge e1, int32_t ymin, int32_t ymax, ScanLine scanLine) {
@@ -52,7 +72,7 @@ static void scanSpans(edge e0, edge e1, int32_t ymin, int32_t ymax, ScanLine sca
}
// scan-line conversion
-static void scanTriangle(const mbgl::vec2<double> a, const mbgl::vec2<double> b, const mbgl::vec2<double> c, int32_t ymin, int32_t ymax, ScanLine& scanLine) {
+static void scanTriangle(const TileCoordinate& a, const TileCoordinate& b, const TileCoordinate& c, int32_t ymin, int32_t ymax, ScanLine& scanLine) {
edge ab = edge(a, b);
edge bc = edge(b, c);
edge ca = edge(c, a);
@@ -67,6 +87,8 @@ static void scanTriangle(const mbgl::vec2<double> a, const mbgl::vec2<double> b,
if (bc.dy) scanSpans(ca, bc, ymin, ymax, scanLine);
}
+} // namespace
+
int32_t coveringZoomLevel(double zoom, SourceType type, uint16_t tileSize) {
zoom += std::log(util::tileSize / tileSize) / std::log(2);
if (type == SourceType::Raster || type == SourceType::Video) {
@@ -76,16 +98,11 @@ int32_t coveringZoomLevel(double zoom, SourceType type, uint16_t tileSize) {
}
}
-static mbgl::vec2<double> zoomTo(const TileCoordinate& c, double z) {
- double scale = std::pow(2, z - c.zoom);
- return { c.column * scale, c.row * scale };
-}
-
-std::vector<TileID> tileCover(const TileCoordinate& tl_,
- const TileCoordinate& tr_,
- const TileCoordinate& br_,
- const TileCoordinate& bl_,
- const TileCoordinate& center,
+std::vector<TileID> tileCover(const TileCoordinate& tl,
+ const TileCoordinate& tr,
+ const TileCoordinate& br,
+ const TileCoordinate& bl,
+ const TileCoordinate& c,
int32_t z,
int32_t actualZ) {
int32_t tiles = 1 << z;
@@ -94,18 +111,12 @@ std::vector<TileID> tileCover(const TileCoordinate& tl_,
auto scanLine = [&](int32_t x0, int32_t x1, int32_t y) {
int32_t x;
if (y >= 0 && y <= tiles) {
- for (x = x0; x < x1; x++) {
+ for (x = x0; x < x1; ++x) {
t.emplace_front(actualZ, x, y, z);
}
}
};
- mbgl::vec2<double> tl = zoomTo(tl_, z);
- mbgl::vec2<double> tr = zoomTo(tr_, z);
- mbgl::vec2<double> br = zoomTo(br_, z);
- mbgl::vec2<double> bl = zoomTo(bl_, z);
- mbgl::vec2<double> c = zoomTo(center, z);
-
// Divide the screen up in two triangles and scan each of them:
// \---+
// | \ |
@@ -138,11 +149,11 @@ std::vector<TileID> tileCover(const LatLngBounds& bounds_, int32_t z, int32_t ac
const TransformState state;
return tileCover(
- state.latLngToCoordinate(bounds.northwest()),
- state.latLngToCoordinate(bounds.northeast()),
- state.latLngToCoordinate(bounds.southeast()),
- state.latLngToCoordinate(bounds.southwest()),
- state.latLngToCoordinate(bounds.center()),
+ TileCoordinate::fromLatLng(state, z, bounds.northwest()),
+ TileCoordinate::fromLatLng(state, z, bounds.northeast()),
+ TileCoordinate::fromLatLng(state, z, bounds.southeast()),
+ TileCoordinate::fromLatLng(state, z, bounds.southwest()),
+ TileCoordinate::fromLatLng(state, z, bounds.center()),
z, actualZ);
}
@@ -150,11 +161,11 @@ std::vector<TileID> tileCover(const TransformState& state, int32_t z, int32_t ac
const double w = state.getWidth();
const double h = state.getHeight();
return tileCover(
- state.pointToCoordinate({ 0, 0 }),
- state.pointToCoordinate({ w, 0 }),
- state.pointToCoordinate({ w, h }),
- state.pointToCoordinate({ 0, h }),
- state.pointToCoordinate({ w/2, h/2 }),
+ TileCoordinate::fromScreenCoordinate(state, z, { 0, 0 }),
+ TileCoordinate::fromScreenCoordinate(state, z, { w, 0 }),
+ TileCoordinate::fromScreenCoordinate(state, z, { w, h }),
+ TileCoordinate::fromScreenCoordinate(state, z, { 0, h }),
+ TileCoordinate::fromScreenCoordinate(state, z, { w/2, h/2 }),
z, actualZ);
}
diff --git a/src/mbgl/util/vec.cpp b/src/mbgl/util/vec.cpp
new file mode 100644
index 0000000000..ab7770eae0
--- /dev/null
+++ b/src/mbgl/util/vec.cpp
@@ -0,0 +1,11 @@
+#include <mbgl/util/vec.hpp>
+
+namespace mbgl {
+
+template struct vec2<double>;
+template struct vec2<float>;
+
+template struct vec3<double>;
+template struct vec4<double>;
+
+} // namespace mbgl
diff --git a/src/mbgl/util/vec4.cpp b/src/mbgl/util/vec4.cpp
deleted file mode 100644
index bee4eaf976..0000000000
--- a/src/mbgl/util/vec4.cpp
+++ /dev/null
@@ -1,33 +0,0 @@
-// This is an incomplete port of http://glmatrix.net/
-//
-// Copyright (c) 2013 Brandon Jones, Colin MacKenzie IV
-//
-// This software is provided 'as-is', without any express or implied warranty.
-// In no event will the authors be held liable for any damages arising from the
-// use of this software.
-//
-// Permission is granted to anyone to use this software for any purpose,
-// including commercial applications, and to alter it and redistribute it
-// freely, subject to the following restrictions:
-//
-// 1. The origin of this software must not be misrepresented; you must not claim
-// that you wrote the original software. If you use this software in a
-// product, an acknowledgment in the product documentation would be
-// appreciated but is not required.
-//
-// 2. Altered source versions must be plainly marked as such, and must not be
-// misrepresented as being the original software.
-//
-// 3. This notice may not be removed or altered from any source distribution.
-
-#include <mbgl/util/vec4.hpp>
-
-using namespace mbgl;
-
-void matrix::transformMat4(vec4& out, vec4& a, mat4& m) {
- double x = a[0], y = a[1], z = a[2], w = a[3];
- out[0] = m[0] * x + m[4] * y + m[8] * z + m[12] * w;
- out[1] = m[1] * x + m[5] * y + m[9] * z + m[13] * w;
- out[2] = m[2] * x + m[6] * y + m[10] * z + m[14] * w;
- out[3] = m[3] * x + m[7] * y + m[11] * z + m[15] * w;
-}
diff --git a/src/mbgl/util/vec4.hpp b/src/mbgl/util/vec4.hpp
deleted file mode 100644
index 8f54f22261..0000000000
--- a/src/mbgl/util/vec4.hpp
+++ /dev/null
@@ -1,40 +0,0 @@
-// This is an incomplete port of http://glmatrix.net/
-//
-// Copyright (c) 2013 Brandon Jones, Colin MacKenzie IV
-//
-// This software is provided 'as-is', without any express or implied warranty.
-// In no event will the authors be held liable for any damages arising from the
-// use of this software.
-//
-// Permission is granted to anyone to use this software for any purpose,
-// including commercial applications, and to alter it and redistribute it
-// freely, subject to the following restrictions:
-//
-// 1. The origin of this software must not be misrepresented; you must not claim
-// that you wrote the original software. If you use this software in a
-// product, an acknowledgment in the product documentation would be
-// appreciated but is not required.
-//
-// 2. Altered source versions must be plainly marked as such, and must not be
-// misrepresented as being the original software.
-//
-// 3. This notice may not be removed or altered from any source distribution.
-
-#ifndef MBGL_UTIL_VEC4
-#define MBGL_UTIL_VEC4
-
-#include <array>
-#include <mbgl/util/mat4.hpp>
-
-namespace mbgl {
-
-namespace matrix {
-
-typedef std::array<double, 4> vec4;
-
-void transformMat4(vec4& out, vec4& a, mat4& m);
-
-} // namespace matrix
-} // namespace mbgl
-
-#endif
diff --git a/test/map/transform.cpp b/test/map/transform.cpp
index 3eb1c1bee1..98fc1223e5 100644
--- a/test/map/transform.cpp
+++ b/test/map/transform.cpp
@@ -109,8 +109,9 @@ TEST(Transform, InvalidBearing) {
TEST(Transform, PerspectiveProjection) {
MockView view;
- Transform transform(view, ConstrainMode::HeightOnly);
+ LatLng loc;
+ Transform transform(view, ConstrainMode::HeightOnly);
transform.resize({{ 1000, 1000 }});
transform.setScale(2 << 9);
transform.setPitch(0.9);
@@ -118,44 +119,71 @@ TEST(Transform, PerspectiveProjection) {
// expected values are from mapbox-gl-js
- LatLng loc = transform.getState().pointToLatLng({ 500, 500 });
+ loc = transform.getLatLng();
ASSERT_NEAR(-77, loc.longitude, 0.0001);
ASSERT_NEAR(38, loc.latitude, 0.0001);
- loc = transform.getState().pointToLatLng({ 0, 1000 });
+ loc = transform.getState().screenCoordinateToLatLng({ 0, 1000 });
ASSERT_NEAR(-77.59198961199148, loc.longitude, 0.0002);
ASSERT_NEAR(38.74661326302018, loc.latitude, 0.0001);
- loc = transform.getState().pointToLatLng({ 1000, 0 });
+ loc = transform.getState().screenCoordinateToLatLng({ 1000, 0 });
ASSERT_NEAR(-76.75823239205641, loc.longitude, 0.0001);
ASSERT_NEAR(37.692872969426375, loc.latitude, 0.0001);
- PrecisionPoint point = transform.getState().latLngToPoint({38.74661326302018, -77.59198961199148});
+ ScreenCoordinate point = transform.getState().latLngToScreenCoordinate({38.74661326302018, -77.59198961199148});
ASSERT_NEAR(point.x, 0, 0.01);
ASSERT_NEAR(point.y, 1000, 0.01);
- point = transform.getState().latLngToPoint({37.692872969426375, -76.75823239205641});
+ point = transform.getState().latLngToScreenCoordinate({37.692872969426375, -76.75823239205641});
ASSERT_NEAR(point.x, 1000, 0.02);
ASSERT_NEAR(point.y, 0, 0.02);
}
+TEST(Transform, UnwrappedLatLng) {
+ MockView view;
+ Transform transform(view, ConstrainMode::HeightOnly);
+ transform.resize({{ 1000, 1000 }});
+ transform.setScale(2 << 9);
+ transform.setPitch(0.9);
+ transform.setLatLng(LatLng(38, -77));
+
+ const TransformState& state = transform.getState();
+
+ LatLng fromGetLatLng = state.getLatLng();
+ ASSERT_DOUBLE_EQ(fromGetLatLng.latitude, 38);
+ ASSERT_DOUBLE_EQ(fromGetLatLng.longitude, -77);
+
+ LatLng fromScreenCoordinate = state.screenCoordinateToLatLng({ 500, 500 });
+ ASSERT_NEAR(fromScreenCoordinate.latitude, 37.999999999999829, 0.0001); // 1.71E-13
+ ASSERT_NEAR(fromScreenCoordinate.longitude, -76.999999999999773, 0.0001); // 2.27E-13
+
+ LatLng wrappedForwards = state.screenCoordinateToLatLng(state.latLngToScreenCoordinate({ 38, 283, LatLng::Wrapped }));
+ ASSERT_NEAR(wrappedForwards.latitude, 37.999999999999716, 0.0001); // 2.84E-13
+ ASSERT_DOUBLE_EQ(wrappedForwards.longitude, fromScreenCoordinate.longitude);
+
+ LatLng wrappedBackwards = state.screenCoordinateToLatLng(state.latLngToScreenCoordinate({ 38, -437, LatLng::Wrapped }));
+ ASSERT_DOUBLE_EQ(wrappedBackwards.latitude, wrappedForwards.latitude);
+ ASSERT_DOUBLE_EQ(wrappedBackwards.longitude, fromScreenCoordinate.longitude);
+}
+
TEST(Transform, ConstrainHeightOnly) {
MockView view;
LatLng loc;
Transform transform(view, ConstrainMode::HeightOnly);
transform.resize({{ 1000, 1000 }});
- transform.setScale(1024);
+ transform.setScale(std::pow(2, util::MAX_ZOOM));
transform.setLatLng(LatLngBounds::world().southwest());
- loc = transform.getState().pointToLatLng({ 500, 500 });
- ASSERT_NEAR(-85.021422866378714, loc.latitude, 0.0001);
- ASSERT_NEAR(180, std::abs(loc.longitude), 0.0001);
+ loc = transform.getLatLng();
+ ASSERT_NEAR(-util::LATITUDE_MAX, loc.latitude, 0.001);
+ ASSERT_NEAR(-util::LONGITUDE_MAX, loc.longitude, 0.001);
transform.setLatLng(LatLngBounds::world().northeast());
- loc = transform.getState().pointToLatLng({ 500, 500 });
- ASSERT_NEAR(85.021422866378742, loc.latitude, 0.0001);
- ASSERT_NEAR(180, std::abs(loc.longitude), 0.0001);
+ loc = transform.getLatLng();
+ ASSERT_NEAR(util::LATITUDE_MAX, loc.latitude, 0.001);
+ ASSERT_NEAR(util::LONGITUDE_MAX, std::abs(loc.longitude), 0.001);
}
TEST(Transform, ConstrainWidthAndHeight) {
@@ -164,17 +192,17 @@ TEST(Transform, ConstrainWidthAndHeight) {
Transform transform(view, ConstrainMode::WidthAndHeight);
transform.resize({{ 1000, 1000 }});
- transform.setScale(1024);
+ transform.setScale(std::pow(2, util::MAX_ZOOM));
transform.setLatLng(LatLngBounds::world().southwest());
- loc = transform.getState().pointToLatLng({ 500, 500 });
- ASSERT_NEAR(-85.021422866378714, loc.latitude, 0.0001);
- ASSERT_NEAR(-179.65667724609375, loc.longitude, 0.0001);
+ loc = transform.getLatLng();
+ ASSERT_NEAR(-util::LATITUDE_MAX, loc.latitude, 0.001);
+ ASSERT_NEAR(-util::LONGITUDE_MAX, loc.longitude, 0.001);
transform.setLatLng(LatLngBounds::world().northeast());
- loc = transform.getState().pointToLatLng({ 500, 500 });
- ASSERT_NEAR(85.021422866378742, loc.latitude, 0.0001);
- ASSERT_NEAR(179.65667724609358, std::abs(loc.longitude), 0.0001);
+ loc = transform.getLatLng();
+ ASSERT_NEAR(util::LATITUDE_MAX, loc.latitude, 0.001);
+ ASSERT_NEAR(util::LONGITUDE_MAX, std::abs(loc.longitude), 0.001);
}
TEST(Transform, Anchor) {
@@ -192,8 +220,8 @@ TEST(Transform, Anchor) {
ASSERT_DOUBLE_EQ(10, transform.getZoom());
ASSERT_DOUBLE_EQ(0, transform.getAngle());
- const PrecisionPoint anchorPoint = {0, 0};
- const LatLng anchorLatLng = transform.getState().pointToLatLng(anchorPoint);
+ const ScreenCoordinate anchorPoint = {0, 0};
+ const LatLng anchorLatLng = transform.getState().screenCoordinateToLatLng(anchorPoint);
transform.setAngle(M_PI_4, anchorPoint);
ASSERT_NEAR(M_PI_4, transform.getAngle(), 0.000001);
@@ -215,7 +243,7 @@ TEST(Transform, Padding) {
ASSERT_DOUBLE_EQ(-100, trueCenter.longitude);
ASSERT_DOUBLE_EQ(10, transform.getZoom());
- const LatLng manualShiftedCenter = transform.getState().pointToLatLng({
+ const LatLng manualShiftedCenter = transform.getState().screenCoordinateToLatLng({
1000.0 / 2.0,
1000.0 / 4.0,
});
diff --git a/test/util/geo.cpp b/test/util/geo.cpp
index 96335c5dba..86f448ebbc 100644
--- a/test/util/geo.cpp
+++ b/test/util/geo.cpp
@@ -1,5 +1,6 @@
#include "../fixtures/util.hpp"
+#include <mbgl/util/constants.hpp>
#include <mbgl/util/geo.hpp>
#include <mbgl/map/tile_id.hpp>
@@ -87,36 +88,36 @@ TEST(LatLngBounds, Northwest) {
TEST(LatLng, FromTileID) {
for (int i = 0; i < 20; i++) {
const LatLng ll{ TileID(i, 0, 0, 0) };
- ASSERT_DOUBLE_EQ(-180, ll.longitude);
- ASSERT_DOUBLE_EQ(85.051128779806604, ll.latitude);
+ ASSERT_DOUBLE_EQ(-util::LONGITUDE_MAX, ll.longitude);
+ ASSERT_DOUBLE_EQ(util::LATITUDE_MAX, ll.latitude);
}
{
const LatLng ll{ TileID(0, 1, 0, 0) };
- ASSERT_DOUBLE_EQ(180, ll.longitude);
- ASSERT_DOUBLE_EQ(85.051128779806604, ll.latitude);
+ ASSERT_DOUBLE_EQ(util::LONGITUDE_MAX, ll.longitude);
+ ASSERT_DOUBLE_EQ(util::LATITUDE_MAX, ll.latitude);
}
{
const LatLng ll{ TileID(0, -1, 0, 0) };
ASSERT_DOUBLE_EQ(-540, ll.longitude);
- ASSERT_DOUBLE_EQ(85.051128779806604, ll.latitude);
+ ASSERT_DOUBLE_EQ(util::LATITUDE_MAX, ll.latitude);
}
}
TEST(LatLngBounds, FromTileID) {
{
const LatLngBounds bounds{ TileID(0, 0, 0, 0) };
- ASSERT_DOUBLE_EQ(-180, bounds.west());
- ASSERT_DOUBLE_EQ(-85.051128779806604, bounds.south());
- ASSERT_DOUBLE_EQ(180, bounds.east());
- ASSERT_DOUBLE_EQ(85.051128779806604, bounds.north());
+ ASSERT_DOUBLE_EQ(-util::LONGITUDE_MAX, bounds.west());
+ ASSERT_DOUBLE_EQ(-util::LATITUDE_MAX, bounds.south());
+ ASSERT_DOUBLE_EQ(util::LONGITUDE_MAX, bounds.east());
+ ASSERT_DOUBLE_EQ(util::LATITUDE_MAX, bounds.north());
}
{
const LatLngBounds bounds{ TileID(1, 0, 1, 0) };
- ASSERT_DOUBLE_EQ(-180, bounds.west());
- ASSERT_DOUBLE_EQ(-85.051128779806604, bounds.south());
+ ASSERT_DOUBLE_EQ(-util::LONGITUDE_MAX, bounds.west());
+ ASSERT_DOUBLE_EQ(-util::LATITUDE_MAX, bounds.south());
ASSERT_DOUBLE_EQ(0, bounds.east());
ASSERT_DOUBLE_EQ(0, bounds.north());
}
@@ -124,16 +125,16 @@ TEST(LatLngBounds, FromTileID) {
{
const LatLngBounds bounds{ TileID(1, 1, 1, 0) };
ASSERT_DOUBLE_EQ(0, bounds.west());
- ASSERT_DOUBLE_EQ(-85.051128779806604, bounds.south());
- ASSERT_DOUBLE_EQ(180, bounds.east());
+ ASSERT_DOUBLE_EQ(-util::LATITUDE_MAX, bounds.south());
+ ASSERT_DOUBLE_EQ(util::LONGITUDE_MAX, bounds.east());
ASSERT_DOUBLE_EQ(0, bounds.north());
}
{
const LatLngBounds bounds{ TileID(1, 0, 0, 0) };
- ASSERT_DOUBLE_EQ(-180, bounds.west());
+ ASSERT_DOUBLE_EQ(-util::LONGITUDE_MAX, bounds.west());
ASSERT_DOUBLE_EQ(0, bounds.south());
ASSERT_DOUBLE_EQ(0, bounds.east());
- ASSERT_DOUBLE_EQ(85.051128779806604, bounds.north());
+ ASSERT_DOUBLE_EQ(util::LATITUDE_MAX, bounds.north());
}
}