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

fix #6379: beef up runtime styling manual tests #6433

Merged
merged 1 commit into from
Sep 23, 2016
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
10,976 changes: 10,976 additions & 0 deletions platform/android/MapboxGLAndroidSDKTestApp/src/main/assets/fill_filter_style.json

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,11 @@
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;
Expand All @@ -62,6 +65,7 @@
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;
Expand Down Expand Up @@ -174,6 +178,15 @@ public boolean onOptionsItemSelected(MenuItem item) {
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);
}
Expand Down Expand Up @@ -452,6 +465,97 @@ private void addCustomTileSource() {
);
}

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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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>
92 changes: 84 additions & 8 deletions platform/ios/app/MBXViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ typedef NS_ENUM(NSInteger, MBXSettingsRuntimeStylingRows) {
MBXSettingsRuntimeStylingBuildings,
MBXSettingsRuntimeStylingFerry,
MBXSettingsRuntimeStylingParks,
MBXSettingsRuntimeStylingFilteredFill,
MBXSettingsRuntimeStylingFilteredLines,
MBXSettingsRuntimeStylingNumericFilteredFill,
};

typedef NS_ENUM(NSInteger, MBXSettingsMiscellaneousRows) {
Expand Down Expand Up @@ -290,14 +293,17 @@ - (void)dismissSettings:(__unused id)sender
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:
Expand Down Expand Up @@ -414,6 +420,15 @@ - (void)performActionForSettingAtIndexPath:(NSIndexPath *)indexPath
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;
Expand Down Expand Up @@ -709,6 +724,67 @@ - (void)removeParkLayer
[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;
Expand Down
Loading