Update generate-style-code and add sort key api for LineLayer and FillLayer. (#209)

This commit is contained in:
Kevin Li
2020-03-06 16:59:32 +08:00
committed by GitHub
parent 77b2ac8ef7
commit 04722fdefd
26 changed files with 201 additions and 28 deletions

View File

@@ -10,6 +10,11 @@ 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;
/**
* The background color or pattern of the map.
*

View File

@@ -10,8 +10,10 @@ 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;
/**
* A filled circle.

View File

@@ -10,8 +10,10 @@ 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;
/**
* An extruded (3D) polygon.

View File

@@ -10,8 +10,10 @@ 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;
/**
* A filled polygon with an optional stroked border.
@@ -141,6 +143,18 @@ public class FillLayer extends Layer {
// Property getters
/**
* Get the FillSortKey property
*
* @return property wrapper value around Float
*/
@NonNull
@SuppressWarnings("unchecked")
public PropertyValue<Float> getFillSortKey() {
checkThread();
return (PropertyValue<Float>) new PropertyValue("fill-sort-key", nativeGetFillSortKey());
}
/**
* Get the FillAntialias property
*
@@ -364,6 +378,10 @@ public class FillLayer extends Layer {
nativeSetFillPatternTransition(options.getDuration(), options.getDelay());
}
@NonNull
@Keep
private native Object nativeGetFillSortKey();
@NonNull
@Keep
private native Object nativeGetFillAntialias();

View File

@@ -10,8 +10,10 @@ 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;
/**
* A heatmap.

View File

@@ -10,6 +10,11 @@ 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;
/**
* Client-side hillshading visualization based on DEM data. Currently, the implementation only supports Mapbox Terrain RGB and Mapzen Terrarium tiles.
*

View File

@@ -10,8 +10,10 @@ 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;
/**
* A stroked line.
@@ -189,6 +191,18 @@ public class LineLayer extends Layer {
return (PropertyValue<Float>) new PropertyValue("line-round-limit", nativeGetLineRoundLimit());
}
/**
* Get the LineSortKey property
*
* @return property wrapper value around Float
*/
@NonNull
@SuppressWarnings("unchecked")
public PropertyValue<Float> getLineSortKey() {
checkThread();
return (PropertyValue<Float>) new PropertyValue("line-sort-key", nativeGetLineSortKey());
}
/**
* Get the LineOpacity property
*
@@ -560,6 +574,10 @@ public class LineLayer extends Layer {
@Keep
private native Object nativeGetLineRoundLimit();
@NonNull
@Keep
private native Object nativeGetLineSortKey();
@NonNull
@Keep
private native Object nativeGetLineOpacity();

View File

@@ -1645,6 +1645,26 @@ public class PropertyFactory {
return new PaintPropertyValue<>("background-opacity", 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.
*
* @param value a Float value
* @return property wrapper around Float
*/
public static PropertyValue<Float> fillSortKey(Float value) {
return new LayoutPropertyValue<>("fill-sort-key", value);
}
/**
* Sorts features in ascending order based on this value. Features with a higher sort key will appear above features with a lower sort key.
*
* @param value a Float value
* @return property wrapper around Float
*/
public static PropertyValue<Expression> fillSortKey(Expression value) {
return new LayoutPropertyValue<>("fill-sort-key", value);
}
/**
* The display of line endings.
*
@@ -1725,6 +1745,26 @@ public class PropertyFactory {
return new LayoutPropertyValue<>("line-round-limit", value);
}
/**
* Sorts features in ascending order based on this value. Features with a higher sort key will appear above features with a lower sort key.
*
* @param value a Float value
* @return property wrapper around Float
*/
public static PropertyValue<Float> lineSortKey(Float value) {
return new LayoutPropertyValue<>("line-sort-key", value);
}
/**
* Sorts features in ascending order based on this value. Features with a higher sort key will appear above features with a lower sort key.
*
* @param value a Float value
* @return property wrapper around Float
*/
public static PropertyValue<Expression> lineSortKey(Expression value) {
return new LayoutPropertyValue<>("line-sort-key", value);
}
/**
* Label placement relative to its geometry.
*
@@ -1766,7 +1806,7 @@ public class PropertyFactory {
}
/**
* If true, the symbols will not cross tile edges to avoid mutual collisions. Recommended in layers that don't have enough padding in the vector tile to prevent collisions, or if it is a point symbol layer placed after a line symbol layer.
* If true, the symbols will not cross tile edges to avoid mutual collisions. Recommended in layers that don't have enough padding in the vector tile to prevent collisions, or if it is a point symbol layer placed after a line symbol layer. When using a client that supports global collision detection, like Mapbox GL JS version 0.42.0 or greater, enabling this property is not needed to prevent clipped labels at tile boundaries.
*
* @param value a Boolean value
* @return property wrapper around Boolean
@@ -1776,7 +1816,7 @@ public class PropertyFactory {
}
/**
* If true, the symbols will not cross tile edges to avoid mutual collisions. Recommended in layers that don't have enough padding in the vector tile to prevent collisions, or if it is a point symbol layer placed after a line symbol layer.
* If true, the symbols will not cross tile edges to avoid mutual collisions. Recommended in layers that don't have enough padding in the vector tile to prevent collisions, or if it is a point symbol layer placed after a line symbol layer. When using a client that supports global collision detection, like Mapbox GL JS version 0.42.0 or greater, enabling this property is not needed to prevent clipped labels at tile boundaries.
*
* @param value a Boolean value
* @return property wrapper around Boolean
@@ -2316,7 +2356,7 @@ public class PropertyFactory {
}
/**
* To increase the chance of placing high-priority labels on the map, you can provide an array of {@link Property.TEXT_ANCHOR} locations: the render will attempt to place the label at each location, in order, before moving onto the next label. Use `text-justify: auto` to choose justification based on anchor position. To apply an offset, use the {@link PropertyFactory#textRadialOffset} or the two-dimensional {@link PropertyFactory#textOffset}.
* To increase the chance of placing high-priority labels on the map, you can provide an array of {@link Property.TEXT_ANCHOR} locations: the renderer will attempt to place the label at each location, in order, before moving onto the next label. Use `text-justify: auto` to choose justification based on anchor position. To apply an offset, use the {@link PropertyFactory#textRadialOffset} or the two-dimensional {@link PropertyFactory#textOffset}.
*
* @param value a String[] value
* @return property wrapper around String[]
@@ -2326,7 +2366,7 @@ public class PropertyFactory {
}
/**
* To increase the chance of placing high-priority labels on the map, you can provide an array of {@link Property.TEXT_ANCHOR} locations: the render will attempt to place the label at each location, in order, before moving onto the next label. Use `text-justify: auto` to choose justification based on anchor position. To apply an offset, use the {@link PropertyFactory#textRadialOffset} or the two-dimensional {@link PropertyFactory#textOffset}.
* To increase the chance of placing high-priority labels on the map, you can provide an array of {@link Property.TEXT_ANCHOR} locations: the renderer will attempt to place the label at each location, in order, before moving onto the next label. Use `text-justify: auto` to choose justification based on anchor position. To apply an offset, use the {@link PropertyFactory#textRadialOffset} or the two-dimensional {@link PropertyFactory#textOffset}.
*
* @param value a String[] value
* @return property wrapper around String[]

View File

@@ -8,6 +8,13 @@ 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;
/**
* Raster map textures such as satellite imagery.
*

View File

@@ -10,9 +10,12 @@ 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;
import com.mapbox.mapboxsdk.style.types.Formatted;
import com.mapbox.mapboxsdk.style.types.FormattedSection;
/**
* An icon or a text label.

View File

@@ -7,11 +7,11 @@
package com.mapbox.mapboxsdk.style.layers;
import android.support.annotation.ColorInt;
import android.support.annotation.Keep;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.annotation.UiThread;
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;

View File

@@ -5,7 +5,7 @@
package com.mapbox.mapboxsdk.style.layers;
import android.support.annotation.StringDef;
import androidx.annotation.StringDef;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;

View File

@@ -6,7 +6,7 @@
package com.mapbox.mapboxsdk.style.layers;
import android.support.annotation.ColorInt;
import androidx.annotation.ColorInt;
import com.mapbox.mapboxsdk.style.expressions.Expression;
import com.mapbox.mapboxsdk.style.types.Formatted;

View File

@@ -6,10 +6,10 @@
package com.mapbox.mapboxsdk.style.light;
import android.support.annotation.ColorInt;
import android.support.annotation.Keep;
import android.support.annotation.NonNull;
import android.support.annotation.UiThread;
import androidx.annotation.ColorInt;
import androidx.annotation.Keep;
import androidx.annotation.NonNull;
import androidx.annotation.UiThread;
import com.mapbox.mapboxsdk.style.layers.Property;
import com.mapbox.mapboxsdk.style.layers.TransitionOptions;

View File

@@ -10,11 +10,13 @@ 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.BackgroundLayer;
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.*;

View File

@@ -99,6 +99,32 @@ public class FillLayerTest extends BaseLayerTest {
@Test
@UiThreadTest
public void testFillSortKeyAsConstant() {
Timber.i("fill-sort-key");
assertNotNull(layer);
assertNull(layer.getFillSortKey().getValue());
// Set and Get
Float propertyValue = 0.3f;
layer.setProperties(fillSortKey(propertyValue));
assertEquals(layer.getFillSortKey().getValue(), propertyValue);
}
@Test
@UiThreadTest
public void testFillSortKeyAsExpression() {
Timber.i("fill-sort-key-expression");
assertNotNull(layer);
assertNull(layer.getFillSortKey().getExpression());
// Set and Get
Expression expression = number(Expression.get("undefined"));
layer.setProperties(fillSortKey(expression));
assertEquals(layer.getFillSortKey().getExpression(), expression);
}
@Test
@UiThreadTest
public void testFillAntialiasAsConstant() {

View File

@@ -2,6 +2,7 @@
package com.mapbox.mapboxsdk.testapp.style;
import android.graphics.Color;
import androidx.test.annotation.UiThreadTest;
import androidx.test.ext.junit.runners.AndroidJUnit4;

View File

@@ -10,11 +10,13 @@ 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.HillshadeLayer;
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.*;

View File

@@ -164,6 +164,32 @@ public class LineLayerTest extends BaseLayerTest {
assertEquals(layer.getLineRoundLimit().getValue(), propertyValue);
}
@Test
@UiThreadTest
public void testLineSortKeyAsConstant() {
Timber.i("line-sort-key");
assertNotNull(layer);
assertNull(layer.getLineSortKey().getValue());
// Set and Get
Float propertyValue = 0.3f;
layer.setProperties(lineSortKey(propertyValue));
assertEquals(layer.getLineSortKey().getValue(), propertyValue);
}
@Test
@UiThreadTest
public void testLineSortKeyAsExpression() {
Timber.i("line-sort-key-expression");
assertNotNull(layer);
assertNull(layer.getLineSortKey().getExpression());
// Set and Get
Expression expression = number(Expression.get("undefined"));
layer.setProperties(lineSortKey(expression));
assertEquals(layer.getLineSortKey().getExpression(), expression);
}
@Test
@UiThreadTest
public void testLineOpacityTransition() {

View File

@@ -2,6 +2,7 @@
package com.mapbox.mapboxsdk.testapp.style;
import android.graphics.Color;
import androidx.test.annotation.UiThreadTest;
import androidx.test.ext.junit.runners.AndroidJUnit4;
@@ -9,11 +10,13 @@ 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.RasterLayer;
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.*;

View File

@@ -7,7 +7,7 @@
package com.mapbox.mapboxsdk.testapp.style;
import android.graphics.Color;
import android.support.test.annotation.UiThreadTest;
import androidx.test.annotation.UiThreadTest;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import com.mapbox.mapboxsdk.maps.BaseLayerTest;

View File

@@ -4,8 +4,8 @@
package com.mapbox.mapboxsdk.testapp.style;
import android.graphics.Color;
import android.support.test.espresso.UiController;
import android.support.test.espresso.ViewAction;
import androidx.test.espresso.UiController;
import androidx.test.espresso.ViewAction;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import android.view.View;
@@ -24,9 +24,9 @@ import org.hamcrest.Matcher;
import org.junit.Test;
import org.junit.runner.RunWith;
import static android.support.test.espresso.Espresso.onView;
import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed;
import static android.support.test.espresso.matcher.ViewMatchers.withId;
import static androidx.test.espresso.Espresso.onView;
import static androidx.test.espresso.matcher.ViewMatchers.isDisplayed;
import static androidx.test.espresso.matcher.ViewMatchers.withId;
import static com.mapbox.mapboxsdk.style.expressions.Expression.eq;
import static com.mapbox.mapboxsdk.style.layers.Property.ANCHOR_MAP;
import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.fillExtrusionBase;

6
package-lock.json generated
View File

@@ -5,9 +5,9 @@
"requires": true,
"dependencies": {
"ejs": {
"version": "2.7.1",
"resolved": "https://registry.npmjs.org/ejs/-/ejs-2.7.1.tgz",
"integrity": "sha512-kS/gEPzZs3Y1rRsbGX4UOSjtP/CeJP0CxSNZHYxGfVM/VgLcv0ZqM7C45YyTj2DI2g7+P9Dd24C+IMIg6D0nYQ==",
"version": "2.7.4",
"resolved": "https://registry.npmjs.org/ejs/-/ejs-2.7.4.tgz",
"integrity": "sha512-7vmuyh5+kuUyJKePhQfRQBhXV5Ce+RnaeeQArKu1EAMpL3WbgMt5WG6uQZpEVvYSSsxMXRKOewtDk9RaTKXRlA==",
"dev": true
},
"esm": {

View File

@@ -13,7 +13,7 @@
"license": "BSD-2-Clause",
"dependencies": {},
"devDependencies": {
"ejs": "^2.5.7",
"ejs": "^2.7.4",
"esm": "~3.1.0",
"lodash": "^4.16.4",
"pixelmatch": "^4.0.2"

View File

@@ -8,8 +8,8 @@ const _ = require('lodash');
// FIXME: https://github.com/mapbox/mapbox-gl-native/issues/15008
delete spec.layout_circle["circle-sort-key"]
delete spec.layout_line["line-sort-key"]
delete spec.layout_fill["fill-sort-key"]
//delete spec.layout_line["line-sort-key"]
//delete spec.layout_fill["fill-sort-key"]
require('../vendor/mapbox-gl-native/scripts/style-code');
@@ -383,6 +383,17 @@ for (const layer of layers) {
writeIfModified(`MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/${camelize(layer.type)}LayerTest.java`, layerJavaUnitTests(layer));
}
// Jni
const layerHpp = ejs.compile(fs.readFileSync('vendor/mapbox-gl-native/platform/android/src/style/layers/layer.hpp.ejs', 'utf8'), {strict: true});
const layerCpp = ejs.compile(fs.readFileSync('vendor/mapbox-gl-native/platform/android/src/style/layers/layer.cpp.ejs', 'utf8'), {strict: true});
for (const layer of layers) {
const layerFileName = layer.type.replace('-', '_');
writeIfModified(`vendor/mapbox-gl-native/platform/android/src/style/layers/${layerFileName}_layer.hpp`, layerHpp(layer));
writeIfModified(`vendor/mapbox-gl-native/platform/android/src/style/layers/${layerFileName}_layer.cpp`, layerCpp(layer));
}
// Java PropertyFactory
const propertiesTemplate = ejs.compile(fs.readFileSync('MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/property_factory.java.ejs', 'utf8'), {strict: true});
writeIfModified(