Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Possible regression of MGLShapeSource.features(matching predicate: NSPredicate?) returns 0 features #13316

Closed
kestred opened this issue Nov 8, 2018 · 3 comments
Labels
archived Archived because of inactivity iOS Mapbox Maps SDK for iOS

Comments

@kestred
Copy link

kestred commented Nov 8, 2018

Querying for features using source.features(matching: nil) (or anything else) returns 0 features.
This seems like a regression of #9767, but presumably it could also be me not using the library correctly, because Swift.

Steps to reproduce

Given some features constructed like so....

/// somewhere above
let points = lineString.asCoordinates
let feature = MGLPolylineFeature(coordinates: points, count: UInt(points.count))
feature.attributes["featureType"] = self.featureType
for attr in self.featureAttributes {
    feature.attributes[attr.name] = attr.value
}
print("Feature(\(feature.id)): \(feature.attributes)")

And source created like so...

let source = MGLShapeSource(identifier: "network", features: features, options: nil)

Add them to the map some long time after didFinishLoading

if let mapStyle = mapView.style {
    mapStyle.addSource(source)
    for layer in layers.values {
        mapStyle.addLayer(layer)

        if let style = layer as? MGLVectorStyleLayer {
            let collection = (source.shape as! MGLShapeCollectionFeature)
            print("Predicate for \(layer.identifier): \(style.predicate)")
            print("Matching features for \(layer.identifier): \(source.features(matching: style.predicate).count) " +
                  "of \(source.features(matching: nil).count) or \(collection.shapes.count)")
        }
    }
}

Expected behavior

It returns more than 0 features.

Actual behavior

It returns 0 features.

Log Output:

Feature(lofeature_Krg4rQm6CyQySqmNWL5C9Z): ["featureType": "FiberCable", "measured_length": "5130", "placement": "Underground"]
...
Predicate for Cable (Other): Optional(featureType == "FiberCable")
Matching features for Cable (Other): 0 of 0 or 3775

Configuration

Mapbox SDK versions: 4.6.0
iOS/macOS versions: iOS 12.1
Device/simulator models: iPhone XR, SimulatorApp-877 CoreSimulator-581.2
Xcode version: 10.1

@tobrun tobrun added the iOS Mapbox Maps SDK for iOS label Nov 8, 2018
@1ec5
Copy link
Contributor

1ec5 commented Jan 18, 2019

It looks like you’re querying the source layer immediately, synchronously, after adding the source to the style. Other feature querying methods like MGLVectorTileSource.features(matching:) only return features in tiles that have already loaded for display in a style layer, which means there would need to be time for a network request and response. This is a shape source, so a network request wouldn’t be necessary, but the interface might still be asynchronous. Can you try querying after a delay?

@kestred
Copy link
Author

kestred commented Jan 18, 2019

@AlJaMa: ^ (when you have time)

@1ec5: as additional information, this further presents itself in having no features visible on the map.
By instead using MGLMapViewDelegate's ____ColorForShapeAnnotation, the features appear but can't be styled as expected via a Mapbox Style document (I think we might also be adding the shapes differently).

With the additional context, are there any other debugging steps / information you might recommend to see what my be the cause of the issue we're experiencing?
I'll try the querying after a delay to see if that issue is a red herring.

@stale stale bot added the archived Archived because of inactivity label Jul 17, 2019
@stale
Copy link

stale bot commented Jul 17, 2019

This issue has been automatically detected as stale because it has not had recent activity and will be archived. Thank you for your contributions.

@stale stale bot closed this as completed Jul 17, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
archived Archived because of inactivity iOS Mapbox Maps SDK for iOS
Projects
None yet
Development

No branches or pull requests

3 participants