Skip to content

Commit 417260a

Browse files
Merge pull request #4 from AtlasProgramming/feature/2025-07-style-filters
Add Style Filters
2 parents 3f0f75e + f70b365 commit 417260a

20 files changed

Lines changed: 251 additions & 6 deletions

CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -972,11 +972,13 @@ list(APPEND SRC_FILES
972972
${PROJECT_SOURCE_DIR}/src/mbgl/plugin/plugin_layer_properties.hpp
973973
${PROJECT_SOURCE_DIR}/src/mbgl/plugin/plugin_layer_impl.hpp
974974
${PROJECT_SOURCE_DIR}/src/mbgl/plugin/plugin_layer_factory.hpp
975+
${PROJECT_SOURCE_DIR}/src/mbgl/plugin/plugin_style_filter.hpp
975976
${PROJECT_SOURCE_DIR}/src/mbgl/plugin/plugin_layer.cpp
976977
${PROJECT_SOURCE_DIR}/src/mbgl/plugin/plugin_layer_render.cpp
977978
${PROJECT_SOURCE_DIR}/src/mbgl/plugin/plugin_layer_properties.cpp
978979
${PROJECT_SOURCE_DIR}/src/mbgl/plugin/plugin_layer_impl.cpp
979980
${PROJECT_SOURCE_DIR}/src/mbgl/plugin/plugin_layer_factory.cpp
981+
${PROJECT_SOURCE_DIR}/src/mbgl/plugin/plugin_style_filter.cpp
980982
${PROJECT_SOURCE_DIR}/src/mbgl/plugin/feature_collection.hpp
981983
${PROJECT_SOURCE_DIR}/src/mbgl/plugin/feature_collection.cpp
982984
${PROJECT_SOURCE_DIR}/src/mbgl/plugin/feature_collection_bucket.hpp

bazel/core.bzl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ MLN_LAYER_PLUGIN_HEADERS = [
44
"src/mbgl/plugin/plugin_layer_impl.hpp",
55
"src/mbgl/plugin/plugin_layer_render.hpp",
66
"src/mbgl/plugin/plugin_layer_properties.hpp",
7+
"src/mbgl/plugin/plugin_style_filter.hpp",
78
"src/mbgl/plugin/feature_collection_bucket.hpp",
89
"src/mbgl/plugin/feature_collection.hpp",
910
]
@@ -14,6 +15,7 @@ MLN_LAYER_PLUGIN_SOURCE = [
1415
"src/mbgl/plugin/plugin_layer_impl.cpp",
1516
"src/mbgl/plugin/plugin_layer_render.cpp",
1617
"src/mbgl/plugin/plugin_layer_properties.cpp",
18+
"src/mbgl/plugin/plugin_style_filter.cpp",
1719
"src/mbgl/plugin/feature_collection_bucket.cpp",
1820
"src/mbgl/plugin/feature_collection.cpp",
1921
]

include/mbgl/style/style.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ namespace style {
2020
class Light;
2121
class Source;
2222
class Layer;
23+
class PluginStyleFilter;
2324

2425
class Style {
2526
public:
@@ -71,6 +72,9 @@ class Style {
7172
void addLayer(std::unique_ptr<Layer>, const std::optional<std::string>& beforeLayerID = std::nullopt);
7273
std::unique_ptr<Layer> removeLayer(const std::string& layerID);
7374

75+
// Add style parsing filter
76+
void addStyleFilter(std::shared_ptr<mbgl::style::PluginStyleFilter>);
77+
7478
// Private implementation
7579
class Impl;
7680
const std::unique_ptr<Impl> impl;

platform/BUILD.bazel

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,8 @@ objc_library(
268268
srcs = [
269269
"//platform/darwin:app/PluginLayerExample.h",
270270
"//platform/darwin:app/PluginLayerExample.mm",
271+
"//platform/darwin:app/StyleFilterExample.h",
272+
"//platform/darwin:app/StyleFilterExample.mm",
271273
"//platform/darwin:app/PluginLayerExampleMetalRendering.h",
272274
"//platform/darwin:app/PluginLayerExampleMetalRendering.mm",
273275
"//platform/darwin:app/CustomStyleLayerExample.h",

platform/darwin/BUILD.bazel

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,8 @@ exports_files(
301301
"app/PluginLayerTestStyle.json",
302302
"app/PluginLayerExample.h",
303303
"app/PluginLayerExample.mm",
304+
"app/StyleFilterExample.h",
305+
"app/StyleFilterExample.mm",
304306
"app/PluginLayerExampleMetalRendering.h",
305307
"app/PluginLayerExampleMetalRendering.mm",
306308
"test/amsterdam.geojson",
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#import "MLNStyleFilter.h"
2+
3+
NS_ASSUME_NONNULL_BEGIN
4+
5+
@interface StyleFilterExample : MLNStyleFilter
6+
7+
@end
8+
9+
NS_ASSUME_NONNULL_END
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#import "StyleFilterExample.h"
2+
3+
@implementation StyleFilterExample
4+
5+
// This will filter the data passed in
6+
-(NSData *)filterData:(NSData *)data {
7+
// Don't call super
8+
9+
// This example will remove any layer that has "metal-rendering-layer" in the id
10+
11+
// Parse the JSON: Make the containers mutable
12+
NSError *error = nil;
13+
NSMutableDictionary *styleDictionary = [NSJSONSerialization JSONObjectWithData:data
14+
options:NSJSONReadingMutableContainers
15+
error:&error];
16+
17+
NSData *tempResult = data;
18+
if (styleDictionary) {
19+
20+
// Get the layer array
21+
NSMutableArray *layerArray = [styleDictionary objectForKey:@"layers"];
22+
23+
// Create an array to hold which objects to remove since we can't remove them in the loop
24+
NSMutableArray *removedLayers = [NSMutableArray array];
25+
26+
// Loop the layers and look for any layers that have the search string in them
27+
for (NSMutableDictionary *layer in layerArray) {
28+
NSString *layerID = [layer objectForKey:@"id"];
29+
30+
// If we find the layers we're looking for, add them to the list of layers to remove
31+
if ([layerID containsString:@"metal-rendering-layer"]) {
32+
[removedLayers addObject:layer];
33+
}
34+
}
35+
36+
// Go through and remove any layers that were found
37+
for (NSMutableDictionary *l in removedLayers) {
38+
[layerArray removeObject:l];
39+
}
40+
41+
// Re-create the JSON, this time the layers we filtered out won't be there
42+
NSData *filteredStyleJSON = [NSJSONSerialization dataWithJSONObject:styleDictionary
43+
options:0
44+
error:&error];
45+
46+
// If the JSON write is successful, then set the output to the new json style
47+
if (filteredStyleJSON) {
48+
tempResult = filteredStyleJSON;
49+
}
50+
51+
}
52+
53+
// Return the data
54+
return tempResult;
55+
56+
}
57+
58+
59+
60+
@end

platform/darwin/bazel/files.bzl

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ MLN_DARWIN_OBJC_HEADERS = [
108108
"src/NSValue+MLNAdditions.h",
109109
"src/MLNPluginLayer.h",
110110
"src/MLNPluginStyleLayer.h",
111+
"src/MLNStyleFilter.h"
111112
]
112113

113114
MLN_DARWIN_OBJCPP_HEADERS = [
@@ -165,8 +166,8 @@ MLN_DARWIN_PRIVATE_HEADERS = [
165166
"src/MLNVectorTileSource_Private.h",
166167
"src/NSExpression+MLNPrivateAdditions.h",
167168
"src/NSPredicate+MLNPrivateAdditions.h",
168-
"src/MLNPluginStyleLayer_Private.h"
169-
169+
"src/MLNPluginStyleLayer_Private.h",
170+
"src/MLNStyleFilter_Private.h"
170171
]
171172

172173
MLN_DARWIN_PUBLIC_OBJCPP_SOURCE = [
@@ -222,8 +223,8 @@ MLN_DARWIN_PUBLIC_OBJCPP_SOURCE = [
222223
"src/NSPredicate+MLNAdditions.mm",
223224
"src/NSValue+MLNStyleAttributeAdditions.mm",
224225
"src/MLNPluginLayer.mm",
225-
"src/MLNPluginStyleLayer.mm"
226-
226+
"src/MLNPluginStyleLayer.mm",
227+
"src/MLNStyleFilter.mm",
227228
]
228229
MLN_DARWIN_PUBLIC_OBJCPP_CUSTOM_DRAWABLE_SOURCE = [
229230
"src/MLNCustomDrawableStyleLayer_Private.h",

platform/darwin/darwin.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ add_library(
164164
"${CMAKE_CURRENT_LIST_DIR}/app/CustomStyleLayerExample.m"
165165
"${CMAKE_CURRENT_LIST_DIR}/app/PluginLayerExample.mm"
166166
"${CMAKE_CURRENT_LIST_DIR}/app/PluginLayerExampleMetalRendering.mm"
167+
"${CMAKE_CURRENT_LIST_DIR}/app/StyleFilterExample.mm"
167168
)
168169

169170
target_link_libraries(
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#import <Foundation/Foundation.h>
2+
3+
NS_ASSUME_NONNULL_BEGIN
4+
5+
@interface MLNStyleFilter : NSObject
6+
7+
// This will filter the data passed in
8+
- (NSData *)filterData:(NSData *)data;
9+
10+
@end
11+
12+
NS_ASSUME_NONNULL_END

0 commit comments

Comments
 (0)