diff --git a/MapboxGLAndroidSDK/src/cpp/CMakeLists.txt b/MapboxGLAndroidSDK/src/cpp/CMakeLists.txt index f59a10e4d..2107533ea 100644 --- a/MapboxGLAndroidSDK/src/cpp/CMakeLists.txt +++ b/MapboxGLAndroidSDK/src/cpp/CMakeLists.txt @@ -156,6 +156,8 @@ add_library( ${PROJECT_SOURCE_DIR}/style/layers/raster_layer.hpp ${PROJECT_SOURCE_DIR}/style/layers/symbol_layer.cpp ${PROJECT_SOURCE_DIR}/style/layers/symbol_layer.hpp + ${PROJECT_SOURCE_DIR}/style/layers/location_indicator_layer.cpp + ${PROJECT_SOURCE_DIR}/style/layers/location_indicator_layer.hpp ${PROJECT_SOURCE_DIR}/style/light.cpp ${PROJECT_SOURCE_DIR}/style/light.hpp ${PROJECT_SOURCE_DIR}/style/position.cpp diff --git a/MapboxGLAndroidSDK/src/cpp/conversion/constant.cpp b/MapboxGLAndroidSDK/src/cpp/conversion/constant.cpp index 46a91026d..292e1a4ac 100644 --- a/MapboxGLAndroidSDK/src/cpp/conversion/constant.cpp +++ b/MapboxGLAndroidSDK/src/cpp/conversion/constant.cpp @@ -52,11 +52,25 @@ Result>> Converter>, std::vect return result; } +Result>> Converter>, std::vector>::operator()(jni::JNIEnv& env, const std::vector& value) const { + auto result = jni::Array::New(env, value.size()); + + for (std::size_t i = 0; i < value.size(); i++) { + result.Set(env, i, jni::Box(env, value.at(i))); + } + + return result; +} + Result>> Converter>, style::expression::Image>::operator()( jni::JNIEnv& env, const style::expression::Image& value) const { return jni::Make(env, value.id()); } +Result>> Converter>, mbgl::style::Rotation>::operator()(jni::JNIEnv& env, const mbgl::style::Rotation& value) const { + return jni::Box(env, value.getAngle()); +} + } // namespace conversion } // namespace style } // namespace mbgl diff --git a/MapboxGLAndroidSDK/src/cpp/conversion/constant.hpp b/MapboxGLAndroidSDK/src/cpp/conversion/constant.hpp index a9239fe84..dc78d6f36 100644 --- a/MapboxGLAndroidSDK/src/cpp/conversion/constant.hpp +++ b/MapboxGLAndroidSDK/src/cpp/conversion/constant.hpp @@ -13,6 +13,7 @@ #include #include #include +#include namespace mbgl { namespace android { @@ -72,6 +73,17 @@ struct Converter>, std::array> { } }; +template +struct Converter>, std::array> { + Result>> operator()(jni::JNIEnv& env, const std::array& value) const { + std::vector v; + for (const double& id : value) { + v.push_back(id); + } + return convert>, std::vector>(env, v); + } +}; + template <> struct Converter>, std::vector> { Result>> operator()(jni::JNIEnv& env, const std::vector& value) const; @@ -82,6 +94,11 @@ struct Converter>, std::vector> { Result>> operator()(jni::JNIEnv& env, const std::vector& value) const; }; +template <> +struct Converter>, std::vector> { + Result>> operator()(jni::JNIEnv& env, const std::vector& value) const; +}; + template struct Converter>, T, typename std::enable_if_t::value>> { Result>> operator()(jni::JNIEnv& env, const T& value) const { @@ -105,6 +122,11 @@ struct Converter>, style::expression::Image> { Result>> operator()(jni::JNIEnv& env, const style::expression::Image& value) const; }; +template <> +struct Converter>, mbgl::style::Rotation> { + Result>> operator()(jni::JNIEnv& env, const mbgl::style::Rotation& value) const; +}; + } // namespace conversion } // namespace android } // namespace mbgl diff --git a/MapboxGLAndroidSDK/src/cpp/style/layers/background_layer.cpp b/MapboxGLAndroidSDK/src/cpp/style/layers/background_layer.cpp index 3eae30677..d0084dc2d 100644 --- a/MapboxGLAndroidSDK/src/cpp/style/layers/background_layer.cpp +++ b/MapboxGLAndroidSDK/src/cpp/style/layers/background_layer.cpp @@ -26,13 +26,16 @@ namespace android { /** * Creates a non-owning peer object (for layers currently attached to the map) */ - BackgroundLayer::BackgroundLayer(mbgl::style::BackgroundLayer& coreLayer) : Layer(coreLayer) {} + BackgroundLayer::BackgroundLayer(mbgl::style::BackgroundLayer& coreLayer) + : Layer(coreLayer) { + } /** * Creates an owning peer object (for layers not attached to the map) */ BackgroundLayer::BackgroundLayer(std::unique_ptr coreLayer) - : Layer(std::move(coreLayer)) {} + : Layer(std::move(coreLayer)) { + } BackgroundLayer::~BackgroundLayer() = default; @@ -105,18 +108,14 @@ namespace android { } } // namespace - jni::Local> BackgroundJavaLayerPeerFactory::createJavaLayerPeer(jni::JNIEnv& env, - mbgl::style::Layer& layer) { + jni::Local> BackgroundJavaLayerPeerFactory::createJavaLayerPeer(jni::JNIEnv& env, mbgl::style::Layer& layer) { assert(layer.baseImpl->getTypeInfo() == getTypeInfo()); return createJavaPeer(env, new BackgroundLayer(toBackgroundLayer(layer))); } - jni::Local> BackgroundJavaLayerPeerFactory::createJavaLayerPeer( - jni::JNIEnv& env, std::unique_ptr layer) { + jni::Local> BackgroundJavaLayerPeerFactory::createJavaLayerPeer(jni::JNIEnv& env, std::unique_ptr layer) { assert(layer->baseImpl->getTypeInfo() == getTypeInfo()); - return createJavaPeer(env, - new BackgroundLayer(std::unique_ptr( - static_cast(layer.release())))); + return createJavaPeer(env, new BackgroundLayer(std::unique_ptr(static_cast(layer.release())))); } void BackgroundJavaLayerPeerFactory::registerNative(jni::JNIEnv& env) { diff --git a/MapboxGLAndroidSDK/src/cpp/style/layers/circle_layer.cpp b/MapboxGLAndroidSDK/src/cpp/style/layers/circle_layer.cpp index 2be603360..705bb9136 100644 --- a/MapboxGLAndroidSDK/src/cpp/style/layers/circle_layer.cpp +++ b/MapboxGLAndroidSDK/src/cpp/style/layers/circle_layer.cpp @@ -26,12 +26,16 @@ namespace android { /** * Creates a non-owning peer object (for layers currently attached to the map) */ - CircleLayer::CircleLayer(mbgl::style::CircleLayer& coreLayer) : Layer(coreLayer) {} + CircleLayer::CircleLayer(mbgl::style::CircleLayer& coreLayer) + : Layer(coreLayer) { + } /** * Creates an owning peer object (for layers not attached to the map) */ - CircleLayer::CircleLayer(std::unique_ptr coreLayer) : Layer(std::move(coreLayer)) {} + CircleLayer::CircleLayer(std::unique_ptr coreLayer) + : Layer(std::move(coreLayer)) { + } CircleLayer::~CircleLayer() = default; @@ -214,18 +218,14 @@ namespace android { } } // namespace - jni::Local> CircleJavaLayerPeerFactory::createJavaLayerPeer(jni::JNIEnv& env, - mbgl::style::Layer& layer) { + jni::Local> CircleJavaLayerPeerFactory::createJavaLayerPeer(jni::JNIEnv& env, mbgl::style::Layer& layer) { assert(layer.baseImpl->getTypeInfo() == getTypeInfo()); return createJavaPeer(env, new CircleLayer(toCircleLayer(layer))); } - jni::Local> CircleJavaLayerPeerFactory::createJavaLayerPeer( - jni::JNIEnv& env, std::unique_ptr layer) { + jni::Local> CircleJavaLayerPeerFactory::createJavaLayerPeer(jni::JNIEnv& env, std::unique_ptr layer) { assert(layer->baseImpl->getTypeInfo() == getTypeInfo()); - return createJavaPeer(env, - new CircleLayer(std::unique_ptr( - static_cast(layer.release())))); + return createJavaPeer(env, new CircleLayer(std::unique_ptr(static_cast(layer.release())))); } void CircleJavaLayerPeerFactory::registerNative(jni::JNIEnv& env) { diff --git a/MapboxGLAndroidSDK/src/cpp/style/layers/fill_extrusion_layer.cpp b/MapboxGLAndroidSDK/src/cpp/style/layers/fill_extrusion_layer.cpp index 55c3d2028..9b7c66a0a 100644 --- a/MapboxGLAndroidSDK/src/cpp/style/layers/fill_extrusion_layer.cpp +++ b/MapboxGLAndroidSDK/src/cpp/style/layers/fill_extrusion_layer.cpp @@ -26,13 +26,16 @@ namespace android { /** * Creates a non-owning peer object (for layers currently attached to the map) */ - FillExtrusionLayer::FillExtrusionLayer(mbgl::style::FillExtrusionLayer& coreLayer) : Layer(coreLayer) {} + FillExtrusionLayer::FillExtrusionLayer(mbgl::style::FillExtrusionLayer& coreLayer) + : Layer(coreLayer) { + } /** * Creates an owning peer object (for layers not attached to the map) */ FillExtrusionLayer::FillExtrusionLayer(std::unique_ptr coreLayer) - : Layer(std::move(coreLayer)) {} + : Layer(std::move(coreLayer)) { + } FillExtrusionLayer::~FillExtrusionLayer() = default; @@ -169,18 +172,14 @@ namespace android { } } // namespace - jni::Local> FillExtrusionJavaLayerPeerFactory::createJavaLayerPeer(jni::JNIEnv& env, - mbgl::style::Layer& layer) { + jni::Local> FillExtrusionJavaLayerPeerFactory::createJavaLayerPeer(jni::JNIEnv& env, mbgl::style::Layer& layer) { assert(layer.baseImpl->getTypeInfo() == getTypeInfo()); return createJavaPeer(env, new FillExtrusionLayer(toFillExtrusionLayer(layer))); } - jni::Local> FillExtrusionJavaLayerPeerFactory::createJavaLayerPeer( - jni::JNIEnv& env, std::unique_ptr layer) { + jni::Local> FillExtrusionJavaLayerPeerFactory::createJavaLayerPeer(jni::JNIEnv& env, std::unique_ptr layer) { assert(layer->baseImpl->getTypeInfo() == getTypeInfo()); - return createJavaPeer(env, - new FillExtrusionLayer(std::unique_ptr( - static_cast(layer.release())))); + return createJavaPeer(env, new FillExtrusionLayer(std::unique_ptr(static_cast(layer.release())))); } void FillExtrusionJavaLayerPeerFactory::registerNative(jni::JNIEnv& env) { @@ -203,10 +202,8 @@ namespace android { METHOD(&FillExtrusionLayer::getFillExtrusionColorTransition, "nativeGetFillExtrusionColorTransition"), METHOD(&FillExtrusionLayer::setFillExtrusionColorTransition, "nativeSetFillExtrusionColorTransition"), METHOD(&FillExtrusionLayer::getFillExtrusionColor, "nativeGetFillExtrusionColor"), - METHOD(&FillExtrusionLayer::getFillExtrusionTranslateTransition, - "nativeGetFillExtrusionTranslateTransition"), - METHOD(&FillExtrusionLayer::setFillExtrusionTranslateTransition, - "nativeSetFillExtrusionTranslateTransition"), + METHOD(&FillExtrusionLayer::getFillExtrusionTranslateTransition, "nativeGetFillExtrusionTranslateTransition"), + METHOD(&FillExtrusionLayer::setFillExtrusionTranslateTransition, "nativeSetFillExtrusionTranslateTransition"), METHOD(&FillExtrusionLayer::getFillExtrusionTranslate, "nativeGetFillExtrusionTranslate"), METHOD(&FillExtrusionLayer::getFillExtrusionTranslateAnchor, "nativeGetFillExtrusionTranslateAnchor"), METHOD(&FillExtrusionLayer::getFillExtrusionPatternTransition, "nativeGetFillExtrusionPatternTransition"), diff --git a/MapboxGLAndroidSDK/src/cpp/style/layers/fill_layer.cpp b/MapboxGLAndroidSDK/src/cpp/style/layers/fill_layer.cpp index 6a646fdc7..ba6ed2179 100644 --- a/MapboxGLAndroidSDK/src/cpp/style/layers/fill_layer.cpp +++ b/MapboxGLAndroidSDK/src/cpp/style/layers/fill_layer.cpp @@ -26,12 +26,16 @@ namespace android { /** * Creates a non-owning peer object (for layers currently attached to the map) */ - FillLayer::FillLayer(mbgl::style::FillLayer& coreLayer) : Layer(coreLayer) {} + FillLayer::FillLayer(mbgl::style::FillLayer& coreLayer) + : Layer(coreLayer) { + } /** * Creates an owning peer object (for layers not attached to the map) */ - FillLayer::FillLayer(std::unique_ptr coreLayer) : Layer(std::move(coreLayer)) {} + FillLayer::FillLayer(std::unique_ptr coreLayer) + : Layer(std::move(coreLayer)) { + } FillLayer::~FillLayer() = default; @@ -155,18 +159,14 @@ namespace android { } } // namespace - jni::Local> FillJavaLayerPeerFactory::createJavaLayerPeer(jni::JNIEnv& env, - mbgl::style::Layer& layer) { + jni::Local> FillJavaLayerPeerFactory::createJavaLayerPeer(jni::JNIEnv& env, mbgl::style::Layer& layer) { assert(layer.baseImpl->getTypeInfo() == getTypeInfo()); return createJavaPeer(env, new FillLayer(toFillLayer(layer))); } - jni::Local> FillJavaLayerPeerFactory::createJavaLayerPeer( - jni::JNIEnv& env, std::unique_ptr layer) { + jni::Local> FillJavaLayerPeerFactory::createJavaLayerPeer(jni::JNIEnv& env, std::unique_ptr layer) { assert(layer->baseImpl->getTypeInfo() == getTypeInfo()); - return createJavaPeer(env, - new FillLayer(std::unique_ptr( - static_cast(layer.release())))); + return createJavaPeer(env, new FillLayer(std::unique_ptr(static_cast(layer.release())))); } void FillJavaLayerPeerFactory::registerNative(jni::JNIEnv& env) { diff --git a/MapboxGLAndroidSDK/src/cpp/style/layers/heatmap_layer.cpp b/MapboxGLAndroidSDK/src/cpp/style/layers/heatmap_layer.cpp index dad3d25e6..dfb8bbb4b 100644 --- a/MapboxGLAndroidSDK/src/cpp/style/layers/heatmap_layer.cpp +++ b/MapboxGLAndroidSDK/src/cpp/style/layers/heatmap_layer.cpp @@ -26,12 +26,16 @@ namespace android { /** * Creates a non-owning peer object (for layers currently attached to the map) */ - HeatmapLayer::HeatmapLayer(mbgl::style::HeatmapLayer& coreLayer) : Layer(coreLayer) {} + HeatmapLayer::HeatmapLayer(mbgl::style::HeatmapLayer& coreLayer) + : Layer(coreLayer) { + } /** * Creates an owning peer object (for layers not attached to the map) */ - HeatmapLayer::HeatmapLayer(std::unique_ptr coreLayer) : Layer(std::move(coreLayer)) {} + HeatmapLayer::HeatmapLayer(std::unique_ptr coreLayer) + : Layer(std::move(coreLayer)) { + } HeatmapLayer::~HeatmapLayer() = default; @@ -118,18 +122,14 @@ namespace android { } } // namespace - jni::Local> HeatmapJavaLayerPeerFactory::createJavaLayerPeer(jni::JNIEnv& env, - mbgl::style::Layer& layer) { + jni::Local> HeatmapJavaLayerPeerFactory::createJavaLayerPeer(jni::JNIEnv& env, mbgl::style::Layer& layer) { assert(layer.baseImpl->getTypeInfo() == getTypeInfo()); return createJavaPeer(env, new HeatmapLayer(toHeatmapLayer(layer))); } - jni::Local> HeatmapJavaLayerPeerFactory::createJavaLayerPeer( - jni::JNIEnv& env, std::unique_ptr layer) { + jni::Local> HeatmapJavaLayerPeerFactory::createJavaLayerPeer(jni::JNIEnv& env, std::unique_ptr layer) { assert(layer->baseImpl->getTypeInfo() == getTypeInfo()); - return createJavaPeer(env, - new HeatmapLayer(std::unique_ptr( - static_cast(layer.release())))); + return createJavaPeer(env, new HeatmapLayer(std::unique_ptr(static_cast(layer.release())))); } void HeatmapJavaLayerPeerFactory::registerNative(jni::JNIEnv& env) { diff --git a/MapboxGLAndroidSDK/src/cpp/style/layers/hillshade_layer.cpp b/MapboxGLAndroidSDK/src/cpp/style/layers/hillshade_layer.cpp index 1f5fe1912..3c72b503b 100644 --- a/MapboxGLAndroidSDK/src/cpp/style/layers/hillshade_layer.cpp +++ b/MapboxGLAndroidSDK/src/cpp/style/layers/hillshade_layer.cpp @@ -26,13 +26,16 @@ namespace android { /** * Creates a non-owning peer object (for layers currently attached to the map) */ - HillshadeLayer::HillshadeLayer(mbgl::style::HillshadeLayer& coreLayer) : Layer(coreLayer) {} + HillshadeLayer::HillshadeLayer(mbgl::style::HillshadeLayer& coreLayer) + : Layer(coreLayer) { + } /** * Creates an owning peer object (for layers not attached to the map) */ HillshadeLayer::HillshadeLayer(std::unique_ptr coreLayer) - : Layer(std::move(coreLayer)) {} + : Layer(std::move(coreLayer)) { + } HillshadeLayer::~HillshadeLayer() = default; @@ -133,18 +136,14 @@ namespace android { } } // namespace - jni::Local> HillshadeJavaLayerPeerFactory::createJavaLayerPeer(jni::JNIEnv& env, - mbgl::style::Layer& layer) { + jni::Local> HillshadeJavaLayerPeerFactory::createJavaLayerPeer(jni::JNIEnv& env, mbgl::style::Layer& layer) { assert(layer.baseImpl->getTypeInfo() == getTypeInfo()); return createJavaPeer(env, new HillshadeLayer(toHillshadeLayer(layer))); } - jni::Local> HillshadeJavaLayerPeerFactory::createJavaLayerPeer( - jni::JNIEnv& env, std::unique_ptr layer) { + jni::Local> HillshadeJavaLayerPeerFactory::createJavaLayerPeer(jni::JNIEnv& env, std::unique_ptr layer) { assert(layer->baseImpl->getTypeInfo() == getTypeInfo()); - return createJavaPeer(env, - new HillshadeLayer(std::unique_ptr( - static_cast(layer.release())))); + return createJavaPeer(env, new HillshadeLayer(std::unique_ptr(static_cast(layer.release())))); } void HillshadeJavaLayerPeerFactory::registerNative(jni::JNIEnv& env) { diff --git a/MapboxGLAndroidSDK/src/cpp/style/layers/layer.cpp b/MapboxGLAndroidSDK/src/cpp/style/layers/layer.cpp index bc87a9d9b..47984e140 100644 --- a/MapboxGLAndroidSDK/src/cpp/style/layers/layer.cpp +++ b/MapboxGLAndroidSDK/src/cpp/style/layers/layer.cpp @@ -5,16 +5,6 @@ #include #include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include #include // Java -> C++ conversion diff --git a/MapboxGLAndroidSDK/src/cpp/style/layers/layer.cpp.ejs b/MapboxGLAndroidSDK/src/cpp/style/layers/layer.cpp.ejs index 5d241e9a3..79df91791 100644 --- a/MapboxGLAndroidSDK/src/cpp/style/layers/layer.cpp.ejs +++ b/MapboxGLAndroidSDK/src/cpp/style/layers/layer.cpp.ejs @@ -20,7 +20,7 @@ namespace android { return static_castLayer&>(layer); } -<% if (type === 'background') { -%> +<% if (type === 'background' || type === 'location-indicator') { -%> /** * Creates an owning peer object (for layers not attached to the map) from the JVM side */ @@ -121,7 +121,7 @@ namespace android { env, javaClass, "nativePtr", -<% if (type === 'background') { -%> +<% if (type === 'background' || type === 'location-indicator') { -%> jni::MakePeer<<%- camelize(type) %>Layer, jni::String&>, <% } else { -%> jni::MakePeer<<%- camelize(type) %>Layer, jni::String&, jni::String&>, diff --git a/MapboxGLAndroidSDK/src/cpp/style/layers/layer.hpp.ejs b/MapboxGLAndroidSDK/src/cpp/style/layers/layer.hpp.ejs index eb8db0620..05fe925c8 100644 --- a/MapboxGLAndroidSDK/src/cpp/style/layers/layer.hpp.ejs +++ b/MapboxGLAndroidSDK/src/cpp/style/layers/layer.hpp.ejs @@ -20,7 +20,7 @@ public: using SuperTag = Layer; static constexpr auto Name() { return "com/mapbox/mapboxsdk/style/layers/<%- camelize(type) %>Layer"; }; -<% if (type === 'background') { -%> +<% if (type === 'background' || type === 'location-indicator') { -%> <%- camelize(type) %>Layer(jni::JNIEnv&, jni::String&); <% } else { -%> <%- camelize(type) %>Layer(jni::JNIEnv&, jni::String&, jni::String&); diff --git a/MapboxGLAndroidSDK/src/cpp/style/layers/layer_manager.cpp b/MapboxGLAndroidSDK/src/cpp/style/layers/layer_manager.cpp index 2d4172a23..1e72b1516 100644 --- a/MapboxGLAndroidSDK/src/cpp/style/layers/layer_manager.cpp +++ b/MapboxGLAndroidSDK/src/cpp/style/layers/layer_manager.cpp @@ -17,6 +17,7 @@ #include "raster_layer.hpp" #include "symbol_layer.hpp" #include "fill_extrusion_layer.hpp" +#include "location_indicator_layer.hpp" namespace mbgl { @@ -73,6 +74,9 @@ LayerManagerAndroid::LayerManagerAndroid() { #elif !defined(MBGL_LAYER_CUSTOM_DISABLE_ALL) addLayerType(std::make_unique()); #endif +#if !defined(MBGL_LAYER_LOCATION_INDICATOR_DISABLE_ALL) + addLayerType(std::make_unique()); +#endif } LayerManagerAndroid::~LayerManagerAndroid() = default; diff --git a/MapboxGLAndroidSDK/src/cpp/style/layers/line_layer.cpp b/MapboxGLAndroidSDK/src/cpp/style/layers/line_layer.cpp index 89c6cb532..bf3a403b6 100644 --- a/MapboxGLAndroidSDK/src/cpp/style/layers/line_layer.cpp +++ b/MapboxGLAndroidSDK/src/cpp/style/layers/line_layer.cpp @@ -26,12 +26,16 @@ namespace android { /** * Creates a non-owning peer object (for layers currently attached to the map) */ - LineLayer::LineLayer(mbgl::style::LineLayer& coreLayer) : Layer(coreLayer) {} + LineLayer::LineLayer(mbgl::style::LineLayer& coreLayer) + : Layer(coreLayer) { + } /** * Creates an owning peer object (for layers not attached to the map) */ - LineLayer::LineLayer(std::unique_ptr coreLayer) : Layer(std::move(coreLayer)) {} + LineLayer::LineLayer(std::unique_ptr coreLayer) + : Layer(std::move(coreLayer)) { + } LineLayer::~LineLayer() = default; @@ -247,18 +251,14 @@ namespace android { } } // namespace - jni::Local> LineJavaLayerPeerFactory::createJavaLayerPeer(jni::JNIEnv& env, - mbgl::style::Layer& layer) { + jni::Local> LineJavaLayerPeerFactory::createJavaLayerPeer(jni::JNIEnv& env, mbgl::style::Layer& layer) { assert(layer.baseImpl->getTypeInfo() == getTypeInfo()); return createJavaPeer(env, new LineLayer(toLineLayer(layer))); } - jni::Local> LineJavaLayerPeerFactory::createJavaLayerPeer( - jni::JNIEnv& env, std::unique_ptr layer) { + jni::Local> LineJavaLayerPeerFactory::createJavaLayerPeer(jni::JNIEnv& env, std::unique_ptr layer) { assert(layer->baseImpl->getTypeInfo() == getTypeInfo()); - return createJavaPeer(env, - new LineLayer(std::unique_ptr( - static_cast(layer.release())))); + return createJavaPeer(env, new LineLayer(std::unique_ptr(static_cast(layer.release())))); } void LineJavaLayerPeerFactory::registerNative(jni::JNIEnv& env) { diff --git a/MapboxGLAndroidSDK/src/cpp/style/layers/location_indicator_layer.cpp b/MapboxGLAndroidSDK/src/cpp/style/layers/location_indicator_layer.cpp new file mode 100644 index 000000000..7b2f36b4f --- /dev/null +++ b/MapboxGLAndroidSDK/src/cpp/style/layers/location_indicator_layer.cpp @@ -0,0 +1,267 @@ +// This file is generated. Edit android/platform/scripts/generate-style-code.js, then run `make android-style-code`. + +#include "location_indicator_layer.hpp" + +#include + +#include "../conversion/property_value.hpp" +#include "../conversion/transition_options.hpp" + +#include + +namespace mbgl { +namespace android { + + inline mbgl::style::LocationIndicatorLayer& toLocationIndicatorLayer(mbgl::style::Layer& layer) { + return static_cast(layer); + } + + /** + * Creates an owning peer object (for layers not attached to the map) from the JVM side + */ + LocationIndicatorLayer::LocationIndicatorLayer(jni::JNIEnv& env, jni::String& layerId) + : Layer(std::make_unique(jni::Make(env, layerId))) { + } + + /** + * Creates a non-owning peer object (for layers currently attached to the map) + */ + LocationIndicatorLayer::LocationIndicatorLayer(mbgl::style::LocationIndicatorLayer& coreLayer) + : Layer(coreLayer) { + } + + /** + * Creates an owning peer object (for layers not attached to the map) + */ + LocationIndicatorLayer::LocationIndicatorLayer(std::unique_ptr coreLayer) + : Layer(std::move(coreLayer)) { + } + + LocationIndicatorLayer::~LocationIndicatorLayer() = default; + + // Property getters + + jni::Local> LocationIndicatorLayer::getTopImage(jni::JNIEnv& env) { + using namespace mbgl::android::conversion; + return std::move(*convert>>(env, toLocationIndicatorLayer(layer).getTopImage())); + } + + jni::Local> LocationIndicatorLayer::getBearingImage(jni::JNIEnv& env) { + using namespace mbgl::android::conversion; + return std::move(*convert>>(env, toLocationIndicatorLayer(layer).getBearingImage())); + } + + jni::Local> LocationIndicatorLayer::getShadowImage(jni::JNIEnv& env) { + using namespace mbgl::android::conversion; + return std::move(*convert>>(env, toLocationIndicatorLayer(layer).getShadowImage())); + } + + jni::Local> LocationIndicatorLayer::getPerspectiveCompensation(jni::JNIEnv& env) { + using namespace mbgl::android::conversion; + return std::move(*convert>>(env, toLocationIndicatorLayer(layer).getPerspectiveCompensation())); + } + + jni::Local> LocationIndicatorLayer::getImageTiltDisplacement(jni::JNIEnv& env) { + using namespace mbgl::android::conversion; + return std::move(*convert>>(env, toLocationIndicatorLayer(layer).getImageTiltDisplacement())); + } + + jni::Local> LocationIndicatorLayer::getBearing(jni::JNIEnv& env) { + using namespace mbgl::android::conversion; + return std::move(*convert>>(env, toLocationIndicatorLayer(layer).getBearing())); + } + + jni::Local> LocationIndicatorLayer::getLocation(jni::JNIEnv& env) { + using namespace mbgl::android::conversion; + return std::move(*convert>>(env, toLocationIndicatorLayer(layer).getLocation())); + } + + jni::Local> LocationIndicatorLayer::getLocationTransition(jni::JNIEnv& env) { + using namespace mbgl::android::conversion; + mbgl::style::TransitionOptions options = toLocationIndicatorLayer(layer).getLocationTransition(); + return std::move(*convert>>(env, options)); + } + + void LocationIndicatorLayer::setLocationTransition(jni::JNIEnv&, jlong duration, jlong delay) { + mbgl::style::TransitionOptions options; + options.duration.emplace(mbgl::Milliseconds(duration)); + options.delay.emplace(mbgl::Milliseconds(delay)); + toLocationIndicatorLayer(layer).setLocationTransition(options); + } + + jni::Local> LocationIndicatorLayer::getAccuracyRadius(jni::JNIEnv& env) { + using namespace mbgl::android::conversion; + return std::move(*convert>>(env, toLocationIndicatorLayer(layer).getAccuracyRadius())); + } + + jni::Local> LocationIndicatorLayer::getAccuracyRadiusTransition(jni::JNIEnv& env) { + using namespace mbgl::android::conversion; + mbgl::style::TransitionOptions options = toLocationIndicatorLayer(layer).getAccuracyRadiusTransition(); + return std::move(*convert>>(env, options)); + } + + void LocationIndicatorLayer::setAccuracyRadiusTransition(jni::JNIEnv&, jlong duration, jlong delay) { + mbgl::style::TransitionOptions options; + options.duration.emplace(mbgl::Milliseconds(duration)); + options.delay.emplace(mbgl::Milliseconds(delay)); + toLocationIndicatorLayer(layer).setAccuracyRadiusTransition(options); + } + + jni::Local> LocationIndicatorLayer::getTopImageSize(jni::JNIEnv& env) { + using namespace mbgl::android::conversion; + return std::move(*convert>>(env, toLocationIndicatorLayer(layer).getTopImageSize())); + } + + jni::Local> LocationIndicatorLayer::getTopImageSizeTransition(jni::JNIEnv& env) { + using namespace mbgl::android::conversion; + mbgl::style::TransitionOptions options = toLocationIndicatorLayer(layer).getTopImageSizeTransition(); + return std::move(*convert>>(env, options)); + } + + void LocationIndicatorLayer::setTopImageSizeTransition(jni::JNIEnv&, jlong duration, jlong delay) { + mbgl::style::TransitionOptions options; + options.duration.emplace(mbgl::Milliseconds(duration)); + options.delay.emplace(mbgl::Milliseconds(delay)); + toLocationIndicatorLayer(layer).setTopImageSizeTransition(options); + } + + jni::Local> LocationIndicatorLayer::getBearingImageSize(jni::JNIEnv& env) { + using namespace mbgl::android::conversion; + return std::move(*convert>>(env, toLocationIndicatorLayer(layer).getBearingImageSize())); + } + + jni::Local> LocationIndicatorLayer::getBearingImageSizeTransition(jni::JNIEnv& env) { + using namespace mbgl::android::conversion; + mbgl::style::TransitionOptions options = toLocationIndicatorLayer(layer).getBearingImageSizeTransition(); + return std::move(*convert>>(env, options)); + } + + void LocationIndicatorLayer::setBearingImageSizeTransition(jni::JNIEnv&, jlong duration, jlong delay) { + mbgl::style::TransitionOptions options; + options.duration.emplace(mbgl::Milliseconds(duration)); + options.delay.emplace(mbgl::Milliseconds(delay)); + toLocationIndicatorLayer(layer).setBearingImageSizeTransition(options); + } + + jni::Local> LocationIndicatorLayer::getShadowImageSize(jni::JNIEnv& env) { + using namespace mbgl::android::conversion; + return std::move(*convert>>(env, toLocationIndicatorLayer(layer).getShadowImageSize())); + } + + jni::Local> LocationIndicatorLayer::getShadowImageSizeTransition(jni::JNIEnv& env) { + using namespace mbgl::android::conversion; + mbgl::style::TransitionOptions options = toLocationIndicatorLayer(layer).getShadowImageSizeTransition(); + return std::move(*convert>>(env, options)); + } + + void LocationIndicatorLayer::setShadowImageSizeTransition(jni::JNIEnv&, jlong duration, jlong delay) { + mbgl::style::TransitionOptions options; + options.duration.emplace(mbgl::Milliseconds(duration)); + options.delay.emplace(mbgl::Milliseconds(delay)); + toLocationIndicatorLayer(layer).setShadowImageSizeTransition(options); + } + + jni::Local> LocationIndicatorLayer::getAccuracyRadiusColor(jni::JNIEnv& env) { + using namespace mbgl::android::conversion; + return std::move(*convert>>(env, toLocationIndicatorLayer(layer).getAccuracyRadiusColor())); + } + + jni::Local> LocationIndicatorLayer::getAccuracyRadiusColorTransition(jni::JNIEnv& env) { + using namespace mbgl::android::conversion; + mbgl::style::TransitionOptions options = toLocationIndicatorLayer(layer).getAccuracyRadiusColorTransition(); + return std::move(*convert>>(env, options)); + } + + void LocationIndicatorLayer::setAccuracyRadiusColorTransition(jni::JNIEnv&, jlong duration, jlong delay) { + mbgl::style::TransitionOptions options; + options.duration.emplace(mbgl::Milliseconds(duration)); + options.delay.emplace(mbgl::Milliseconds(delay)); + toLocationIndicatorLayer(layer).setAccuracyRadiusColorTransition(options); + } + + jni::Local> LocationIndicatorLayer::getAccuracyRadiusBorderColor(jni::JNIEnv& env) { + using namespace mbgl::android::conversion; + return std::move(*convert>>(env, toLocationIndicatorLayer(layer).getAccuracyRadiusBorderColor())); + } + + jni::Local> LocationIndicatorLayer::getAccuracyRadiusBorderColorTransition(jni::JNIEnv& env) { + using namespace mbgl::android::conversion; + mbgl::style::TransitionOptions options = toLocationIndicatorLayer(layer).getAccuracyRadiusBorderColorTransition(); + return std::move(*convert>>(env, options)); + } + + void LocationIndicatorLayer::setAccuracyRadiusBorderColorTransition(jni::JNIEnv&, jlong duration, jlong delay) { + mbgl::style::TransitionOptions options; + options.duration.emplace(mbgl::Milliseconds(duration)); + options.delay.emplace(mbgl::Milliseconds(delay)); + toLocationIndicatorLayer(layer).setAccuracyRadiusBorderColorTransition(options); + } + + + // LocationIndicatorJavaLayerPeerFactory + + LocationIndicatorJavaLayerPeerFactory::~LocationIndicatorJavaLayerPeerFactory() = default; + + namespace { + jni::Local> createJavaPeer(jni::JNIEnv& env, Layer* layer) { + static auto& javaClass = jni::Class::Singleton(env); + static auto constructor = javaClass.GetConstructor(env); + return javaClass.New(env, constructor, reinterpret_cast(layer)); + } + } // namespace + + jni::Local> LocationIndicatorJavaLayerPeerFactory::createJavaLayerPeer(jni::JNIEnv& env, mbgl::style::Layer& layer) { + assert(layer.baseImpl->getTypeInfo() == getTypeInfo()); + return createJavaPeer(env, new LocationIndicatorLayer(toLocationIndicatorLayer(layer))); + } + + jni::Local> LocationIndicatorJavaLayerPeerFactory::createJavaLayerPeer(jni::JNIEnv& env, std::unique_ptr layer) { + assert(layer->baseImpl->getTypeInfo() == getTypeInfo()); + return createJavaPeer(env, new LocationIndicatorLayer(std::unique_ptr(static_cast(layer.release())))); + } + + void LocationIndicatorJavaLayerPeerFactory::registerNative(jni::JNIEnv& env) { + // Lookup the class + static auto& javaClass = jni::Class::Singleton(env); + + #define METHOD(MethodPtr, name) jni::MakeNativePeerMethod(name) + + // Register the peer + jni::RegisterNativePeer( + env, + javaClass, + "nativePtr", + jni::MakePeer, + "initialize", + "finalize", + METHOD(&LocationIndicatorLayer::getTopImage, "nativeGetTopImage"), + METHOD(&LocationIndicatorLayer::getBearingImage, "nativeGetBearingImage"), + METHOD(&LocationIndicatorLayer::getShadowImage, "nativeGetShadowImage"), + METHOD(&LocationIndicatorLayer::getPerspectiveCompensation, "nativeGetPerspectiveCompensation"), + METHOD(&LocationIndicatorLayer::getImageTiltDisplacement, "nativeGetImageTiltDisplacement"), + METHOD(&LocationIndicatorLayer::getBearing, "nativeGetBearing"), + METHOD(&LocationIndicatorLayer::getLocationTransition, "nativeGetLocationTransition"), + METHOD(&LocationIndicatorLayer::setLocationTransition, "nativeSetLocationTransition"), + METHOD(&LocationIndicatorLayer::getLocation, "nativeGetLocation"), + METHOD(&LocationIndicatorLayer::getAccuracyRadiusTransition, "nativeGetAccuracyRadiusTransition"), + METHOD(&LocationIndicatorLayer::setAccuracyRadiusTransition, "nativeSetAccuracyRadiusTransition"), + METHOD(&LocationIndicatorLayer::getAccuracyRadius, "nativeGetAccuracyRadius"), + METHOD(&LocationIndicatorLayer::getTopImageSizeTransition, "nativeGetTopImageSizeTransition"), + METHOD(&LocationIndicatorLayer::setTopImageSizeTransition, "nativeSetTopImageSizeTransition"), + METHOD(&LocationIndicatorLayer::getTopImageSize, "nativeGetTopImageSize"), + METHOD(&LocationIndicatorLayer::getBearingImageSizeTransition, "nativeGetBearingImageSizeTransition"), + METHOD(&LocationIndicatorLayer::setBearingImageSizeTransition, "nativeSetBearingImageSizeTransition"), + METHOD(&LocationIndicatorLayer::getBearingImageSize, "nativeGetBearingImageSize"), + METHOD(&LocationIndicatorLayer::getShadowImageSizeTransition, "nativeGetShadowImageSizeTransition"), + METHOD(&LocationIndicatorLayer::setShadowImageSizeTransition, "nativeSetShadowImageSizeTransition"), + METHOD(&LocationIndicatorLayer::getShadowImageSize, "nativeGetShadowImageSize"), + METHOD(&LocationIndicatorLayer::getAccuracyRadiusColorTransition, "nativeGetAccuracyRadiusColorTransition"), + METHOD(&LocationIndicatorLayer::setAccuracyRadiusColorTransition, "nativeSetAccuracyRadiusColorTransition"), + METHOD(&LocationIndicatorLayer::getAccuracyRadiusColor, "nativeGetAccuracyRadiusColor"), + METHOD(&LocationIndicatorLayer::getAccuracyRadiusBorderColorTransition, "nativeGetAccuracyRadiusBorderColorTransition"), + METHOD(&LocationIndicatorLayer::setAccuracyRadiusBorderColorTransition, "nativeSetAccuracyRadiusBorderColorTransition"), + METHOD(&LocationIndicatorLayer::getAccuracyRadiusBorderColor, "nativeGetAccuracyRadiusBorderColor")); + } + +} // namespace android +} // namespace mbgl diff --git a/MapboxGLAndroidSDK/src/cpp/style/layers/location_indicator_layer.hpp b/MapboxGLAndroidSDK/src/cpp/style/layers/location_indicator_layer.hpp new file mode 100644 index 000000000..6b7621efd --- /dev/null +++ b/MapboxGLAndroidSDK/src/cpp/style/layers/location_indicator_layer.hpp @@ -0,0 +1,86 @@ +// This file is generated. Edit android/platform/scripts/generate-style-code.js, then run `make android-style-code`. + +#pragma once + +#include "layer.hpp" +#include "../transition_options.hpp" +#include +#include +#include + +namespace mbgl { +namespace android { + +class LocationIndicatorLayer : public Layer { +public: + using SuperTag = Layer; + static constexpr auto Name() { return "com/mapbox/mapboxsdk/style/layers/LocationIndicatorLayer"; }; + + LocationIndicatorLayer(jni::JNIEnv&, jni::String&); + + LocationIndicatorLayer(mbgl::style::LocationIndicatorLayer&); + + LocationIndicatorLayer(std::unique_ptr); + + ~LocationIndicatorLayer(); + + // Properties + + jni::Local> getTopImage(jni::JNIEnv&); + + jni::Local> getBearingImage(jni::JNIEnv&); + + jni::Local> getShadowImage(jni::JNIEnv&); + + jni::Local> getPerspectiveCompensation(jni::JNIEnv&); + + jni::Local> getImageTiltDisplacement(jni::JNIEnv&); + + jni::Local> getBearing(jni::JNIEnv&); + + jni::Local> getLocation(jni::JNIEnv&); + void setLocationTransition(jni::JNIEnv&, jlong duration, jlong delay); + jni::Local> getLocationTransition(jni::JNIEnv&); + + jni::Local> getAccuracyRadius(jni::JNIEnv&); + void setAccuracyRadiusTransition(jni::JNIEnv&, jlong duration, jlong delay); + jni::Local> getAccuracyRadiusTransition(jni::JNIEnv&); + + jni::Local> getTopImageSize(jni::JNIEnv&); + void setTopImageSizeTransition(jni::JNIEnv&, jlong duration, jlong delay); + jni::Local> getTopImageSizeTransition(jni::JNIEnv&); + + jni::Local> getBearingImageSize(jni::JNIEnv&); + void setBearingImageSizeTransition(jni::JNIEnv&, jlong duration, jlong delay); + jni::Local> getBearingImageSizeTransition(jni::JNIEnv&); + + jni::Local> getShadowImageSize(jni::JNIEnv&); + void setShadowImageSizeTransition(jni::JNIEnv&, jlong duration, jlong delay); + jni::Local> getShadowImageSizeTransition(jni::JNIEnv&); + + jni::Local> getAccuracyRadiusColor(jni::JNIEnv&); + void setAccuracyRadiusColorTransition(jni::JNIEnv&, jlong duration, jlong delay); + jni::Local> getAccuracyRadiusColorTransition(jni::JNIEnv&); + + jni::Local> getAccuracyRadiusBorderColor(jni::JNIEnv&); + void setAccuracyRadiusBorderColorTransition(jni::JNIEnv&, jlong duration, jlong delay); + jni::Local> getAccuracyRadiusBorderColorTransition(jni::JNIEnv&); + +}; // class LocationIndicatorLayer + +class LocationIndicatorJavaLayerPeerFactory final : public JavaLayerPeerFactory, public mbgl::LocationIndicatorLayerFactory { +public: + ~LocationIndicatorJavaLayerPeerFactory() override; + + // JavaLayerPeerFactory overrides. + jni::Local> createJavaLayerPeer(jni::JNIEnv&, mbgl::style::Layer&) final; + jni::Local> createJavaLayerPeer(jni::JNIEnv& env, std::unique_ptr) final; + + void registerNative(jni::JNIEnv&) final; + + LayerFactory* getLayerFactory() final { return this; } + +}; // class LocationIndicatorJavaLayerPeerFactory + +} // namespace android +} // namespace mbgl diff --git a/MapboxGLAndroidSDK/src/cpp/style/layers/raster_layer.cpp b/MapboxGLAndroidSDK/src/cpp/style/layers/raster_layer.cpp index d9cce949c..53442c0a9 100644 --- a/MapboxGLAndroidSDK/src/cpp/style/layers/raster_layer.cpp +++ b/MapboxGLAndroidSDK/src/cpp/style/layers/raster_layer.cpp @@ -26,12 +26,16 @@ namespace android { /** * Creates a non-owning peer object (for layers currently attached to the map) */ - RasterLayer::RasterLayer(mbgl::style::RasterLayer& coreLayer) : Layer(coreLayer) {} + RasterLayer::RasterLayer(mbgl::style::RasterLayer& coreLayer) + : Layer(coreLayer) { + } /** * Creates an owning peer object (for layers not attached to the map) */ - RasterLayer::RasterLayer(std::unique_ptr coreLayer) : Layer(std::move(coreLayer)) {} + RasterLayer::RasterLayer(std::unique_ptr coreLayer) + : Layer(std::move(coreLayer)) { + } RasterLayer::~RasterLayer() = default; @@ -168,18 +172,14 @@ namespace android { } } // namespace - jni::Local> RasterJavaLayerPeerFactory::createJavaLayerPeer(jni::JNIEnv& env, - mbgl::style::Layer& layer) { + jni::Local> RasterJavaLayerPeerFactory::createJavaLayerPeer(jni::JNIEnv& env, mbgl::style::Layer& layer) { assert(layer.baseImpl->getTypeInfo() == getTypeInfo()); return createJavaPeer(env, new RasterLayer(toRasterLayer(layer))); } - jni::Local> RasterJavaLayerPeerFactory::createJavaLayerPeer( - jni::JNIEnv& env, std::unique_ptr layer) { + jni::Local> RasterJavaLayerPeerFactory::createJavaLayerPeer(jni::JNIEnv& env, std::unique_ptr layer) { assert(layer->baseImpl->getTypeInfo() == getTypeInfo()); - return createJavaPeer(env, - new RasterLayer(std::unique_ptr( - static_cast(layer.release())))); + return createJavaPeer(env, new RasterLayer(std::unique_ptr(static_cast(layer.release())))); } void RasterJavaLayerPeerFactory::registerNative(jni::JNIEnv& env) { diff --git a/MapboxGLAndroidSDK/src/cpp/style/layers/symbol_layer.cpp b/MapboxGLAndroidSDK/src/cpp/style/layers/symbol_layer.cpp index f24fb3542..198dbe635 100644 --- a/MapboxGLAndroidSDK/src/cpp/style/layers/symbol_layer.cpp +++ b/MapboxGLAndroidSDK/src/cpp/style/layers/symbol_layer.cpp @@ -26,12 +26,16 @@ namespace android { /** * Creates a non-owning peer object (for layers currently attached to the map) */ - SymbolLayer::SymbolLayer(mbgl::style::SymbolLayer& coreLayer) : Layer(coreLayer) {} + SymbolLayer::SymbolLayer(mbgl::style::SymbolLayer& coreLayer) + : Layer(coreLayer) { + } /** * Creates an owning peer object (for layers not attached to the map) */ - SymbolLayer::SymbolLayer(std::unique_ptr coreLayer) : Layer(std::move(coreLayer)) {} + SymbolLayer::SymbolLayer(std::unique_ptr coreLayer) + : Layer(std::move(coreLayer)) { + } SymbolLayer::~SymbolLayer() = default; @@ -481,18 +485,14 @@ namespace android { } } // namespace - jni::Local> SymbolJavaLayerPeerFactory::createJavaLayerPeer(jni::JNIEnv& env, - mbgl::style::Layer& layer) { + jni::Local> SymbolJavaLayerPeerFactory::createJavaLayerPeer(jni::JNIEnv& env, mbgl::style::Layer& layer) { assert(layer.baseImpl->getTypeInfo() == getTypeInfo()); return createJavaPeer(env, new SymbolLayer(toSymbolLayer(layer))); } - jni::Local> SymbolJavaLayerPeerFactory::createJavaLayerPeer( - jni::JNIEnv& env, std::unique_ptr layer) { + jni::Local> SymbolJavaLayerPeerFactory::createJavaLayerPeer(jni::JNIEnv& env, std::unique_ptr layer) { assert(layer->baseImpl->getTypeInfo() == getTypeInfo()); - return createJavaPeer(env, - new SymbolLayer(std::unique_ptr( - static_cast(layer.release())))); + return createJavaPeer(env, new SymbolLayer(std::unique_ptr(static_cast(layer.release())))); } void SymbolJavaLayerPeerFactory::registerNative(jni::JNIEnv& env) { diff --git a/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/IndicatorLocationLayerRenderer.java b/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/IndicatorLocationLayerRenderer.java new file mode 100644 index 000000000..6f4f0080d --- /dev/null +++ b/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/IndicatorLocationLayerRenderer.java @@ -0,0 +1,211 @@ +package com.mapbox.mapboxsdk.location; + +import android.graphics.Bitmap; + +import androidx.annotation.Nullable; + +import com.mapbox.mapboxsdk.geometry.LatLng; +import com.mapbox.mapboxsdk.location.modes.RenderMode; +import com.mapbox.mapboxsdk.maps.Style; +import com.mapbox.mapboxsdk.style.expressions.Expression; +import com.mapbox.mapboxsdk.style.layers.LocationIndicatorLayer; +import com.mapbox.mapboxsdk.style.layers.PropertyFactory; +import com.mapbox.mapboxsdk.utils.BitmapUtils; +import com.mapbox.mapboxsdk.utils.ColorUtils; + +import static com.mapbox.mapboxsdk.location.LocationComponentConstants.BACKGROUND_ICON; +import static com.mapbox.mapboxsdk.location.LocationComponentConstants.BACKGROUND_STALE_ICON; +import static com.mapbox.mapboxsdk.location.LocationComponentConstants.BEARING_ICON; +import static com.mapbox.mapboxsdk.location.LocationComponentConstants.BEARING_STALE_ICON; +import static com.mapbox.mapboxsdk.location.LocationComponentConstants.FOREGROUND_ICON; +import static com.mapbox.mapboxsdk.location.LocationComponentConstants.FOREGROUND_STALE_ICON; +import static com.mapbox.mapboxsdk.location.LocationComponentConstants.SHADOW_ICON; +import static com.mapbox.mapboxsdk.style.expressions.Expression.rgba; +import static com.mapbox.mapboxsdk.style.layers.Property.NONE; +import static com.mapbox.mapboxsdk.style.layers.Property.VISIBLE; +import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.visibility; + +class IndicatorLocationLayerRenderer implements LocationLayerRenderer { + + private Style style; + private final LayerSourceProvider layerSourceProvider; + private LocationIndicatorLayer layer; + + @Nullable + private LatLng latLng; + + IndicatorLocationLayerRenderer(Style style, + LayerSourceProvider layerSourceProvider) { + this.style = style; + this.layerSourceProvider = layerSourceProvider; + } + + @Override + public void initializeComponents(Style style) { + this.style = style; + } + + @Override + public void addLayers(LocationComponentPositionManager positionManager) { + layer = layerSourceProvider.generateLocationComponentLayer(); + setLayerLocation(latLng); + positionManager.addLayerToMap(layer); + } + + @Override + public void removeLayers() { + style.removeLayer(layer); + } + + @Override + public void hide() { + setLayerVisibility(false); + } + + @Override + public void cameraTiltUpdated(double tilt) { + // ignored + } + + @Override + public void cameraBearingUpdated(double bearing) { + // ignored + } + + @Override + public void show(@RenderMode.Mode int renderMode, boolean isStale) { + setImages(renderMode, isStale); + setLayerVisibility(true); + } + + @Override + public void styleAccuracy(float accuracyAlpha, int accuracyColor) { + float[] colorArray = ColorUtils.colorToRgbaArray(accuracyColor); + colorArray[3] = accuracyAlpha; + Expression rgbaExpression = rgba(colorArray[0], colorArray[1], colorArray[2], colorArray[3]); + layer.setProperties( + PropertyFactory.accuracyRadiusColor(rgbaExpression), + PropertyFactory.accuracyRadiusBorderColor(rgbaExpression) + ); + } + + @Override + public void setLatLng(LatLng latLng) { + setLayerLocation(latLng); + } + + @Override + public void setGpsBearing(Float gpsBearing) { + setLayerBearing(gpsBearing); + } + + @Override + public void setCompassBearing(Float compassBearing) { + setLayerBearing(compassBearing); + } + + @Override + public void setAccuracyRadius(Float accuracy) { + layer.setProperties( + PropertyFactory.accuracyRadius(accuracy) + ); + } + + @Override + public void styleScaling(Expression scaleExpression) { + layer.setProperties( + PropertyFactory.shadowImageSize(scaleExpression), + PropertyFactory.bearingImageSize(scaleExpression), + PropertyFactory.topImageSize(scaleExpression) + ); + } + + @Override + public void setLocationStale(boolean isStale, int renderMode) { + setImages(renderMode, isStale); + } + + @Override + public void updateIconIds(String foregroundIconString, String foregroundStaleIconString, String backgroundIconString, + String backgroundStaleIconString, String bearingIconString) { + // not supported + } + + @Override + public void addBitmaps(@RenderMode.Mode int renderMode, @Nullable Bitmap shadowBitmap, Bitmap backgroundBitmap, + Bitmap backgroundStaleBitmap, Bitmap bearingBitmap, + Bitmap foregroundBitmap, Bitmap foregroundStaleBitmap) { + if (shadowBitmap != null) { + style.addImage(SHADOW_ICON, shadowBitmap); + } else { + style.removeImage(SHADOW_ICON); + } + style.addImage(FOREGROUND_ICON, foregroundBitmap); + style.addImage(FOREGROUND_STALE_ICON, foregroundStaleBitmap); + + if (renderMode == RenderMode.COMPASS) { + float leftOffset = (bearingBitmap.getWidth() - backgroundBitmap.getWidth()) / 2f; + float topOffset = (bearingBitmap.getHeight() - backgroundBitmap.getHeight()) / 2f; + style.addImage(BEARING_ICON, BitmapUtils.mergeBitmap(bearingBitmap, backgroundBitmap, leftOffset, topOffset)); + + float staleLeftOffset = (bearingBitmap.getWidth() - backgroundStaleBitmap.getWidth()) / 2f; + float staleTopOffset = (bearingBitmap.getHeight() - backgroundStaleBitmap.getHeight()) / 2f; + style.addImage(BEARING_STALE_ICON, + BitmapUtils.mergeBitmap(bearingBitmap, backgroundStaleBitmap, staleLeftOffset, staleTopOffset)); + } else { + style.addImage(BACKGROUND_ICON, backgroundBitmap); + style.addImage(BACKGROUND_STALE_ICON, backgroundStaleBitmap); + style.addImage(BEARING_ICON, bearingBitmap); + } + } + + private void setLayerVisibility(boolean visible) { + layer.setProperties(visibility(visible ? VISIBLE : NONE)); + } + + private void setLayerLocation(@Nullable LatLng latLng) { + this.latLng = latLng; + if (latLng != null) { + Double[] values = new Double[] {latLng.getLatitude(), latLng.getLongitude(), 0d}; + layer.setProperties( + PropertyFactory.location(values) + ); + } + } + + private void setLayerBearing(double bearing) { + layer.setProperties( + PropertyFactory.bearing(bearing) + ); + } + + private void setImages(@RenderMode.Mode int renderMode, boolean isStale) { + String topImage = ""; + String bearingImage = ""; + String shadowImage = ""; + + switch (renderMode) { + case RenderMode.COMPASS: + topImage = isStale ? FOREGROUND_STALE_ICON : FOREGROUND_ICON; + bearingImage = isStale ? BEARING_STALE_ICON : BEARING_ICON; + shadowImage = SHADOW_ICON; + break; + case RenderMode.GPS: + topImage = ""; + bearingImage = isStale ? FOREGROUND_STALE_ICON : FOREGROUND_ICON; + shadowImage = ""; + setAccuracyRadius(0f); + break; + case RenderMode.NORMAL: + topImage = isStale ? FOREGROUND_STALE_ICON : FOREGROUND_ICON; + bearingImage = isStale ? BACKGROUND_STALE_ICON : BACKGROUND_ICON; + shadowImage = SHADOW_ICON; + break; + } + layer.setProperties( + PropertyFactory.topImage(topImage), + PropertyFactory.bearingImage(bearingImage), + PropertyFactory.shadowImage(shadowImage) + ); + } +} diff --git a/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/LayerFeatureProvider.java b/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/LayerFeatureProvider.java index 69e08caed..1ad948908 100644 --- a/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/LayerFeatureProvider.java +++ b/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/LayerFeatureProvider.java @@ -13,14 +13,14 @@ import static com.mapbox.mapboxsdk.location.LocationComponentConstants.PROPERTY_ class LayerFeatureProvider { @NonNull - Feature generateLocationFeature(@Nullable Feature locationFeature, @NonNull LocationComponentOptions options) { + Feature generateLocationFeature(@Nullable Feature locationFeature, boolean isStale) { if (locationFeature != null) { return locationFeature; } locationFeature = Feature.fromGeometry(Point.fromLngLat(0.0, 0.0)); locationFeature.addNumberProperty(PROPERTY_GPS_BEARING, 0f); locationFeature.addNumberProperty(PROPERTY_COMPASS_BEARING, 0f); - locationFeature.addBooleanProperty(PROPERTY_LOCATION_STALE, options.enableStaleState()); + locationFeature.addBooleanProperty(PROPERTY_LOCATION_STALE, isStale); return locationFeature; } } diff --git a/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/LayerSourceProvider.java b/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/LayerSourceProvider.java index e3c6ebd91..2d3e969ec 100644 --- a/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/LayerSourceProvider.java +++ b/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/LayerSourceProvider.java @@ -1,14 +1,20 @@ package com.mapbox.mapboxsdk.location; import androidx.annotation.NonNull; + import com.mapbox.geojson.Feature; import com.mapbox.mapboxsdk.style.layers.CircleLayer; import com.mapbox.mapboxsdk.style.layers.Layer; +import com.mapbox.mapboxsdk.style.layers.LocationIndicatorLayer; import com.mapbox.mapboxsdk.style.layers.Property; +import com.mapbox.mapboxsdk.style.layers.PropertyFactory; import com.mapbox.mapboxsdk.style.layers.SymbolLayer; import com.mapbox.mapboxsdk.style.sources.GeoJsonOptions; import com.mapbox.mapboxsdk.style.sources.GeoJsonSource; +import java.util.HashSet; +import java.util.Set; + import static com.mapbox.mapboxsdk.location.LocationComponentConstants.ACCURACY_LAYER; import static com.mapbox.mapboxsdk.location.LocationComponentConstants.BACKGROUND_LAYER; import static com.mapbox.mapboxsdk.location.LocationComponentConstants.BEARING_LAYER; @@ -108,4 +114,17 @@ class LayerSourceProvider { circlePitchAlignment(Property.CIRCLE_PITCH_ALIGNMENT_MAP) ); } + + Set getEmptyLayerSet() { + return new HashSet<>(); + } + + LocationIndicatorLayer generateLocationComponentLayer() { + LocationIndicatorLayer layer = new LocationIndicatorLayer(FOREGROUND_LAYER); + layer.setProperties( + PropertyFactory.perspectiveCompensation(0.9f), + PropertyFactory.imageTiltDisplacement(4f) + ); + return layer; + } } diff --git a/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/LocationComponent.java b/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/LocationComponent.java index 0f7dfded0..733dbb259 100644 --- a/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/LocationComponent.java +++ b/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/LocationComponent.java @@ -140,6 +140,12 @@ public final class LocationComponent { */ private boolean isComponentInitialized; + /** + * Indicates whether we're using the {@link com.mapbox.mapboxsdk.style.layers.LocationIndicatorLayer} + * or the stack of {@link com.mapbox.mapboxsdk.style.layers.SymbolLayer}s. + */ + private boolean useSpecializedLocationLayer; + /** * Indicates that the component is enabled and should be displaying location if Mapbox components are available and * the lifecycle is in a started state. @@ -341,7 +347,7 @@ public final class LocationComponent { @Deprecated public void activateLocationComponent(@NonNull Context context, @NonNull Style style, @NonNull LocationComponentOptions options) { - initialize(context, style, options); + initialize(context, style, false, options); initializeLocationEngine(context); applyStyle(options); } @@ -425,7 +431,7 @@ public final class LocationComponent { public void activateLocationComponent(@NonNull Context context, @NonNull Style style, @Nullable LocationEngine locationEngine, @NonNull LocationComponentOptions options) { - initialize(context, style, options); + initialize(context, style, false, options); setLocationEngine(locationEngine); applyStyle(options); } @@ -446,7 +452,7 @@ public final class LocationComponent { @Nullable LocationEngine locationEngine, @NonNull LocationEngineRequest locationEngineRequest, @NonNull LocationComponentOptions options) { - initialize(context, style, options); + initialize(context, style, false, options); setLocationEngineRequest(locationEngineRequest); setLocationEngine(locationEngine); applyStyle(options); @@ -470,7 +476,8 @@ public final class LocationComponent { // Initialize the LocationComponent with Context, the map's `Style`, and either custom LocationComponentOptions // or backup options created from default/custom attributes - initialize(activationOptions.context(), activationOptions.style(), options); + initialize(activationOptions.context(), activationOptions.style(), + activationOptions.useSpecializedLocationLayer(), options); // Apply the LocationComponent styling // TODO avoid doubling style initialization @@ -1255,7 +1262,7 @@ public final class LocationComponent { mapboxMap.removeOnCameraIdleListener(onCameraIdleListener); } - private void initialize(@NonNull final Context context, @NonNull Style style, + private void initialize(@NonNull final Context context, @NonNull Style style, boolean useSpecializedLocationLayer, @NonNull final LocationComponentOptions options) { if (isComponentInitialized) { return; @@ -1268,6 +1275,7 @@ public final class LocationComponent { this.style = style; this.options = options; + this.useSpecializedLocationLayer = useSpecializedLocationLayer; mapboxMap.addOnMapClickListener(onMapClickListener); mapboxMap.addOnMapLongClickListener(onMapLongClickListener); @@ -1276,7 +1284,7 @@ public final class LocationComponent { LayerFeatureProvider featureProvider = new LayerFeatureProvider(); LayerBitmapProvider bitmapProvider = new LayerBitmapProvider(context); locationLayerController = new LocationLayerController(mapboxMap, style, sourceProvider, featureProvider, - bitmapProvider, options, renderModeChangedListener); + bitmapProvider, options, renderModeChangedListener, useSpecializedLocationLayer); locationCameraController = new LocationCameraController( context, mapboxMap, transform, cameraTrackingChangedListener, options, onCameraMoveInvalidateListener); @@ -1446,20 +1454,24 @@ public final class LocationComponent { @SuppressLint("MissingPermission") private void updateLayerOffsets(boolean forceUpdate) { + if (useSpecializedLocationLayer) { + return; + } + CameraPosition position = mapboxMap.getCameraPosition(); if (lastCameraPosition == null || forceUpdate) { lastCameraPosition = position; - locationLayerController.updateForegroundBearing((float) position.bearing); - locationLayerController.updateForegroundOffset(position.tilt); + locationLayerController.cameraBearingUpdated(position.bearing); + locationLayerController.cameraTiltUpdated(position.tilt); updateAccuracyRadius(getLastKnownLocation(), true); return; } if (position.bearing != lastCameraPosition.bearing) { - locationLayerController.updateForegroundBearing((float) position.bearing); + locationLayerController.cameraBearingUpdated(position.bearing); } if (position.tilt != lastCameraPosition.tilt) { - locationLayerController.updateForegroundOffset(position.tilt); + locationLayerController.cameraTiltUpdated(position.tilt); } if (position.zoom != lastCameraPosition.zoom) { updateAccuracyRadius(getLastKnownLocation(), true); @@ -1468,7 +1480,15 @@ public final class LocationComponent { } private void updateAccuracyRadius(Location location, boolean noAnimation) { - locationAnimatorCoordinator.feedNewAccuracyRadius(Utils.calculateZoomLevelRadius(mapboxMap, location), noAnimation); + float radius; + if (location == null) { + radius = 0; + } else if (useSpecializedLocationLayer) { + radius = location.getAccuracy(); + } else { + radius = Utils.calculateZoomLevelRadius(mapboxMap, location); + } + locationAnimatorCoordinator.feedNewAccuracyRadius(radius, noAnimation); } private void updateAnimatorListenerHolders() { diff --git a/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/LocationComponentActivationOptions.java b/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/LocationComponentActivationOptions.java index 7a7b24149..91f6141dd 100644 --- a/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/LocationComponentActivationOptions.java +++ b/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/LocationComponentActivationOptions.java @@ -1,6 +1,7 @@ package com.mapbox.mapboxsdk.location; import android.content.Context; + import androidx.annotation.NonNull; import androidx.annotation.Nullable; @@ -21,13 +22,15 @@ public class LocationComponentActivationOptions { private final LocationComponentOptions locationComponentOptions; private final int styleRes; private final boolean useDefaultLocationEngine; + private final boolean useSpecializedLocationLayer; private LocationComponentActivationOptions(@NonNull Context context, @NonNull Style style, @Nullable LocationEngine locationEngine, @Nullable LocationEngineRequest locationEngineRequest, @Nullable LocationComponentOptions locationComponentOptions, int styleRes, - boolean useDefaultLocationEngine) { + boolean useDefaultLocationEngine, + boolean useSpecializedLocationLayer) { this.context = context; this.style = style; this.locationEngine = locationEngine; @@ -35,6 +38,7 @@ public class LocationComponentActivationOptions { this.locationComponentOptions = locationComponentOptions; this.styleRes = styleRes; this.useDefaultLocationEngine = useDefaultLocationEngine; + this.useSpecializedLocationLayer = useSpecializedLocationLayer; } /** @@ -116,6 +120,25 @@ public class LocationComponentActivationOptions { return useDefaultLocationEngine; } + /** + * True if you want to initialize and use the specialized location layer to render the location puck. + *

+ * The specialized layer comes with significant performance improvements, + * but since it's not based on the runtime styling, + * it's not fully compatible with the traditional implementation. The incompatibilities are: + *

    + *
  • Constants like {@link LocationComponentConstants#FOREGROUND_LAYER} + * or {@link LocationComponentConstants#LOCATION_SOURCE} are ignored. + *
  • All options that alter the image ID, like {@link LocationComponentOptions#foregroundName()}, are ignored. + * Use {@link LocationComponentOptions#foregroundDrawable()} instead. + *
+ * + * @return whether the default specialized location layer is used + */ + public boolean useSpecializedLocationLayer() { + return useSpecializedLocationLayer; + } + /** * Builder class for constructing a new instance of {@link LocationComponentActivationOptions}. */ @@ -136,6 +159,8 @@ public class LocationComponentActivationOptions { */ private boolean useDefaultLocationEngine = true; + private boolean useSpecializedLocationLayer = false; + /** * Constructor for the {@link LocationComponentActivationOptions} builder class. * While other activation options are optional, the activation process always requires @@ -208,6 +233,28 @@ public class LocationComponentActivationOptions { return this; } + /** + * True if you want to initialize and use the specialized location layer to render the location puck. + *

+ * The specialized layer comes with significant performance improvements, + * but since it's not based on the runtime styling, + * it's not fully compatible with the traditional implementation. The incompatibilities are: + *

    + *
  • Constants like {@link LocationComponentConstants#FOREGROUND_LAYER} + * or {@link LocationComponentConstants#LOCATION_SOURCE} are ignored. + *
  • All options that alter the image ID, like {@link LocationComponentOptions#foregroundName()}, are ignored. + * Use {@link LocationComponentOptions#foregroundDrawable()} instead. + *
+ * + * @param useSpecializedLocationLayer true if you want to initialize and use the + * specialized location layer. Defaults to false. + * @return the {@link Builder} object being constructed + */ + public Builder useSpecializedLocationLayer(boolean useSpecializedLocationLayer) { + this.useSpecializedLocationLayer = useSpecializedLocationLayer; + return this; + } + /** * Method which actually builds the {@link LocationComponentActivationOptions} object while * taking the various options into account. @@ -217,28 +264,29 @@ public class LocationComponentActivationOptions { public LocationComponentActivationOptions build() { if (styleRes != 0 && locationComponentOptions != null) { throw new IllegalArgumentException( - "You've provided both a style resource and a LocationComponentOptions object to the " - + "LocationComponentActivationOptions builder. You can't use both and " - + "you must choose one of the two to style the LocationComponent."); + "You've provided both a style resource and a LocationComponentOptions object to the " + + "LocationComponentActivationOptions builder. You can't use both and " + + "you must choose one of the two to style the LocationComponent."); } if (context == null) { throw new NullPointerException( - "Context in LocationComponentActivationOptions is null."); + "Context in LocationComponentActivationOptions is null."); } if (style == null) { throw new NullPointerException( - "Style in LocationComponentActivationOptions is null. Make sure the " - + "Style object isn't null. Wait for the map to fully load before passing " - + "the Style object to LocationComponentActivationOptions."); + "Style in LocationComponentActivationOptions is null. Make sure the " + + "Style object isn't null. Wait for the map to fully load before passing " + + "the Style object to LocationComponentActivationOptions."); } if (!style.isFullyLoaded()) { throw new IllegalArgumentException( - "Style in LocationComponentActivationOptions isn't fully loaded. Wait for the " - + "map to fully load before passing the Style object to " - + "LocationComponentActivationOptions."); + "Style in LocationComponentActivationOptions isn't fully loaded. Wait for the " + + "map to fully load before passing the Style object to " + + "LocationComponentActivationOptions."); } return new LocationComponentActivationOptions(context, style, locationEngine, - locationEngineRequest, locationComponentOptions, styleRes, useDefaultLocationEngine); + locationEngineRequest, locationComponentOptions, styleRes, useDefaultLocationEngine, + useSpecializedLocationLayer); } } } \ No newline at end of file diff --git a/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/LocationComponentConstants.java b/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/LocationComponentConstants.java index f2158584c..a3b4804b7 100644 --- a/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/LocationComponentConstants.java +++ b/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/LocationComponentConstants.java @@ -87,6 +87,7 @@ public final class LocationComponentConstants { static final String BACKGROUND_STALE_ICON = "mapbox-location-background-stale-icon"; static final String SHADOW_ICON = "mapbox-location-shadow-icon"; static final String BEARING_ICON = "mapbox-location-bearing-icon"; + static final String BEARING_STALE_ICON = "mapbox-location-bearing-stale-icon"; private LocationComponentConstants() { // Class should not be initialized diff --git a/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/LocationLayerController.java b/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/LocationLayerController.java index aeb011e81..556254297 100644 --- a/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/LocationLayerController.java +++ b/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/LocationLayerController.java @@ -2,28 +2,22 @@ package com.mapbox.mapboxsdk.location; import android.graphics.Bitmap; import android.graphics.PointF; -import androidx.annotation.ColorInt; + import androidx.annotation.NonNull; import androidx.annotation.Nullable; -import androidx.annotation.VisibleForTesting; -import com.google.gson.JsonArray; -import com.google.gson.JsonObject; import com.mapbox.geojson.Feature; -import com.mapbox.geojson.Point; import com.mapbox.mapboxsdk.geometry.LatLng; import com.mapbox.mapboxsdk.location.modes.RenderMode; +import com.mapbox.mapboxsdk.log.Logger; import com.mapbox.mapboxsdk.maps.MapboxMap; import com.mapbox.mapboxsdk.maps.Style; -import com.mapbox.mapboxsdk.style.layers.Layer; -import com.mapbox.mapboxsdk.style.layers.SymbolLayer; -import com.mapbox.mapboxsdk.style.sources.GeoJsonSource; +import com.mapbox.mapboxsdk.style.expressions.Expression; import java.util.HashSet; import java.util.List; import java.util.Set; -import static com.mapbox.mapboxsdk.location.LocationComponentConstants.ACCURACY_LAYER; import static com.mapbox.mapboxsdk.location.LocationComponentConstants.BACKGROUND_ICON; import static com.mapbox.mapboxsdk.location.LocationComponentConstants.BACKGROUND_LAYER; import static com.mapbox.mapboxsdk.location.LocationComponentConstants.BACKGROUND_STALE_ICON; @@ -32,71 +26,58 @@ import static com.mapbox.mapboxsdk.location.LocationComponentConstants.BEARING_L import static com.mapbox.mapboxsdk.location.LocationComponentConstants.FOREGROUND_ICON; import static com.mapbox.mapboxsdk.location.LocationComponentConstants.FOREGROUND_LAYER; import static com.mapbox.mapboxsdk.location.LocationComponentConstants.FOREGROUND_STALE_ICON; -import static com.mapbox.mapboxsdk.location.LocationComponentConstants.LOCATION_SOURCE; -import static com.mapbox.mapboxsdk.location.LocationComponentConstants.PROPERTY_ACCURACY_ALPHA; -import static com.mapbox.mapboxsdk.location.LocationComponentConstants.PROPERTY_ACCURACY_COLOR; -import static com.mapbox.mapboxsdk.location.LocationComponentConstants.PROPERTY_ACCURACY_RADIUS; -import static com.mapbox.mapboxsdk.location.LocationComponentConstants.PROPERTY_BACKGROUND_ICON; -import static com.mapbox.mapboxsdk.location.LocationComponentConstants.PROPERTY_BACKGROUND_STALE_ICON; -import static com.mapbox.mapboxsdk.location.LocationComponentConstants.PROPERTY_BEARING_ICON; -import static com.mapbox.mapboxsdk.location.LocationComponentConstants.PROPERTY_COMPASS_BEARING; -import static com.mapbox.mapboxsdk.location.LocationComponentConstants.PROPERTY_FOREGROUND_ICON; -import static com.mapbox.mapboxsdk.location.LocationComponentConstants.PROPERTY_FOREGROUND_ICON_OFFSET; -import static com.mapbox.mapboxsdk.location.LocationComponentConstants.PROPERTY_FOREGROUND_STALE_ICON; -import static com.mapbox.mapboxsdk.location.LocationComponentConstants.PROPERTY_GPS_BEARING; -import static com.mapbox.mapboxsdk.location.LocationComponentConstants.PROPERTY_LOCATION_STALE; -import static com.mapbox.mapboxsdk.location.LocationComponentConstants.PROPERTY_SHADOW_ICON_OFFSET; -import static com.mapbox.mapboxsdk.location.LocationComponentConstants.SHADOW_ICON; -import static com.mapbox.mapboxsdk.location.LocationComponentConstants.SHADOW_LAYER; import static com.mapbox.mapboxsdk.style.expressions.Expression.interpolate; import static com.mapbox.mapboxsdk.style.expressions.Expression.linear; import static com.mapbox.mapboxsdk.style.expressions.Expression.stop; import static com.mapbox.mapboxsdk.style.expressions.Expression.zoom; -import static com.mapbox.mapboxsdk.style.layers.Property.NONE; -import static com.mapbox.mapboxsdk.style.layers.Property.VISIBLE; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.iconSize; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.visibility; -import static com.mapbox.mapboxsdk.utils.ColorUtils.colorToRgbaString; final class LocationLayerController { + private static final String TAG = "Mbgl-LocationLayerController"; + @RenderMode.Mode private int renderMode; private final MapboxMap mapboxMap; private Style style; - private final LayerSourceProvider layerSourceProvider; private final LayerBitmapProvider bitmapProvider; private LocationComponentOptions options; private final OnRenderModeChangedListener internalRenderModeChangedListener; - - @VisibleForTesting - final Set layerSet = new HashSet<>(); - private Feature locationFeature; - private GeoJsonSource locationSource; + private final boolean useSpecializedLocationLayer; private boolean isHidden = true; + private boolean isStale; private LocationComponentPositionManager positionManager; - LocationLayerController(MapboxMap mapboxMap, Style style, LayerSourceProvider layerSourceProvider, - LayerFeatureProvider featureProvider, LayerBitmapProvider bitmapProvider, + private LocationLayerRenderer locationLayerRenderer; + + LocationLayerController(MapboxMap mapboxMap, Style style, + LayerSourceProvider layerSourceProvider, + LayerFeatureProvider featureProvider, + LayerBitmapProvider bitmapProvider, @NonNull LocationComponentOptions options, - @NonNull OnRenderModeChangedListener internalRenderModeChangedListener) { + @NonNull OnRenderModeChangedListener internalRenderModeChangedListener, + boolean useSpecializedLocationLayer) { this.mapboxMap = mapboxMap; this.style = style; - this.layerSourceProvider = layerSourceProvider; this.bitmapProvider = bitmapProvider; - this.locationFeature = featureProvider.generateLocationFeature(locationFeature, options); this.internalRenderModeChangedListener = internalRenderModeChangedListener; + this.useSpecializedLocationLayer = useSpecializedLocationLayer; + this.isStale = options.enableStaleState(); + if (useSpecializedLocationLayer) { + locationLayerRenderer = new IndicatorLocationLayerRenderer(style, layerSourceProvider); + } else { + locationLayerRenderer = new SymbolLocationLayerRenderer(style, layerSourceProvider, featureProvider, isStale); + } initializeComponents(style, options); } void initializeComponents(Style style, LocationComponentOptions options) { this.style = style; this.positionManager = new LocationComponentPositionManager(style, options.layerAbove(), options.layerBelow()); - addLocationSource(); - addLayers(); + locationLayerRenderer.initializeComponents(style); + locationLayerRenderer.addLayers(positionManager); applyStyle(options); if (isHidden) { @@ -108,24 +89,16 @@ final class LocationLayerController { void applyStyle(@NonNull LocationComponentOptions options) { if (positionManager.update(options.layerAbove(), options.layerBelow())) { - removeLayers(); - addLayers(); + locationLayerRenderer.removeLayers(); + locationLayerRenderer.addLayers(positionManager); if (isHidden) { hide(); } } this.options = options; - - float elevation = options.elevation(); - // Only add icon elevation if the values greater than 0. - if (elevation > 0) { - styleShadow(options); - } - styleForeground(options); - styleBackground(options); - styleBearing(options); - styleAccuracy(options.accuracyAlpha(), options.accuracyColor()); + styleBitmaps(options); + locationLayerRenderer.styleAccuracy(options.accuracyAlpha(), options.accuracyColor()); styleScaling(options); determineIconsSource(options); @@ -140,7 +113,7 @@ final class LocationLayerController { } this.renderMode = renderMode; - styleForeground(options); + styleBitmaps(options); determineIconsSource(options); if (!isHidden) { show(); @@ -158,59 +131,12 @@ final class LocationLayerController { void show() { isHidden = false; - boolean isStale = locationFeature.getBooleanProperty(PROPERTY_LOCATION_STALE); - switch (renderMode) { - case RenderMode.NORMAL: - setLayerVisibility(SHADOW_LAYER, true); - setLayerVisibility(FOREGROUND_LAYER, true); - setLayerVisibility(BACKGROUND_LAYER, true); - setLayerVisibility(ACCURACY_LAYER, !isStale); - setLayerVisibility(BEARING_LAYER, false); - break; - case RenderMode.COMPASS: - setLayerVisibility(SHADOW_LAYER, true); - setLayerVisibility(FOREGROUND_LAYER, true); - setLayerVisibility(BACKGROUND_LAYER, true); - setLayerVisibility(ACCURACY_LAYER, !isStale); - setLayerVisibility(BEARING_LAYER, true); - break; - case RenderMode.GPS: - setLayerVisibility(SHADOW_LAYER, false); - setLayerVisibility(FOREGROUND_LAYER, true); - setLayerVisibility(BACKGROUND_LAYER, true); - setLayerVisibility(ACCURACY_LAYER, false); - setLayerVisibility(BEARING_LAYER, false); - break; - default: - break; - } + locationLayerRenderer.show(renderMode, isStale); } void hide() { isHidden = true; - for (String layerId : layerSet) { - setLayerVisibility(layerId, false); - } - } - - void updateForegroundOffset(double tilt) { - JsonArray foregroundJsonArray = new JsonArray(); - foregroundJsonArray.add(0f); - foregroundJsonArray.add((float) (-0.05 * tilt)); - locationFeature.addProperty(PROPERTY_FOREGROUND_ICON_OFFSET, foregroundJsonArray); - - JsonArray backgroundJsonArray = new JsonArray(); - backgroundJsonArray.add(0f); - backgroundJsonArray.add((float) (0.05 * tilt)); - locationFeature.addProperty(PROPERTY_SHADOW_ICON_OFFSET, backgroundJsonArray); - - refreshSource(); - } - - void updateForegroundBearing(float bearing) { - if (renderMode != RenderMode.GPS) { - setBearingProperty(PROPERTY_GPS_BEARING, bearing); - } + locationLayerRenderer.hide(); } boolean isHidden() { @@ -221,148 +147,63 @@ final class LocationLayerController { return renderMode == RenderMode.COMPASS; } - private void setLayerVisibility(@NonNull String layerId, boolean visible) { - Layer layer = style.getLayer(layerId); - if (layer != null) { - String targetVisibility = visible ? VISIBLE : NONE; - if (!layer.getVisibility().value.equals(targetVisibility)) { - layer.setProperties(visibility(visible ? VISIBLE : NONE)); - } - } - } - - private void addLayers() { - // positions the top-most reference layer - Layer layer = layerSourceProvider.generateLayer(BEARING_LAYER); - positionManager.addLayerToMap(layer); - layerSet.add(layer.getId()); - - // adds remaining layers while keeping the order - addSymbolLayer(FOREGROUND_LAYER, BEARING_LAYER); - addSymbolLayer(BACKGROUND_LAYER, FOREGROUND_LAYER); - addSymbolLayer(SHADOW_LAYER, BACKGROUND_LAYER); - addAccuracyLayer(); - } - - private void addSymbolLayer(@NonNull String layerId, @NonNull String beforeLayerId) { - Layer layer = layerSourceProvider.generateLayer(layerId); - addLayerToMap(layer, beforeLayerId); - } - - private void addAccuracyLayer() { - Layer accuracyLayer = layerSourceProvider.generateAccuracyLayer(); - addLayerToMap(accuracyLayer, BACKGROUND_LAYER); - } - - private void addLayerToMap(Layer layer, @NonNull String idBelowLayer) { - style.addLayerBelow(layer, idBelowLayer); - layerSet.add(layer.getId()); - } - - private void removeLayers() { - for (String layerId : layerSet) { - style.removeLayer(layerId); - } - layerSet.clear(); - } - - private void setBearingProperty(@NonNull String propertyId, float bearing) { - locationFeature.addNumberProperty(propertyId, bearing); - refreshSource(); - } - - private void updateAccuracyRadius(float accuracy) { - locationFeature.addNumberProperty(PROPERTY_ACCURACY_RADIUS, accuracy); - refreshSource(); - } - - // - // Source actions - // - - private void addLocationSource() { - locationSource = layerSourceProvider.generateSource(locationFeature); - style.addSource(locationSource); - } - - private void refreshSource() { - GeoJsonSource source = style.getSourceAs(LOCATION_SOURCE); - if (source != null) { - locationSource.setGeoJson(locationFeature); - } - } - - private void setLocationPoint(Point locationPoint) { - JsonObject properties = locationFeature.properties(); - if (properties != null) { - locationFeature = Feature.fromGeometry(locationPoint, properties); - refreshSource(); - } - } - // // Styling // - private void styleBackground(LocationComponentOptions options) { + private void styleBitmaps(LocationComponentOptions options) { + // shadow + Bitmap shadowBitmap = null; + if (options.elevation() > 0) { + // Only add icon elevation if the values greater than 0. + shadowBitmap = bitmapProvider.generateShadowBitmap(options); + } + + // background Bitmap backgroundBitmap = bitmapProvider.generateBitmap( options.backgroundDrawable(), options.backgroundTintColor() ); Bitmap backgroundStaleBitmap = bitmapProvider.generateBitmap( options.backgroundDrawableStale(), options.backgroundStaleTintColor() ); - style.addImage(BACKGROUND_ICON, backgroundBitmap); - style.addImage(BACKGROUND_STALE_ICON, backgroundStaleBitmap); - } - private void styleShadow(@NonNull LocationComponentOptions options) { - style.addImage(SHADOW_ICON, bitmapProvider.generateShadowBitmap(options)); - } - - private void styleBearing(LocationComponentOptions options) { + // compass bearing Bitmap bearingBitmap = bitmapProvider.generateBitmap(options.bearingDrawable(), options.bearingTintColor()); - style.addImage(BEARING_ICON, bearingBitmap); - } - private void styleAccuracy(float accuracyAlpha, @ColorInt int accuracyColor) { - locationFeature.addNumberProperty(PROPERTY_ACCURACY_ALPHA, accuracyAlpha); - locationFeature.addStringProperty(PROPERTY_ACCURACY_COLOR, colorToRgbaString(accuracyColor)); - refreshSource(); - } - - private void styleForeground(LocationComponentOptions options) { + // foreground Bitmap foregroundBitmap = bitmapProvider.generateBitmap( options.foregroundDrawable(), options.foregroundTintColor() ); - Bitmap foregroundBitmapStale = bitmapProvider.generateBitmap( + Bitmap foregroundStaleBitmap = bitmapProvider.generateBitmap( options.foregroundDrawableStale(), options.foregroundStaleTintColor() ); if (renderMode == RenderMode.GPS) { foregroundBitmap = bitmapProvider.generateBitmap( options.gpsDrawable(), options.foregroundTintColor() ); - foregroundBitmapStale = bitmapProvider.generateBitmap( + foregroundStaleBitmap = bitmapProvider.generateBitmap( options.gpsDrawable(), options.foregroundStaleTintColor() ); } - style.addImage(FOREGROUND_ICON, foregroundBitmap); - style.addImage(FOREGROUND_STALE_ICON, foregroundBitmapStale); + + locationLayerRenderer.addBitmaps( + renderMode, + shadowBitmap, + backgroundBitmap, + backgroundStaleBitmap, + bearingBitmap, + foregroundBitmap, + foregroundStaleBitmap + ); } private void styleScaling(@NonNull LocationComponentOptions options) { - for (String layerId : layerSet) { - Layer layer = style.getLayer(layerId); - if (layer instanceof SymbolLayer) { - layer.setProperties( - iconSize( - interpolate(linear(), zoom(), - stop(mapboxMap.getMinZoomLevel(), options.minZoomIconScale()), - stop(mapboxMap.getMaxZoomLevel(), options.maxZoomIconScale()) - ) - ) - ); - } - } + Expression scaleExpression = interpolate(linear(), zoom(), + stop(mapboxMap.getMinZoomLevel(), options.minZoomIconScale()), + stop(mapboxMap.getMaxZoomLevel(), options.maxZoomIconScale()) + ); + + locationLayerRenderer.styleScaling(scaleExpression); } private void determineIconsSource(LocationComponentOptions options) { @@ -373,28 +214,30 @@ final class LocationLayerController { String backgroundStaleIconString = buildIconString(options.backgroundStaleName(), BACKGROUND_STALE_ICON); String bearingIconString = buildIconString(options.bearingName(), BEARING_ICON); - locationFeature.addStringProperty(PROPERTY_FOREGROUND_ICON, foregroundIconString); - locationFeature.addStringProperty(PROPERTY_BACKGROUND_ICON, backgroundIconString); - locationFeature.addStringProperty(PROPERTY_FOREGROUND_STALE_ICON, foregroundStaleIconString); - locationFeature.addStringProperty(PROPERTY_BACKGROUND_STALE_ICON, backgroundStaleIconString); - locationFeature.addStringProperty(PROPERTY_BEARING_ICON, bearingIconString); - refreshSource(); + locationLayerRenderer.updateIconIds( + foregroundIconString, + foregroundStaleIconString, + backgroundIconString, + backgroundStaleIconString, + bearingIconString + ); } @NonNull private String buildIconString(@Nullable String bitmapName, @NonNull String drawableName) { if (bitmapName != null) { + if (useSpecializedLocationLayer) { + Logger.e(TAG, bitmapName + " replacement ID provided for an unsupported specialized location layer"); + return drawableName; + } return bitmapName; } return drawableName; } void setLocationsStale(boolean isStale) { - locationFeature.addBooleanProperty(PROPERTY_LOCATION_STALE, isStale); - refreshSource(); - if (renderMode != RenderMode.GPS) { - setLayerVisibility(ACCURACY_LAYER, !isStale); - } + this.isStale = isStale; + locationLayerRenderer.setLocationStale(isStale, renderMode); } // @@ -415,8 +258,7 @@ final class LocationLayerController { new MapboxAnimator.AnimationsValueChangeListener() { @Override public void onNewAnimationValue(LatLng value) { - Point point = Point.fromLngLat(value.getLongitude(), value.getLatitude()); - setLocationPoint(point); + locationLayerRenderer.setLatLng(value); } }; @@ -424,7 +266,7 @@ final class LocationLayerController { new MapboxAnimator.AnimationsValueChangeListener() { @Override public void onNewAnimationValue(Float value) { - setBearingProperty(PROPERTY_GPS_BEARING, value); + locationLayerRenderer.setGpsBearing(value); } }; @@ -432,7 +274,7 @@ final class LocationLayerController { new MapboxAnimator.AnimationsValueChangeListener() { @Override public void onNewAnimationValue(Float value) { - setBearingProperty(PROPERTY_COMPASS_BEARING, value); + locationLayerRenderer.setCompassBearing(value); } }; @@ -440,7 +282,7 @@ final class LocationLayerController { new MapboxAnimator.AnimationsValueChangeListener() { @Override public void onNewAnimationValue(Float value) { - updateAccuracyRadius(value); + locationLayerRenderer.setAccuracyRadius(value); } }; @@ -461,4 +303,14 @@ final class LocationLayerController { return holders; } + + void cameraBearingUpdated(double bearing) { + if (renderMode != RenderMode.GPS) { + locationLayerRenderer.cameraBearingUpdated(bearing); + } + } + + void cameraTiltUpdated(double tilt) { + locationLayerRenderer.cameraTiltUpdated(tilt); + } } \ No newline at end of file diff --git a/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/LocationLayerRenderer.java b/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/LocationLayerRenderer.java new file mode 100644 index 000000000..01d4d1272 --- /dev/null +++ b/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/LocationLayerRenderer.java @@ -0,0 +1,47 @@ +package com.mapbox.mapboxsdk.location; + +import android.graphics.Bitmap; + +import androidx.annotation.Nullable; + +import com.mapbox.mapboxsdk.geometry.LatLng; +import com.mapbox.mapboxsdk.location.modes.RenderMode; +import com.mapbox.mapboxsdk.maps.Style; +import com.mapbox.mapboxsdk.style.expressions.Expression; + +interface LocationLayerRenderer { + void initializeComponents(Style style); + + void addLayers(LocationComponentPositionManager positionManager); + + void removeLayers(); + + void hide(); + + void cameraTiltUpdated(double tilt); + + void cameraBearingUpdated(double bearing); + + void show(@RenderMode.Mode int renderMode, boolean isStale); + + void styleAccuracy(float accuracyAlpha, int accuracyColor); + + void setLatLng(LatLng latLng); + + void setGpsBearing(Float gpsBearing); + + void setCompassBearing(Float compassBearing); + + void setAccuracyRadius(Float accuracy); + + void styleScaling(Expression scaleExpression); + + void setLocationStale(boolean isStale, int renderMode); + + void updateIconIds(String foregroundIconString, String foregroundStaleIconString, String backgroundIconString, + String backgroundStaleIconString, String bearingIconString); + + void addBitmaps(@RenderMode.Mode int renderMode, @Nullable Bitmap shadowBitmap, Bitmap backgroundBitmap, + Bitmap backgroundStaleBitmap, Bitmap bearingBitmap, + Bitmap foregroundBitmap, Bitmap foregroundStaleBitmap); +} diff --git a/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/SymbolLocationLayerRenderer.java b/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/SymbolLocationLayerRenderer.java new file mode 100644 index 000000000..7ad336313 --- /dev/null +++ b/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/SymbolLocationLayerRenderer.java @@ -0,0 +1,293 @@ +package com.mapbox.mapboxsdk.location; + +import android.graphics.Bitmap; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; + +import com.google.gson.JsonArray; +import com.google.gson.JsonObject; +import com.mapbox.geojson.Feature; +import com.mapbox.geojson.Point; +import com.mapbox.mapboxsdk.geometry.LatLng; +import com.mapbox.mapboxsdk.location.modes.RenderMode; +import com.mapbox.mapboxsdk.maps.Style; +import com.mapbox.mapboxsdk.style.expressions.Expression; +import com.mapbox.mapboxsdk.style.layers.Layer; +import com.mapbox.mapboxsdk.style.layers.SymbolLayer; +import com.mapbox.mapboxsdk.style.sources.GeoJsonSource; + +import java.util.Set; + +import static com.mapbox.mapboxsdk.location.LocationComponentConstants.ACCURACY_LAYER; +import static com.mapbox.mapboxsdk.location.LocationComponentConstants.BACKGROUND_ICON; +import static com.mapbox.mapboxsdk.location.LocationComponentConstants.BACKGROUND_LAYER; +import static com.mapbox.mapboxsdk.location.LocationComponentConstants.BACKGROUND_STALE_ICON; +import static com.mapbox.mapboxsdk.location.LocationComponentConstants.BEARING_ICON; +import static com.mapbox.mapboxsdk.location.LocationComponentConstants.BEARING_LAYER; +import static com.mapbox.mapboxsdk.location.LocationComponentConstants.FOREGROUND_ICON; +import static com.mapbox.mapboxsdk.location.LocationComponentConstants.FOREGROUND_LAYER; +import static com.mapbox.mapboxsdk.location.LocationComponentConstants.FOREGROUND_STALE_ICON; +import static com.mapbox.mapboxsdk.location.LocationComponentConstants.LOCATION_SOURCE; +import static com.mapbox.mapboxsdk.location.LocationComponentConstants.PROPERTY_ACCURACY_ALPHA; +import static com.mapbox.mapboxsdk.location.LocationComponentConstants.PROPERTY_ACCURACY_COLOR; +import static com.mapbox.mapboxsdk.location.LocationComponentConstants.PROPERTY_ACCURACY_RADIUS; +import static com.mapbox.mapboxsdk.location.LocationComponentConstants.PROPERTY_BACKGROUND_ICON; +import static com.mapbox.mapboxsdk.location.LocationComponentConstants.PROPERTY_BACKGROUND_STALE_ICON; +import static com.mapbox.mapboxsdk.location.LocationComponentConstants.PROPERTY_BEARING_ICON; +import static com.mapbox.mapboxsdk.location.LocationComponentConstants.PROPERTY_COMPASS_BEARING; +import static com.mapbox.mapboxsdk.location.LocationComponentConstants.PROPERTY_FOREGROUND_ICON; +import static com.mapbox.mapboxsdk.location.LocationComponentConstants.PROPERTY_FOREGROUND_ICON_OFFSET; +import static com.mapbox.mapboxsdk.location.LocationComponentConstants.PROPERTY_FOREGROUND_STALE_ICON; +import static com.mapbox.mapboxsdk.location.LocationComponentConstants.PROPERTY_GPS_BEARING; +import static com.mapbox.mapboxsdk.location.LocationComponentConstants.PROPERTY_LOCATION_STALE; +import static com.mapbox.mapboxsdk.location.LocationComponentConstants.PROPERTY_SHADOW_ICON_OFFSET; +import static com.mapbox.mapboxsdk.location.LocationComponentConstants.SHADOW_ICON; +import static com.mapbox.mapboxsdk.location.LocationComponentConstants.SHADOW_LAYER; +import static com.mapbox.mapboxsdk.style.layers.Property.NONE; +import static com.mapbox.mapboxsdk.style.layers.Property.VISIBLE; +import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.iconSize; +import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.visibility; +import static com.mapbox.mapboxsdk.utils.ColorUtils.colorToRgbaString; + +final class SymbolLocationLayerRenderer implements LocationLayerRenderer { + private Style style; + private final LayerSourceProvider layerSourceProvider; + + private final Set layerSet; + private Feature locationFeature; + private GeoJsonSource locationSource; + + SymbolLocationLayerRenderer(Style style, + LayerSourceProvider layerSourceProvider, + LayerFeatureProvider featureProvider, + boolean isStale) { + this.style = style; + this.layerSourceProvider = layerSourceProvider; + this.layerSet = layerSourceProvider.getEmptyLayerSet(); + this.locationFeature = featureProvider.generateLocationFeature(locationFeature, isStale); + } + + @Override + public void initializeComponents(Style style) { + this.style = style; + addLocationSource(); + } + + @Override + public void addLayers(LocationComponentPositionManager positionManager) { + // positions the top-most reference layer + Layer layer = layerSourceProvider.generateLayer(BEARING_LAYER); + positionManager.addLayerToMap(layer); + layerSet.add(layer.getId()); + + // adds remaining layers while keeping the order + addSymbolLayer(FOREGROUND_LAYER, BEARING_LAYER); + addSymbolLayer(BACKGROUND_LAYER, FOREGROUND_LAYER); + addSymbolLayer(SHADOW_LAYER, BACKGROUND_LAYER); + addAccuracyLayer(); + } + + @Override + public void removeLayers() { + for (String layerId : layerSet) { + style.removeLayer(layerId); + } + layerSet.clear(); + } + + @Override + public void hide() { + for (String layerId : layerSet) { + setLayerVisibility(layerId, false); + } + } + + @Override + public void cameraTiltUpdated(double tilt) { + updateForegroundOffset(tilt); + } + + @Override + public void cameraBearingUpdated(double bearing) { + updateForegroundBearing((float) bearing); + } + + @Override + public void show(@RenderMode.Mode int renderMode, boolean isStale) { + switch (renderMode) { + case RenderMode.NORMAL: + setLayerVisibility(SHADOW_LAYER, true); + setLayerVisibility(FOREGROUND_LAYER, true); + setLayerVisibility(BACKGROUND_LAYER, true); + setLayerVisibility(ACCURACY_LAYER, !isStale); + setLayerVisibility(BEARING_LAYER, false); + break; + case RenderMode.COMPASS: + setLayerVisibility(SHADOW_LAYER, true); + setLayerVisibility(FOREGROUND_LAYER, true); + setLayerVisibility(BACKGROUND_LAYER, true); + setLayerVisibility(ACCURACY_LAYER, !isStale); + setLayerVisibility(BEARING_LAYER, true); + break; + case RenderMode.GPS: + setLayerVisibility(SHADOW_LAYER, false); + setLayerVisibility(FOREGROUND_LAYER, true); + setLayerVisibility(BACKGROUND_LAYER, true); + setLayerVisibility(ACCURACY_LAYER, false); + setLayerVisibility(BEARING_LAYER, false); + break; + default: + break; + } + } + + @Override + public void styleAccuracy(float accuracyAlpha, int accuracyColor) { + locationFeature.addNumberProperty(PROPERTY_ACCURACY_ALPHA, accuracyAlpha); + locationFeature.addStringProperty(PROPERTY_ACCURACY_COLOR, colorToRgbaString(accuracyColor)); + refreshSource(); + } + + @Override + public void setLatLng(LatLng latLng) { + Point point = Point.fromLngLat(latLng.getLongitude(), latLng.getLatitude()); + setLocationPoint(point); + } + + @Override + public void setGpsBearing(Float gpsBearing) { + setBearingProperty(PROPERTY_GPS_BEARING, gpsBearing); + } + + @Override + public void setCompassBearing(Float compassBearing) { + setBearingProperty(PROPERTY_COMPASS_BEARING, compassBearing); + } + + @Override + public void setAccuracyRadius(Float accuracy) { + updateAccuracyRadius(accuracy); + } + + @Override + public void styleScaling(Expression scaleExpression) { + for (String layerId : layerSet) { + Layer layer = style.getLayer(layerId); + if (layer instanceof SymbolLayer) { + layer.setProperties( + iconSize(scaleExpression) + ); + } + } + } + + @Override + public void setLocationStale(boolean isStale, int renderMode) { + locationFeature.addBooleanProperty(PROPERTY_LOCATION_STALE, isStale); + refreshSource(); + if (renderMode != RenderMode.GPS) { + setLayerVisibility(ACCURACY_LAYER, !isStale); + } + } + + @Override + public void updateIconIds(String foregroundIconString, String foregroundStaleIconString, String backgroundIconString, + String backgroundStaleIconString, String bearingIconString) { + locationFeature.addStringProperty(PROPERTY_FOREGROUND_ICON, foregroundIconString); + locationFeature.addStringProperty(PROPERTY_BACKGROUND_ICON, backgroundIconString); + locationFeature.addStringProperty(PROPERTY_FOREGROUND_STALE_ICON, foregroundStaleIconString); + locationFeature.addStringProperty(PROPERTY_BACKGROUND_STALE_ICON, backgroundStaleIconString); + locationFeature.addStringProperty(PROPERTY_BEARING_ICON, bearingIconString); + refreshSource(); + } + + @Override + public void addBitmaps(@RenderMode.Mode int renderMode, @Nullable Bitmap shadowBitmap, Bitmap backgroundBitmap, + Bitmap backgroundStaleBitmap, Bitmap bearingBitmap, + Bitmap foregroundBitmap, Bitmap foregroundBitmapStale) { + if (shadowBitmap != null) { + style.addImage(SHADOW_ICON, shadowBitmap); + } else { + style.removeImage(SHADOW_ICON); + } + style.addImage(BACKGROUND_ICON, backgroundBitmap); + style.addImage(BACKGROUND_STALE_ICON, backgroundStaleBitmap); + style.addImage(BEARING_ICON, bearingBitmap); + style.addImage(FOREGROUND_ICON, foregroundBitmap); + style.addImage(FOREGROUND_STALE_ICON, foregroundBitmapStale); + } + + private void updateForegroundOffset(double tilt) { + JsonArray foregroundJsonArray = new JsonArray(); + foregroundJsonArray.add(0f); + foregroundJsonArray.add((float) (-0.05 * tilt)); + locationFeature.addProperty(PROPERTY_FOREGROUND_ICON_OFFSET, foregroundJsonArray); + + JsonArray backgroundJsonArray = new JsonArray(); + backgroundJsonArray.add(0f); + backgroundJsonArray.add((float) (0.05 * tilt)); + locationFeature.addProperty(PROPERTY_SHADOW_ICON_OFFSET, backgroundJsonArray); + + refreshSource(); + } + + private void updateForegroundBearing(float bearing) { + setBearingProperty(PROPERTY_GPS_BEARING, bearing); + } + + private void setLayerVisibility(@NonNull String layerId, boolean visible) { + Layer layer = style.getLayer(layerId); + if (layer != null) { + String targetVisibility = visible ? VISIBLE : NONE; + if (!layer.getVisibility().value.equals(targetVisibility)) { + layer.setProperties(visibility(visible ? VISIBLE : NONE)); + } + } + } + + private void addSymbolLayer(@NonNull String layerId, @NonNull String beforeLayerId) { + Layer layer = layerSourceProvider.generateLayer(layerId); + addLayerToMap(layer, beforeLayerId); + } + + private void addAccuracyLayer() { + Layer accuracyLayer = layerSourceProvider.generateAccuracyLayer(); + addLayerToMap(accuracyLayer, BACKGROUND_LAYER); + } + + private void addLayerToMap(Layer layer, @NonNull String idBelowLayer) { + style.addLayerBelow(layer, idBelowLayer); + layerSet.add(layer.getId()); + } + + private void addLocationSource() { + locationSource = layerSourceProvider.generateSource(locationFeature); + style.addSource(locationSource); + } + + private void refreshSource() { + GeoJsonSource source = style.getSourceAs(LOCATION_SOURCE); + if (source != null) { + locationSource.setGeoJson(locationFeature); + } + } + + private void setLocationPoint(Point locationPoint) { + JsonObject properties = locationFeature.properties(); + if (properties != null) { + locationFeature = Feature.fromGeometry(locationPoint, properties); + refreshSource(); + } + } + + private void setBearingProperty(@NonNull String propertyId, float bearing) { + locationFeature.addNumberProperty(propertyId, bearing); + refreshSource(); + } + + private void updateAccuracyRadius(float accuracy) { + locationFeature.addNumberProperty(PROPERTY_ACCURACY_RADIUS, accuracy); + refreshSource(); + } +} diff --git a/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/LocationIndicatorLayer.java b/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/LocationIndicatorLayer.java new file mode 100644 index 000000000..eefd65924 --- /dev/null +++ b/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/LocationIndicatorLayer.java @@ -0,0 +1,565 @@ +// This file is generated. Edit android/platform/scripts/generate-style-code.js, then run `make android-style-code`. + +package com.mapbox.mapboxsdk.style.layers; + +import androidx.annotation.ColorInt; +import androidx.annotation.Keep; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.annotation.UiThread; + +import static com.mapbox.mapboxsdk.utils.ColorUtils.rgbaToColor; + +import com.google.gson.JsonArray; +import com.google.gson.JsonElement; +import com.mapbox.mapboxsdk.style.expressions.Expression; +import com.mapbox.mapboxsdk.style.layers.TransitionOptions; + +/** + * + * + * @see The online documentation + */ +@UiThread +public class LocationIndicatorLayer extends Layer { + + /** + * Creates a LocationIndicatorLayer. + * + * @param nativePtr pointer used by core + */ + @Keep + LocationIndicatorLayer(long nativePtr) { + super(nativePtr); + } + + /** + * Creates a LocationIndicatorLayer. + * + * @param layerId the id of the layer + */ + public LocationIndicatorLayer(String layerId) { + super(); + initialize(layerId); + } + + @Keep + protected native void initialize(String layerId); + + /** + * Get the source id. + * + * @return id of the source + */ + @NonNull + public String getSourceId() { + checkThread(); + return nativeGetSourceId(); + } + + /** + * Get the source layer. + * + * @return sourceLayer the source layer to get + */ + @NonNull + public String getSourceLayer() { + checkThread(); + return nativeGetSourceLayer(); + } + + /** + * Set a single expression filter. + * + * @param filter the expression filter to set + */ + public void setFilter(@NonNull Expression filter) { + checkThread(); + nativeSetFilter(filter.toArray()); + } + + /** + * Set a single expression filter. + * + * @param filter the expression filter to set + * @return This + */ + @NonNull + public LocationIndicatorLayer withFilter(@NonNull Expression filter) { + setFilter(filter); + return this; + } + + /** + * Get a single expression filter. + * + * @return the expression filter to get + */ + @Nullable + public Expression getFilter() { + checkThread(); + JsonElement jsonElement = nativeGetFilter(); + if (jsonElement != null) { + return Expression.Converter.convert(jsonElement); + } else { + return null; + } + } + + /** + * Set a property or properties. + * + * @param properties the var-args properties + * @return This + */ + @NonNull + public LocationIndicatorLayer withProperties(@NonNull PropertyValue... properties) { + setProperties(properties); + return this; + } + + // Property getters + + /** + * Get the TopImage property + * + * @return property wrapper value around String + */ + @NonNull + @SuppressWarnings("unchecked") + public PropertyValue getTopImage() { + checkThread(); + return (PropertyValue) new PropertyValue("top-image", nativeGetTopImage()); + } + + /** + * Get the BearingImage property + * + * @return property wrapper value around String + */ + @NonNull + @SuppressWarnings("unchecked") + public PropertyValue getBearingImage() { + checkThread(); + return (PropertyValue) new PropertyValue("bearing-image", nativeGetBearingImage()); + } + + /** + * Get the ShadowImage property + * + * @return property wrapper value around String + */ + @NonNull + @SuppressWarnings("unchecked") + public PropertyValue getShadowImage() { + checkThread(); + return (PropertyValue) new PropertyValue("shadow-image", nativeGetShadowImage()); + } + + /** + * Get the PerspectiveCompensation property + * + * @return property wrapper value around Float + */ + @NonNull + @SuppressWarnings("unchecked") + public PropertyValue getPerspectiveCompensation() { + checkThread(); + return (PropertyValue) new PropertyValue("perspective-compensation", nativeGetPerspectiveCompensation()); + } + + /** + * Get the ImageTiltDisplacement property + * + * @return property wrapper value around Float + */ + @NonNull + @SuppressWarnings("unchecked") + public PropertyValue getImageTiltDisplacement() { + checkThread(); + return (PropertyValue) new PropertyValue("image-tilt-displacement", nativeGetImageTiltDisplacement()); + } + + /** + * Get the Bearing property + * + * @return property wrapper value around Double + */ + @NonNull + @SuppressWarnings("unchecked") + public PropertyValue getBearing() { + checkThread(); + return (PropertyValue) new PropertyValue("bearing", nativeGetBearing()); + } + + /** + * Get the Location property + * + * @return property wrapper value around Double[] + */ + @NonNull + @SuppressWarnings("unchecked") + public PropertyValue getLocation() { + checkThread(); + return (PropertyValue) new PropertyValue("location", nativeGetLocation()); + } + + /** + * Get the Location property transition options + * + * @return transition options for Double[] + */ + @NonNull + public TransitionOptions getLocationTransition() { + checkThread(); + return nativeGetLocationTransition(); + } + + /** + * Set the Location property transition options + * + * @param options transition options for Double[] + */ + public void setLocationTransition(@NonNull TransitionOptions options) { + checkThread(); + nativeSetLocationTransition(options.getDuration(), options.getDelay()); + } + + /** + * Get the AccuracyRadius property + * + * @return property wrapper value around Float + */ + @NonNull + @SuppressWarnings("unchecked") + public PropertyValue getAccuracyRadius() { + checkThread(); + return (PropertyValue) new PropertyValue("accuracy-radius", nativeGetAccuracyRadius()); + } + + /** + * Get the AccuracyRadius property transition options + * + * @return transition options for Float + */ + @NonNull + public TransitionOptions getAccuracyRadiusTransition() { + checkThread(); + return nativeGetAccuracyRadiusTransition(); + } + + /** + * Set the AccuracyRadius property transition options + * + * @param options transition options for Float + */ + public void setAccuracyRadiusTransition(@NonNull TransitionOptions options) { + checkThread(); + nativeSetAccuracyRadiusTransition(options.getDuration(), options.getDelay()); + } + + /** + * Get the TopImageSize property + * + * @return property wrapper value around Float + */ + @NonNull + @SuppressWarnings("unchecked") + public PropertyValue getTopImageSize() { + checkThread(); + return (PropertyValue) new PropertyValue("top-image-size", nativeGetTopImageSize()); + } + + /** + * Get the TopImageSize property transition options + * + * @return transition options for Float + */ + @NonNull + public TransitionOptions getTopImageSizeTransition() { + checkThread(); + return nativeGetTopImageSizeTransition(); + } + + /** + * Set the TopImageSize property transition options + * + * @param options transition options for Float + */ + public void setTopImageSizeTransition(@NonNull TransitionOptions options) { + checkThread(); + nativeSetTopImageSizeTransition(options.getDuration(), options.getDelay()); + } + + /** + * Get the BearingImageSize property + * + * @return property wrapper value around Float + */ + @NonNull + @SuppressWarnings("unchecked") + public PropertyValue getBearingImageSize() { + checkThread(); + return (PropertyValue) new PropertyValue("bearing-image-size", nativeGetBearingImageSize()); + } + + /** + * Get the BearingImageSize property transition options + * + * @return transition options for Float + */ + @NonNull + public TransitionOptions getBearingImageSizeTransition() { + checkThread(); + return nativeGetBearingImageSizeTransition(); + } + + /** + * Set the BearingImageSize property transition options + * + * @param options transition options for Float + */ + public void setBearingImageSizeTransition(@NonNull TransitionOptions options) { + checkThread(); + nativeSetBearingImageSizeTransition(options.getDuration(), options.getDelay()); + } + + /** + * Get the ShadowImageSize property + * + * @return property wrapper value around Float + */ + @NonNull + @SuppressWarnings("unchecked") + public PropertyValue getShadowImageSize() { + checkThread(); + return (PropertyValue) new PropertyValue("shadow-image-size", nativeGetShadowImageSize()); + } + + /** + * Get the ShadowImageSize property transition options + * + * @return transition options for Float + */ + @NonNull + public TransitionOptions getShadowImageSizeTransition() { + checkThread(); + return nativeGetShadowImageSizeTransition(); + } + + /** + * Set the ShadowImageSize property transition options + * + * @param options transition options for Float + */ + public void setShadowImageSizeTransition(@NonNull TransitionOptions options) { + checkThread(); + nativeSetShadowImageSizeTransition(options.getDuration(), options.getDelay()); + } + + /** + * Get the AccuracyRadiusColor property + * + * @return property wrapper value around String + */ + @NonNull + @SuppressWarnings("unchecked") + public PropertyValue getAccuracyRadiusColor() { + checkThread(); + return (PropertyValue) new PropertyValue("accuracy-radius-color", nativeGetAccuracyRadiusColor()); + } + + /** + * The color for drawing the accuracy radius, as a circle. To adjust transparency, set the alpha component of the color accordingly. + * + * @return int representation of a rgba string color + * @throws RuntimeException thrown if property isn't a value + */ + @ColorInt + public int getAccuracyRadiusColorAsInt() { + checkThread(); + PropertyValue value = getAccuracyRadiusColor(); + if (value.isValue()) { + return rgbaToColor(value.getValue()); + } else { + throw new RuntimeException("accuracy-radius-color was set as a Function"); + } + } + + /** + * Get the AccuracyRadiusColor property transition options + * + * @return transition options for String + */ + @NonNull + public TransitionOptions getAccuracyRadiusColorTransition() { + checkThread(); + return nativeGetAccuracyRadiusColorTransition(); + } + + /** + * Set the AccuracyRadiusColor property transition options + * + * @param options transition options for String + */ + public void setAccuracyRadiusColorTransition(@NonNull TransitionOptions options) { + checkThread(); + nativeSetAccuracyRadiusColorTransition(options.getDuration(), options.getDelay()); + } + + /** + * Get the AccuracyRadiusBorderColor property + * + * @return property wrapper value around String + */ + @NonNull + @SuppressWarnings("unchecked") + public PropertyValue getAccuracyRadiusBorderColor() { + checkThread(); + return (PropertyValue) new PropertyValue("accuracy-radius-border-color", nativeGetAccuracyRadiusBorderColor()); + } + + /** + * The color for drawing the accuracy radius border. To adjust transparency, set the alpha component of the color accordingly. + * + * @return int representation of a rgba string color + * @throws RuntimeException thrown if property isn't a value + */ + @ColorInt + public int getAccuracyRadiusBorderColorAsInt() { + checkThread(); + PropertyValue value = getAccuracyRadiusBorderColor(); + if (value.isValue()) { + return rgbaToColor(value.getValue()); + } else { + throw new RuntimeException("accuracy-radius-border-color was set as a Function"); + } + } + + /** + * Get the AccuracyRadiusBorderColor property transition options + * + * @return transition options for String + */ + @NonNull + public TransitionOptions getAccuracyRadiusBorderColorTransition() { + checkThread(); + return nativeGetAccuracyRadiusBorderColorTransition(); + } + + /** + * Set the AccuracyRadiusBorderColor property transition options + * + * @param options transition options for String + */ + public void setAccuracyRadiusBorderColorTransition(@NonNull TransitionOptions options) { + checkThread(); + nativeSetAccuracyRadiusBorderColorTransition(options.getDuration(), options.getDelay()); + } + + @NonNull + @Keep + private native Object nativeGetTopImage(); + + @NonNull + @Keep + private native Object nativeGetBearingImage(); + + @NonNull + @Keep + private native Object nativeGetShadowImage(); + + @NonNull + @Keep + private native Object nativeGetPerspectiveCompensation(); + + @NonNull + @Keep + private native Object nativeGetImageTiltDisplacement(); + + @NonNull + @Keep + private native Object nativeGetBearing(); + + @NonNull + @Keep + private native Object nativeGetLocation(); + + @NonNull + @Keep + private native TransitionOptions nativeGetLocationTransition(); + + @Keep + private native void nativeSetLocationTransition(long duration, long delay); + + @NonNull + @Keep + private native Object nativeGetAccuracyRadius(); + + @NonNull + @Keep + private native TransitionOptions nativeGetAccuracyRadiusTransition(); + + @Keep + private native void nativeSetAccuracyRadiusTransition(long duration, long delay); + + @NonNull + @Keep + private native Object nativeGetTopImageSize(); + + @NonNull + @Keep + private native TransitionOptions nativeGetTopImageSizeTransition(); + + @Keep + private native void nativeSetTopImageSizeTransition(long duration, long delay); + + @NonNull + @Keep + private native Object nativeGetBearingImageSize(); + + @NonNull + @Keep + private native TransitionOptions nativeGetBearingImageSizeTransition(); + + @Keep + private native void nativeSetBearingImageSizeTransition(long duration, long delay); + + @NonNull + @Keep + private native Object nativeGetShadowImageSize(); + + @NonNull + @Keep + private native TransitionOptions nativeGetShadowImageSizeTransition(); + + @Keep + private native void nativeSetShadowImageSizeTransition(long duration, long delay); + + @NonNull + @Keep + private native Object nativeGetAccuracyRadiusColor(); + + @NonNull + @Keep + private native TransitionOptions nativeGetAccuracyRadiusColorTransition(); + + @Keep + private native void nativeSetAccuracyRadiusColorTransition(long duration, long delay); + + @NonNull + @Keep + private native Object nativeGetAccuracyRadiusBorderColor(); + + @NonNull + @Keep + private native TransitionOptions nativeGetAccuracyRadiusBorderColorTransition(); + + @Keep + private native void nativeSetAccuracyRadiusBorderColorTransition(long duration, long delay); + + @Override + @Keep + protected native void finalize() throws Throwable; + +} diff --git a/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/PropertyFactory.java b/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/PropertyFactory.java index b3ae7a325..907867707 100644 --- a/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/PropertyFactory.java +++ b/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/PropertyFactory.java @@ -1645,6 +1645,226 @@ public class PropertyFactory { return new PaintPropertyValue<>("background-opacity", expression); } + /** + * The amount of the perspective compensation, between 0 and 1. A value of 1 produces a location indicator of constant width across the screen. A value of 0 makes it scale naturally according to the viewing projection. + * + * @param value a Float value + * @return property wrapper around Float + */ + public static PropertyValue perspectiveCompensation(Float value) { + return new PaintPropertyValue<>("perspective-compensation", value); + } + + /** + * The amount of the perspective compensation, between 0 and 1. A value of 1 produces a location indicator of constant width across the screen. A value of 0 makes it scale naturally according to the viewing projection. + * + * @param expression an expression statement + * @return property wrapper around an expression statement + */ + public static PropertyValue perspectiveCompensation(Expression expression) { + return new PaintPropertyValue<>("perspective-compensation", expression); + } + + /** + * The displacement off the center of the top image and the shadow image when the pitch of the map is greater than 0. This helps producing a three-dimensional appearence. + * + * @param value a Float value + * @return property wrapper around Float + */ + public static PropertyValue imageTiltDisplacement(Float value) { + return new PaintPropertyValue<>("image-tilt-displacement", value); + } + + /** + * The displacement off the center of the top image and the shadow image when the pitch of the map is greater than 0. This helps producing a three-dimensional appearence. + * + * @param expression an expression statement + * @return property wrapper around an expression statement + */ + public static PropertyValue imageTiltDisplacement(Expression expression) { + return new PaintPropertyValue<>("image-tilt-displacement", expression); + } + + /** + * The bearing of the location indicator. + * + * @param value a Double value + * @return property wrapper around Double + */ + public static PropertyValue bearing(Double value) { + return new PaintPropertyValue<>("bearing", value); + } + + /** + * The bearing of the location indicator. + * + * @param expression an expression statement + * @return property wrapper around an expression statement + */ + public static PropertyValue bearing(Expression expression) { + return new PaintPropertyValue<>("bearing", expression); + } + + /** + * An array of [latitude, longitude, altitude] position of the location indicator. + * + * @param value a Double[] value + * @return property wrapper around Double[] + */ + public static PropertyValue location(Double[] value) { + return new PaintPropertyValue<>("location", value); + } + + /** + * An array of [latitude, longitude, altitude] position of the location indicator. + * + * @param expression an expression statement + * @return property wrapper around an expression statement + */ + public static PropertyValue location(Expression expression) { + return new PaintPropertyValue<>("location", expression); + } + + /** + * The accuracy, in meters, of the position source used to retrieve the position of the location indicator. + * + * @param value a Float value + * @return property wrapper around Float + */ + public static PropertyValue accuracyRadius(Float value) { + return new PaintPropertyValue<>("accuracy-radius", value); + } + + /** + * The accuracy, in meters, of the position source used to retrieve the position of the location indicator. + * + * @param expression an expression statement + * @return property wrapper around an expression statement + */ + public static PropertyValue accuracyRadius(Expression expression) { + return new PaintPropertyValue<>("accuracy-radius", expression); + } + + /** + * The size of the top image, as a scale factor applied to the size of the specified image. + * + * @param value a Float value + * @return property wrapper around Float + */ + public static PropertyValue topImageSize(Float value) { + return new PaintPropertyValue<>("top-image-size", value); + } + + /** + * The size of the top image, as a scale factor applied to the size of the specified image. + * + * @param expression an expression statement + * @return property wrapper around an expression statement + */ + public static PropertyValue topImageSize(Expression expression) { + return new PaintPropertyValue<>("top-image-size", expression); + } + + /** + * The size of the bearing image, as a scale factor applied to the size of the specified image. + * + * @param value a Float value + * @return property wrapper around Float + */ + public static PropertyValue bearingImageSize(Float value) { + return new PaintPropertyValue<>("bearing-image-size", value); + } + + /** + * The size of the bearing image, as a scale factor applied to the size of the specified image. + * + * @param expression an expression statement + * @return property wrapper around an expression statement + */ + public static PropertyValue bearingImageSize(Expression expression) { + return new PaintPropertyValue<>("bearing-image-size", expression); + } + + /** + * The size of the shadow image, as a scale factor applied to the size of the specified image. + * + * @param value a Float value + * @return property wrapper around Float + */ + public static PropertyValue shadowImageSize(Float value) { + return new PaintPropertyValue<>("shadow-image-size", value); + } + + /** + * The size of the shadow image, as a scale factor applied to the size of the specified image. + * + * @param expression an expression statement + * @return property wrapper around an expression statement + */ + public static PropertyValue shadowImageSize(Expression expression) { + return new PaintPropertyValue<>("shadow-image-size", expression); + } + + /** + * The color for drawing the accuracy radius, as a circle. To adjust transparency, set the alpha component of the color accordingly. + * + * @param value a int color value + * @return property wrapper around String color + */ + public static PropertyValue accuracyRadiusColor(@ColorInt int value) { + return new PaintPropertyValue<>("accuracy-radius-color", colorToRgbaString(value)); + } + + /** + * The color for drawing the accuracy radius, as a circle. To adjust transparency, set the alpha component of the color accordingly. + * + * @param value a String value + * @return property wrapper around String + */ + public static PropertyValue accuracyRadiusColor(String value) { + return new PaintPropertyValue<>("accuracy-radius-color", value); + } + + /** + * The color for drawing the accuracy radius, as a circle. To adjust transparency, set the alpha component of the color accordingly. + * + * @param expression an expression statement + * @return property wrapper around an expression statement + */ + public static PropertyValue accuracyRadiusColor(Expression expression) { + return new PaintPropertyValue<>("accuracy-radius-color", expression); + } + + /** + * The color for drawing the accuracy radius border. To adjust transparency, set the alpha component of the color accordingly. + * + * @param value a int color value + * @return property wrapper around String color + */ + public static PropertyValue accuracyRadiusBorderColor(@ColorInt int value) { + return new PaintPropertyValue<>("accuracy-radius-border-color", colorToRgbaString(value)); + } + + /** + * The color for drawing the accuracy radius border. To adjust transparency, set the alpha component of the color accordingly. + * + * @param value a String value + * @return property wrapper around String + */ + public static PropertyValue accuracyRadiusBorderColor(String value) { + return new PaintPropertyValue<>("accuracy-radius-border-color", value); + } + + /** + * The color for drawing the accuracy radius border. To adjust transparency, set the alpha component of the color accordingly. + * + * @param expression an expression statement + * @return property wrapper around an expression statement + */ + public static PropertyValue accuracyRadiusBorderColor(Expression expression) { + return new PaintPropertyValue<>("accuracy-radius-border-color", expression); + } + /** * Sorts features in ascending order based on this value. Features with a higher sort key will appear above features with a lower sort key. * @@ -2615,4 +2835,64 @@ public class PropertyFactory { return new LayoutPropertyValue<>("circle-sort-key", value); } + /** + * Name of image in sprite to use as the top of the location indicator. + * + * @param value a String value + * @return property wrapper around String + */ + public static PropertyValue topImage(String value) { + return new LayoutPropertyValue<>("top-image", value); + } + + /** + * Name of image in sprite to use as the top of the location indicator. + * + * @param value a String value + * @return property wrapper around String + */ + public static PropertyValue topImage(Expression value) { + return new LayoutPropertyValue<>("top-image", value); + } + + /** + * Name of image in sprite to use as the middle of the location indicator. + * + * @param value a String value + * @return property wrapper around String + */ + public static PropertyValue bearingImage(String value) { + return new LayoutPropertyValue<>("bearing-image", value); + } + + /** + * Name of image in sprite to use as the middle of the location indicator. + * + * @param value a String value + * @return property wrapper around String + */ + public static PropertyValue bearingImage(Expression value) { + return new LayoutPropertyValue<>("bearing-image", value); + } + + /** + * Name of image in sprite to use as the background of the location indicator. + * + * @param value a String value + * @return property wrapper around String + */ + public static PropertyValue shadowImage(String value) { + return new LayoutPropertyValue<>("shadow-image", value); + } + + /** + * Name of image in sprite to use as the background of the location indicator. + * + * @param value a String value + * @return property wrapper around String + */ + public static PropertyValue shadowImage(Expression value) { + return new LayoutPropertyValue<>("shadow-image", value); + } + } diff --git a/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/layer.java.ejs b/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/layer.java.ejs index 3d2ccffba..db1510aab 100644 --- a/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/layer.java.ejs +++ b/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/layer.java.ejs @@ -42,7 +42,7 @@ public class <%- camelize(type) %>Layer extends Layer { super(nativePtr); } -<% if (type === 'background') { -%> +<% if (type === 'background' || type === 'location-indicator') { -%> /** * Creates a <%- camelize(type) %>Layer. * diff --git a/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/utils/BitmapUtils.java b/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/utils/BitmapUtils.java index aa0b370e4..195f8ad89 100644 --- a/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/utils/BitmapUtils.java +++ b/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/utils/BitmapUtils.java @@ -53,10 +53,23 @@ public class BitmapUtils { * @return the merged bitmap */ public static Bitmap mergeBitmap(@NonNull Bitmap background, @NonNull Bitmap foreground) { + return mergeBitmap(background, foreground, 10f, 10f); + } + + /** + * Create a bitmap from a background and a foreground bitmap + * + * @param background The bitmap placed in the background + * @param foreground The bitmap placed in the foreground + * @param left position of the left side of the foreground bitmap + * @param top position of the top side of the foreground bitmap + * @return the merged bitmap + */ + public static Bitmap mergeBitmap(@NonNull Bitmap background, @NonNull Bitmap foreground, float left, float top) { Bitmap result = Bitmap.createBitmap(background.getWidth(), background.getHeight(), background.getConfig()); Canvas canvas = new Canvas(result); canvas.drawBitmap(background, 0f, 0f, null); - canvas.drawBitmap(foreground, 10, 10, null); + canvas.drawBitmap(foreground, left, top, null); return result; } diff --git a/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/location/LocationLayerControllerTest.java b/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/location/LocationLayerControllerTest.java index 5ff7c2bb3..c41732bc9 100644 --- a/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/location/LocationLayerControllerTest.java +++ b/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/location/LocationLayerControllerTest.java @@ -16,6 +16,7 @@ import org.junit.Before; import org.junit.Test; import org.mockito.Mockito; +import java.util.HashSet; import java.util.Set; import static com.mapbox.mapboxsdk.location.LocationComponentConstants.ACCURACY_LAYER; @@ -68,7 +69,7 @@ public class LocationLayerControllerTest { LocationComponentOptions options = mock(LocationComponentOptions.class); new LocationLayerController(mapboxMap, mapboxMap.getStyle(), sourceProvider, buildFeatureProvider(options), - bitmapProvider, options, internalRenderModeChangedListener); + bitmapProvider, options, internalRenderModeChangedListener, false); verify(style).addSource(locationSource); } @@ -85,7 +86,7 @@ public class LocationLayerControllerTest { LocationComponentOptions options = mock(LocationComponentOptions.class); new LocationLayerController(mapboxMap, mapboxMap.getStyle(), sourceProvider, buildFeatureProvider(options), - bitmapProvider, options, internalRenderModeChangedListener); + bitmapProvider, options, internalRenderModeChangedListener, false); verify(style).addLayerBelow(shadowLayer, BACKGROUND_LAYER); } @@ -102,7 +103,7 @@ public class LocationLayerControllerTest { LocationComponentOptions options = mock(LocationComponentOptions.class); new LocationLayerController(mapboxMap, mapboxMap.getStyle(), sourceProvider, buildFeatureProvider(options), - bitmapProvider, options, internalRenderModeChangedListener); + bitmapProvider, options, internalRenderModeChangedListener, false); verify(style).addLayerBelow(backgroundLayer, FOREGROUND_LAYER); } @@ -119,7 +120,7 @@ public class LocationLayerControllerTest { LocationComponentOptions options = mock(LocationComponentOptions.class); new LocationLayerController(mapboxMap, mapboxMap.getStyle(), sourceProvider, buildFeatureProvider(options), - bitmapProvider, options, internalRenderModeChangedListener); + bitmapProvider, options, internalRenderModeChangedListener, false); verify(style).addLayerBelow(foregroundLayer, BEARING_LAYER); } @@ -138,7 +139,7 @@ public class LocationLayerControllerTest { when(options.layerBelow()).thenReturn(layerBelow); new LocationLayerController(mapboxMap, mapboxMap.getStyle(), sourceProvider, buildFeatureProvider(options), - bitmapProvider, options, internalRenderModeChangedListener); + bitmapProvider, options, internalRenderModeChangedListener, false); verify(style).addLayerBelow(bearingLayer, layerBelow); } @@ -155,7 +156,7 @@ public class LocationLayerControllerTest { LocationComponentOptions options = mock(LocationComponentOptions.class); new LocationLayerController(mapboxMap, mapboxMap.getStyle(), sourceProvider, buildFeatureProvider(options), - bitmapProvider, options, internalRenderModeChangedListener); + bitmapProvider, options, internalRenderModeChangedListener, false); verify(style).addLayerBelow(accuracyLayer, BACKGROUND_LAYER); } @@ -166,16 +167,18 @@ public class LocationLayerControllerTest { LayerSourceProvider sourceProvider = buildLayerProvider(); GeoJsonSource locationSource = mock(GeoJsonSource.class); when(sourceProvider.generateSource(any(Feature.class))).thenReturn(locationSource); + Set layerSet = new HashSet<>(); + when(sourceProvider.getEmptyLayerSet()).thenReturn(layerSet); LayerBitmapProvider bitmapProvider = mock(LayerBitmapProvider.class); LocationComponentOptions options = mock(LocationComponentOptions.class); LocationLayerController controller = new LocationLayerController(mapboxMap, mapboxMap.getStyle(), sourceProvider, buildFeatureProvider(options), - bitmapProvider, options, internalRenderModeChangedListener); + bitmapProvider, options, internalRenderModeChangedListener, false); controller.initializeComponents(mapboxMap.getStyle(), options); - assertEquals(5, controller.layerSet.size()); + assertEquals(5, layerSet.size()); } @Test @@ -191,7 +194,7 @@ public class LocationLayerControllerTest { // Style is applied on initialization new LocationLayerController(mapboxMap, mapboxMap.getStyle(), sourceProvider, buildFeatureProvider(options), - bitmapProvider, options, internalRenderModeChangedListener); + bitmapProvider, options, internalRenderModeChangedListener, false); verify(style).addImage(SHADOW_ICON, bitmap); } @@ -208,7 +211,7 @@ public class LocationLayerControllerTest { when(options.elevation()).thenReturn(0f); new LocationLayerController(mapboxMap, mapboxMap.getStyle(), sourceProvider, buildFeatureProvider(options), - bitmapProvider, options, internalRenderModeChangedListener); + bitmapProvider, options, internalRenderModeChangedListener, false); verify(style, times(0)).addImage(SHADOW_ICON, bitmap); } @@ -228,7 +231,7 @@ public class LocationLayerControllerTest { when(bitmapProvider.generateBitmap(drawableResId, tintColor)).thenReturn(bitmap); new LocationLayerController(mapboxMap, mapboxMap.getStyle(), sourceProvider, buildFeatureProvider(options), - bitmapProvider, options, internalRenderModeChangedListener); + bitmapProvider, options, internalRenderModeChangedListener, false); verify(style).addImage(FOREGROUND_ICON, bitmap); } @@ -248,7 +251,7 @@ public class LocationLayerControllerTest { when(bitmapProvider.generateBitmap(drawableResId, tintColor)).thenReturn(bitmap); new LocationLayerController(mapboxMap, mapboxMap.getStyle(), sourceProvider, buildFeatureProvider(options), - bitmapProvider, options, internalRenderModeChangedListener); + bitmapProvider, options, internalRenderModeChangedListener, false); verify(style).addImage(FOREGROUND_STALE_ICON, bitmap); } @@ -268,7 +271,7 @@ public class LocationLayerControllerTest { when(bitmapProvider.generateBitmap(drawableResId, tintColor)).thenReturn(bitmap); new LocationLayerController(mapboxMap, mapboxMap.getStyle(), sourceProvider, buildFeatureProvider(options), - bitmapProvider, options, internalRenderModeChangedListener); + bitmapProvider, options, internalRenderModeChangedListener, false); verify(style).addImage(BACKGROUND_ICON, bitmap); } @@ -288,7 +291,7 @@ public class LocationLayerControllerTest { when(bitmapProvider.generateBitmap(drawableResId, tintColor)).thenReturn(bitmap); new LocationLayerController(mapboxMap, mapboxMap.getStyle(), sourceProvider, buildFeatureProvider(options), - bitmapProvider, options, internalRenderModeChangedListener); + bitmapProvider, options, internalRenderModeChangedListener, false); verify(style).addImage(BACKGROUND_STALE_ICON, bitmap); } @@ -308,7 +311,7 @@ public class LocationLayerControllerTest { when(bitmapProvider.generateBitmap(drawableResId, tintColor)).thenReturn(bitmap); new LocationLayerController(mapboxMap, mapboxMap.getStyle(), sourceProvider, buildFeatureProvider(options), - bitmapProvider, options, internalRenderModeChangedListener); + bitmapProvider, options, internalRenderModeChangedListener, false); verify(style).addImage(BEARING_ICON, bitmap); } @@ -326,7 +329,7 @@ public class LocationLayerControllerTest { LocationLayerController layerController = new LocationLayerController(mapboxMap, mapboxMap.getStyle(), sourceProvider, buildFeatureProvider(options), - bitmapProvider, options, internalRenderModeChangedListener); + bitmapProvider, options, internalRenderModeChangedListener, false); Layer bearingLayer2 = mock(Layer.class); when(sourceProvider.generateLayer(BEARING_LAYER)).thenReturn(bearingLayer2); @@ -371,7 +374,7 @@ public class LocationLayerControllerTest { LocationLayerController layerController = new LocationLayerController(mapboxMap, mapboxMap.getStyle(), sourceProvider, buildFeatureProvider(options), - bitmapProvider, options, internalRenderModeChangedListener); + bitmapProvider, options, internalRenderModeChangedListener, false); options = mock(LocationComponentOptions.class); layerBelow = "layer-below"; @@ -394,7 +397,7 @@ public class LocationLayerControllerTest { LocationLayerController layerController = new LocationLayerController(mapboxMap, mapboxMap.getStyle(), sourceProvider, buildFeatureProvider(options), - bitmapProvider, options, internalRenderModeChangedListener); + bitmapProvider, options, internalRenderModeChangedListener, false); options = mock(LocationComponentOptions.class); layerController.applyStyle(options); @@ -415,10 +418,9 @@ public class LocationLayerControllerTest { Feature locationFeature = mock(Feature.class); LocationLayerController layer = new LocationLayerController( mapboxMap, mapboxMap.getStyle(), sourceProvider, buildFeatureProvider(locationFeature, options), - bitmapProvider, options, internalRenderModeChangedListener - ); + bitmapProvider, options, internalRenderModeChangedListener, false); - layer.updateForegroundOffset(2d); + layer.cameraTiltUpdated(2d); verify(locationFeature).addProperty(eq(PROPERTY_FOREGROUND_ICON_OFFSET), any(JsonElement.class)); } @@ -434,9 +436,8 @@ public class LocationLayerControllerTest { Feature locationFeature = mock(Feature.class); LocationLayerController layer = new LocationLayerController( mapboxMap, mapboxMap.getStyle(), sourceProvider, buildFeatureProvider(locationFeature, options), - bitmapProvider, options, internalRenderModeChangedListener - ); - layer.updateForegroundOffset(2d); + bitmapProvider, options, internalRenderModeChangedListener, false); + layer.cameraTiltUpdated(2d); verify(locationFeature).addProperty(eq(PROPERTY_SHADOW_ICON_OFFSET), any(JsonElement.class)); } @@ -453,8 +454,7 @@ public class LocationLayerControllerTest { Feature locationFeature = mock(Feature.class); LocationLayerController layer = new LocationLayerController( mapboxMap, mapboxMap.getStyle(), sourceProvider, buildFeatureProvider(locationFeature, options), - bitmapProvider, options, internalRenderModeChangedListener - ); + bitmapProvider, options, internalRenderModeChangedListener, false); getAnimationListener(ANIMATOR_LAYER_LATLNG, layer.getAnimationListeners()).onNewAnimationValue(new LatLng()); @@ -474,8 +474,7 @@ public class LocationLayerControllerTest { Feature locationFeature = mock(Feature.class); LocationLayerController layer = new LocationLayerController( mapboxMap, mapboxMap.getStyle(), sourceProvider, buildFeatureProvider(locationFeature, options), - bitmapProvider, options, internalRenderModeChangedListener - ); + bitmapProvider, options, internalRenderModeChangedListener, false); layer.setRenderMode(RenderMode.GPS); float gpsBearing = 2f; @@ -496,8 +495,7 @@ public class LocationLayerControllerTest { Feature locationFeature = mock(Feature.class); LocationLayerController layer = new LocationLayerController( mapboxMap, mapboxMap.getStyle(), sourceProvider, buildFeatureProvider(locationFeature, options), - bitmapProvider, options, internalRenderModeChangedListener - ); + bitmapProvider, options, internalRenderModeChangedListener, false); layer.setRenderMode(RenderMode.COMPASS); float gpsBearing = 2f; @@ -517,8 +515,7 @@ public class LocationLayerControllerTest { Feature locationFeature = mock(Feature.class); LocationLayerController layer = new LocationLayerController( mapboxMap, mapboxMap.getStyle(), sourceProvider, buildFeatureProvider(locationFeature, options), - bitmapProvider, options, internalRenderModeChangedListener - ); + bitmapProvider, options, internalRenderModeChangedListener, false); layer.setRenderMode(RenderMode.COMPASS); float compassBearing = 2f; @@ -540,8 +537,7 @@ public class LocationLayerControllerTest { Feature locationFeature = mock(Feature.class); LocationLayerController layer = new LocationLayerController( mapboxMap, mapboxMap.getStyle(), sourceProvider, buildFeatureProvider(locationFeature, options), - bitmapProvider, options, internalRenderModeChangedListener - ); + bitmapProvider, options, internalRenderModeChangedListener, false); layer.setRenderMode(RenderMode.GPS); float compassBearing = 2f; @@ -561,8 +557,7 @@ public class LocationLayerControllerTest { Feature locationFeature = mock(Feature.class); LocationLayerController layer = new LocationLayerController( mapboxMap, mapboxMap.getStyle(), sourceProvider, buildFeatureProvider(locationFeature, options), - bitmapProvider, options, internalRenderModeChangedListener - ); + bitmapProvider, options, internalRenderModeChangedListener, false); layer.setRenderMode(RenderMode.NORMAL); float accuracyRadiusValue = 2f; @@ -584,8 +579,7 @@ public class LocationLayerControllerTest { Feature locationFeature = mock(Feature.class); LocationLayerController layer = new LocationLayerController( mapboxMap, mapboxMap.getStyle(), sourceProvider, buildFeatureProvider(locationFeature, options), - bitmapProvider, options, internalRenderModeChangedListener - ); + bitmapProvider, options, internalRenderModeChangedListener, false); layer.setRenderMode(RenderMode.GPS); float accuracyRadiusValue = 2f; @@ -605,7 +599,7 @@ public class LocationLayerControllerTest { LocationLayerController controller = new LocationLayerController(mapboxMap, mapboxMap.getStyle(), sourceProvider, buildFeatureProvider(options), - bitmapProvider, options, internalRenderModeChangedListener); + bitmapProvider, options, internalRenderModeChangedListener, false); controller.setRenderMode(RenderMode.NORMAL); controller.setRenderMode(RenderMode.NORMAL); @@ -624,7 +618,7 @@ public class LocationLayerControllerTest { LocationLayerController controller = new LocationLayerController(mapboxMap, mapboxMap.getStyle(), sourceProvider, buildFeatureProvider(options), - bitmapProvider, options, internalRenderModeChangedListener); + bitmapProvider, options, internalRenderModeChangedListener, false); controller.setRenderMode(RenderMode.GPS); controller.setRenderMode(RenderMode.GPS); @@ -648,7 +642,7 @@ public class LocationLayerControllerTest { LocationLayerController controller = new LocationLayerController(mapboxMap, mapboxMap.getStyle(), sourceProvider, buildFeatureProvider(options), - bitmapProvider, options, internalRenderModeChangedListener); + bitmapProvider, options, internalRenderModeChangedListener, false); verify(style).addImage(FOREGROUND_ICON, bitmap); @@ -669,13 +663,13 @@ public class LocationLayerControllerTest { private LayerFeatureProvider buildFeatureProvider(@NonNull LocationComponentOptions options) { LayerFeatureProvider provider = mock(LayerFeatureProvider.class); - when(provider.generateLocationFeature(null, options)).thenReturn(mock(Feature.class)); + when(provider.generateLocationFeature(null, options.enableStaleState())).thenReturn(mock(Feature.class)); return provider; } private LayerFeatureProvider buildFeatureProvider(Feature feature, @NonNull LocationComponentOptions options) { LayerFeatureProvider provider = mock(LayerFeatureProvider.class); - when(provider.generateLocationFeature(null, options)).thenReturn(feature); + when(provider.generateLocationFeature(null, options.enableStaleState())).thenReturn(feature); return provider; } diff --git a/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/LocationIndicatorLayerTest.java b/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/LocationIndicatorLayerTest.java new file mode 100644 index 000000000..1a14d242f --- /dev/null +++ b/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/LocationIndicatorLayerTest.java @@ -0,0 +1,330 @@ +// This file is generated. Edit android/platform/scripts/generate-style-code.js, then run `make android-style-code`. + +package com.mapbox.mapboxsdk.testapp.style; + +import android.graphics.Color; +import androidx.test.annotation.UiThreadTest; +import androidx.test.ext.junit.runners.AndroidJUnit4; + +import com.mapbox.mapboxsdk.maps.BaseLayerTest; +import org.junit.Before; +import timber.log.Timber; + +import com.mapbox.mapboxsdk.style.expressions.Expression; +import com.mapbox.mapboxsdk.style.layers.LocationIndicatorLayer; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import static com.mapbox.mapboxsdk.style.expressions.Expression.*; +import static org.junit.Assert.*; +import static com.mapbox.mapboxsdk.style.layers.Property.*; +import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.*; + +import com.mapbox.mapboxsdk.style.layers.TransitionOptions; + +/** + * Basic smoke tests for LocationIndicatorLayer + */ +@RunWith(AndroidJUnit4.class) +public class LocationIndicatorLayerTest extends BaseLayerTest { + + private LocationIndicatorLayer layer; + + @Before + @UiThreadTest + public void beforeTest(){ + super.before(); + layer = new LocationIndicatorLayer("my-layer"); + setupLayer(layer); + } + + @Test + @UiThreadTest + public void testSetVisibility() { + Timber.i("Visibility"); + assertNotNull(layer); + + // Get initial + assertEquals(layer.getVisibility().getValue(), VISIBLE); + + // Set + layer.setProperties(visibility(NONE)); + assertEquals(layer.getVisibility().getValue(), NONE); + } + + @Test + @UiThreadTest + public void testTopImageAsConstant() { + Timber.i("top-image"); + assertNotNull(layer); + assertNull(layer.getTopImage().getValue()); + + // Set and Get + String propertyValue = "undefined"; + layer.setProperties(topImage(propertyValue)); + assertEquals(layer.getTopImage().getValue(), propertyValue); + } + + @Test + @UiThreadTest + public void testBearingImageAsConstant() { + Timber.i("bearing-image"); + assertNotNull(layer); + assertNull(layer.getBearingImage().getValue()); + + // Set and Get + String propertyValue = "undefined"; + layer.setProperties(bearingImage(propertyValue)); + assertEquals(layer.getBearingImage().getValue(), propertyValue); + } + + @Test + @UiThreadTest + public void testShadowImageAsConstant() { + Timber.i("shadow-image"); + assertNotNull(layer); + assertNull(layer.getShadowImage().getValue()); + + // Set and Get + String propertyValue = "undefined"; + layer.setProperties(shadowImage(propertyValue)); + assertEquals(layer.getShadowImage().getValue(), propertyValue); + } + + @Test + @UiThreadTest + public void testPerspectiveCompensationAsConstant() { + Timber.i("perspective-compensation"); + assertNotNull(layer); + assertNull(layer.getPerspectiveCompensation().getValue()); + + // Set and Get + Float propertyValue = 0.3f; + layer.setProperties(perspectiveCompensation(propertyValue)); + assertEquals(layer.getPerspectiveCompensation().getValue(), propertyValue); + } + + @Test + @UiThreadTest + public void testImageTiltDisplacementAsConstant() { + Timber.i("image-tilt-displacement"); + assertNotNull(layer); + assertNull(layer.getImageTiltDisplacement().getValue()); + + // Set and Get + Float propertyValue = 0.3f; + layer.setProperties(imageTiltDisplacement(propertyValue)); + assertEquals(layer.getImageTiltDisplacement().getValue(), propertyValue); + } + + @Test + @UiThreadTest + public void testBearingAsConstant() { + Timber.i("bearing"); + assertNotNull(layer); + assertNull(layer.getBearing().getValue()); + + // Set and Get + Double propertyValue = 0.3; + layer.setProperties(bearing(propertyValue)); + assertEquals(layer.getBearing().getValue(), propertyValue); + } + + @Test + @UiThreadTest + public void testLocationTransition() { + Timber.i("locationTransitionOptions"); + assertNotNull(layer); + + // Set and Get + TransitionOptions options = new TransitionOptions(300, 100); + layer.setLocationTransition(options); + assertEquals(layer.getLocationTransition(), options); + } + + @Test + @UiThreadTest + public void testLocationAsConstant() { + Timber.i("location"); + assertNotNull(layer); + assertNull(layer.getLocation().getValue()); + + // Set and Get + Double[] propertyValue = new Double[] {0.0, 0.0, 0.0}; + layer.setProperties(location(propertyValue)); + assertEquals(layer.getLocation().getValue(), propertyValue); + } + + @Test + @UiThreadTest + public void testAccuracyRadiusTransition() { + Timber.i("accuracy-radiusTransitionOptions"); + assertNotNull(layer); + + // Set and Get + TransitionOptions options = new TransitionOptions(300, 100); + layer.setAccuracyRadiusTransition(options); + assertEquals(layer.getAccuracyRadiusTransition(), options); + } + + @Test + @UiThreadTest + public void testAccuracyRadiusAsConstant() { + Timber.i("accuracy-radius"); + assertNotNull(layer); + assertNull(layer.getAccuracyRadius().getValue()); + + // Set and Get + Float propertyValue = 0.3f; + layer.setProperties(accuracyRadius(propertyValue)); + assertEquals(layer.getAccuracyRadius().getValue(), propertyValue); + } + + @Test + @UiThreadTest + public void testTopImageSizeTransition() { + Timber.i("top-image-sizeTransitionOptions"); + assertNotNull(layer); + + // Set and Get + TransitionOptions options = new TransitionOptions(300, 100); + layer.setTopImageSizeTransition(options); + assertEquals(layer.getTopImageSizeTransition(), options); + } + + @Test + @UiThreadTest + public void testTopImageSizeAsConstant() { + Timber.i("top-image-size"); + assertNotNull(layer); + assertNull(layer.getTopImageSize().getValue()); + + // Set and Get + Float propertyValue = 0.3f; + layer.setProperties(topImageSize(propertyValue)); + assertEquals(layer.getTopImageSize().getValue(), propertyValue); + } + + @Test + @UiThreadTest + public void testBearingImageSizeTransition() { + Timber.i("bearing-image-sizeTransitionOptions"); + assertNotNull(layer); + + // Set and Get + TransitionOptions options = new TransitionOptions(300, 100); + layer.setBearingImageSizeTransition(options); + assertEquals(layer.getBearingImageSizeTransition(), options); + } + + @Test + @UiThreadTest + public void testBearingImageSizeAsConstant() { + Timber.i("bearing-image-size"); + assertNotNull(layer); + assertNull(layer.getBearingImageSize().getValue()); + + // Set and Get + Float propertyValue = 0.3f; + layer.setProperties(bearingImageSize(propertyValue)); + assertEquals(layer.getBearingImageSize().getValue(), propertyValue); + } + + @Test + @UiThreadTest + public void testShadowImageSizeTransition() { + Timber.i("shadow-image-sizeTransitionOptions"); + assertNotNull(layer); + + // Set and Get + TransitionOptions options = new TransitionOptions(300, 100); + layer.setShadowImageSizeTransition(options); + assertEquals(layer.getShadowImageSizeTransition(), options); + } + + @Test + @UiThreadTest + public void testShadowImageSizeAsConstant() { + Timber.i("shadow-image-size"); + assertNotNull(layer); + assertNull(layer.getShadowImageSize().getValue()); + + // Set and Get + Float propertyValue = 0.3f; + layer.setProperties(shadowImageSize(propertyValue)); + assertEquals(layer.getShadowImageSize().getValue(), propertyValue); + } + + @Test + @UiThreadTest + public void testAccuracyRadiusColorTransition() { + Timber.i("accuracy-radius-colorTransitionOptions"); + assertNotNull(layer); + + // Set and Get + TransitionOptions options = new TransitionOptions(300, 100); + layer.setAccuracyRadiusColorTransition(options); + assertEquals(layer.getAccuracyRadiusColorTransition(), options); + } + + @Test + @UiThreadTest + public void testAccuracyRadiusColorAsConstant() { + Timber.i("accuracy-radius-color"); + assertNotNull(layer); + assertNull(layer.getAccuracyRadiusColor().getValue()); + + // Set and Get + String propertyValue = "rgba(255,128,0,0.7)"; + layer.setProperties(accuracyRadiusColor(propertyValue)); + assertEquals(layer.getAccuracyRadiusColor().getValue(), propertyValue); + } + + @Test + @UiThreadTest + public void testAccuracyRadiusColorAsIntConstant() { + Timber.i("accuracy-radius-color"); + assertNotNull(layer); + + // Set and Get + layer.setProperties(accuracyRadiusColor(Color.argb(127, 255, 127, 0))); + assertEquals(layer.getAccuracyRadiusColorAsInt(), Color.argb(127, 255, 127, 0)); + } + + @Test + @UiThreadTest + public void testAccuracyRadiusBorderColorTransition() { + Timber.i("accuracy-radius-border-colorTransitionOptions"); + assertNotNull(layer); + + // Set and Get + TransitionOptions options = new TransitionOptions(300, 100); + layer.setAccuracyRadiusBorderColorTransition(options); + assertEquals(layer.getAccuracyRadiusBorderColorTransition(), options); + } + + @Test + @UiThreadTest + public void testAccuracyRadiusBorderColorAsConstant() { + Timber.i("accuracy-radius-border-color"); + assertNotNull(layer); + assertNull(layer.getAccuracyRadiusBorderColor().getValue()); + + // Set and Get + String propertyValue = "rgba(255,128,0,0.7)"; + layer.setProperties(accuracyRadiusBorderColor(propertyValue)); + assertEquals(layer.getAccuracyRadiusBorderColor().getValue(), propertyValue); + } + + @Test + @UiThreadTest + public void testAccuracyRadiusBorderColorAsIntConstant() { + Timber.i("accuracy-radius-border-color"); + assertNotNull(layer); + + // Set and Get + layer.setProperties(accuracyRadiusBorderColor(Color.argb(127, 255, 127, 0))); + assertEquals(layer.getAccuracyRadiusBorderColorAsInt(), Color.argb(127, 255, 127, 0)); + } +} diff --git a/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/layer.junit.ejs b/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/layer.junit.ejs index dd18ad581..c5515a396 100644 --- a/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/layer.junit.ejs +++ b/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/layer.junit.ejs @@ -43,7 +43,7 @@ public class <%- camelize(type) %>LayerTest extends BaseLayerTest { @UiThreadTest public void beforeTest(){ super.before(); -<% if (type === 'background') { -%> +<% if (type === 'background' || type === 'location-indicator') { -%> layer = new <%- camelize(type) %>Layer("my-layer"); <% } else { -%> layer = new <%- camelize(type) %>Layer("my-layer", "composite"); @@ -51,7 +51,7 @@ public class <%- camelize(type) %>LayerTest extends BaseLayerTest { <% } -%> setupLayer(layer); } -<% if (type !== 'background') { -%> +<% if (type !== 'background' && type !== 'location-indicator') { -%> @Test @UiThreadTest @@ -75,7 +75,7 @@ public class <%- camelize(type) %>LayerTest extends BaseLayerTest { layer.setProperties(visibility(NONE)); assertEquals(layer.getVisibility().getValue(), NONE); } -<% if (!(type === 'background' || type === 'raster' || type === 'hillshade')) { -%> +<% if (!(type === 'background' || type === 'location-indicator' || type === 'raster' || type === 'hillshade')) { -%> @Test @UiThreadTest diff --git a/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/location/LocationModesActivity.java b/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/location/LocationModesActivity.java index e76fb59e5..f805918cc 100644 --- a/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/location/LocationModesActivity.java +++ b/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/location/LocationModesActivity.java @@ -129,6 +129,7 @@ public class LocationModesActivity extends AppCompatActivity implements OnMapRea locationComponent.activateLocationComponent( LocationComponentActivationOptions .builder(this, style) + .useSpecializedLocationLayer(true) .useDefaultLocationEngine(true) .locationEngineRequest(new LocationEngineRequest.Builder(750) .setFastestInterval(750) diff --git a/core-files.json b/core-files.json deleted file mode 100644 index 70b748234..000000000 --- a/core-files.json +++ /dev/null @@ -1,195 +0,0 @@ -{ - "//": "This file can be edited manually and is the canonical source.", - "sources": [ - "vendor-android/mapbox-gl-native/platform/android/src/main.cpp", - "vendor-android/mapbox-gl-native/platform/android/src/android_renderer_backend.cpp", - "vendor-android/mapbox-gl-native/platform/android/src/android_renderer_frontend.cpp", - "vendor-android/mapbox-gl-native/platform/android/src/annotation/marker.cpp", - "vendor-android/mapbox-gl-native/platform/android/src/annotation/polygon.cpp", - "vendor-android/mapbox-gl-native/platform/android/src/annotation/polyline.cpp", - "vendor-android/mapbox-gl-native/platform/android/src/async_task.cpp", - "vendor-android/mapbox-gl-native/platform/android/src/attach_env.cpp", - "vendor-android/mapbox-gl-native/platform/android/src/bitmap.cpp", - "vendor-android/mapbox-gl-native/platform/android/src/bitmap_factory.cpp", - "vendor-android/mapbox-gl-native/platform/android/src/conversion/collection.cpp", - "vendor-android/mapbox-gl-native/platform/android/src/conversion/color.cpp", - "vendor-android/mapbox-gl-native/platform/android/src/conversion/constant.cpp", - "vendor-android/mapbox-gl-native/platform/android/src/geojson/feature.cpp", - "vendor-android/mapbox-gl-native/platform/android/src/geojson/feature_collection.cpp", - "vendor-android/mapbox-gl-native/platform/android/src/geojson/geometry.cpp", - "vendor-android/mapbox-gl-native/platform/android/src/geojson/geometry_collection.cpp", - "vendor-android/mapbox-gl-native/platform/android/src/geojson/line_string.cpp", - "vendor-android/mapbox-gl-native/platform/android/src/geojson/multi_line_string.cpp", - "vendor-android/mapbox-gl-native/platform/android/src/geojson/multi_point.cpp", - "vendor-android/mapbox-gl-native/platform/android/src/geojson/multi_polygon.cpp", - "vendor-android/mapbox-gl-native/platform/android/src/geojson/point.cpp", - "vendor-android/mapbox-gl-native/platform/android/src/geojson/polygon.cpp", - "vendor-android/mapbox-gl-native/platform/android/src/geometry/lat_lng.cpp", - "vendor-android/mapbox-gl-native/platform/android/src/geometry/lat_lng_bounds.cpp", - "vendor-android/mapbox-gl-native/platform/android/src/geometry/lat_lng_quad.cpp", - "vendor-android/mapbox-gl-native/platform/android/src/geometry/projected_meters.cpp", - "vendor-android/mapbox-gl-native/platform/android/src/graphics/pointf.cpp", - "vendor-android/mapbox-gl-native/platform/android/src/graphics/rectf.cpp", - "vendor-android/mapbox-gl-native/platform/android/src/gson/json_array.cpp", - "vendor-android/mapbox-gl-native/platform/android/src/gson/json_element.cpp", - "vendor-android/mapbox-gl-native/platform/android/src/gson/json_object.cpp", - "vendor-android/mapbox-gl-native/platform/android/src/gson/json_primitive.cpp", - "vendor-android/mapbox-gl-native/platform/android/src/i18n/collator.cpp", - "vendor-android/mapbox-gl-native/platform/android/src/i18n/number_format.cpp", - "vendor-android/mapbox-gl-native/platform/android/src/image.cpp", - "vendor-android/mapbox-gl-native/platform/android/src/java/util.cpp", - "vendor-android/mapbox-gl-native/platform/android/src/java_types.cpp", - "vendor-android/mapbox-gl-native/platform/android/src/jni.cpp", - "vendor-android/mapbox-gl-native/platform/android/src/jni_native.cpp", - "vendor-android/mapbox-gl-native/platform/android/src/logger.cpp", - "vendor-android/mapbox-gl-native/platform/android/src/logging_android.cpp", - "vendor-android/mapbox-gl-native/platform/android/src/mapbox.cpp", - "vendor-android/mapbox-gl-native/platform/android/src/map/camera_position.cpp", - "vendor-android/mapbox-gl-native/platform/android/src/map/image.cpp", - "vendor-android/mapbox-gl-native/platform/android/src/map_renderer.cpp", - "vendor-android/mapbox-gl-native/platform/android/src/map_renderer_runnable.cpp", - "vendor-android/mapbox-gl-native/platform/android/src/native_map_view.cpp", - "vendor-android/mapbox-gl-native/platform/android/src/run_loop.cpp", - "vendor-android/mapbox-gl-native/platform/android/src/snapshotter/map_snapshot.cpp", - "vendor-android/mapbox-gl-native/platform/android/src/snapshotter/map_snapshotter.cpp", - "vendor-android/mapbox-gl-native/platform/android/src/string_util.cpp", - "vendor-android/mapbox-gl-native/platform/android/src/style/conversion/filter.cpp", - "vendor-android/mapbox-gl-native/platform/android/src/style/conversion/position.cpp", - "vendor-android/mapbox-gl-native/platform/android/src/style/conversion/transition_options.cpp", - "vendor-android/mapbox-gl-native/platform/android/src/style/conversion/url_or_tileset.cpp", - "vendor-android/mapbox-gl-native/platform/android/src/style/formatted.cpp", - "vendor-android/mapbox-gl-native/platform/android/src/style/formatted_section.cpp", - "vendor-android/mapbox-gl-native/platform/android/src/style/layers/background_layer.cpp", - "vendor-android/mapbox-gl-native/platform/android/src/style/layers/circle_layer.cpp", - "vendor-android/mapbox-gl-native/platform/android/src/style/layers/custom_layer.cpp", - "vendor-android/mapbox-gl-native/platform/android/src/style/layers/fill_extrusion_layer.cpp", - "vendor-android/mapbox-gl-native/platform/android/src/style/layers/fill_layer.cpp", - "vendor-android/mapbox-gl-native/platform/android/src/style/layers/heatmap_layer.cpp", - "vendor-android/mapbox-gl-native/platform/android/src/style/layers/hillshade_layer.cpp", - "vendor-android/mapbox-gl-native/platform/android/src/style/layers/layer.cpp", - "vendor-android/mapbox-gl-native/platform/android/src/style/layers/layer_manager.cpp", - "vendor-android/mapbox-gl-native/platform/android/src/style/layers/line_layer.cpp", - "vendor-android/mapbox-gl-native/platform/android/src/style/layers/raster_layer.cpp", - "vendor-android/mapbox-gl-native/platform/android/src/style/layers/symbol_layer.cpp", - "vendor-android/mapbox-gl-native/platform/android/src/style/light.cpp", - "vendor-android/mapbox-gl-native/platform/android/src/style/position.cpp", - "vendor-android/mapbox-gl-native/platform/android/src/style/sources/custom_geometry_source.cpp", - "vendor-android/mapbox-gl-native/platform/android/src/style/sources/geojson_source.cpp", - "vendor-android/mapbox-gl-native/platform/android/src/style/sources/image_source.cpp", - "vendor-android/mapbox-gl-native/platform/android/src/style/sources/raster_dem_source.cpp", - "vendor-android/mapbox-gl-native/platform/android/src/style/sources/raster_source.cpp", - "vendor-android/mapbox-gl-native/platform/android/src/style/sources/source.cpp", - "vendor-android/mapbox-gl-native/platform/android/src/style/sources/unknown_source.cpp", - "vendor-android/mapbox-gl-native/platform/android/src/style/sources/vector_source.cpp", - "vendor-android/mapbox-gl-native/platform/android/src/style/transition_options.cpp", - "vendor-android/mapbox-gl-native/platform/android/src/style/value.cpp", - "vendor-android/mapbox-gl-native/platform/android/src/text/local_glyph_rasterizer.cpp", - "vendor-android/mapbox-gl-native/platform/android/src/gl_functions.cpp", - "vendor-android/mapbox-gl-native/platform/android/src/thread.cpp", - "vendor-android/mapbox-gl-native/platform/android/src/timer.cpp", - "vendor-android/mapbox-gl-native/platform/default/src/mbgl/gfx/headless_backend.cpp", - "vendor-android/mapbox-gl-native/platform/default/src/mbgl/gfx/headless_frontend.cpp", - "vendor-android/mapbox-gl-native/platform/default/src/mbgl/gl/headless_backend.cpp", - "vendor-android/mapbox-gl-native/platform/default/src/mbgl/map/map_snapshotter.cpp", - "vendor-android/mapbox-gl-native/platform/default/src/mbgl/text/bidi.cpp", - "vendor-android/mapbox-gl-native/platform/default/src/mbgl/util/compression.cpp", - "vendor-android/mapbox-gl-native/platform/default/src/mbgl/util/monotonic_timer.cpp", - "vendor-android/mapbox-gl-native/platform/default/src/mbgl/util/png_writer.cpp", - "vendor-android/mapbox-gl-native/platform/default/src/mbgl/util/thread_local.cpp", - "vendor-android/mapbox-gl-native/platform/default/src/mbgl/util/utf.cpp", - "vendor-android/mapbox-gl-native/platform/linux/src/headless_backend_egl.cpp" - ], - "public_headers": { - "jni/string_conversion.hpp": "vendor-android/mapbox-gl-native/platform/default/include/jni/string_conversion.hpp", - "mbgl/gfx/headless_backend.hpp": "vendor-android/mapbox-gl-native/platform/default/include/mbgl/gfx/headless_backend.hpp", - "mbgl/gfx/headless_frontend.hpp": "vendor-android/mapbox-gl-native/platform/default/include/mbgl/gfx/headless_frontend.hpp", - "mbgl/gl/headless_backend.hpp": "vendor-android/mapbox-gl-native/platform/default/include/mbgl/gl/headless_backend.hpp", - "mbgl/map/map_snapshotter.hpp": "vendor-android/mapbox-gl-native/platform/default/include/mbgl/map/map_snapshotter.hpp" - }, - "private_headers": { - "android_renderer_backend.hpp": "vendor-android/mapbox-gl-native/platform/android/src/android_renderer_backend.hpp", - "android_renderer_frontend.hpp": "vendor-android/mapbox-gl-native/platform/android/src/android_renderer_frontend.hpp", - "annotation/marker.hpp": "vendor-android/mapbox-gl-native/platform/android/src/annotation/marker.hpp", - "annotation/multi_point.hpp": "vendor-android/mapbox-gl-native/platform/android/src/annotation/multi_point.hpp", - "annotation/polygon.hpp": "vendor-android/mapbox-gl-native/platform/android/src/annotation/polygon.hpp", - "annotation/polyline.hpp": "vendor-android/mapbox-gl-native/platform/android/src/annotation/polyline.hpp", - "attach_env.hpp": "vendor-android/mapbox-gl-native/platform/android/src/attach_env.hpp", - "bitmap.hpp": "vendor-android/mapbox-gl-native/platform/android/src/bitmap.hpp", - "bitmap_factory.hpp": "vendor-android/mapbox-gl-native/platform/android/src/bitmap_factory.hpp", - "conversion/collection.hpp": "vendor-android/mapbox-gl-native/platform/android/src/conversion/collection.hpp", - "conversion/color.hpp": "vendor-android/mapbox-gl-native/platform/android/src/conversion/color.hpp", - "conversion/constant.hpp": "vendor-android/mapbox-gl-native/platform/android/src/conversion/constant.hpp", - "conversion/conversion.hpp": "vendor-android/mapbox-gl-native/platform/android/src/conversion/conversion.hpp", - "geojson/feature.hpp": "vendor-android/mapbox-gl-native/platform/android/src/geojson/feature.hpp", - "geojson/feature_collection.hpp": "vendor-android/mapbox-gl-native/platform/android/src/geojson/feature_collection.hpp", - "geojson/geometry.hpp": "vendor-android/mapbox-gl-native/platform/android/src/geojson/geometry.hpp", - "geojson/geometry_collection.hpp": "vendor-android/mapbox-gl-native/platform/android/src/geojson/geometry_collection.hpp", - "geojson/line_string.hpp": "vendor-android/mapbox-gl-native/platform/android/src/geojson/line_string.hpp", - "geojson/multi_line_string.hpp": "vendor-android/mapbox-gl-native/platform/android/src/geojson/multi_line_string.hpp", - "geojson/multi_point.hpp": "vendor-android/mapbox-gl-native/platform/android/src/geojson/multi_point.hpp", - "geojson/multi_polygon.hpp": "vendor-android/mapbox-gl-native/platform/android/src/geojson/multi_polygon.hpp", - "geojson/point.hpp": "vendor-android/mapbox-gl-native/platform/android/src/geojson/point.hpp", - "geojson/polygon.hpp": "vendor-android/mapbox-gl-native/platform/android/src/geojson/polygon.hpp", - "geojson/util.hpp": "vendor-android/mapbox-gl-native/platform/android/src/geojson/util.hpp", - "geometry/lat_lng.hpp": "vendor-android/mapbox-gl-native/platform/android/src/geometry/lat_lng.hpp", - "geometry/lat_lng_bounds.hpp": "vendor-android/mapbox-gl-native/platform/android/src/geometry/lat_lng_bounds.hpp", - "geometry/lat_lng_quad.hpp": "vendor-android/mapbox-gl-native/platform/android/src/geometry/lat_lng_quad.hpp", - "geometry/projected_meters.hpp": "vendor-android/mapbox-gl-native/platform/android/src/geometry/projected_meters.hpp", - "graphics/pointf.hpp": "vendor-android/mapbox-gl-native/platform/android/src/graphics/pointf.hpp", - "graphics/rectf.hpp": "vendor-android/mapbox-gl-native/platform/android/src/graphics/rectf.hpp", - "gson/json_array.hpp": "vendor-android/mapbox-gl-native/platform/android/src/gson/json_array.hpp", - "gson/json_element.hpp": "vendor-android/mapbox-gl-native/platform/android/src/gson/json_element.hpp", - "gson/json_object.hpp": "vendor-android/mapbox-gl-native/platform/android/src/gson/json_object.hpp", - "gson/json_primitive.hpp": "vendor-android/mapbox-gl-native/platform/android/src/gson/json_primitive.hpp", - "java/util.hpp": "vendor-android/mapbox-gl-native/platform/android/src/java/util.hpp", - "java_types.hpp": "vendor-android/mapbox-gl-native/platform/android/src/java_types.hpp", - "jni.hpp": "vendor-android/mapbox-gl-native/platform/android/src/jni.hpp", - "jni_native.hpp": "vendor-android/mapbox-gl-native/platform/android/src/jni_native.hpp", - "i18n/collator_jni.hpp": "vendor-android/mapbox-gl-native/platform/android/src/i18n/collator_jni.hpp", - "i18n/number_format_jni.hpp": "vendor-android/mapbox-gl-native/platform/android/src/i18n/number_format_jni.hpp", - "logger.hpp": "vendor-android/mapbox-gl-native/platform/android/src/logger.hpp", - "mapbox.hpp": "vendor-android/mapbox-gl-native/platform/android/src/mapbox.hpp", - "map/camera_position.hpp": "vendor-android/mapbox-gl-native/platform/android/src/map/camera_position.hpp", - "map/image.hpp": "vendor-android/mapbox-gl-native/platform/android/src/map/image.hpp", - "map_renderer.hpp": "vendor-android/mapbox-gl-native/platform/android/src/map_renderer.hpp", - "map_renderer_runnable.hpp": "vendor-android/mapbox-gl-native/platform/android/src/map_renderer_runnable.hpp", - "native_map_view.hpp": "vendor-android/mapbox-gl-native/platform/android/src/native_map_view.hpp", - "run_loop_impl.hpp": "vendor-android/mapbox-gl-native/platform/android/src/run_loop_impl.hpp", - "snapshotter/map_snapshot.hpp": "vendor-android/mapbox-gl-native/platform/android/src/snapshotter/map_snapshot.hpp", - "snapshotter/map_snapshotter.hpp": "vendor-android/mapbox-gl-native/platform/android/src/snapshotter/map_snapshotter.hpp", - "style/android_conversion.hpp": "vendor-android/mapbox-gl-native/platform/android/src/style/android_conversion.hpp", - "style/conversion/filter.hpp": "vendor-android/mapbox-gl-native/platform/android/src/style/conversion/filter.hpp", - "style/conversion/position.hpp": "vendor-android/mapbox-gl-native/platform/android/src/style/conversion/position.hpp", - "style/conversion/property_expression.hpp": "vendor-android/mapbox-gl-native/platform/android/src/style/conversion/property_expression.hpp", - "style/conversion/property_value.hpp": "vendor-android/mapbox-gl-native/platform/android/src/style/conversion/property_value.hpp", - "style/conversion/transition_options.hpp": "vendor-android/mapbox-gl-native/platform/android/src/style/conversion/transition_options.hpp", - "style/conversion/url_or_tileset.hpp": "vendor-android/mapbox-gl-native/platform/android/src/style/conversion/url_or_tileset.hpp", - "style/formatted.hpp": "vendor-android/mapbox-gl-native/platform/android/src/style/formatted.hpp", - "style/formatted_section.hpp": "vendor-android/mapbox-gl-native/platform/android/src/style/formatted_section.hpp", - "style/layers/background_layer.hpp": "vendor-android/mapbox-gl-native/platform/android/src/style/layers/background_layer.hpp", - "style/layers/circle_layer.hpp": "vendor-android/mapbox-gl-native/platform/android/src/style/layers/circle_layer.hpp", - "style/layers/custom_layer.hpp": "vendor-android/mapbox-gl-native/platform/android/src/style/layers/custom_layer.hpp", - "style/layers/fill_extrusion_layer.hpp": "vendor-android/mapbox-gl-native/platform/android/src/style/layers/fill_extrusion_layer.hpp", - "style/layers/fill_layer.hpp": "vendor-android/mapbox-gl-native/platform/android/src/style/layers/fill_layer.hpp", - "style/layers/heatmap_layer.hpp": "vendor-android/mapbox-gl-native/platform/android/src/style/layers/heatmap_layer.hpp", - "style/layers/hillshade_layer.hpp": "vendor-android/mapbox-gl-native/platform/android/src/style/layers/hillshade_layer.hpp", - "style/layers/layer.hpp": "vendor-android/mapbox-gl-native/platform/android/src/style/layers/layer.hpp", - "style/layers/layer_manager.hpp": "vendor-android/mapbox-gl-native/platform/android/src/style/layers/layer_manager.hpp", - "style/layers/line_layer.hpp": "vendor-android/mapbox-gl-native/platform/android/src/style/layers/line_layer.hpp", - "style/layers/raster_layer.hpp": "vendor-android/mapbox-gl-native/platform/android/src/style/layers/raster_layer.hpp", - "style/layers/symbol_layer.hpp": "vendor-android/mapbox-gl-native/platform/android/src/style/layers/symbol_layer.hpp", - "style/light.hpp": "vendor-android/mapbox-gl-native/platform/android/src/style/light.hpp", - "style/position.hpp": "vendor-android/mapbox-gl-native/platform/android/src/style/position.hpp", - "style/sources/custom_geometry_source.hpp": "vendor-android/mapbox-gl-native/platform/android/src/style/sources/custom_geometry_source.hpp", - "style/sources/geojson_source.hpp": "vendor-android/mapbox-gl-native/platform/android/src/style/sources/geojson_source.hpp", - "style/sources/image_source.hpp": "vendor-android/mapbox-gl-native/platform/android/src/style/sources/image_source.hpp", - "style/sources/raster_dem_source.hpp": "vendor-android/mapbox-gl-native/platform/android/src/style/sources/raster_dem_source.hpp", - "style/sources/raster_source.hpp": "vendor-android/mapbox-gl-native/platform/android/src/style/sources/raster_source.hpp", - "style/sources/source.hpp": "vendor-android/mapbox-gl-native/platform/android/src/style/sources/source.hpp", - "style/sources/unknown_source.hpp": "vendor-android/mapbox-gl-native/platform/android/src/style/sources/unknown_source.hpp", - "style/sources/vector_source.hpp": "vendor-android/mapbox-gl-native/platform/android/src/style/sources/vector_source.hpp", - "style/transition_options.hpp": "vendor-android/mapbox-gl-native/platform/android/src/style/transition_options.hpp", - "style/value.hpp": "vendor-android/mapbox-gl-native/platform/android/src/style/value.hpp", - "text/local_glyph_rasterizer_jni.hpp": "vendor-android/mapbox-gl-native/platform/android/src/text/local_glyph_rasterizer_jni.hpp" - } -} \ No newline at end of file diff --git a/filesource-files.json b/filesource-files.json deleted file mode 100644 index 7be8bc8a0..000000000 --- a/filesource-files.json +++ /dev/null @@ -1,27 +0,0 @@ -{ - "//": "This file can be edited manually and is the canonical source.", - "sources": [ - "vendor-android/mapbox-gl-native/platform/android/src/asset_manager_file_source.cpp", - "vendor-android/mapbox-gl-native/platform/android/src/connectivity_listener.cpp", - "vendor-android/mapbox-gl-native/platform/android/src/file_source.cpp", - "vendor-android/mapbox-gl-native/platform/android/src/http_file_source.cpp", - "vendor-android/mapbox-gl-native/platform/android/src/offline/offline_manager.cpp", - "vendor-android/mapbox-gl-native/platform/android/src/offline/offline_region.cpp", - "vendor-android/mapbox-gl-native/platform/android/src/offline/offline_region_definition.cpp", - "vendor-android/mapbox-gl-native/platform/android/src/offline/offline_region_error.cpp", - "vendor-android/mapbox-gl-native/platform/android/src/offline/offline_region_status.cpp", - "vendor-android/mapbox-gl-native/platform/default/src/mbgl/storage/sqlite3.cpp" - ], - "public_headers": {}, - "private_headers": { - "asset_manager.hpp": "vendor-android/mapbox-gl-native/platform/android/src/asset_manager.hpp", - "asset_manager_file_source.hpp": "vendor-android/mapbox-gl-native/platform/android/src/asset_manager_file_source.hpp", - "connectivity_listener.hpp": "vendor-android/mapbox-gl-native/platform/android/src/connectivity_listener.hpp", - "file_source.hpp": "vendor-android/mapbox-gl-native/platform/android/src/file_source.hpp", - "offline/offline_manager.hpp": "vendor-android/mapbox-gl-native/platform/android/src/offline/offline_manager.hpp", - "offline/offline_region.hpp": "vendor-android/mapbox-gl-native/platform/android/src/offline/offline_region.hpp", - "offline/offline_region_definition.hpp": "vendor-android/mapbox-gl-native/platform/android/src/offline/offline_region_definition.hpp", - "offline/offline_region_error.hpp": "vendor-android/mapbox-gl-native/platform/android/src/offline/offline_region_error.hpp", - "offline/offline_region_status.hpp": "vendor-android/mapbox-gl-native/platform/android/src/offline/offline_region_status.hpp" - } -} \ No newline at end of file diff --git a/scripts/generate-style-code.js b/scripts/generate-style-code.js index 3ed77405a..821f03666 100755 --- a/scripts/generate-style-code.js +++ b/scripts/generate-style-code.js @@ -68,7 +68,12 @@ global.propertyType = function propertyType(property) { case 'boolean': return 'Boolean'; case 'number': - return 'Float'; + if (/bearing$/.test(property.name) && + property.period == 360 && + property.units =='degrees') { + return 'Double'; + } + return /location$/.test(property.name) ? 'Double' : 'Float'; case 'formatted': return 'Formatted'; case 'string': @@ -79,7 +84,7 @@ global.propertyType = function propertyType(property) { case 'color': return 'String'; case 'array': - return `${propertyType({type:property.value})}[]`; + return `${propertyType({type:property.value, name: property.name})}[]`; default: throw new Error(`unknown type for ${property.name}`); } @@ -205,6 +210,11 @@ global.defaultValueJava = function(property) { case 'boolean': return 'true'; case 'number': + if (/bearing$/.test(property.name) && + property.period == 360 && + property.units =='degrees') { + return '0.3'; + } return '0.3f'; case 'formatted': return 'new Formatted(new FormattedSection("default"))' @@ -225,14 +235,16 @@ global.defaultValueJava = function(property) { return 'new String[0]'; } case 'number': - var result ='new Float[] {'; + var isDouble = /location$/.test(property.name) + console.log(isDouble) + var result = 'new ' + (isDouble ? 'Double' : 'Float') + '[] {'; for (var i = 0; i < property.length; i++) { - result += "0f"; + result += isDouble ? '0.0' : '0f'; if (i +1 != property.length) { - result += ", "; + result += ', '; } } - return result + "}"; + return result + '}'; } default: throw new Error(`unknown type for ${property.name}`) } diff --git a/vendor/mapbox-gl-native b/vendor/mapbox-gl-native index c4b061bd9..3d2e20810 160000 --- a/vendor/mapbox-gl-native +++ b/vendor/mapbox-gl-native @@ -1 +1 @@ -Subproject commit c4b061bd959a0efa5d0202d16d39e92e4f416abb +Subproject commit 3d2e20810cb9a4e2f351774889fd04b87814694c