Skip to content

Commit a7cf398

Browse files
author
“Malcolm
committed
Merge branch 'maplibre-plus' into feature/2025-07-custom-protocol
# Conflicts: # CMakeLists.txt # bazel/core.bzl # platform/BUILD.bazel # platform/darwin/bazel/files.bzl # platform/darwin/darwin.cmake # platform/ios/app/MBXViewController.mm # platform/ios/src/MLNMapView.h # platform/ios/src/MLNMapView.mm
2 parents 4a8010c + 417260a commit a7cf398

35 files changed

Lines changed: 881 additions & 23 deletions

CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -972,12 +972,18 @@ 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
980981
${PROJECT_SOURCE_DIR}/src/mbgl/plugin/plugin_file_source.hpp
982+
${PROJECT_SOURCE_DIR}/src/mbgl/plugin/plugin_style_filter.cpp
983+
${PROJECT_SOURCE_DIR}/src/mbgl/plugin/feature_collection.hpp
984+
${PROJECT_SOURCE_DIR}/src/mbgl/plugin/feature_collection.cpp
985+
${PROJECT_SOURCE_DIR}/src/mbgl/plugin/feature_collection_bucket.hpp
986+
${PROJECT_SOURCE_DIR}/src/mbgl/plugin/feature_collection_bucket.cpp
981987
)
982988

983989

bazel/core.bzl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ MLN_LAYER_PLUGIN_HEADERS = [
55
"src/mbgl/plugin/plugin_layer_render.hpp",
66
"src/mbgl/plugin/plugin_layer_properties.hpp",
77
"src/mbgl/plugin/plugin_file_source.hpp",
8+
"src/mbgl/plugin/plugin_style_filter.hpp",
9+
"src/mbgl/plugin/feature_collection_bucket.hpp",
10+
"src/mbgl/plugin/feature_collection.hpp",
811
]
912

