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

Commit

Permalink
[darwin, android] SDK bindings for circle-stroke properties
Browse files Browse the repository at this point in the history
  • Loading branch information
jfirebaugh committed Dec 9, 2016
1 parent 3b2a421 commit 82856fd
Show file tree
Hide file tree
Showing 12 changed files with 329 additions and 6 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"express": "^4.11.1",
"lodash": "^4.16.4",
"mapbox-gl-shaders": "mapbox/mapbox-gl-shaders#b51b85ffb8c512e228c36c5405293ce51d123519",
"mapbox-gl-style-spec": "mapbox/mapbox-gl-style-spec#deb30918f8637e7675a00731b799a5caec894b17",
"mapbox-gl-style-spec": "mapbox/mapbox-gl-style-spec#49e8b407bdbbe6f7c92dbcb56d3d51f425fc2653",
"mapbox-gl-test-suite": "mapbox/mapbox-gl-test-suite#9252ffc5108131704b5acf52d78258ac05687871",
"mkdirp": "^0.5.1",
"node-cmake": "^1.2.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,52 @@ public PropertyValue<String> getCirclePitchScale() {
return (PropertyValue<String>) new PropertyValue(nativeGetCirclePitchScale());
}

/**
* Get the CircleStrokeWidth property
*
* @return property wrapper value around Float
*/
@SuppressWarnings("unchecked")
public PropertyValue<Float> getCircleStrokeWidth() {
return (PropertyValue<Float>) new PropertyValue(nativeGetCircleStrokeWidth());
}

/**
* Get the CircleStrokeColor property
*
* @return property wrapper value around String
*/
@SuppressWarnings("unchecked")
public PropertyValue<String> getCircleStrokeColor() {
return (PropertyValue<String>) new PropertyValue(nativeGetCircleStrokeColor());
}
/**
* The stroke color of the circle.
*
* @return int representation of a rgba string color
* @throws RuntimeException thrown if property isn't a value
*/
@ColorInt
public int getCircleStrokeColorAsInt() {
PropertyValue<String> value = getCircleStrokeColor();
if (value.isValue()) {
return rgbaToColor(value.getValue());
} else {
throw new RuntimeException("circle-stroke-color was set as a Function");
}
}


/**
* Get the CircleStrokeOpacity property
*
* @return property wrapper value around Float
*/
@SuppressWarnings("unchecked")
public PropertyValue<Float> getCircleStrokeOpacity() {
return (PropertyValue<Float>) new PropertyValue(nativeGetCircleStrokeOpacity());
}

private native Object nativeGetCircleRadius();

private native Object nativeGetCircleColor();
Expand All @@ -210,6 +256,12 @@ public PropertyValue<String> getCirclePitchScale() {

private native Object nativeGetCirclePitchScale();

private native Object nativeGetCircleStrokeWidth();

private native Object nativeGetCircleStrokeColor();

private native Object nativeGetCircleStrokeOpacity();


@Override
protected native void finalize() throws Throwable;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -871,6 +871,76 @@ public static Property<Function<String>> circlePitchScale(Function<String> funct
return new PaintProperty<>("circle-pitch-scale", function);
}

/**
* The width of the circle's stroke. Strokes are placed outside of the "circle-radius".
*
* @param value a Float value
* @return property wrapper around Float
*/
public static Property<Float> circleStrokeWidth(Float value) {
return new PaintProperty<>("circle-stroke-width", value);
}

/**
* The width of the circle's stroke. Strokes are placed outside of the "circle-radius".
*
* @param function a wrapper function for Float
* @return property wrapper around a Float function
*/
public static Property<Function<Float>> circleStrokeWidth(Function<Float> function) {
return new PaintProperty<>("circle-stroke-width", function);
}

/**
* The stroke color of the circle.
*
* @param value a int color value
* @return property wrapper around String color
*/
public static Property<String> circleStrokeColor(@ColorInt int value) {
return new PaintProperty<>("circle-stroke-color", colorToRgbaString(value));
}

/**
* The stroke color of the circle.
*
* @param value a String value
* @return property wrapper around String
*/
public static Property<String> circleStrokeColor(String value) {
return new PaintProperty<>("circle-stroke-color", value);
}

/**
* The stroke color of the circle.
*
* @param function a wrapper function for String
* @return property wrapper around a String function
*/
public static Property<Function<String>> circleStrokeColor(Function<String> function) {
return new PaintProperty<>("circle-stroke-color", function);
}

/**
* The opacity of the circle's stroke.
*
* @param value a Float value
* @return property wrapper around Float
*/
public static Property<Float> circleStrokeOpacity(Float value) {
return new PaintProperty<>("circle-stroke-opacity", value);
}

/**
* The opacity of the circle's stroke.
*
* @param function a wrapper function for Float
* @return property wrapper around a Float function
*/
public static Property<Function<Float>> circleStrokeOpacity(Function<Float> function) {
return new PaintProperty<>("circle-stroke-opacity", function);
}

/**
* The opacity at which the image will be drawn.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,94 @@ public void testCirclePitchScale() {
assertEquals((String) layer.getCirclePitchScale().getValue(), (String) CIRCLE_PITCH_SCALE_MAP);
}

@Test
public void testCircleStrokeWidth() {
checkViewIsDisplayed(R.id.mapView);

mapboxMap = rule.getActivity().getMapboxMap();

if ((layer = mapboxMap.getLayerAs("my-layer")) == null) {
Timber.i("Adding layer");
layer = new CircleLayer("my-layer", "composite");
layer.setSourceLayer("composite");
mapboxMap.addLayer(layer);
//Layer reference is now stale, get new reference
layer = mapboxMap.getLayerAs("my-layer");
}
Timber.i("circle-stroke-width");
assertNotNull(layer);

//Set and Get
layer.setProperties(circleStrokeWidth(0.3f));
assertEquals((Float) layer.getCircleStrokeWidth().getValue(), (Float) 0.3f);
}

@Test
public void testCircleStrokeColor() {
checkViewIsDisplayed(R.id.mapView);

mapboxMap = rule.getActivity().getMapboxMap();

if ((layer = mapboxMap.getLayerAs("my-layer")) == null) {
Timber.i("Adding layer");
layer = new CircleLayer("my-layer", "composite");
layer.setSourceLayer("composite");
mapboxMap.addLayer(layer);
//Layer reference is now stale, get new reference
layer = mapboxMap.getLayerAs("my-layer");
}
Timber.i("circle-stroke-color");
assertNotNull(layer);

//Set and Get
layer.setProperties(circleStrokeColor("rgba(0, 0, 0, 1)"));
assertEquals((String) layer.getCircleStrokeColor().getValue(), (String) "rgba(0, 0, 0, 1)");
}

@Test
public void testCircleStrokeColorAsInt() {
checkViewIsDisplayed(R.id.mapView);

mapboxMap = rule.getActivity().getMapboxMap();

if ((layer = mapboxMap.getLayerAs("my-layer")) == null) {
Timber.i("Adding layer");
layer = new CircleLayer("my-layer", "composite");
layer.setSourceLayer("composite");
mapboxMap.addLayer(layer);
//Layer reference is now stale, get new reference
layer = mapboxMap.getLayerAs("my-layer");
}
Timber.i("circle-stroke-color");
assertNotNull(layer);

//Set and Get
layer.setProperties(circleStrokeColor(Color.RED));
assertEquals(layer.getCircleStrokeColorAsInt(), Color.RED);
}

@Test
public void testCircleStrokeOpacity() {
checkViewIsDisplayed(R.id.mapView);

mapboxMap = rule.getActivity().getMapboxMap();

if ((layer = mapboxMap.getLayerAs("my-layer")) == null) {
Timber.i("Adding layer");
layer = new CircleLayer("my-layer", "composite");
layer.setSourceLayer("composite");
mapboxMap.addLayer(layer);
//Layer reference is now stale, get new reference
layer = mapboxMap.getLayerAs("my-layer");
}
Timber.i("circle-stroke-opacity");
assertNotNull(layer);

//Set and Get
layer.setProperties(circleStrokeOpacity(0.3f));
assertEquals((Float) layer.getCircleStrokeOpacity().getValue(), (Float) 0.3f);
}


@After
public void unregisterIntentServiceIdlingResource() {
Expand Down
4 changes: 2 additions & 2 deletions platform/android/scripts/generate-style-code.js
Original file line number Diff line number Diff line change
Expand Up @@ -221,8 +221,8 @@ const layerJava = ejs.compile(fs.readFileSync('platform/android/MapboxGLAndroidS
const layerJavaUnitTests = ejs.compile(fs.readFileSync('platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/layer.junit.ejs', 'utf8'), {strict: true});

for (const layer of layers) {
writeIfModified(`platform/android/src/style/layers/${layer.type}_layer.hpp`, layerHpp(layer));
writeIfModified(`platform/android/src/style/layers/${layer.type}_layer.cpp`, layerCpp(layer));
writeIfModified(`platform/android/src/style/layers/${layer.type.replace('-', '_')}_layer.hpp`, layerHpp(layer));
writeIfModified(`platform/android/src/style/layers/${layer.type.replace('-', '_')}_layer.cpp`, layerCpp(layer));
writeIfModified(`platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/${camelize(layer.type)}Layer.java`, layerJava(layer));
writeIfModified(`platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/${camelize(layer.type)}LayerTest.java`, layerJavaUnitTests(layer));
}
Expand Down
23 changes: 22 additions & 1 deletion platform/android/src/style/layers/circle_layer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,24 @@ namespace android {
return jni::Object<jni::ObjectTag>(*converted);
}

jni::Object<jni::ObjectTag> CircleLayer::getCircleStrokeWidth(jni::JNIEnv& env) {
using namespace mbgl::android::conversion;
Result<jni::jobject*> converted = convert<jni::jobject*>(env, layer.as<mbgl::style::CircleLayer>()->CircleLayer::getCircleStrokeWidth());
return jni::Object<jni::ObjectTag>(*converted);
}

jni::Object<jni::ObjectTag> CircleLayer::getCircleStrokeColor(jni::JNIEnv& env) {
using namespace mbgl::android::conversion;
Result<jni::jobject*> converted = convert<jni::jobject*>(env, layer.as<mbgl::style::CircleLayer>()->CircleLayer::getCircleStrokeColor());
return jni::Object<jni::ObjectTag>(*converted);
}

jni::Object<jni::ObjectTag> CircleLayer::getCircleStrokeOpacity(jni::JNIEnv& env) {
using namespace mbgl::android::conversion;
Result<jni::jobject*> converted = convert<jni::jobject*>(env, layer.as<mbgl::style::CircleLayer>()->CircleLayer::getCircleStrokeOpacity());
return jni::Object<jni::ObjectTag>(*converted);
}

jni::Class<CircleLayer> CircleLayer::javaClass;

jni::jobject* CircleLayer::createJavaPeer(jni::JNIEnv& env) {
Expand All @@ -88,7 +106,10 @@ namespace android {
METHOD(&CircleLayer::getCircleOpacity, "nativeGetCircleOpacity"),
METHOD(&CircleLayer::getCircleTranslate, "nativeGetCircleTranslate"),
METHOD(&CircleLayer::getCircleTranslateAnchor, "nativeGetCircleTranslateAnchor"),
METHOD(&CircleLayer::getCirclePitchScale, "nativeGetCirclePitchScale"));
METHOD(&CircleLayer::getCirclePitchScale, "nativeGetCirclePitchScale"),
METHOD(&CircleLayer::getCircleStrokeWidth, "nativeGetCircleStrokeWidth"),
METHOD(&CircleLayer::getCircleStrokeColor, "nativeGetCircleStrokeColor"),
METHOD(&CircleLayer::getCircleStrokeOpacity, "nativeGetCircleStrokeOpacity"));
}

} // namespace android
Expand Down
6 changes: 6 additions & 0 deletions platform/android/src/style/layers/circle_layer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ class CircleLayer : public Layer {

jni::Object<jni::ObjectTag> getCirclePitchScale(jni::JNIEnv&);

jni::Object<jni::ObjectTag> getCircleStrokeWidth(jni::JNIEnv&);

jni::Object<jni::ObjectTag> getCircleStrokeColor(jni::JNIEnv&);

jni::Object<jni::ObjectTag> getCircleStrokeOpacity(jni::JNIEnv&);

jni::jobject* createJavaPeer(jni::JNIEnv&);

}; // class CircleLayer
Expand Down
2 changes: 1 addition & 1 deletion platform/android/src/style/layers/layer.hpp.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#pragma once

#include "layer.hpp"
#include <mbgl/style/layers/<%- type %>_layer.hpp>
#include <mbgl/style/layers/<%- type.replace('-', '_') %>_layer.hpp>
#include <jni/jni.hpp>

namespace mbgl {
Expand Down
32 changes: 32 additions & 0 deletions platform/darwin/src/MGLCircleStyleLayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,38 @@ typedef NS_ENUM(NSUInteger, MGLCircleTranslateAnchor) {
*/
@property (nonatomic, null_resettable) MGLStyleValue<NSNumber *> *circleRadius;

#if TARGET_OS_IPHONE
/**
The stroke color of the circle.
The default value of this property is an `MGLStyleValue` object containing `UIColor.blackColor`. Set this property to `nil` to reset it to the default value.
*/
@property (nonatomic, null_resettable) MGLStyleValue<MGLColor *> *circleStrokeColor;
#else
/**
The stroke color of the circle.
The default value of this property is an `MGLStyleValue` object containing `NSColor.blackColor`. Set this property to `nil` to reset it to the default value.
*/
@property (nonatomic, null_resettable) MGLStyleValue<MGLColor *> *circleStrokeColor;
#endif

/**
The opacity of the circle's stroke.
The default value of this property is an `MGLStyleValue` object containing an `NSNumber` object containing the float `1`. Set this property to `nil` to reset it to the default value.
*/
@property (nonatomic, null_resettable) MGLStyleValue<NSNumber *> *circleStrokeOpacity;

/**
The width of the circle's stroke. Strokes are placed outside of the `circleRadius`.
This property is measured in points.
The default value of this property is an `MGLStyleValue` object containing an `NSNumber` object containing the float `0`. Set this property to `nil` to reset it to the default value.
*/
@property (nonatomic, null_resettable) MGLStyleValue<NSNumber *> *circleStrokeWidth;

/**
The geometry's offset.
Expand Down
Loading

0 comments on commit 82856fd

Please sign in to comment.