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

[core] Do not consider X axis when constraining scale #13463

Merged
merged 3 commits into from
Nov 29, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions include/mbgl/style/layers/fill_extrusion_layer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,12 @@ class FillExtrusionLayer : public Layer {
void setFillExtrusionBaseTransition(const TransitionOptions&);
TransitionOptions getFillExtrusionBaseTransition() const;

static PropertyValue<bool> getDefaultFillExtrusionVerticalGradient();
PropertyValue<bool> getFillExtrusionVerticalGradient() const;
void setFillExtrusionVerticalGradient(PropertyValue<bool>);
void setFillExtrusionVerticalGradientTransition(const TransitionOptions&);
TransitionOptions getFillExtrusionVerticalGradientTransition() const;

// Private implementation

class Impl;
Expand Down
2 changes: 1 addition & 1 deletion mapbox-gl-js
Submodule mapbox-gl-js updated 246 files
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"aws-sdk": "^2.285.1",
"csscolorparser": "^1.0.2",
"ejs": "^2.4.1",
"esm": "^3.0.55",
"esm": "^3.0.84",
"express": "^4.11.1",
"flow-remove-types": "^1.2.1",
"json-stringify-pretty-compact": "^1.0.4",
Expand Down
1 change: 1 addition & 0 deletions platform/android/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Mapbox welcomes participation and contributions from everyone. If you'd like to

## master
- Add "localIdeographFontFamily" setting to MapSnapshotter to reduce font data usage while snapshotting CJK maps [#13427](https://github.com/mapbox/mapbox-gl-native/pull/13427)
- Add `fill-extrusion-vertical-gradient` fill paint property [#13463](https://github.com/mapbox/mapbox-gl-native/pull/13463)

## 7.0.0-alpha.2 - November 21, 2018
- Add overlay example with custom drawing using paint and canvas [#13431](https://github.com/mapbox/mapbox-gl-native/pull/13431)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,18 @@ public void setFillExtrusionBaseTransition(@NonNull TransitionOptions options) {
nativeSetFillExtrusionBaseTransition(options.getDuration(), options.getDelay());
}

/**
* Get the FillExtrusionVerticalGradient property
*
* @return property wrapper value around Boolean
*/
@NonNull
@SuppressWarnings("unchecked")
public PropertyValue<Boolean> getFillExtrusionVerticalGradient() {
checkThread();
return (PropertyValue<Boolean>) new PropertyValue("fill-extrusion-vertical-gradient", nativeGetFillExtrusionVerticalGradient());
}

@NonNull
@Keep
private native Object nativeGetFillExtrusionOpacity();
Expand Down Expand Up @@ -440,6 +452,10 @@ public void setFillExtrusionBaseTransition(@NonNull TransitionOptions options) {
@Keep
private native void nativeSetFillExtrusionBaseTransition(long duration, long delay);

@NonNull
@Keep
private native Object nativeGetFillExtrusionVerticalGradient();

@Override
@Keep
protected native void finalize() throws Throwable;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1244,6 +1244,26 @@ public static PropertyValue<Expression> fillExtrusionBase(Expression expression)
return new PaintPropertyValue<>("fill-extrusion-base", expression);
}

/**
* Whether to apply a vertical gradient to the sides of a fill-extrusion layer. If true, sides will be shaded slightly darker farther down.
*
* @param value a Boolean value
* @return property wrapper around Boolean
*/
public static PropertyValue<Boolean> fillExtrusionVerticalGradient(Boolean value) {
return new PaintPropertyValue<>("fill-extrusion-vertical-gradient", value);
}

/**
* Whether to apply a vertical gradient to the sides of a fill-extrusion layer. If true, sides will be shaded slightly darker farther down.
*
* @param expression an expression statement
* @return property wrapper around an expression statement
*/
public static PropertyValue<Expression> fillExtrusionVerticalGradient(Expression expression) {
return new PaintPropertyValue<>("fill-extrusion-vertical-gradient", expression);
}

/**
* The opacity at which the image will be drawn.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -401,4 +401,20 @@ public void testFillExtrusionBaseAsExpression() {
assertEquals(layer.getFillExtrusionBase().getExpression(), expression);
});
}

@Test
public void testFillExtrusionVerticalGradientAsConstant() {
validateTestSetup();
setupLayer();
Timber.i("fill-extrusion-vertical-gradient");
invoke(mapboxMap, (uiController, mapboxMap) -> {
assertNotNull(layer);
assertNull(layer.getFillExtrusionVerticalGradient().getValue());

// Set and Get
Boolean propertyValue = true;
layer.setProperties(fillExtrusionVerticalGradient(propertyValue));
assertEquals(layer.getFillExtrusionVerticalGradient().getValue(), propertyValue);
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,11 @@ namespace android {
toFillExtrusionLayer(layer).setFillExtrusionBaseTransition(options);
}

jni::Local<jni::Object<>> FillExtrusionLayer::getFillExtrusionVerticalGradient(jni::JNIEnv& env) {
using namespace mbgl::android::conversion;
return std::move(*convert<jni::Local<jni::Object<>>>(env, toFillExtrusionLayer(layer).getFillExtrusionVerticalGradient()));
}


// FillExtrusionJavaLayerPeerFactory

Expand Down Expand Up @@ -207,7 +212,8 @@ namespace android {
METHOD(&FillExtrusionLayer::getFillExtrusionHeight, "nativeGetFillExtrusionHeight"),
METHOD(&FillExtrusionLayer::getFillExtrusionBaseTransition, "nativeGetFillExtrusionBaseTransition"),
METHOD(&FillExtrusionLayer::setFillExtrusionBaseTransition, "nativeSetFillExtrusionBaseTransition"),
METHOD(&FillExtrusionLayer::getFillExtrusionBase, "nativeGetFillExtrusionBase"));
METHOD(&FillExtrusionLayer::getFillExtrusionBase, "nativeGetFillExtrusionBase"),
METHOD(&FillExtrusionLayer::getFillExtrusionVerticalGradient, "nativeGetFillExtrusionVerticalGradient"));
}

} // namespace android
Expand Down
2 changes: 2 additions & 0 deletions platform/android/src/style/layers/fill_extrusion_layer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ class FillExtrusionLayer : public Layer {
void setFillExtrusionBaseTransition(jni::JNIEnv&, jlong duration, jlong delay);
jni::Local<jni::Object<TransitionOptions>> getFillExtrusionBaseTransition(jni::JNIEnv&);

jni::Local<jni::Object<jni::ObjectTag>> getFillExtrusionVerticalGradient(jni::JNIEnv&);

}; // class FillExtrusionLayer

class FillExtrusionJavaLayerPeerFactory final : public JavaLayerPeerFactory, public mbgl::FillExtrusionLayerFactory {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@
},
"paint_fill-extrusion": {
"fill-extrusion-translate": "fill-extrusion-translation",
"fill-extrusion-translate-anchor": "fill-extrusion-translation-anchor"
"fill-extrusion-translate-anchor": "fill-extrusion-translation-anchor",
"fill-extrusion-vertical-gradient": "fill-extrusion-has-vertical-gradient"
},
"paint_raster": {
"raster-brightness-min": "minimum-raster-brightness",
Expand Down
27 changes: 27 additions & 0 deletions platform/darwin/src/MGLFillExtrusionStyleLayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,33 @@ MGL_EXPORT
*/
@property (nonatomic) MGLTransition fillExtrusionColorTransition;

/**
Whether to apply a vertical gradient to the sides of a fill-extrusion layer. If
true, sides will be shaded slightly darker farther down.

The default value of this property is an expression that evaluates to `YES`.
Set this property to `nil` to reset it to the default value.

This attribute corresponds to the <a
href="https://www.mapbox.com/mapbox-gl-style-spec/#paint-fill-extrusion-vertical-gradient"><code>fill-extrusion-vertical-gradient</code></a>
layout property in the Mapbox Style Specification.

You can set this property to an expression containing any of the following:

* Constant Boolean values
* Predefined functions, including mathematical and string operators
* Conditional expressions
* Variable assignments and references to assigned variables
* Step functions applied to the `$zoomLevel` variable

This property does not support applying interpolation functions to the
`$zoomLevel` variable or applying interpolation or step functions to feature
attributes.
*/
@property (nonatomic, null_resettable) NSExpression *fillExtrusionHasVerticalGradient;

@property (nonatomic, null_resettable) NSExpression *fillExtrusionVerticalGradient __attribute__((unavailable("Use fillExtrusionHasVerticalGradient instead.")));

/**
The height with which to extrude this layer.

Expand Down
25 changes: 25 additions & 0 deletions platform/darwin/src/MGLFillExtrusionStyleLayer.mm
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,31 @@ - (MGLTransition)fillExtrusionColorTransition {
return transition;
}

- (void)setFillExtrusionHasVerticalGradient:(NSExpression *)fillExtrusionHasVerticalGradient {
MGLAssertStyleLayerIsValid();
MGLLogDebug(@"Setting fillExtrusionHasVerticalGradient: %@", fillExtrusionHasVerticalGradient);

auto mbglValue = MGLStyleValueTransformer<bool, NSNumber *>().toPropertyValue<mbgl::style::PropertyValue<bool>>(fillExtrusionHasVerticalGradient, false);
self.rawLayer->setFillExtrusionVerticalGradient(mbglValue);
}

- (NSExpression *)fillExtrusionHasVerticalGradient {
MGLAssertStyleLayerIsValid();

auto propertyValue = self.rawLayer->getFillExtrusionVerticalGradient();
if (propertyValue.isUndefined()) {
propertyValue = self.rawLayer->getDefaultFillExtrusionVerticalGradient();
}
return MGLStyleValueTransformer<bool, NSNumber *>().toExpression(propertyValue);
}

- (void)setFillExtrusionVerticalGradient:(NSExpression *)fillExtrusionVerticalGradient {
}

- (NSExpression *)fillExtrusionVerticalGradient {
return self.fillExtrusionHasVerticalGradient;
}

- (void)setFillExtrusionHeight:(NSExpression *)fillExtrusionHeight {
MGLAssertStyleLayerIsValid();
MGLLogDebug(@"Setting fillExtrusionHeight: %@", fillExtrusionHeight);
Expand Down
45 changes: 45 additions & 0 deletions platform/darwin/test/MGLFillExtrusionStyleLayerTests.mm
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,50 @@ - (void)testProperties {
XCTAssertEqual(fillExtrusionColorTransition.duration, transitionTest.duration);
}

// fill-extrusion-vertical-gradient
{
XCTAssertTrue(rawLayer->getFillExtrusionVerticalGradient().isUndefined(),
@"fill-extrusion-vertical-gradient should be unset initially.");
NSExpression *defaultExpression = layer.fillExtrusionHasVerticalGradient;

NSExpression *constantExpression = [NSExpression expressionWithFormat:@"false"];
layer.fillExtrusionHasVerticalGradient = constantExpression;
mbgl::style::PropertyValue<bool> propertyValue = { false };
XCTAssertEqual(rawLayer->getFillExtrusionVerticalGradient(), propertyValue,
@"Setting fillExtrusionHasVerticalGradient to a constant value expression should update fill-extrusion-vertical-gradient.");
XCTAssertEqualObjects(layer.fillExtrusionHasVerticalGradient, constantExpression,
@"fillExtrusionHasVerticalGradient should round-trip constant value expressions.");

constantExpression = [NSExpression expressionWithFormat:@"false"];
NSExpression *functionExpression = [NSExpression expressionWithFormat:@"mgl_step:from:stops:($zoomLevel, %@, %@)", constantExpression, @{@18: constantExpression}];
layer.fillExtrusionHasVerticalGradient = functionExpression;

{
using namespace mbgl::style::expression::dsl;
propertyValue = mbgl::style::PropertyExpression<bool>(
step(zoom(), literal(false), 18.0, literal(false))
);
}

XCTAssertEqual(rawLayer->getFillExtrusionVerticalGradient(), propertyValue,
@"Setting fillExtrusionHasVerticalGradient to a camera expression should update fill-extrusion-vertical-gradient.");
XCTAssertEqualObjects(layer.fillExtrusionHasVerticalGradient, functionExpression,
@"fillExtrusionHasVerticalGradient should round-trip camera expressions.");


layer.fillExtrusionHasVerticalGradient = nil;
XCTAssertTrue(rawLayer->getFillExtrusionVerticalGradient().isUndefined(),
@"Unsetting fillExtrusionHasVerticalGradient should return fill-extrusion-vertical-gradient to the default value.");
XCTAssertEqualObjects(layer.fillExtrusionHasVerticalGradient, defaultExpression,
@"fillExtrusionHasVerticalGradient should return the default value after being unset.");

functionExpression = [NSExpression expressionForKeyPath:@"bogus"];
XCTAssertThrowsSpecificNamed(layer.fillExtrusionHasVerticalGradient = functionExpression, NSException, NSInvalidArgumentException, @"MGLFillExtrusionLayer should raise an exception if a camera-data expression is applied to a property that does not support key paths to feature attributes.");
functionExpression = [NSExpression expressionWithFormat:@"mgl_step:from:stops:(bogus, %@, %@)", constantExpression, @{@18: constantExpression}];
functionExpression = [NSExpression expressionWithFormat:@"mgl_interpolate:withCurveType:parameters:stops:($zoomLevel, 'linear', nil, %@)", @{@10: functionExpression}];
XCTAssertThrowsSpecificNamed(layer.fillExtrusionHasVerticalGradient = functionExpression, NSException, NSInvalidArgumentException, @"MGLFillExtrusionLayer should raise an exception if a camera-data expression is applied to a property that does not support key paths to feature attributes.");
}

// fill-extrusion-height
{
XCTAssertTrue(rawLayer->getFillExtrusionHeight().isUndefined(),
Expand Down Expand Up @@ -481,6 +525,7 @@ - (void)testProperties {
- (void)testPropertyNames {
[self testPropertyName:@"fill-extrusion-base" isBoolean:NO];
[self testPropertyName:@"fill-extrusion-color" isBoolean:NO];
[self testPropertyName:@"fill-extrusion-has-vertical-gradient" isBoolean:YES];
[self testPropertyName:@"fill-extrusion-height" isBoolean:NO];
[self testPropertyName:@"fill-extrusion-opacity" isBoolean:NO];
[self testPropertyName:@"fill-extrusion-pattern" isBoolean:NO];
Expand Down
3 changes: 3 additions & 0 deletions platform/ios/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

Mapbox welcomes participation and contributions from everyone. Please read [CONTRIBUTING.md](../../CONTRIBUTING.md) to get started.

## master
* Added the `MGLFillExtrusionStyleLayer.fillExtrusionHasVerticalGradient` property. ([#13463](https://github.com/mapbox/mapbox-gl-native/pull/13463))

## 4.7.0

### Styles and rendering
Expand Down
1 change: 1 addition & 0 deletions platform/ios/docs/guides/For Style Authors.md
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ In style JSON | In Objective-C | In Swift

In style JSON | In Objective-C | In Swift
--------------|----------------|---------
`fill-extrusion-vertical-gradient` | `MGLFillExtrusionStyleLayer.fillExtrusionHasVerticalGradient` | `MGLFillExtrusionStyleLayer.fillExtrusionHasVerticalGradient`
`fill-extrusion-translate` | `MGLFillExtrusionStyleLayer.fillExtrusionTranslation` | `MGLFillExtrusionStyleLayer.fillExtrusionTranslation`
`fill-extrusion-translate-anchor` | `MGLFillExtrusionStyleLayer.fillExtrusionTranslationAnchor` | `MGLFillExtrusionStyleLayer.fillExtrusionTranslationAnchor`

Expand Down
1 change: 1 addition & 0 deletions platform/macos/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* Fixed an issue where the `{prefix}` token in tile URL templates was evaluated incorrectly when requesting a source’s tiles. ([#13429](https://github.com/mapbox/mapbox-gl-native/pull/13429))
* Added `-[MGLStyle removeSource:error:]` that returns a `BOOL` indicating success (and an optional `NSError` in case of failure). ([#13399](https://github.com/mapbox/mapbox-gl-native/pull/13399))
* Added support for setting `MGLCollisionBehaviorPre4_0` in `NSUserDefaults`. ([#13426](https://github.com/mapbox/mapbox-gl-native/pull/13426))
* Added the `MGLFillExtrusionStyleLayer.fillExtrusionHasVerticalGradient` property. ([#13463](https://github.com/mapbox/mapbox-gl-native/pull/13463))

## 0.12.0 - November 8, 2018

Expand Down
1 change: 1 addition & 0 deletions platform/macos/docs/guides/For Style Authors.md
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ In style JSON | In Objective-C | In Swift

In style JSON | In Objective-C | In Swift
--------------|----------------|---------
`fill-extrusion-vertical-gradient` | `MGLFillExtrusionStyleLayer.fillExtrusionHasVerticalGradient` | `MGLFillExtrusionStyleLayer.fillExtrusionHasVerticalGradient`
`fill-extrusion-translate` | `MGLFillExtrusionStyleLayer.fillExtrusionTranslation` | `MGLFillExtrusionStyleLayer.fillExtrusionTranslation`
`fill-extrusion-translate-anchor` | `MGLFillExtrusionStyleLayer.fillExtrusionTranslationAnchor` | `MGLFillExtrusionStyleLayer.fillExtrusionTranslationAnchor`

Expand Down
2 changes: 2 additions & 0 deletions platform/node/test/ignores.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
"render-tests/canvas/default": "skip - js specific",
"render-tests/collator/resolved-locale": "Some test platforms don't resolve 'en' locale",
"render-tests/collator/default": "Some test platforms don't resolve 'en' locale",
"render-tests/custom-layer-js/depth": "skip - js specific",
"render-tests/custom-layer-js/null-island": "skip - js specific",
"render-tests/custom-layer-js/tent-3d": "skip - js specific",
"render-tests/debug/collision": "https://github.com/mapbox/mapbox-gl-native/issues/3841",
Expand All @@ -90,6 +91,7 @@
"render-tests/fill-extrusion-pattern/missing": "https://github.com/mapbox/mapbox-gl-js/issues/3327",
"render-tests/fill-extrusion-pattern/opacity": "https://github.com/mapbox/mapbox-gl-js/issues/3327",
"render-tests/fill-extrusion-pattern/feature-expression": "https://github.com/mapbox/mapbox-gl-js/issues/3327",
"render-tests/fill-extrusion-vertical-gradient/false": "https://github.com/mapbox/mapbox-gl-native/issues/13462",
"render-tests/fill-pattern/update-feature-state": "skip - port https://github.com/mapbox/mapbox-gl-js/pull/6263 - needs issue",
"render-tests/geojson/inline-linestring-fill": "current behavior is arbitrary",
"render-tests/geojson/inline-polygon-symbol": "behavior needs reconciliation with gl-js",
Expand Down
7 changes: 2 additions & 5 deletions src/mbgl/map/transform_state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -375,12 +375,9 @@ void TransformState::constrain(double& scale_, double& x_, double& y_) const {
return;
}

const double ratioX = (rotatedNorth() ? size.height : size.width) / util::tileSize;
// Constrain scale to avoid zooming out far enough to show off-world areas on the Y axis.
const double ratioY = (rotatedNorth() ? size.width : size.height) / util::tileSize;

// Constrain minimum scale to avoid zooming out far enough to show off-world areas on the Y axis.
// If Y axis ratio is too small to be constrained, use X axis ratio instead.
scale_ = util::max(scale_, ratioY < 1.0 ? ratioX : ratioY);
scale_ = util::max(scale_, ratioY);

// Constrain min/max pan to avoid showing off-world areas on the Y axis.
double max_y = (scale_ * util::tileSize - (rotatedNorth() ? size.width : size.height)) / 2;
Expand Down
7 changes: 3 additions & 4 deletions src/mbgl/renderer/buckets/heatmap_bucket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,9 @@ void HeatmapBucket::addFeature(const GeometryTileFeature& feature,
auto y = point.y;

// Do not include points that are outside the tile boundaries.
// Include all points in Still mode. You need to include points from
// neighbouring tiles so that they are not clipped at tile boundaries.
if ((mode == MapMode::Continuous) &&
(x < 0 || x >= util::EXTENT || y < 0 || y >= util::EXTENT)) continue;
if (x < 0 || x >= util::EXTENT || y < 0 || y >= util::EXTENT) {
continue;
}

if (segments.empty() || segments.back().vertexLength + vertexLength > std::numeric_limits<uint16_t>::max()) {
// Move to a new segments because the old one can't hold the geometry.
Expand Down
3 changes: 2 additions & 1 deletion src/mbgl/renderer/layers/render_fill_extrusion_layer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,8 @@ style::FillExtrusionPaintProperties::PossiblyEvaluated RenderFillExtrusionLayer:
evaluated.get<style::FillExtrusionTranslateAnchor>(),
evaluated.get<style::FillExtrusionPattern>(),
evaluated.get<style::FillExtrusionHeight>(),
evaluated.get<style::FillExtrusionBase>()
evaluated.get<style::FillExtrusionBase>(),
evaluated.get<style::FillExtrusionVerticalGradient>()
};
}

Expand Down
4 changes: 2 additions & 2 deletions src/mbgl/shaders/extrusion_texture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ namespace mbgl {
namespace shaders {

const char* extrusion_texture::name = "extrusion_texture";
const char* extrusion_texture::vertexSource = source() + 35603;
const char* extrusion_texture::fragmentSource = source() + 35819;
const char* extrusion_texture::vertexSource = source() + 36207;
const char* extrusion_texture::fragmentSource = source() + 36423;

// Uncompressed source of extrusion_texture.vertex.glsl:
/*
Expand Down
Loading