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

Commit

Permalink
[ios, macos] Add support for data-driven property functions
Browse files Browse the repository at this point in the history
  • Loading branch information
boundsj committed Feb 2, 2017
1 parent 7a37fdc commit fd7b289
Show file tree
Hide file tree
Showing 28 changed files with 3,891 additions and 1,926 deletions.
5 changes: 5 additions & 0 deletions include/mbgl/style/data_driven_property_value.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ class DataDrivenPropertyValue {
return lhs.value == rhs.value;
}

friend bool operator!=(const DataDrivenPropertyValue& lhs,
const DataDrivenPropertyValue& rhs) {
return !(lhs == rhs);
}

public:
DataDrivenPropertyValue() = default;
DataDrivenPropertyValue( T v) : value(std::move(v)) {}
Expand Down
14 changes: 7 additions & 7 deletions platform/darwin/src/MGLBackgroundStyleLayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ NS_ASSUME_NONNULL_BEGIN
map content. If the style’s other layers use the Mapbox Streets source, the
background style layer is responsible for drawing land, whereas the oceans and
other bodies of water are drawn by `MGLFillStyleLayer` objects.
A background style layer is typically the bottommost layer in a style, because
it covers the entire map and can occlude any layers below it. You can therefore
access it by getting the last item in the `MGLStyle.layers` array.
If the background style layer is transparent or omitted from the style, any
portion of the map view that does not show another style layer is transparent.
*/
Expand All @@ -31,23 +31,23 @@ MGL_EXPORT
#if TARGET_OS_IPHONE
/**
The color with which the background will be drawn.
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.
This property is only applied to the style if `backgroundPattern` is set to
`nil`. Otherwise, it is ignored.
*/
@property (nonatomic, null_resettable) MGLStyleValue<UIColor *> *backgroundColor;
#else
/**
The color with which the background will be drawn.
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.
This property is only applied to the style if `backgroundPattern` is set to
`nil`. Otherwise, it is ignored.
*/
Expand All @@ -56,7 +56,7 @@ MGL_EXPORT

/**
The opacity at which the background will be drawn.
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.
Expand Down
19 changes: 14 additions & 5 deletions platform/darwin/src/MGLBackgroundStyleLayer.mm
Original file line number Diff line number Diff line change
Expand Up @@ -86,28 +86,34 @@ - (void)removeFromMapView:(MGLMapView *)mapView
- (void)setBackgroundColor:(MGLStyleValue<MGLColor *> *)backgroundColor {
MGLAssertStyleLayerIsValid();

auto mbglValue = MGLStyleValueTransformer<mbgl::Color, MGLColor *>().toPropertyValue(backgroundColor);
auto mbglValue = MGLStyleValueTransformer<mbgl::Color, MGLColor *>().toInterpolatablePropertyValue(backgroundColor);
self.rawLayer->setBackgroundColor(mbglValue);
}

- (MGLStyleValue<MGLColor *> *)backgroundColor {
MGLAssertStyleLayerIsValid();

auto propertyValue = self.rawLayer->getBackgroundColor() ?: self.rawLayer->getDefaultBackgroundColor();
auto propertyValue = self.rawLayer->getBackgroundColor();
if (propertyValue.isUndefined()) {
return MGLStyleValueTransformer<mbgl::Color, MGLColor *>().toStyleValue(self.rawLayer->getDefaultBackgroundColor());
}
return MGLStyleValueTransformer<mbgl::Color, MGLColor *>().toStyleValue(propertyValue);
}

- (void)setBackgroundOpacity:(MGLStyleValue<NSNumber *> *)backgroundOpacity {
MGLAssertStyleLayerIsValid();

auto mbglValue = MGLStyleValueTransformer<float, NSNumber *>().toPropertyValue(backgroundOpacity);
auto mbglValue = MGLStyleValueTransformer<float, NSNumber *>().toInterpolatablePropertyValue(backgroundOpacity);
self.rawLayer->setBackgroundOpacity(mbglValue);
}

- (MGLStyleValue<NSNumber *> *)backgroundOpacity {
MGLAssertStyleLayerIsValid();

auto propertyValue = self.rawLayer->getBackgroundOpacity() ?: self.rawLayer->getDefaultBackgroundOpacity();
auto propertyValue = self.rawLayer->getBackgroundOpacity();
if (propertyValue.isUndefined()) {
return MGLStyleValueTransformer<float, NSNumber *>().toStyleValue(self.rawLayer->getDefaultBackgroundOpacity());
}
return MGLStyleValueTransformer<float, NSNumber *>().toStyleValue(propertyValue);
}

Expand All @@ -121,7 +127,10 @@ - (void)setBackgroundPattern:(MGLStyleValue<NSString *> *)backgroundPattern {
- (MGLStyleValue<NSString *> *)backgroundPattern {
MGLAssertStyleLayerIsValid();

auto propertyValue = self.rawLayer->getBackgroundPattern() ?: self.rawLayer->getDefaultBackgroundPattern();
auto propertyValue = self.rawLayer->getBackgroundPattern();
if (propertyValue.isUndefined()) {
return MGLStyleValueTransformer<std::string, NSString *>().toStyleValue(self.rawLayer->getDefaultBackgroundPattern());
}
return MGLStyleValueTransformer<std::string, NSString *>().toStyleValue(propertyValue);
}

Expand Down
50 changes: 25 additions & 25 deletions platform/darwin/src/MGLCircleStyleLayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,12 @@ typedef NS_ENUM(NSUInteger, MGLCircleTranslationAnchor) {
/**
An `MGLCircleStyleLayer` is a style layer that renders one or more filled
circles on the map.
Use a circle style layer to configure the visual appearance of point or point
collection features in vector tiles loaded by an `MGLVectorSource` object or
`MGLPointAnnotation`, `MGLPointFeature`, `MGLPointCollection`, or
`MGLPointCollectionFeature` instances in an `MGLShapeSource` object.
A circle style layer renders circles whose radii are measured in screen units.
To display circles on the map whose radii correspond to real-world distances,
use many-sided regular polygons and configure their appearance using an
Expand Down Expand Up @@ -84,7 +84,7 @@ MGL_EXPORT
/**
Amount to blur the circle. 1 blurs the circle such that only the centerpoint is
full opacity.
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.
Expand All @@ -94,7 +94,7 @@ MGL_EXPORT
#if TARGET_OS_IPHONE
/**
The fill 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.
Expand All @@ -103,7 +103,7 @@ MGL_EXPORT
#else
/**
The fill 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.
Expand All @@ -113,7 +113,7 @@ MGL_EXPORT

/**
The opacity at which the circle will be drawn.
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.
Expand All @@ -122,9 +122,9 @@ MGL_EXPORT

/**
Circle radius.
This property is measured in points.
The default value of this property is an `MGLStyleValue` object containing an
`NSNumber` object containing the float `5`. Set this property to `nil` to reset
it to the default value.
Expand All @@ -133,11 +133,11 @@ MGL_EXPORT

/**
Controls the scaling behavior of the circle when the map is pitched.
The default value of this property is an `MGLStyleValue` object containing an
`NSValue` object containing `MGLCircleScaleAlignmentMap`. 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-circle-pitch-scale"><code>circle-pitch-scale</code></a>
layout property in the Mapbox Style Specification.
Expand All @@ -149,7 +149,7 @@ MGL_EXPORT
#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.
Expand All @@ -158,7 +158,7 @@ MGL_EXPORT
#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.
Expand All @@ -168,7 +168,7 @@ MGL_EXPORT

/**
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.
Expand All @@ -177,10 +177,10 @@ MGL_EXPORT

/**
The width of the circle's stroke. Strokes are placed outside of the
"circle-radius".
`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.
Expand All @@ -190,13 +190,13 @@ MGL_EXPORT
#if TARGET_OS_IPHONE
/**
The geometry's offset.
This property is measured in points.
The default value of this property is an `MGLStyleValue` object containing an
`NSValue` object containing a `CGVector` struct set to 0 points rightward and 0
points downward. 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-circle-translate"><code>circle-translate</code></a>
layout property in the Mapbox Style Specification.
Expand All @@ -205,13 +205,13 @@ MGL_EXPORT
#else
/**
The geometry's offset.
This property is measured in points.
The default value of this property is an `MGLStyleValue` object containing an
`NSValue` object containing a `CGVector` struct set to 0 points rightward and 0
points upward. 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-circle-translate"><code>circle-translate</code></a>
layout property in the Mapbox Style Specification.
Expand All @@ -223,14 +223,14 @@ MGL_EXPORT

/**
Controls the translation reference point.
The default value of this property is an `MGLStyleValue` object containing an
`NSValue` object containing `MGLCircleTranslationAnchorMap`. Set this property
to `nil` to reset it to the default value.
This property is only applied to the style if `circleTranslation` is non-`nil`.
Otherwise, it is ignored.
This attribute corresponds to the <a
href="https://www.mapbox.com/mapbox-gl-style-spec/#paint-circle-translate-anchor"><code>circle-translate-anchor</code></a>
layout property in the Mapbox Style Specification.
Expand Down
Loading

0 comments on commit fd7b289

Please sign in to comment.