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

featuresInSourceLayersWithIdentifiers returning empty every time. #9646

Closed
ThiyagarajanShivSankaran opened this issue Jul 29, 2017 · 19 comments
Assignees
Labels
Core The cross-platform C++ core, aka mbgl iOS Mapbox Maps SDK for iOS
Milestone

Comments

@ThiyagarajanShivSankaran
Copy link

ThiyagarajanShivSankaran commented Jul 29, 2017

Platform: IOS
Mapbox SDK version: ios-v3.6.0

Steps to trigger behavior

  1. Fetch the array of features from MGLVectorSource by using sourceLayerIdentifiers
  2. It's returning empty array every time.

Expected behavior

It should return all the features from sourceLayers

Actual behavior

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.

@Guardiola31337 Guardiola31337 added the iOS Mapbox Maps SDK for iOS label Jul 30, 2017
@fabian-guerra fabian-guerra added the Core The cross-platform C++ core, aka mbgl label Aug 1, 2017
@jmkiley
Copy link
Contributor

jmkiley commented Aug 1, 2017

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 c2b0037#diff-3f30d11bf1ea37d78c1c04b6c00a605dL62 but not with a235032.

cc @jfirebaugh

@friedbunny friedbunny added this to the ios-v3.6.2 milestone Aug 2, 2017
@boundsj boundsj removed this from the ios-v3.6.2 milestone Aug 2, 2017
@jmkiley
Copy link
Contributor

jmkiley commented Aug 2, 2017

Noting that this issue seems to be both on master and release-ios-v3.6.0-android-v5.1.0.

cc @boundsj

@AF-cgi
Copy link

AF-cgi commented Aug 3, 2017

I have the same problem. I test it with ios-v3.5.4, it's working there.

@epau
Copy link

epau commented Aug 10, 2017

I have repro'd this as well. I had to revert back to 3.5 on iOS. Would love to see this fixed soon.

@fabian-guerra
Copy link
Contributor

This was fixed in #9784. Will be released as part of iOS SDK v3.6.2

@fabian-guerra fabian-guerra added this to the ios-v3.6.2 milestone Aug 17, 2017
@fabian-guerra fabian-guerra self-assigned this Aug 17, 2017
@fabian-guerra
Copy link
Contributor

iOS SDK v3.6.2 has been released.

@ThiyagarajanShivSankaran
Copy link
Author

@fabian-guerra Thank you.

@ThiyagarajanShivSankaran
Copy link
Author

ThiyagarajanShivSankaran commented Aug 23, 2017

@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.

@AF-cgi
Copy link

AF-cgi commented Aug 23, 2017

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.

@fabian-guerra
Copy link
Contributor

@ThiyagarajanShivSankaran sorry to hear you are still having issues. Could you please provide a test app?

@AF-cgi
Copy link

AF-cgi commented Aug 24, 2017

@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 }

@fabian-guerra
Copy link
Contributor

@AFcgi could you please make a separate ticket and attach the crash log?

@ThiyagarajanShivSankaran
Copy link
Author

ThiyagarajanShivSankaran commented Aug 30, 2017

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.

@AF-cgi
Copy link

AF-cgi commented Aug 30, 2017

@ThiyagarajanShivSankaran I think it's the same issue like #9888

@ThiyagarajanShivSankaran
Copy link
Author

Hi @fabian-guerra I need to fetch non-rendered features as well. Is it possible in mapbox IOS SDK.

@fabian-guerra
Copy link
Contributor

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.

@ThiyagarajanShivSankaran
Copy link
Author

@fabian-guerra Okay.So there is no way to get non-rendered features.
Anyways thank you for your reply.

@troutinsights
Copy link

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)

@Ibeihl
Copy link

Ibeihl commented Sep 9, 2019

any update on this? would love to get not rendered features from MGLShapeSource

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Core The cross-platform C++ core, aka mbgl iOS Mapbox Maps SDK for iOS
Projects
None yet
Development

No branches or pull requests

10 participants