2

I've imported a GeoJSON layer into TileMill and am having trouble styling based on the properties in the features. The features' properties objects have objects nested within them, and I haven't found any examples of using nested properties in selectors. I have tried something like the following:

#geojsonlayer[submission_sets.comments.length=1] {
  marker-width:2;
  marker-fill:#f45;
  marker-line-color:#f45;
  marker-allow-overlap:true;
  marker-ignore-placement:true;
}

But I get a "missing closing ] of filter" error. Is this construction valid? Is there some other valid construction that allows me to do something similar?

Edit:

For reference, here's a sample feature that I'm trying to style:

{
   "type":"Feature",
   "id":166995,
   "geometry":{
      "coordinates":[-75.1694440842,39.9707152354],
      "type":"Point"
   },
   "properties":{
      "description":"...",
      "updated_datetime":"2014-03-28T01:31:29.492896+00:00",
      "visible":true,
      "created_datetime":"2014-03-07T17:10:00+00:00",
      "attachments":[],
      "url":"http://data.shareabouts.org/api/v2/mjumbewu/datasets/philly-bike-share/places/166995",
      "_imported_id":1402,
      "id":166995,
      "submission_sets":{
         "comments":{
            "length":1
         }
      },
      "name":"20th and Ogden Street",
      "dataset":223
   }
}

(from http://data.shareabouts.org/api/v2/mjumbewu/datasets/philly-bike-share/places?format=json&page=5)

1

As far as I can tell I don't think so, the reason is that the nested properties are imported to the attribute table as Strings by Tilemill, so to style them you'd need to do something like:

#geojsonlayer [submission_sets = '{ "comments": { "length": 1 } }']{
  marker-width:2;
  marker-fill:#f45;
  marker-line-color:#f45;
  marker-allow-overlap:true;
  marker-ignore-placement:true;
}

Which is fine, as long as you only have one nested property...

One trick to get around this could be to use the regex abilities of the filter selectors (using the =~ operator), as described here:

Mapbox Selectors

This could allow you to access objects that had certain values within the nested properties that you can't sufficiently describe using the above (e.g. where there were loads of other nested values in the same String). So an example could be:

#geojsonlayer [submission_sets =~ ".* \"comments\": \{ \"length\": 1 \} .*" ]{ 
  marker-width:2;
  marker-fill:#f45;
  marker-line-color:#f45;
  marker-allow-overlap:true;
  marker-ignore-placement:true;
}

(Notice you need to escape some characters, like curly braces)

Which would colour all of the ones that had a comment length value of 1, irrespective of other nested data values in the String.

I've tested both of these my side and they seem to work fine. Does that make sense?

  • Yup, makes a lot of sense. Wish it were otherwise, but it'll do. Thanks! – mjumbewu May 8 '14 at 23:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.