Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Commit

Permalink
[android] - add get source id to supported layer types
Browse files Browse the repository at this point in the history
  • Loading branch information
tobrun committed Sep 4, 2018
1 parent 18b43f2 commit 42aaf3e
Show file tree
Hide file tree
Showing 21 changed files with 229 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,16 @@ public CircleLayer withSourceLayer(String sourceLayer) {
return this;
}

/**
* Get the source id.
*
* @return id of the source
*/
public String getSourceId() {
checkThread();
return nativeGetSourceId();
}

/**
* Get the source layer.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,16 @@ public FillExtrusionLayer withSourceLayer(String sourceLayer) {
return this;
}

/**
* Get the source id.
*
* @return id of the source
*/
public String getSourceId() {
checkThread();
return nativeGetSourceId();
}

/**
* Get the source layer.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,16 @@ public FillLayer withSourceLayer(String sourceLayer) {
return this;
}

/**
* Get the source id.
*
* @return id of the source
*/
public String getSourceId() {
checkThread();
return nativeGetSourceId();
}

/**
* Get the source layer.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,16 @@ public HeatmapLayer withSourceLayer(String sourceLayer) {
return this;
}

/**
* Get the source id.
*
* @return id of the source
*/
public String getSourceId() {
checkThread();
return nativeGetSourceId();
}

/**
* Get the source layer.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,16 @@ public HillshadeLayer withSourceLayer(String sourceLayer) {
return this;
}

/**
* Get the source id.
*
* @return id of the source
*/
public String getSourceId() {
checkThread();
return nativeGetSourceId();
}

/**
* Set a property or properties.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,9 @@ public void setMaxZoom(float zoom) {
@Keep
protected native String nativeGetSourceLayer();

@Keep
protected native String nativeGetSourceId();

@Keep
protected native float nativeGetMinZoom();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,16 @@ public LineLayer withSourceLayer(String sourceLayer) {
return this;
}

/**
* Get the source id.
*
* @return id of the source
*/
public String getSourceId() {
checkThread();
return nativeGetSourceId();
}

/**
* Get the source layer.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,16 @@ public RasterLayer withSourceLayer(String sourceLayer) {
return this;
}

/**
* Get the source id.
*
* @return id of the source
*/
public String getSourceId() {
checkThread();
return nativeGetSourceId();
}

/**
* Set a property or properties.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,16 @@ public SymbolLayer withSourceLayer(String sourceLayer) {
return this;
}

/**
* Get the source id.
*
* @return id of the source
*/
public String getSourceId() {
checkThread();
return nativeGetSourceId();
}

/**
* Get the source layer.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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') { -%>
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,18 @@ private void setupLayer() {
});
}

@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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,18 @@ private void setupLayer() {
});
}

@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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,18 @@ private void setupLayer() {
});
}

@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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,18 @@ private void setupLayer() {
});
}

@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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,18 @@ private void setupLayer() {
});
}

@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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,18 @@ private void setupLayer() {
});
}

@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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,18 @@ private void setupLayer() {
});
}

@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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,18 @@ private void setupLayer() {
});
}

@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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
22 changes: 22 additions & 0 deletions platform/android/src/style/layers/layer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -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();
}
Expand Down Expand Up @@ -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"),
Expand Down
2 changes: 2 additions & 0 deletions platform/android/src/style/layers/layer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ class Layer : private mbgl::util::noncopyable {

jni::String getId(jni::JNIEnv&);

jni::String getSourceId(jni::JNIEnv&);

style::Layer& get();

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

0 comments on commit 42aaf3e

Please sign in to comment.