[android] - add get source id to supported layer types

This commit is contained in:
tobrun
2018-09-03 15:43:12 +02:00
committed by Tobrun
parent 18b43f29cf
commit 42aaf3e346
21 changed files with 229 additions and 0 deletions

View File

@@ -67,6 +67,16 @@ public class CircleLayer extends Layer {
return this;
}
/**
* Get the source id.
*
* @return id of the source
*/
public String getSourceId() {
checkThread();
return nativeGetSourceId();
}
/**
* Get the source layer.
*

View File

@@ -67,6 +67,16 @@ public class FillExtrusionLayer extends Layer {
return this;
}
/**
* Get the source id.
*
* @return id of the source
*/
public String getSourceId() {
checkThread();
return nativeGetSourceId();
}
/**
* Get the source layer.
*

View File

@@ -67,6 +67,16 @@ public class FillLayer extends Layer {
return this;
}
/**
* Get the source id.
*
* @return id of the source
*/
public String getSourceId() {
checkThread();
return nativeGetSourceId();
}
/**
* Get the source layer.
*

View File

@@ -67,6 +67,16 @@ public class HeatmapLayer extends Layer {
return this;
}
/**
* Get the source id.
*
* @return id of the source
*/
public String getSourceId() {
checkThread();
return nativeGetSourceId();
}
/**
* Get the source layer.
*

View File

@@ -67,6 +67,16 @@ public class HillshadeLayer extends Layer {
return this;
}
/**
* Get the source id.
*
* @return id of the source
*/
public String getSourceId() {
checkThread();
return nativeGetSourceId();
}
/**
* Set a property or properties.
*

View File

@@ -108,6 +108,9 @@ public abstract class Layer {
@Keep
protected native String nativeGetSourceLayer();
@Keep
protected native String nativeGetSourceId();
@Keep
protected native float nativeGetMinZoom();

View File

@@ -67,6 +67,16 @@ public class LineLayer extends Layer {
return this;
}
/**
* Get the source id.
*
* @return id of the source
*/
public String getSourceId() {
checkThread();
return nativeGetSourceId();
}
/**
* Get the source layer.
*

View File

@@ -67,6 +67,16 @@ public class RasterLayer extends Layer {
return this;
}
/**
* Get the source id.
*
* @return id of the source
*/
public String getSourceId() {
checkThread();
return nativeGetSourceId();
}
/**
* Set a property or properties.
*

View File

@@ -67,6 +67,16 @@ public class SymbolLayer extends Layer {
return this;
}
/**
* Get the source id.
*
* @return id of the source
*/
public String getSourceId() {
checkThread();
return nativeGetSourceId();
}
/**
* Get the source layer.
*

View File

@@ -87,6 +87,18 @@ public class <%- camelize(type) %>Layer extends Layer {
return this;
}
<% } -%>
<% if (type !== 'background' && type !== 'custom') { -%>
/**
* Get the source id.
*
* @return id of the source
*/
public String getSourceId() {
checkThread();
return nativeGetSourceId();
}
<% } -%>
<% if (type !== 'background' && type !== 'raster' && type !== 'hillshade') { -%>
/**

View File

@@ -50,6 +50,18 @@ public class CircleLayerTest extends BaseActivityTest {
});
}
@Test
public void testSourceId() {
validateTestSetup();
setupLayer();
Timber.i("SourceId");
invoke(mapboxMap, (uiController, mapboxMap) -> {
assertNotNull(layer);
// Get source id
assertEquals(layer.getSourceId(), "composite");
});
}
@Test
public void testSetVisibility() {
validateTestSetup();

View File

@@ -50,6 +50,18 @@ public class FillExtrusionLayerTest extends BaseActivityTest {
});
}
@Test
public void testSourceId() {
validateTestSetup();
setupLayer();
Timber.i("SourceId");
invoke(mapboxMap, (uiController, mapboxMap) -> {
assertNotNull(layer);
// Get source id
assertEquals(layer.getSourceId(), "composite");
});
}
@Test
public void testSetVisibility() {
validateTestSetup();

View File

@@ -50,6 +50,18 @@ public class FillLayerTest extends BaseActivityTest {
});
}
@Test
public void testSourceId() {
validateTestSetup();
setupLayer();
Timber.i("SourceId");
invoke(mapboxMap, (uiController, mapboxMap) -> {
assertNotNull(layer);
// Get source id
assertEquals(layer.getSourceId(), "composite");
});
}
@Test
public void testSetVisibility() {
validateTestSetup();

View File

@@ -50,6 +50,18 @@ public class HeatmapLayerTest extends BaseActivityTest {
});
}
@Test
public void testSourceId() {
validateTestSetup();
setupLayer();
Timber.i("SourceId");
invoke(mapboxMap, (uiController, mapboxMap) -> {
assertNotNull(layer);
// Get source id
assertEquals(layer.getSourceId(), "composite");
});
}
@Test
public void testSetVisibility() {
validateTestSetup();

View File

@@ -50,6 +50,18 @@ public class HillshadeLayerTest extends BaseActivityTest {
});
}
@Test
public void testSourceId() {
validateTestSetup();
setupLayer();
Timber.i("SourceId");
invoke(mapboxMap, (uiController, mapboxMap) -> {
assertNotNull(layer);
// Get source id
assertEquals(layer.getSourceId(), "composite");
});
}
@Test
public void testSetVisibility() {
validateTestSetup();

View File

@@ -50,6 +50,18 @@ public class LineLayerTest extends BaseActivityTest {
});
}
@Test
public void testSourceId() {
validateTestSetup();
setupLayer();
Timber.i("SourceId");
invoke(mapboxMap, (uiController, mapboxMap) -> {
assertNotNull(layer);
// Get source id
assertEquals(layer.getSourceId(), "composite");
});
}
@Test
public void testSetVisibility() {
validateTestSetup();

View File

@@ -50,6 +50,18 @@ public class RasterLayerTest extends BaseActivityTest {
});
}
@Test
public void testSourceId() {
validateTestSetup();
setupLayer();
Timber.i("SourceId");
invoke(mapboxMap, (uiController, mapboxMap) -> {
assertNotNull(layer);
// Get source id
assertEquals(layer.getSourceId(), "composite");
});
}
@Test
public void testSetVisibility() {
validateTestSetup();

View File

@@ -50,6 +50,18 @@ public class SymbolLayerTest extends BaseActivityTest {
});
}
@Test
public void testSourceId() {
validateTestSetup();
setupLayer();
Timber.i("SourceId");
invoke(mapboxMap, (uiController, mapboxMap) -> {
assertNotNull(layer);
// Get source id
assertEquals(layer.getSourceId(), "composite");
});
}
@Test
public void testSetVisibility() {
validateTestSetup();

View File

@@ -60,6 +60,20 @@ public class <%- camelize(type) %>LayerTest extends BaseActivityTest {
});
<% } -%>
}
<% if (type !== 'background') { -%>
@Test
public void testSourceId() {
validateTestSetup();
setupLayer();
Timber.i("SourceId");
invoke(mapboxMap, (uiController, mapboxMap) -> {
assertNotNull(layer);
// Get source id
assertEquals(layer.getSourceId(), "composite");
});
}
<% } -%>
@Test
public void testSetVisibility() {

View File

@@ -25,6 +25,8 @@
// C++ -> Java conversion
#include "../conversion/property_value.hpp"
#include "custom_layer.hpp"
#include "background_layer.hpp"
#include <mbgl/style/filter.hpp>
#include <string>
@@ -204,6 +206,25 @@ namespace android {
return jni::Make<jni::String>(env, layer.accept(GetSourceLayerEvaluator()));
}
struct GetSourceIdEvaluator {
std::string noop(std::string layerType) {
Log::Warning(mbgl::Event::JNI, "%s doesn't support get source id", layerType.c_str());
return {};
}
std::string operator()(style::BackgroundLayer&) { return noop("BackgroundLayer"); }
std::string operator()(style::CustomLayer&) { return noop("CustomLayer"); }
template <class LayerType>
std::string operator()(LayerType& layer) {
return layer.getSourceID();
}
};
jni::String Layer::getSourceId(jni::JNIEnv& env) {
return jni::Make<jni::String>(env, layer.accept(GetSourceIdEvaluator()));
}
jni::jfloat Layer::getMinZoom(jni::JNIEnv&){
return layer.getMinZoom();
}
@@ -242,6 +263,7 @@ namespace android {
METHOD(&Layer::getFilter, "nativeGetFilter"),
METHOD(&Layer::setSourceLayer, "nativeSetSourceLayer"),
METHOD(&Layer::getSourceLayer, "nativeGetSourceLayer"),
METHOD(&Layer::getSourceId, "nativeGetSourceId"),
METHOD(&Layer::getMinZoom, "nativeGetMinZoom"),
METHOD(&Layer::getMaxZoom, "nativeGetMaxZoom"),
METHOD(&Layer::setMinZoom, "nativeSetMinZoom"),

View File

@@ -49,6 +49,8 @@ public:
jni::String getId(jni::JNIEnv&);
jni::String getSourceId(jni::JNIEnv&);
style::Layer& get();
void setLayoutProperty(jni::JNIEnv&, jni::String, jni::Object<> value);