#pragma once #include #include #include #include #include #include #include #include #include #include "file_source.hpp" #include "annotation/marker.hpp" #include "annotation/polygon.hpp" #include "annotation/polyline.hpp" #include "graphics/pointf.hpp" #include "graphics/rectf.hpp" #include "geojson/feature.hpp" #include "geometry/lat_lng.hpp" #include "geometry/projected_meters.hpp" #include "style/layers/layers.hpp" #include "style/sources/sources.hpp" #include "geometry/lat_lng_bounds.hpp" #include "map/camera_position.hpp" #include "style/light.hpp" #include #include #include #include #include #include namespace mbgl { namespace android { class AndroidRendererFrontend; class NativeMapView : public RendererBackend, public MapObserver { public: static constexpr auto Name() { return "com/mapbox/mapboxsdk/maps/NativeMapView"; }; static jni::Class javaClass; static void registerNative(jni::JNIEnv&); NativeMapView(jni::JNIEnv&, jni::Object, jni::Object, jni::jfloat pixelRatio, jni::String programCacheDir); virtual ~NativeMapView(); // mbgl::RendererBackend // void bind() override; void updateAssumedState() override; // Deprecated // void notifyMapChange(mbgl::MapChange); // mbgl::RendererBackend (mbgl::MapObserver) // void onCameraWillChange(MapObserver::CameraChangeMode) override; void onCameraIsChanging() override; void onCameraDidChange(MapObserver::CameraChangeMode) override; void onWillStartLoadingMap() override; void onDidFinishLoadingMap() override; void onDidFailLoadingMap(std::exception_ptr) override; void onWillStartRenderingFrame() override; void onDidFinishRenderingFrame(MapObserver::RenderMode) override; void onWillStartRenderingMap() override; void onDidFinishRenderingMap(MapObserver::RenderMode) override; void onDidFinishLoadingStyle() override; void onSourceChanged(mbgl::style::Source&) override; // Signal the view system, we want to redraw void invalidate(); // JNI // void render(jni::JNIEnv&); void update(jni::JNIEnv&); void resizeView(jni::JNIEnv&, int, int); void resizeFramebuffer(jni::JNIEnv&, int, int); void createSurface(jni::JNIEnv&, jni::Object<>); void destroySurface(jni::JNIEnv&); jni::String getStyleUrl(jni::JNIEnv&); void setStyleUrl(jni::JNIEnv&, jni::String); jni::String getStyleJson(jni::JNIEnv&); void setStyleJson(jni::JNIEnv&, jni::String); void setLatLngBounds(jni::JNIEnv&, jni::Object); void cancelTransitions(jni::JNIEnv&); void setGestureInProgress(jni::JNIEnv&, jni::jboolean); void moveBy(jni::JNIEnv&, jni::jdouble, jni::jdouble, jni::jlong); void jumpTo(jni::JNIEnv&, jni::jdouble, jni::jdouble, jni::jdouble, jni::jdouble, jni::jdouble); void easeTo(jni::JNIEnv&, jni::jdouble, jni::jdouble, jni::jdouble, jni::jlong, jni::jdouble, jni::jdouble, jni::jboolean); void flyTo(jni::JNIEnv&, jni::jdouble, jni::jdouble, jni::jdouble, jni::jlong, jni::jdouble, jni::jdouble); jni::Object getLatLng(JNIEnv&); void setLatLng(jni::JNIEnv&, jni::jdouble, jni::jdouble, jni::jlong); jni::Object getCameraForLatLngBounds(jni::JNIEnv&, jni::Object); void setReachability(jni::JNIEnv&, jni::jboolean); void resetPosition(jni::JNIEnv&); jni::jdouble getPitch(jni::JNIEnv&); void setPitch(jni::JNIEnv&, jni::jdouble, jni::jlong); void setZoom(jni::JNIEnv&, jni::jdouble, jni::jdouble, jni::jdouble, jni::jlong); jni::jdouble getZoom(jni::JNIEnv&); void resetZoom(jni::JNIEnv&); void setMinZoom(jni::JNIEnv&, jni::jdouble); jni::jdouble getMinZoom(jni::JNIEnv&); void setMaxZoom(jni::JNIEnv&, jni::jdouble); jni::jdouble getMaxZoom(jni::JNIEnv&); void rotateBy(jni::JNIEnv&, jni::jdouble, jni::jdouble, jni::jdouble, jni::jdouble, jni::jlong); void setBearing(jni::JNIEnv&, jni::jdouble, jni::jlong); void setBearingXY(jni::JNIEnv&, jni::jdouble, jni::jdouble, jni::jdouble, jni::jlong); jni::jdouble getBearing(jni::JNIEnv&); void resetNorth(jni::JNIEnv&); void setVisibleCoordinateBounds(JNIEnv&, jni::Array>, jni::Object, jni::jdouble, jni::jlong); void setContentPadding(JNIEnv&, double, double, double, double); void scheduleSnapshot(jni::JNIEnv&); void enableFps(jni::JNIEnv&, jni::jboolean enable); jni::Object getCameraPosition(jni::JNIEnv&); void updateMarker(jni::JNIEnv&, jni::jlong, jni::jdouble, jni::jdouble, jni::String); jni::Array addMarkers(jni::JNIEnv&, jni::Array>); void onLowMemory(JNIEnv& env); void setDebug(JNIEnv&, jni::jboolean); void cycleDebugOptions(JNIEnv&); jni::jboolean getDebug(JNIEnv&); jni::jboolean isFullyLoaded(JNIEnv&); jni::jdouble getMetersPerPixelAtLatitude(JNIEnv&, jni::jdouble, jni::jdouble); jni::Object projectedMetersForLatLng(JNIEnv&, jni::jdouble, jni::jdouble); jni::Object pixelForLatLng(JNIEnv&, jdouble, jdouble); jni::Object latLngForProjectedMeters(JNIEnv&, jdouble, jdouble); jni::Object latLngForPixel(JNIEnv&, jfloat, jfloat); jni::Array addPolylines(JNIEnv&, jni::Array>); jni::Array addPolygons(JNIEnv&, jni::Array>); void updatePolyline(JNIEnv&, jlong, jni::Object); void updatePolygon(JNIEnv&, jlong, jni::Object); void removeAnnotations(JNIEnv&, jni::Array); void addAnnotationIcon(JNIEnv&, jni::String, jint, jint, jfloat, jni::Array); jni::jdouble getTopOffsetPixelsForAnnotationSymbol(JNIEnv&, jni::String); jni::jlong getTransitionDuration(JNIEnv&); void setTransitionDuration(JNIEnv&, jni::jlong); jni::jlong getTransitionDelay(JNIEnv&); void setTransitionDelay(JNIEnv&, jni::jlong); jni::Array queryPointAnnotations(JNIEnv&, jni::Object); jni::Array> queryRenderedFeaturesForPoint(JNIEnv&, jni::jfloat, jni::jfloat, jni::Array, jni::Array> jfilter); jni::Array> queryRenderedFeaturesForBox(JNIEnv&, jni::jfloat, jni::jfloat, jni::jfloat, jni::jfloat, jni::Array, jni::Array> jfilter); jni::Object getLight(JNIEnv&); jni::Array> getLayers(JNIEnv&); jni::Object getLayer(JNIEnv&, jni::String); void addLayer(JNIEnv&, jlong, jni::String); void addLayerAbove(JNIEnv&, jlong, jni::String); void addLayerAt(JNIEnv&, jni::jlong, jni::jint); jni::Object removeLayerById(JNIEnv&, jni::String); jni::Object removeLayerAt(JNIEnv&, jni::jint); void removeLayer(JNIEnv&, jlong); jni::Array> getSources(JNIEnv&); jni::Object getSource(JNIEnv&, jni::String); void addSource(JNIEnv&, jni::jlong); jni::Object removeSourceById(JNIEnv&, jni::String); void removeSource(JNIEnv&, jlong); void addImage(JNIEnv&, jni::String, jni::jint, jni::jint, jni::jfloat, jni::Array); void removeImage(JNIEnv&, jni::String); void setPrefetchesTiles(JNIEnv&, jni::jboolean); jni::jboolean getPrefetchesTiles(JNIEnv&); protected: // mbgl::RendererBackend // gl::ProcAddress initializeExtension(const char*) override; void activate() override; void deactivate() override; private: void _initializeDisplay(); void _terminateDisplay(); void _initializeContext(); void _terminateContext(); void _createSurface(ANativeWindow*); void _destroySurface(); EGLConfig chooseConfig(const EGLConfig configs[], EGLint numConfigs); mbgl::Size getFramebufferSize() const; void updateFps(); private: std::unique_ptr rendererFrontend; JavaVM *vm = nullptr; jni::UniqueWeakObject javaPeer; std::string styleUrl; std::string apiKey; ANativeWindow *window = nullptr; EGLConfig config = nullptr; EGLint format = -1; EGLDisplay oldDisplay = EGL_NO_DISPLAY; EGLSurface oldReadSurface = EGL_NO_SURFACE; EGLSurface oldDrawSurface = EGL_NO_SURFACE; EGLContext oldContext = EGL_NO_CONTEXT; EGLDisplay display = EGL_NO_DISPLAY; EGLSurface surface = EGL_NO_SURFACE; EGLContext context = EGL_NO_CONTEXT; float pixelRatio; bool fpsEnabled = false; bool snapshot = false; bool firstRender = true; double fps = 0.0; // Minimum texture size according to OpenGL ES 2.0 specification. int width = 64; int height = 64; int fbWidth = 64; int fbHeight = 64; bool framebufferSizeChanged = true; // Ensure these are initialised last std::shared_ptr threadPool; std::unique_ptr map; mbgl::EdgeInsets insets; }; } // namespace android } // namespace mbgl