Skip to content

Conversation

@AtlasProgramming
Copy link
Collaborator

Protocol Handler

This adds support similar to plugin-layers and style filters by exposing a data loading paradigm via a plug-in class and lambda implementation. This does not create or implement a way to chain FileSources together.

To add a custom handler, descend from MLNPluginProtocolHandler and implement the two methods to let the system know if this handler can handle the request and then return data when the system asks for it. There's a sample implementation which just loads the local test style file when the url starts with "pluginProtocol"

Like other plug in items, these handlers are added to the map view at runtime with a single call.

    [self.mapView addPluginProtocolHandler:[PluginProtocolExample class]];
#import "PluginProtocolExample.h"

@implementation PluginProtocolExample

-(BOOL)canRequestResource:(MLNPluginProtocolHandlerResource *)resource {
    if ([resource.resourceURL containsString:@"pluginProtocol"]) {
        return YES;
    }
    return NO;
}

-(MLNPluginProtocolHandlerResponse *)requestResource:(MLNPluginProtocolHandlerResource *)resource {
    
    NSData *data = [NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"PluginLayerTestStyle.json" ofType:nil]];
    
    MLNPluginProtocolHandlerResponse *response = [[MLNPluginProtocolHandlerResponse alloc] init];
    response.data = data;
    return response;
    
}

@end

Supported on Android as well. Just descend from the PluginProtocolHandler class and implement the two methods, one for if this handler can support the request and returning the actual data for the request.

package org.maplibre.android.testapp.activity.plugin

import org.maplibre.android.plugin.PluginProtocolHandler
import org.maplibre.android.plugin.PluginProtocolHandlerResource
import org.maplibre.android.plugin.PluginProtocolHandlerResponse

class PluginProtocolExample : PluginProtocolHandler() {

    override fun canRequestResource(resource: PluginProtocolHandlerResource?): Boolean {

      // Put whatever logic is needed to determine if the protocol handler should handle this request here
    }


    override fun requestResource(resource: PluginProtocolHandlerResource?): PluginProtocolHandlerResponse? {
        // Return some data here
        return null;
    }

}

and register the plugin using the mapview

mapView.getMapAsync {
            val protocolExample = PluginProtocolExample();
            mapView.addPluginProtocolHandler(protocolExample);

@github-actions github-actions bot added build Related to build, configuration or CI/CD android iOS cpp-core labels Nov 19, 2025
@github-actions
Copy link

Bloaty Results (iOS) 🐋

Compared to main

    FILE SIZE        VM SIZE    
 --------------  -------------- 
  +0.7%  +102Ki  +0.5% +80.0Ki    TOTAL

Full report: https://maplibre-native.s3.eu-central-1.amazonaws.com/bloaty-results-ios/pr-3958-compared-to-main.txt

@sjg-wdw
Copy link
Collaborator

sjg-wdw commented Nov 19, 2025

Looks reasonable. Do the MapLibreJS folks have any thoughts? For some reason I thought they had a way of doing this too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

android build Related to build, configuration or CI/CD cpp-core iOS

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants