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

MGLGeoJSONSource should have a features initializer #6302

Closed
1ec5 opened this issue Sep 9, 2016 · 2 comments · Fixed by #6524
Closed

MGLGeoJSONSource should have a features initializer #6302

1ec5 opened this issue Sep 9, 2016 · 2 comments · Fixed by #6524
Assignees
Labels
feature iOS Mapbox Maps SDK for iOS macOS Mapbox Maps SDK for macOS navigation For the Mapbox Navigation SDK for Android or iOS or navigation use cases in general runtime styling
Milestone

Comments

@1ec5
Copy link
Contributor

1ec5 commented Sep 9, 2016

MGLGeoJSONSource currently has four initializers: two that accept a GeoJSON-formatted NSData object, and two that accept a URL to a local or remote GeoJSON file. MGLGeoJSONSource should have an additional initializer that accepts an array of MGLFeatures and would accompany the existing read-only features property.

Consider this basic use case: the developer wants to create a GeoJSON source containing a particular polyline feature. Currently, they have to either compose a GeoJSON string and stuff it into an NSData object or write out a GeoJSON file and refer to it by its path. Instead, it would be much more convenient to create the source using an MGLPolyline object directly.

To simplify MGLGeoJSONSource, we should remove -initWithSourceIdentifier:geoJSONData: and -initWithSourceIdentifier:URL: and make the options parameter on the remaining initializers nullable. MGLGeoJSONSource would be left with three initializers corresponding to the three properties features, geoJSONData, and URL.

We should also make MGLFeature.attributes read-write so that it’s possible to create a feature with specific attributes that a layer might filter for.

/cc @boundsj @incanus @frederoni

@1ec5 1ec5 added iOS Mapbox Maps SDK for iOS macOS Mapbox Maps SDK for macOS runtime styling labels Sep 9, 2016
@1ec5 1ec5 added this to the ios-v3.4.0 milestone Sep 9, 2016
@1ec5
Copy link
Contributor Author

1ec5 commented Sep 9, 2016

This will require functionality for writing out MGLFeature objects as mapbox::geojson types or, alternatively, as GeoJSON strings. Each of the MGLFeature subclasses would implement a -geoJSONFeature method similar to the existing -annotationObjectWithDelegate: method, but using the attributes dictionary instead of MGLMultiPointDelegate.

In order to convert the attribute dictionary into a mapbox::geojson::property_map, we can implement category methods similar to -[NSNumber(MGLStyleAttributeAdditions) mbgl_boolPropertyValue]. Or, if that proves to be too cumbersome, a single recursive method would also work.

@1ec5 1ec5 added the feature label Sep 9, 2016
@boundsj boundsj self-assigned this Sep 13, 2016
@1ec5 1ec5 added the navigation For the Mapbox Navigation SDK for Android or iOS or navigation use cases in general label Sep 26, 2016
@1ec5
Copy link
Contributor Author

1ec5 commented Sep 26, 2016

This will require functionality for writing out MGLFeature objects as mapbox::geojson types

The manual MGLFeature-to-GeoJSON conversion in nitaliano/react-native-mapbox-gl#419 could serve as a template for the kind of transformation we’d need to do here.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
feature iOS Mapbox Maps SDK for iOS macOS Mapbox Maps SDK for macOS navigation For the Mapbox Navigation SDK for Android or iOS or navigation use cases in general runtime styling
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants