Platform: IOS
Mapbox SDK version: ios-v3.6.0
MGLVectorSource by using sourceLayerIdentifiers It should return all the features from sourceLayers
But it's returning empty array.
Below is my code,
func featuresInSourceLayers(WithIdentifiers sourceLayerIdentifiers: [String], andPredicate predicate: NSPredicate?) -> [MGLFeature]{
if let source = self.mapView.style?.source(withIdentifier: "my-composite") as? MGLVectorSource {
let features = source.features(sourceLayerIdentifiers: Set(sourceLayerIdentifiers), predicate: predicate)
return features
}
return [MGLFeature]()
}
I have checked the older SDK ios-v3.5.4 , it's working there. Thanks.
I was able to repro this in iosapp by adding this code to to - (IBAction)handleLongPress:(UILongPressGestureRecognizer *)longPress
MGLVectorSource *source = [_mapView.style sourceWithIdentifier:@"composite"];
NSArray *f = [source featuresInSourceLayersWithIdentifiers:[NSSet setWithArray:@[@"poi_label"]] predicate:nil];
I see the issue in iosapp with https://github.com/mapbox/mapbox-gl-native/commit/c2b00378b78b55d50968a9b11ed75bb4edf62ec9#diff-3f30d11bf1ea37d78c1c04b6c00a605dL62 but not with a235032.
cc @jfirebaugh
Noting that this issue seems to be both on master and release-ios-v3.6.0-android-v5.1.0.
cc @boundsj
I have the same problem. I test it with ios-v3.5.4, it's working there.
I have repro'd this as well. I had to revert back to 3.5 on iOS. Would love to see this fixed soon.
This was fixed in https://github.com/mapbox/mapbox-gl-native/pull/9784. Will be released as part of iOS SDK v3.6.2
iOS SDK v3.6.2 has been released.
@fabian-guerra Thank you.
@fabian-guerra sometimes it's fetching only the visible features from source. But, it should fetch all the features right. This is not working consistently.
I have the same issue. I have a cluster on map and zoom in until the cluster has dissolved. In this case the sdk crashes at the first zoom operation.
@ThiyagarajanShivSankaran sorry to hear you are still having issues. Could you please provide a test app?
@fabian-guerra I have a map with cluster and poi layers. Over a button you can select pois that are within a cluster. To show the poi layer on the map, I center the map first inn the poi coordinates. Then I increase the zoom level recursively until the cluster has resolved.
With the iOS SDK v3.5.4 wasn't a problem and works fine. With the v3.6.2 crash the SDK after the first zoom in.
let source = self.mapView.style?.source(withIdentifier: "identifier") as? MGLShapeSource
let predicate = NSPredicate(format: "%K == %i", "id", poiID)
guard let poi = source?.features(matching: predicate).first else { return }
@AFcgi could you please make a separate ticket and attach the crash log?
Hi @fabian-guerra I need to fetch all the features from the vector source, despite of zoom level or visible rect. Is there any way to do that. Thanks.
@ThiyagarajanShivSankaran I think it's the same issue like https://github.com/mapbox/mapbox-gl-native/issues/9888
Hi @fabian-guerra I need to fetch non-rendered features as well. Is it possible in mapbox IOS SDK.
Hi @ThiyagarajanShivSankaran there is https://www.mapbox.com/ios-sdk/api/3.6.2/Classes/MGLVectorSource.html#/c:objc(cs)MGLVectorSource(im)featuresInSourceLayersWithIdentifiers:predicate with the following restriction: the source was associated with a layer that was recently used and the features were in the bounds of a recently scrolled to region.
@fabian-guerra Okay.So there is no way to get non-rendered features.
Anyways thank you for your reply.
I am having the same issue with Mapbox iOS SDK 4.2. My end goal is to implement UISearch functionality against an MGLLineStyleLayer which has hundreds of lines with attributes. I was given the suggestion to use the -featuresInSourceLayersWithIdentifiers function. However, I have tried several implementation styles and always get nil return. The code below does:
1) Adds source from URL. I've hidden the actual URL
2) Adds MGLLineStyleLayer using source above
3) Attempt to get MGLFeature[] by querying source with identifier.
4) Not shown, implement UISearch to allow user to search for map objects using MGLFeature[] attributes.
Thank you!
//1. Add Mapbox URL Source
let source = MGLVectorTileSource(identifier: "generic-lines", configurationURL: URL(string: "mapbox://hidden.b8doe4rp")!)
mapView.style?.addSource(source)
//2. Create Polyline layer and add to map
let lyrLinesAll = MGLLineStyleLayer(identifier: "generic-lines", source: source)
lyrLinesAll.sourceLayerIdentifier = "hidden-hidden-all-origina-dana5w"
mapView.style?.addLayer(lyrLinesAll)
//3. Obtain MGLFeature[] object from source using identifier. Use MGLFeature array to implement Xcode UISearch
let sourcelayeridentifier = "generic-lines"
let features = source.features(sourceLayerIdentifiers: Set([sourcelayeridentifier]), predicate: nil)
//Check, did we get anything?
print(features.count)
any update on this? would love to get not rendered features from MGLShapeSource