1013
MLN_LAYER_PLUGIN_SOURCE = [
@@ -13,6 +16,9 @@ MLN_LAYER_PLUGIN_SOURCE = [
1316
"src/mbgl/plugin/plugin_layer_impl.cpp",
1417
"src/mbgl/plugin/plugin_layer_render.cpp",
1518
"src/mbgl/plugin/plugin_layer_properties.cpp",
19+
"src/mbgl/plugin/plugin_style_filter.cpp",
20+
"src/mbgl/plugin/feature_collection_bucket.cpp",
21+
"src/mbgl/plugin/feature_collection.cpp",
1622
]
1723

1824
MLN_PUBLIC_GENERATED_STYLE_HEADERS = [

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
@@ -270,6 +270,8 @@ objc_library(
270270
"//platform/darwin:app/PluginLayerExample.mm",
271271
"//platform/darwin:app/PluginProtocolExample.h",
272272
"//platform/darwin:app/PluginProtocolExample.mm",
273+
"//platform/darwin:app/StyleFilterExample.h",
274+
"//platform/darwin:app/StyleFilterExample.mm",
273275
"//platform/darwin:app/PluginLayerExampleMetalRendering.h",
274276
"//platform/darwin:app/PluginLayerExampleMetalRendering.mm",
275277
"//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
"app/PluginProtocolExample.h",
Lines changed: 69 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,39 @@
11
#import "PluginLayerExample.h"
22

3+
@interface PluginLayerExample () {
4+
5+
}
6+
7+
@property BOOL logFeatures;
8+
9+
@end
10+
11+
312
@implementation PluginLayerExample
413

514

615
// This is the layer type in the style that is used
716
+(MLNPluginLayerCapabilities *)layerCapabilities {
817

918
MLNPluginLayerCapabilities *tempResult = [[MLNPluginLayerCapabilities alloc] init];
10-
tempResult.layerID = @"plugin-layer-test";
19+
tempResult.layerID = @"maplibre::filter_features";
1120
tempResult.requiresPass3D = YES;
21+
tempResult.supportsReadingTileFeatures = YES;
1222
return tempResult;
1323

1424
}
1525

26+
-(id)init {
27+
if (self = [super init]) {
28+
self.logFeatures = NO;
29+
}
30+
return self;
31+
}
32+
1633
// The overrides
17-
-(void)onRenderLayer {
18-
NSLog(@"PluginLayerExample: On Render Layer");
34+
-(void)onRenderLayer:(MLNMapView *)mapView
35+
renderEncoder:(id<MTLRenderCommandEncoder>)renderEncoder {
36+
//NSLog(@"PluginLayerExample: On Render Layer");
1937

2038
}
2139

@@ -24,7 +42,54 @@ -(void)onUpdateLayer {
2442
}
2543

2644
-(void)onUpdateLayerProperties:(NSDictionary *)layerProperties {
27-
// NSLog(@"Layer Properties: %@", layerProperties);
45+
// NSLog(@"Layer Properties: %@", layerProperties);
46+
}
47+
48+
-(void)featureLoaded:(MLNPluginLayerTileFeature *)tileFeature {
49+
50+
// Writing a single string since the tile loading is multithreaded and the output can get interwoven
51+
NSMutableString *outputStr = [NSMutableString string];
52+
[outputStr appendFormat:@"Tile Feature (id:%@) Properties: %@\n", tileFeature.featureID, tileFeature.featureProperties];
53+
54+
for (NSValue *v in tileFeature.featureCoordinates) {
55+
56+
CLLocationCoordinate2D coord;
57+
[v getValue:&coord];
58+
59+
[outputStr appendFormat:@" -> (%f, %f) \n", coord.latitude, coord.longitude];
60+
61+
}
62+
63+
NSLog(@"Feature: %@", outputStr);
64+
}
65+
66+
-(void)featureUnloaded:(MLNPluginLayerTileFeature *)tileFeature {
67+
// NSLog(@"Tile Features Unloaded: %@", tileFeature.featureProperties);
68+
69+
}
70+
71+
72+
- (void)onFeatureLoaded:(MLNPluginLayerTileFeature *)tileFeature {
73+
74+
[self featureLoaded:tileFeature];
75+
76+
}
77+
78+
/// Called when a set of features are loaded from the tile
79+
- (void)onFeatureCollectionLoaded:(MLNPluginLayerTileFeatureCollection *)tileFeatureCollection {
80+
//NSLog(@"Feature Collection Loaded for tile: %@", tileFeatureCollection.tileID);
81+
for (MLNPluginLayerTileFeature *feature in tileFeatureCollection.features) {
82+
[self featureLoaded:feature];
83+
}
84+
85+
}
86+
87+
/// Called when a set of features are unloaded because the tile goes out of scene/etc
88+
- (void)onFeatureCollectionUnloaded:(MLNPluginLayerTileFeatureCollection *)tileFeatureCollection {
89+
//NSLog(@"Feature Collection Unloaded for tile: %@", tileFeatureCollection.tileID);
90+
for (MLNPluginLayerTileFeature *feature in tileFeatureCollection.features) {
91+
[self featureUnloaded:feature];
92+
}
2893
}
2994

3095
@end

platform/darwin/app/PluginLayerTestStyle.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -583,6 +583,13 @@
583583
]
584584
}
585585
},
586+
{ "id": "centroid-features",
587+
"type": "maplibre::filter_features",
588+
"source": "maplibre",
589+
"source-layer": "countries",
590+
"maxzoom": 24,
591+
"minzoom": 1
592+
},
586593
{
587594
"id": "crimea-fill",
588595
"type": "fill",
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: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,8 @@ MLN_DARWIN_OBJC_HEADERS = [
108108
"src/NSValue+MLNAdditions.h",
109109
"src/MLNPluginLayer.h",
110110
"src/MLNPluginStyleLayer.h",
111-
"src/MLNPluginProtocolHandler.h"
111+
"src/MLNPluginProtocolHandler.h",
112+
"src/MLNStyleFilter.h",
112113
]
113114

114115
MLN_DARWIN_OBJCPP_HEADERS = [
@@ -166,8 +167,8 @@ MLN_DARWIN_PRIVATE_HEADERS = [
166167
"src/MLNVectorTileSource_Private.h",
167168
"src/NSExpression+MLNPrivateAdditions.h",
168169
"src/NSPredicate+MLNPrivateAdditions.h",
169-
"src/MLNPluginStyleLayer_Private.h"
170-
170+
"src/MLNPluginStyleLayer_Private.h",
171+
"src/MLNStyleFilter_Private.h"
171172
]
172173

173174
MLN_DARWIN_PUBLIC_OBJCPP_SOURCE = [
@@ -224,8 +225,8 @@ MLN_DARWIN_PUBLIC_OBJCPP_SOURCE = [
224225
"src/NSValue+MLNStyleAttributeAdditions.mm",
225226
"src/MLNPluginLayer.mm",
226227
"src/MLNPluginStyleLayer.mm",
227-
"src/MLNPluginProtocolHandler.mm"
228-
228+
"src/MLNPluginProtocolHandler.mm",
229+
"src/MLNStyleFilter.mm",
229230
]
230231
MLN_DARWIN_PUBLIC_OBJCPP_CUSTOM_DRAWABLE_SOURCE = [
231232
"src/MLNCustomDrawableStyleLayer_Private.h",

0 commit comments

Comments
 (0)