Skip to content

Conversation

@louwers
Copy link
Member

@louwers louwers commented Oct 4, 2025

Implements #1698 for iOS. feature-state was already implemented in the core.

Also ports the GLFW example to the Swift-based example app.

FeatureState.mp4

TODO:

  • Think about the API.
  • Tests

@github-actions
Copy link

github-actions bot commented Oct 4, 2025

Bloaty Results (iOS) 🐋

Compared to main

    FILE SIZE        VM SIZE    
 --------------  -------------- 
  +0.1% +19.3Ki  +0.1% +16.0Ki    TOTAL

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

@louwers louwers requested a review from Copilot October 4, 2025 08:11
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR implements feature state functionality for iOS MapLibre, enabling dynamic styling of map features based on user-defined state properties. The implementation adds APIs to set, get, and remove feature state, along with a comprehensive example demonstrating interactive map styling.

  • Adds feature state management methods to MLNMapView with support for both convenience and explicit parameter APIs
  • Creates a complete Swift example showcasing interactive US state selection with feature-state expressions
  • Updates documentation with comprehensive guides and API references for the new functionality

Reviewed Changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
platform/ios/src/MLNMapView.mm Implements core feature state methods with MBGL integration and state conversion
platform/ios/src/MLNMapView.h Adds public API declarations and comprehensive documentation for feature state methods
platform/ios/app-swift/Sources/FeatureStateExample.swift Complete interactive example demonstrating feature state usage with US states data
platform/ios/app-swift/Sources/MapLibreNavigationView.swift Adds navigation link to the new feature state example
platform/ios/MapLibre.docc/FeatureStateExample.md Comprehensive documentation with code examples and best practices
platform/ios/MapLibre.docc/MapLibre.md Updates main documentation index to include feature state example
platform/ios/MapLibre.docc/ObserverExample.md Minor code formatting improvement in observer example
platform/ios/MapLibre.docc/ActionJournalExample.md Adds rendering stats report interval configuration

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

return;
}

NSString *featureID = [NSString stringWithFormat:@"%@", feature.identifier];
Copy link

Copilot AI Oct 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line could crash if feature.identifier is nil. The stringWithFormat will convert nil to '(null)' string, which may not be the intended behavior for feature identification.

Copilot uses AI. Check for mistakes.
return nil;
}

NSString *featureID = [NSString stringWithFormat:@"%@", feature.identifier];
Copy link

Copilot AI Oct 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line could crash if feature.identifier is nil. The stringWithFormat will convert nil to '(null)' string, which may not be the intended behavior for feature identification.

Copilot uses AI. Check for mistakes.
return;
}

NSString *featureID = [NSString stringWithFormat:@"%@", feature.identifier];
Copy link

Copilot AI Oct 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line could crash if feature.identifier is nil. The stringWithFormat will convert nil to '(null)' string, which may not be the intended behavior for feature identification.

Copilot uses AI. Check for mistakes.
mapView.setFeatureState(feature, sourceID: "states", state: ["selected": true])

// Set feature state using explicit identifiers
mapView.setFeatureState("states", sourceLayer: nil, featureID: "54", state: ["selected": true])
Copy link

Copilot AI Oct 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method call is incorrect. The first parameter should be sourceID, but the method name suggests it should be setFeatureStateForSource. The correct call should be mapView.setFeatureStateForSource(\"states\", sourceLayer: nil, featureID: \"54\", state: [\"selected\": true]).

Suggested change
mapView.setFeatureState("states", sourceLayer: nil, featureID: "54", state: ["selected": true])
mapView.setFeatureStateForSource("states", sourceLayer: nil, featureID: "54", state: ["selected": true])

Copilot uses AI. Check for mistakes.
let isSelected = currentState?["selected"] as? Bool ?? false

// Get state using explicit identifiers
let state = mapView.getFeatureState("states", sourceLayer: nil, featureID: "54")
Copy link

Copilot AI Oct 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method call is incorrect. The method name should be getFeatureStateForSource. The correct call should be mapView.getFeatureStateForSource(\"states\", sourceLayer: nil, featureID: \"54\").

Suggested change
let state = mapView.getFeatureState("states", sourceLayer: nil, featureID: "54")
let state = mapView.getFeatureStateForSource("states", sourceLayer: nil, featureID: "54")

Copilot uses AI. Check for mistakes.
Comment on lines +216 to +220
- ``MLNMapView/setFeatureState:sourceLayer:featureID:state:`` - Set state with explicit identifiers
- ``MLNMapView/getFeatureState:sourceID:`` - Get current state of a feature
- ``MLNMapView/getFeatureState:sourceLayer:featureID:`` - Get state with explicit identifiers
- ``MLNMapView/removeFeatureState:sourceID:stateKey:`` - Remove state from a feature
- ``MLNMapView/removeFeatureState:sourceLayer:featureID:stateKey:`` - Remove state with explicit identifiers
Copy link

Copilot AI Oct 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The documentation references are incorrect for the explicit identifier methods. Lines 216, 218, and 220 should reference setFeatureStateForSource:sourceLayer:featureID:state:, getFeatureStateForSource:sourceLayer:featureID:, and removeFeatureStateForSource:sourceLayer:featureID:stateKey: respectively.

Suggested change
- ``MLNMapView/setFeatureState:sourceLayer:featureID:state:`` - Set state with explicit identifiers
- ``MLNMapView/getFeatureState:sourceID:`` - Get current state of a feature
- ``MLNMapView/getFeatureState:sourceLayer:featureID:`` - Get state with explicit identifiers
- ``MLNMapView/removeFeatureState:sourceID:stateKey:`` - Remove state from a feature
- ``MLNMapView/removeFeatureState:sourceLayer:featureID:stateKey:`` - Remove state with explicit identifiers
- ``MLNMapView/setFeatureStateForSource:sourceLayer:featureID:state:`` - Set state with explicit identifiers
- ``MLNMapView/getFeatureState:sourceID:`` - Get current state of a feature
- ``MLNMapView/getFeatureStateForSource:sourceLayer:featureID:`` - Get state with explicit identifiers
- ``MLNMapView/removeFeatureState:sourceID:stateKey:`` - Remove state from a feature
- ``MLNMapView/removeFeatureStateForSource:sourceLayer:featureID:stateKey:`` - Remove state with explicit identifiers

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant