[ios, android] add visual tests for fill, line, & numeric filter styling (#6433)

This commit is contained in:
Justin R. Miller
2016-09-23 10:13:11 -07:00
committed by GitHub
parent a03e6c14b6
commit 6aa00afd31
10 changed files with 57125 additions and 9 deletions

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -44,8 +44,11 @@ import java.io.Writer;
import java.util.ArrayList;
import java.util.List;
import static android.os.Looper.getMainLooper;
import static com.mapbox.mapboxsdk.style.layers.Filter.all;
import static com.mapbox.mapboxsdk.style.layers.Filter.eq;
import static com.mapbox.mapboxsdk.style.layers.Filter.gte;
import static com.mapbox.mapboxsdk.style.layers.Filter.lt;
import static com.mapbox.mapboxsdk.style.layers.Function.Stop;
import static com.mapbox.mapboxsdk.style.layers.Function.stop;
import static com.mapbox.mapboxsdk.style.layers.Function.zoom;
@@ -62,6 +65,7 @@ import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.fillTranslateAnc
import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.lineCap;
import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.lineColor;
import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.lineJoin;
import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.lineOpacity;
import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.lineWidth;
import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.symbolPlacement;
import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.visibility;
@@ -174,6 +178,15 @@ public class RuntimeStyleActivity extends AppCompatActivity {
case R.id.action_add_custom_tiles:
addCustomTileSource();
return true;
case R.id.action_fill_filter:
styleFillFilterLayer();
return true;
case R.id.action_line_filter:
styleLineFilterLayer();
return true;
case R.id.action_numeric_filter:
styleNumericFillLayer();
return true;
default:
return super.onOptionsItemSelected(item);
}
@@ -452,6 +465,97 @@ public class RuntimeStyleActivity extends AppCompatActivity {
);
}
private void styleFillFilterLayer() {
mapboxMap.setStyleUrl("asset://fill_filter_style.json");
mapboxMap.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(31, -100), 3));
Handler handler = new Handler(getMainLooper());
handler.postDelayed(new Runnable() {
@Override
public void run() {
if (mapboxMap == null) {
return;
}
Log.d(TAG, "Styling filtered fill layer");
FillLayer states = (FillLayer) mapboxMap.getLayer("states");
if (states != null) {
states.setFilter(eq("name", "Texas"));
states.setProperties(
fillColor(Color.RED),
fillOpacity(0.25f)
);
} else {
Toast.makeText(RuntimeStyleActivity.this, "No states layer in this style", Toast.LENGTH_SHORT).show();
}
}
}, 2000);
}
private void styleLineFilterLayer() {
mapboxMap.setStyleUrl("asset://line_filter_style.json");
mapboxMap.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(40, -97), 5));
Handler handler = new Handler(getMainLooper());
handler.postDelayed(new Runnable() {
@Override
public void run() {
if (mapboxMap == null) {
return;
}
Log.d(TAG, "Styling filtered line layer");
LineLayer counties = (LineLayer) mapboxMap.getLayer("counties");
if (counties != null) {
counties.setFilter(eq("NAME10", "Washington"));
counties.setProperties(
lineColor(Color.RED),
lineOpacity(0.75f),
lineWidth(5f)
);
} else {
Toast.makeText(RuntimeStyleActivity.this, "No counties layer in this style", Toast.LENGTH_SHORT).show();
}
}
}, 2000);
}
private void styleNumericFillLayer() {
mapboxMap.setStyleUrl("asset://numeric_filter_style.json");
mapboxMap.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(40, -97), 5));
Handler handler = new Handler(getMainLooper());
handler.postDelayed(new Runnable() {
@Override
public void run() {
if (mapboxMap == null) {
return;
}
Log.d(TAG, "Styling numeric fill layer");
FillLayer regions = (FillLayer) mapboxMap.getLayer("regions");
if (regions != null) {
regions.setFilter(all(gte("HRRNUM", 200), lt("HRRNUM", 300)));
regions.setProperties(
fillColor(Color.BLUE),
fillOpacity(0.5f)
);
} else {
Toast.makeText(RuntimeStyleActivity.this, "No regions layer in this style", Toast.LENGTH_SHORT).show();
}
}
}, 2000);
}
private static class DefaultCallback implements MapboxMap.CancelableCallback {
@Override

View File

@@ -24,7 +24,7 @@
mapbox:showAsAction="never" />
<item
android:id="@+id/action_add_dynamic_parks_layer"
android:title="Add a dynamic geojson source"
android:title="Add a dynamic GeoJSON source"
mapbox:showAsAction="never" />
<item
android:id="@+id/action_remove_layer"
@@ -46,4 +46,16 @@
android:id="@+id/action_add_custom_tiles"
android:title="Custom tiles"
mapbox:showAsAction="never" />
<item
android:id="@+id/action_fill_filter"
android:title="Apply filtered fill"
mapbox:showAsAction="never" />
<item
android:id="@+id/action_line_filter"
android:title="Apply filtered line"
mapbox:showAsAction="never" />
<item
android:id="@+id/action_numeric_filter"
android:title="Apply numeric fill filter"
mapbox:showAsAction="never" />
</menu>

View File

@@ -58,6 +58,9 @@ typedef NS_ENUM(NSInteger, MBXSettingsRuntimeStylingRows) {
MBXSettingsRuntimeStylingBuildings,
MBXSettingsRuntimeStylingFerry,
MBXSettingsRuntimeStylingParks,
MBXSettingsRuntimeStylingFilteredFill,
MBXSettingsRuntimeStylingFilteredLines,
MBXSettingsRuntimeStylingNumericFilteredFill,
};
typedef NS_ENUM(NSInteger, MBXSettingsMiscellaneousRows) {
@@ -290,14 +293,17 @@ typedef NS_ENUM(NSInteger, MBXSettingsMiscellaneousRows) {
break;
case MBXSettingsRuntimeStyling:
[settingsTitles addObjectsFromArray:@[
@"Apply Water Functions",
@"Apply Road Line Functions",
@"Create Raster & Apply Function",
@"Create GeoJSON & Apply Fill",
@"Apply Symbol Color",
@"Apply Building Fill Color",
@"Apply Ferry Line Color",
@"Remove Park Layer",
@"Style Water With Function",
@"Style Roads With Function",
@"Add Raster & Apply Function",
@"Add GeoJSON & Apply Fill",
@"Style Symbol Color",
@"Style Building Fill Color",
@"Style Ferry Line Color",
@"Remove Parks",
@"Style Fill With Filter",
@"Style Lines With Filter",
@"Style Fill With Numeric Filter",
]];
break;
case MBXSettingsMiscellaneous:
@@ -414,6 +420,15 @@ typedef NS_ENUM(NSInteger, MBXSettingsMiscellaneousRows) {
case MBXSettingsRuntimeStylingParks:
[self removeParkLayer];
break;
case MBXSettingsRuntimeStylingFilteredFill:
[self styleFilteredFill];
break;
case MBXSettingsRuntimeStylingFilteredLines:
[self styleFilteredLines];
break;
case MBXSettingsRuntimeStylingNumericFilteredFill:
[self styleNumericFilteredFills];
break;
default:
NSAssert(NO, @"All runtime styling setting rows should be implemented");
break;
@@ -709,6 +724,67 @@ typedef NS_ENUM(NSInteger, MBXSettingsMiscellaneousRows) {
[self.mapView.style removeLayer:parkLayer];
}
- (void)styleFilteredFill
{
// set style and focus on Texas
[self.mapView setStyleURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"fill_filter_style" ofType:@"json"]]];
[self.mapView setCenterCoordinate:CLLocationCoordinate2DMake(31, -100) zoomLevel:3 animated:NO];
// after slight delay, fill in Texas (atypical use; we want to clearly see the change for test purposes)
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^
{
MGLFillStyleLayer *statesLayer = (MGLFillStyleLayer *)[self.mapView.style layerWithIdentifier:@"states"];
// filter
statesLayer.predicate = [NSPredicate predicateWithFormat:@"name == 'Texas'"];
// paint properties
statesLayer.fillColor = [UIColor redColor];
statesLayer.fillOpacity = @(0.25);
});
}
- (void)styleFilteredLines
{
// set style and focus on lower 48
[self.mapView setStyleURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"line_filter_style" ofType:@"json"]]];
[self.mapView setCenterCoordinate:CLLocationCoordinate2DMake(40, -97) zoomLevel:5 animated:NO];
// after slight delay, change styling for all Washington-named counties (atypical use; we want to clearly see the change for test purposes)
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^
{
MGLLineStyleLayer *countiesLayer = (MGLLineStyleLayer *)[self.mapView.style layerWithIdentifier:@"counties"];
// filter
countiesLayer.predicate = [NSPredicate predicateWithFormat:@"NAME10 == 'Washington'"];
// paint properties
countiesLayer.lineColor = [UIColor redColor];
countiesLayer.lineOpacity = @(0.75);
countiesLayer.lineWidth = @(5);
});
}
- (void)styleNumericFilteredFills
{
// set style and focus on lower 48
[self.mapView setStyleURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"numeric_filter_style" ofType:@"json"]]];
[self.mapView setCenterCoordinate:CLLocationCoordinate2DMake(40, -97) zoomLevel:5 animated:NO];
// after slight delay, change styling for regions 200-299 (atypical use; we want to clearly see the change for test purposes)
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^
{
MGLFillStyleLayer *regionsLayer = (MGLFillStyleLayer *)[self.mapView.style layerWithIdentifier:@"regions"];
// filter (testing both inline and format strings)
regionsLayer.predicate = [NSPredicate predicateWithFormat:@"HRRNUM >= %@ AND HRRNUM < 300", @(200)];
// paint properties
regionsLayer.fillColor = [UIColor blueColor];
regionsLayer.fillOpacity = @(0.5);
});
}
- (IBAction)startWorldTour
{
_isTouringWorld = YES;

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -404,6 +404,9 @@
DAED38641D62D0FC00D7640F /* NSURL+MGLAdditions.h in Headers */ = {isa = PBXBuildFile; fileRef = DAED38611D62D0FC00D7640F /* NSURL+MGLAdditions.h */; };
DAED38651D62D0FC00D7640F /* NSURL+MGLAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = DAED38621D62D0FC00D7640F /* NSURL+MGLAdditions.m */; };
DAED38661D62D0FC00D7640F /* NSURL+MGLAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = DAED38621D62D0FC00D7640F /* NSURL+MGLAdditions.m */; };
DD4823751D94AE6C00EB71B7 /* fill_filter_style.json in Resources */ = {isa = PBXBuildFile; fileRef = DD4823721D94AE6C00EB71B7 /* fill_filter_style.json */; };
DD4823761D94AE6C00EB71B7 /* line_filter_style.json in Resources */ = {isa = PBXBuildFile; fileRef = DD4823731D94AE6C00EB71B7 /* line_filter_style.json */; };
DD4823771D94AE6C00EB71B7 /* numeric_filter_style.json in Resources */ = {isa = PBXBuildFile; fileRef = DD4823741D94AE6C00EB71B7 /* numeric_filter_style.json */; };
DD58A4C61D822BD000E1F038 /* MGLExpressionTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = DD58A4C51D822BD000E1F038 /* MGLExpressionTests.mm */; };
/* End PBXBuildFile section */
@@ -758,6 +761,9 @@
DAD165771CF4CDFF001FF4B9 /* MGLShapeCollection.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MGLShapeCollection.m; sourceTree = "<group>"; };
DAED38611D62D0FC00D7640F /* NSURL+MGLAdditions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSURL+MGLAdditions.h"; sourceTree = "<group>"; };
DAED38621D62D0FC00D7640F /* NSURL+MGLAdditions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSURL+MGLAdditions.m"; sourceTree = "<group>"; };
DD4823721D94AE6C00EB71B7 /* fill_filter_style.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = fill_filter_style.json; sourceTree = "<group>"; };
DD4823731D94AE6C00EB71B7 /* line_filter_style.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = line_filter_style.json; sourceTree = "<group>"; };
DD4823741D94AE6C00EB71B7 /* numeric_filter_style.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = numeric_filter_style.json; sourceTree = "<group>"; };
DD58A4C51D822BD000E1F038 /* MGLExpressionTests.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = MGLExpressionTests.mm; path = ../../darwin/test/MGLExpressionTests.mm; sourceTree = "<group>"; };
/* End PBXFileReference section */
@@ -996,6 +1002,9 @@
DA1DC96D1CB6C6CE006E619F /* polyline.geojson */,
DA1DC96F1CB6C6CE006E619F /* threestates.geojson */,
353BAEF51D646370009A8DA9 /* amsterdam.geojson */,
DD4823721D94AE6C00EB71B7 /* fill_filter_style.json */,
DD4823731D94AE6C00EB71B7 /* line_filter_style.json */,
DD4823741D94AE6C00EB71B7 /* numeric_filter_style.json */,
DA1DC95E1CB6C1C2006E619F /* Info.plist */,
DA1DC99C1CB6E076006E619F /* Default-568h@2x.png */,
DA1DC94D1CB6C1C2006E619F /* Supporting Files */,
@@ -1759,13 +1768,16 @@
buildActionMask = 2147483647;
files = (
DA25D5CD1CCDA11500607828 /* Settings.bundle in Resources */,
DD4823771D94AE6C00EB71B7 /* numeric_filter_style.json in Resources */,
DA1DC9701CB6C6CE006E619F /* points.geojson in Resources */,
353BAEF61D646370009A8DA9 /* amsterdam.geojson in Resources */,
DA1DC9711CB6C6CE006E619F /* polyline.geojson in Resources */,
DD4823761D94AE6C00EB71B7 /* line_filter_style.json in Resources */,
DA1DC99D1CB6E076006E619F /* Default-568h@2x.png in Resources */,
DA821D071CCC6D59007508D4 /* Main.storyboard in Resources */,
DA1DC9731CB6C6CE006E619F /* threestates.geojson in Resources */,
DA821D061CCC6D59007508D4 /* LaunchScreen.storyboard in Resources */,
DD4823751D94AE6C00EB71B7 /* fill_filter_style.json in Resources */,
DA1DC99F1CB6E088006E619F /* Assets.xcassets in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;