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

Commit

Permalink
[core] Update shaders.
Browse files Browse the repository at this point in the history
Implements 'icon-pitch-alignment' (issue #9345)
Fixes issue #9456 (map-aligned point label regression)
  • Loading branch information
ChrisLoer committed Jul 11, 2017
1 parent 4f63a39 commit 0ec9633
Show file tree
Hide file tree
Showing 25 changed files with 470 additions and 148 deletions.
1 change: 1 addition & 0 deletions include/mbgl/style/conversion/make_property_setters.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ auto makeLayoutPropertySetters() {
result["icon-padding"] = &setProperty<V, SymbolLayer, PropertyValue<float>, &SymbolLayer::setIconPadding>;
result["icon-keep-upright"] = &setProperty<V, SymbolLayer, PropertyValue<bool>, &SymbolLayer::setIconKeepUpright>;
result["icon-offset"] = &setProperty<V, SymbolLayer, DataDrivenPropertyValue<std::array<float, 2>>, &SymbolLayer::setIconOffset>;
result["icon-pitch-alignment"] = &setProperty<V, SymbolLayer, PropertyValue<AlignmentType>, &SymbolLayer::setIconPitchAlignment>;
result["text-pitch-alignment"] = &setProperty<V, SymbolLayer, PropertyValue<AlignmentType>, &SymbolLayer::setTextPitchAlignment>;
result["text-rotation-alignment"] = &setProperty<V, SymbolLayer, PropertyValue<AlignmentType>, &SymbolLayer::setTextRotationAlignment>;
result["text-field"] = &setProperty<V, SymbolLayer, DataDrivenPropertyValue<std::string>, &SymbolLayer::setTextField>;
Expand Down
4 changes: 4 additions & 0 deletions include/mbgl/style/layers/symbol_layer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ class SymbolLayer : public Layer {
DataDrivenPropertyValue<std::array<float, 2>> getIconOffset() const;
void setIconOffset(DataDrivenPropertyValue<std::array<float, 2>>);

static PropertyValue<AlignmentType> getDefaultIconPitchAlignment();
PropertyValue<AlignmentType> getIconPitchAlignment() const;
void setIconPitchAlignment(PropertyValue<AlignmentType>);

static PropertyValue<AlignmentType> getDefaultTextPitchAlignment();
PropertyValue<AlignmentType> getTextPitchAlignment() const;
void setTextPitchAlignment(PropertyValue<AlignmentType>);
Expand Down
4 changes: 4 additions & 0 deletions include/mbgl/util/size.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ class Size {
constexpr uint32_t area() const {
return width * height;
}

constexpr float aspectRatio() const {
return static_cast<float>(width) / static_cast<float>(height);
}

constexpr bool isEmpty() const {
return width == 0 || height == 0;
Expand Down
2 changes: 1 addition & 1 deletion mapbox-gl-js
Submodule mapbox-gl-js updated 37 files
+112 −0 build/generate-flow-typed-style-spec.js
+0 −0 build/minifyify_style_spec.js
+0 −0 build/strictify.js
+290 −0 flow-typed/style-spec.js
+15 −0 flow-typed/tilejson.js
+3 −2 package.json
+3 −2 src/source/geojson_source.js
+3 −3 src/source/geojson_worker_source.js
+1 −1 src/source/rtl_text_plugin.js
+2 −2 src/source/source.js
+65 −56 src/source/tile_coord.js
+2 −2 src/source/vector_tile_worker_source.js
+2 −2 src/source/worker.js
+2 −2 src/source/worker_tile.js
+12 −3 src/style/style_layer_index.js
+33 −27 src/util/ajax.js
+16 −10 src/util/evented.js
+5 −5 src/util/mapbox.js
+1 −1 src/util/util.js
+0 −3 test/integration/render-tests/icon-pitch-alignment/auto-rotation-alignment-map/style.json
+0 −3 test/integration/render-tests/icon-pitch-alignment/auto-rotation-alignment-viewport/style.json
+0 −3 test/integration/render-tests/icon-pitch-alignment/map-rotation-alignment-viewport/style.json
+0 −3 test/integration/render-tests/icon-pitch-alignment/viewport-rotation-alignment-map/style.json
+1 −4 test/integration/render-tests/icon-text-fit/placement-line/style.json
+0 −3 test/integration/render-tests/regressions/mapbox-gl-js#4860/style.json
+1 −4 test/integration/render-tests/symbol-placement/point-polygon/style.json
+1 −4 test/integration/render-tests/symbol-spacing/line-close/style.json
+1 −4 test/integration/render-tests/symbol-spacing/line-overscaled/style.json
+1 −4 test/integration/render-tests/text-keep-upright/line-placement-false/style.json
+1 −4 test/integration/render-tests/text-keep-upright/line-placement-true-pitched/style.json
+1 −4 test/integration/render-tests/text-keep-upright/line-placement-true-rotated/style.json
+1 −4 test/integration/render-tests/text-keep-upright/line-placement-true/style.json
+1 −4 test/integration/render-tests/text-max-angle/literal/style.json
+1 −4 test/integration/render-tests/text-size/composite-function-line-placement/style.json
+1 −4 test/integration/render-tests/text-writing-mode/chinese/style.json
+1 −4 test/integration/render-tests/text-writing-mode/mixed/style.json
+10 −0 test/unit/source/geojson_source.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,32 @@ public final class Property {
@Retention(RetentionPolicy.SOURCE)
public @interface ICON_TEXT_FIT {}

// ICON_PITCH_ALIGNMENT: Orientation of icon when map is pitched.

/**
* The icon is aligned to the plane of the map.
*/
public static final String ICON_PITCH_ALIGNMENT_MAP = "map";
/**
* The icon is aligned to the plane of the viewport.
*/
public static final String ICON_PITCH_ALIGNMENT_VIEWPORT = "viewport";
/**
* Automatically matches the value of {@link ICON_ROTATION_ALIGNMENT}.
*/
public static final String ICON_PITCH_ALIGNMENT_AUTO = "auto";

/**
* Orientation of icon when map is pitched.
*/
@StringDef({
ICON_PITCH_ALIGNMENT_MAP,
ICON_PITCH_ALIGNMENT_VIEWPORT,
ICON_PITCH_ALIGNMENT_AUTO,
})
@Retention(RetentionPolicy.SOURCE)
public @interface ICON_PITCH_ALIGNMENT {}

// TEXT_PITCH_ALIGNMENT: Orientation of text when map is pitched.

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1881,6 +1881,29 @@ public static <T> PropertyValue<Function<T, Float[]>> iconOffset(Function<T, Flo
return new LayoutPropertyValue<>("icon-offset", function);
}

/**
* Orientation of icon when map is pitched.
*
* @param value a String value
* @return property wrapper around String
*/
public static PropertyValue<String> iconPitchAlignment(@Property.ICON_PITCH_ALIGNMENT String value) {
return new LayoutPropertyValue<>("icon-pitch-alignment", value);
}



/**
* Orientation of icon when map is pitched.
*
* @param <Z> the zoom parameter type
* @param function a wrapper {@link CameraFunction} for String
* @return property wrapper around a String function
*/
public static <Z extends Number> PropertyValue<CameraFunction<Z, String>> iconPitchAlignment(CameraFunction<Z, String> function) {
return new LayoutPropertyValue<>("icon-pitch-alignment", function);
}

/**
* Orientation of text when map is pitched.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,16 @@ public PropertyValue<Float[]> getIconOffset() {
return (PropertyValue<Float[]>) new PropertyValue("icon-offset", nativeGetIconOffset());
}

/**
* Get the IconPitchAlignment property
*
* @return property wrapper value around String
*/
@SuppressWarnings("unchecked")
public PropertyValue<String> getIconPitchAlignment() {
return (PropertyValue<String>) new PropertyValue("icon-pitch-alignment", nativeGetIconPitchAlignment());
}

/**
* Get the TextPitchAlignment property
*
Expand Down Expand Up @@ -891,6 +901,8 @@ public PropertyValue<String> getTextTranslateAnchor() {

private native Object nativeGetIconOffset();

private native Object nativeGetIconPitchAlignment();

private native Object nativeGetTextPitchAlignment();

private native Object nativeGetTextRotationAlignment();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@ public void setAnchor(@Property.ANCHOR String anchor) {
*
* @return anchor as String
*/
@Property.ANCHOR
public String getAnchor() {
@Property.ANCHOR public String getAnchor() {
return nativeGetAnchor();
}

Expand Down Expand Up @@ -107,7 +106,7 @@ public void setColor(String color) {
*
* @return color as String
*/
public String getColor() {
public String getColor() {
return nativeGetColor();
}

Expand Down Expand Up @@ -143,7 +142,7 @@ public void setIntensity(float intensity) {
*
* @return intensity as Float
*/
public float getIntensity() {
public float getIntensity() {
return nativeGetIntensity();
}

Expand All @@ -166,30 +165,17 @@ public void setIntensityTransition(TransitionOptions options) {
}

private native void nativeSetAnchor(String anchor);

private native String nativeGetAnchor();

private native void nativeSetPosition(Position position);

private native Position nativeGetPosition();

private native TransitionOptions nativeGetPositionTransition();

private native void nativeSetPositionTransition(long duration, long delay);

private native void nativeSetColor(String color);

private native String nativeGetColor();

private native TransitionOptions nativeGetColorTransition();

private native void nativeSetColorTransition(long duration, long delay);

private native void nativeSetIntensity(float intensity);

private native float nativeGetIntensity();

private native TransitionOptions nativeGetIntensityTransition();

private native void nativeSetIntensityTransition(long duration, long delay);
}
Original file line number Diff line number Diff line change
Expand Up @@ -1052,37 +1052,47 @@ public void testCirclePitchAlignmentAsConstant() {
validateTestSetup();
setupLayer();
Timber.i("circle-pitch-alignment");
assertNotNull(layer);
invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() {
@Override
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
assertNotNull(layer);

// Set and Get
layer.setProperties(circlePitchAlignment(CIRCLE_PITCH_ALIGNMENT_MAP));
assertEquals((String) layer.getCirclePitchAlignment().getValue(), (String) CIRCLE_PITCH_ALIGNMENT_MAP);
// Set and Get
layer.setProperties(circlePitchAlignment(CIRCLE_PITCH_ALIGNMENT_MAP));
assertEquals((String) layer.getCirclePitchAlignment().getValue(), (String) CIRCLE_PITCH_ALIGNMENT_MAP);
}
});
}

@Test
public void testCirclePitchAlignmentAsCameraFunction() {
validateTestSetup();
setupLayer();
Timber.i("circle-pitch-alignment");
assertNotNull(layer);

// Set
layer.setProperties(
circlePitchAlignment(
zoom(
interval(
stop(2, circlePitchAlignment(CIRCLE_PITCH_ALIGNMENT_MAP))
invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() {
@Override
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
assertNotNull(layer);

// Set
layer.setProperties(
circlePitchAlignment(
zoom(
interval(
stop(2, circlePitchAlignment(CIRCLE_PITCH_ALIGNMENT_MAP))
)
)
)
)
)
);

// Verify
assertNotNull(layer.getCirclePitchAlignment());
assertNotNull(layer.getCirclePitchAlignment().getFunction());
assertEquals(CameraFunction.class, layer.getCirclePitchAlignment().getFunction().getClass());
assertEquals(IntervalStops.class, layer.getCirclePitchAlignment().getFunction().getStops().getClass());
assertEquals(1, ((IntervalStops) layer.getCirclePitchAlignment().getFunction().getStops()).size());
);

// Verify
assertNotNull(layer.getCirclePitchAlignment());
assertNotNull(layer.getCirclePitchAlignment().getFunction());
assertEquals(CameraFunction.class, layer.getCirclePitchAlignment().getFunction().getClass());
assertEquals(IntervalStops.class, layer.getCirclePitchAlignment().getFunction().getStops().getClass());
assertEquals(1, ((IntervalStops) layer.getCirclePitchAlignment().getFunction().getStops()).size());
}
});
}

@Test
Expand Down
Loading

0 comments on commit 0ec9633

Please sign in to comment.