summaryrefslogtreecommitdiff
path: root/platform/android/src/style/layers/layer.hpp
blob: 67baf789aa2a2e1aeca4cc80ffbd27481b6a9bdd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#pragma once

#include <mbgl/layermanager/layer_factory.hpp>
#include <mbgl/map/map.hpp>
#include <mbgl/style/layer.hpp>
#include "../../gson/json_array.hpp"
#include "../value.hpp"
#include "../../gson/json_element.hpp"

#include <jni/jni.hpp>

namespace mbgl {

namespace android {

class Layer {
public:

    static constexpr auto Name() { return "com/mapbox/mapboxsdk/style/layers/Layer"; };

    static void registerNative(jni::JNIEnv&);

    virtual ~Layer();

    /**
     * Set core layer (ie return ownership after remove)
     */
    void setLayer(std::unique_ptr<mbgl::style::Layer>);

    void addToMap(mbgl::Map&, mbgl::optional<std::string>);

    jni::Local<jni::String> getId(jni::JNIEnv&);

    jni::Local<jni::String> getSourceId(jni::JNIEnv&);

    style::Layer& get();

    void setDetached(jni::JNIEnv&);

    jboolean isDetached(jni::JNIEnv&);

    void setLayoutProperty(jni::JNIEnv&, const jni::String&, const jni::Object<>& value);

    void setPaintProperty(jni::JNIEnv&, const jni::String&, const jni::Object<>& value);

    // Zoom

    jni::jfloat getMinZoom(jni::JNIEnv&);

    jni::jfloat getMaxZoom(jni::JNIEnv&);

    void setMinZoom(jni::JNIEnv&, jni::jfloat zoom);

    void setMaxZoom(jni::JNIEnv&, jni::jfloat zoom);

    /* common properties, but not shared by all */

    void setFilter(jni::JNIEnv&, const jni::Array<jni::Object<>>&);

    jni::Local<jni::Object<gson::JsonElement>> getFilter(jni::JNIEnv&);

    void setSourceLayer(jni::JNIEnv&, const jni::String&);

    jni::Local<jni::String> getSourceLayer(jni::JNIEnv&);

    // Property getters

    jni::Local<jni::Object<jni::ObjectTag>> getVisibility(jni::JNIEnv&);

protected:
    /*
     * Called when a non-owning peer object is created on the c++ side
     */
    Layer(mbgl::Map&, mbgl::style::Layer&);

    /*
     * Called when a owning peer object is created on the c++ side
     */
    Layer(mbgl::Map&, std::unique_ptr<mbgl::style::Layer>);

    /*
     * Called when a Java object was created from the jvm side
     */
    Layer(std::unique_ptr<mbgl::style::Layer>);

    // Release the owned view and return it
    std::unique_ptr<mbgl::style::Layer> releaseCoreLayer();

    // Owned layer is set when creating a new layer, before adding it to the map
    std::unique_ptr<mbgl::style::Layer> ownedLayer;

    // Raw reference to the layer
    mbgl::style::Layer& layer;

    // Map is set when the layer is retrieved or after adding to the map
    mbgl::Map* map;

    // new style has started loading, making this layer invalid
    bool detached;
};

/**
 * @brief A factory class for a layer Java peer objects of a certain type.
 */
class JavaLayerPeerFactory {
public:
    virtual ~JavaLayerPeerFactory() = default;
    /**
     * @brief Create a non-owning peer.
     */
    virtual jni::Local<jni::Object<Layer>> createJavaLayerPeer(jni::JNIEnv&, mbgl::Map&, mbgl::style::Layer&) = 0;

    /**
     * @brief Create an owning peer.
     */
    virtual jni::Local<jni::Object<Layer>> createJavaLayerPeer(jni::JNIEnv& env, mbgl::Map& map, std::unique_ptr<mbgl::style::Layer>) = 0;

    /**
     * @brief Register peer methods.
     */
    virtual void registerNative(jni::JNIEnv&) = 0;

    /**
     * @brief Get the corresponding layer factory.
     * 
     * @return style::LayerFactory* must not be \c nullptr.
     */
    virtual LayerFactory* getLayerFactory() = 0;
};


} // namespace android
} // namespace mbgl