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

MGLGeoJSONSource and Line Styling #7006

Closed
nitrag opened this issue Nov 10, 2016 · 5 comments
Closed

MGLGeoJSONSource and Line Styling #7006

nitrag opened this issue Nov 10, 2016 · 5 comments

Comments

@nitrag
Copy link
Contributor

nitrag commented Nov 10, 2016

I have need to implement thousands of GeoJSON LineString's, each with a color in the feature's properties. I'm also aware that line-color might be the GeoJSON spec. Or perhaps stroke? I've tried them all in the example file below.

Either way, when loading the MGLGeoJSONSource, it does not pull in this style information. Rather it defaults to black.

It does not make sense to set all Polylines the same color in MGLLineStyle nor to loop through all the features and apply styling individually.

iOS
3.4.0-beta2

This works but black line appears

let path = Bundle.main.url(forResource: "example", withExtension: "geojson")!
let geoJsonSource1 = MGLGeoJSONSource(identifier: "asdfasadfas", url: path, options: [String : Any]())
self.mapView.style().add(geoJsonSource1)
let lineTest = MGLLineStyleLayer(identifier: "line-geojson", source: geoJsonSource1)
self.mapView.style().add(lineTest)
NSLog("Source has been created and added")	
//snippet of example.geojson
{
  "type": "FeatureCollection",
  "features": [
    {
      "type": "Feature",
      "properties": {
        "name": "Crema to Council Crest",
        "id": 12345,
        "color": "#0000FF",
        "line-color": "#FF0000",
        "stroke": "#85FF0B"
      },
      "geometry": {
        "type": "LineString",
        "coordinates": [
          [
            -122.63748,
            45.52214
          ],
          [
            -122.64855,
            45.52218
          ],
         ......

or see full file attached:
example.geojson.txt

EXPECTED:

MGLGeoJSON parsing should read the properties and assign "run time styling" (is that what this is?) If there is an issue open on this, I looked but couldn't find anything that I thought fit.

@boundsj
Copy link
Contributor

boundsj commented Nov 10, 2016

@nitrag If there is an issue open on this, I looked but couldn't find anything that I thought fit.

I think you are describing data driven styling (DDS). Let's close this ticket and continue to use #4860 to track that. The iOS 3.4.0 release will enable "runtime styling". Runtime styling is the foundation for many things including DDS that will land in a future release.

@boundsj boundsj closed this as completed Nov 10, 2016
@boundsj
Copy link
Contributor

boundsj commented Nov 10, 2016

@nitrag also, if you want to get a sense of what is coming to native mobile with DDS in the future, this GL JS demo may be useful

@nitrag
Copy link
Contributor Author

nitrag commented Nov 10, 2016

@boundsj That does seem what I'm looking for, although I'm not sure the methods conform well to my needs. I'll keep an eye on DDS, hope it will be ready by the New Year.

My use case: User scrolls around on the map and each time a BoundingBox is sent to an API server; returning GeoJSON features (each with different line colors - all other styling properties are the same). Currently I am using MGLGeoJSONSource.geojson = ... to add the data and it is working.

DDS - Will this cover my use case, it seems for for one-time load of vector data?

Now - Are you saying at this point I will have to parse the GeoJSON manually....into separate source layers, one for each color? Can I use predicates somehow (not sure how to use them) to solve my problem?

@boundsj
Copy link
Contributor

boundsj commented Nov 10, 2016

For now, you could go the route of separate GeoJSON sources and layers to style them. Or (as you say) you should be able to use a single GeoJSON source and add multiple layers with predicate filters so each layer only applies to certain features in your source. That is, where the layer predicate matches some key/value from the properties hash in the features in your source.

We are still working to release this runtime styling and part of that work will include examples to help illustrate things like this.

@nitrag
Copy link
Contributor Author

nitrag commented Nov 19, 2016

Oh wow, predicate works beautifully! It's super fast too. Thanks @rmnblm for the sample code.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants