Skip to content
Closed
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
4 changes: 4 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -977,6 +977,10 @@ list(APPEND SRC_FILES
${PROJECT_SOURCE_DIR}/src/mbgl/plugin/plugin_layer_properties.cpp
${PROJECT_SOURCE_DIR}/src/mbgl/plugin/plugin_layer_impl.cpp
${PROJECT_SOURCE_DIR}/src/mbgl/plugin/plugin_layer_factory.cpp
${PROJECT_SOURCE_DIR}/src/mbgl/plugin/feature_collection.hpp
${PROJECT_SOURCE_DIR}/src/mbgl/plugin/feature_collection.cpp
${PROJECT_SOURCE_DIR}/src/mbgl/plugin/feature_collection_bucket.hpp
${PROJECT_SOURCE_DIR}/src/mbgl/plugin/feature_collection_bucket.cpp
)


Expand Down
4 changes: 4 additions & 0 deletions bazel/core.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ MLN_LAYER_PLUGIN_HEADERS = [
"src/mbgl/plugin/plugin_layer_impl.hpp",
"src/mbgl/plugin/plugin_layer_render.hpp",
"src/mbgl/plugin/plugin_layer_properties.hpp",
"src/mbgl/plugin/feature_collection_bucket.hpp",
"src/mbgl/plugin/feature_collection.hpp",
]

MLN_LAYER_PLUGIN_SOURCE = [
Expand All @@ -12,6 +14,8 @@ MLN_LAYER_PLUGIN_SOURCE = [
"src/mbgl/plugin/plugin_layer_impl.cpp",
"src/mbgl/plugin/plugin_layer_render.cpp",
"src/mbgl/plugin/plugin_layer_properties.cpp",
"src/mbgl/plugin/feature_collection_bucket.cpp",
"src/mbgl/plugin/feature_collection.cpp",
]

MLN_PUBLIC_GENERATED_STYLE_HEADERS = [
Expand Down
73 changes: 69 additions & 4 deletions platform/darwin/app/PluginLayerExample.mm
Original file line number Diff line number Diff line change
@@ -1,21 +1,39 @@
#import "PluginLayerExample.h"

@interface PluginLayerExample () {

}

@property BOOL logFeatures;

@end


@implementation PluginLayerExample


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

MLNPluginLayerCapabilities *tempResult = [[MLNPluginLayerCapabilities alloc] init];
tempResult.layerID = @"plugin-layer-test";
tempResult.layerID = @"maplibre::filter_features";
tempResult.requiresPass3D = YES;
tempResult.supportsReadingTileFeatures = YES;
return tempResult;

}

-(id)init {
if (self = [super init]) {
self.logFeatures = NO;
}
return self;
}

// The overrides
-(void)onRenderLayer {
NSLog(@"PluginLayerExample: On Render Layer");
-(void)onRenderLayer:(MLNMapView *)mapView
renderEncoder:(id<MTLRenderCommandEncoder>)renderEncoder {
//NSLog(@"PluginLayerExample: On Render Layer");

}

Expand All @@ -24,7 +42,54 @@ -(void)onUpdateLayer {
}

-(void)onUpdateLayerProperties:(NSDictionary *)layerProperties {
// NSLog(@"Layer Properties: %@", layerProperties);
// NSLog(@"Layer Properties: %@", layerProperties);
}

-(void)featureLoaded:(MLNPluginLayerTileFeature *)tileFeature {

// Writing a single string since the tile loading is multithreaded and the output can get interwoven
NSMutableString *outputStr = [NSMutableString string];
[outputStr appendFormat:@"Tile Feature (id:%@) Properties: %@\n", tileFeature.featureID, tileFeature.featureProperties];

for (NSValue *v in tileFeature.featureCoordinates) {

CLLocationCoordinate2D coord;
[v getValue:&coord];

[outputStr appendFormat:@" -> (%f, %f) \n", coord.latitude, coord.longitude];

}

NSLog(@"Feature: %@", outputStr);
}

-(void)featureUnloaded:(MLNPluginLayerTileFeature *)tileFeature {
// NSLog(@"Tile Features Unloaded: %@", tileFeature.featureProperties);

}


- (void)onFeatureLoaded:(MLNPluginLayerTileFeature *)tileFeature {

[self featureLoaded:tileFeature];

}

/// Called when a set of features are loaded from the tile
- (void)onFeatureCollectionLoaded:(MLNPluginLayerTileFeatureCollection *)tileFeatureCollection {
//NSLog(@"Feature Collection Loaded for tile: %@", tileFeatureCollection.tileID);
for (MLNPluginLayerTileFeature *feature in tileFeatureCollection.features) {
[self featureLoaded:feature];
}

}

/// Called when a set of features are unloaded because the tile goes out of scene/etc
- (void)onFeatureCollectionUnloaded:(MLNPluginLayerTileFeatureCollection *)tileFeatureCollection {
//NSLog(@"Feature Collection Unloaded for tile: %@", tileFeatureCollection.tileID);
for (MLNPluginLayerTileFeature *feature in tileFeatureCollection.features) {
[self featureUnloaded:feature];
}
}

@end
7 changes: 7 additions & 0 deletions platform/darwin/app/PluginLayerTestStyle.json
Original file line number Diff line number Diff line change
Expand Up @@ -583,6 +583,13 @@
]
}
},
{ "id": "centroid-features",
"type": "maplibre::filter_features",
"source": "maplibre",
"source-layer": "countries",
"maxzoom": 24,
"minzoom": 1
},
{
"id": "crimea-fill",
"type": "fill",
Expand Down
32 changes: 32 additions & 0 deletions platform/darwin/src/MLNPluginLayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,22 @@ MLN_EXPORT

@end

@interface MLNPluginLayerTileFeature : NSObject

// This is the unique feature ID in the tile source if applicable. Can be empty
@property NSString *featureID;
@property NSDictionary *featureProperties;
@property NSArray *featureCoordinates;

@end

@interface MLNPluginLayerTileFeatureCollection : NSObject

@property NSArray *features;
@property NSString *tileID; // z,x,y

@end

typedef enum {
MLNPluginLayerTileKindGeometry,
MLNPluginLayerTileKindRaster,
Expand All @@ -55,6 +71,9 @@ MLN_EXPORT
@property (copy) NSString *layerID;
@property BOOL requiresPass3D;

//! Set this to true if this layer can support reading features from the tiles
@property BOOL supportsReadingTileFeatures;

//! This is a list of layer properties that this layer supports.
@property (copy) NSArray<MLNPluginLayerProperty *> *layerProperties;

Expand Down Expand Up @@ -104,6 +123,19 @@ MLN_EXPORT
/// dynamic properties are updated
- (void)onUpdateLayerProperties:(NSDictionary *)layerProperties;

/// Called when a feature is loaded from the tile
- (void)onFeatureLoaded:(MLNPluginLayerTileFeature *)tileFeature;

/// Called when a set of features are loaded from the tile
/*
TODO: Think about returning that this layer doesn't care about this feature collection via a
bool/etc and then the underlying layer won't have to track this collection.
*/
- (void)onFeatureCollectionLoaded:(MLNPluginLayerTileFeatureCollection *)tileFeatureCollection;

/// Called when a set of features are unloaded because the tile goes out of scene/etc
- (void)onFeatureCollectionUnloaded:(MLNPluginLayerTileFeatureCollection *)tileFeatureCollection;

/// Added to a map view
- (void)didMoveToMapView:(MLNMapView *)mapView;

Expand Down
27 changes: 27 additions & 0 deletions platform/darwin/src/MLNPluginLayer.mm
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
#import "MLNPluginLayer.h"

@implementation MLNPluginLayerTileFeature

@end

@implementation MLNPluginLayerTileFeatureCollection

@end

@implementation MLNPluginLayerProperty

+(MLNPluginLayerProperty *)propertyWithName:(NSString *)propertyName
Expand Down Expand Up @@ -66,12 +74,31 @@ -(void)onUpdateLayerProperties:(NSDictionary *)layerProperties {
// Base class does nothing
}

// If the layer properties indicate that this layer has a the ability to intercept
// features, then this method will be called when a feature is loaded
- (void)onFeatureLoaded:(MLNPluginLayerTileFeature *)tileFeature {
// Base class does nothing
}

// If the layer properties indicate that this layer has a the ability to intercept
// features, then this method will be called when a feature is loaded
- (void)onFeatureCollectionLoaded:(MLNPluginLayerTileFeatureCollection *)tileFeatureCollection {
// Base class does nothing
}

/// Called when a set of features are unloaded because the tile goes out of scene/etc
- (void)onFeatureCollectionUnloaded:(MLNPluginLayerTileFeatureCollection *)tileFeatureCollection {
// Base class does nothing
}


/// Added to a map view
- (void)didMoveToMapView:(MLNMapView *)mapView {
// Base class does nothing
}



@end


Expand Down
11 changes: 6 additions & 5 deletions platform/ios/app/MBXViewController.mm
Original file line number Diff line number Diff line change
Expand Up @@ -2332,17 +2332,18 @@ - (void)setStyles




/// Style that does not require an `apiKey` nor any further configuration
[self.styleNames addObject:@"MapLibre Basic"];
[self.styleURLs addObject:[NSURL URLWithString:@"https://demotiles.maplibre.org/style.json"]];

/// This is hte same style as above but copied locally and the three instances of the metal plug-in layer added to the style
/// Look for "type": "plugin-layer-metal-rendering" in the PluginLayerTestStyle.json for an example of how the layer is defined
[self.styleNames addObject:@"MapLibre Basic - Local With Plugin"];
NSURL *url = [[NSBundle mainBundle] URLForResource:@"PluginLayerTestStyle.json" withExtension:nil];
[self.styleURLs addObject:url];


/// Style that does not require an `apiKey` nor any further configuration
[self.styleNames addObject:@"MapLibre Basic"];
[self.styleURLs addObject:[NSURL URLWithString:@"https://demotiles.maplibre.org/style.json"]];


/// Add MapLibre Styles if an `apiKey` exists
NSString* apiKey = [MLNSettings apiKey];
if (apiKey.length)
Expand Down
Loading
Loading