Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add highlight/query similar features example #2404

Closed
wants to merge 1 commit into from

Conversation

tristen
Copy link
Member

@tristen tristen commented Apr 6, 2016

});

// Change the cursor style as a UI indicator.
map.getCanvas().style.cursor = (features.length) ? 'pointer' : '';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No parens around features.length.

@tristen tristen force-pushed the query-similar-features branch from 8dffcd8 to 72788df Compare April 6, 2016 20:13
@tristen tristen force-pushed the query-similar-features branch from 72788df to 425ae63 Compare April 6, 2016 21:17
@tristen
Copy link
Member Author

tristen commented Apr 7, 2016

🚢'd 5342aa9

@tristen tristen closed this Apr 7, 2016
@tristen tristen deleted the query-similar-features branch April 7, 2016 16:26
@nitins1
Copy link

nitins1 commented Mar 13, 2017

How do I find the data stored in the source file (mapbox://mapbox.82pkq93d) so I can manipulate the contents differently. For example, select counties in certain states as well, but using "STATES" as the key in the filter argument of the setFilter method doesn't work. Any ideas?

@tristen
Copy link
Member Author

tristen commented Mar 13, 2017

👋 @nitins1 sounds like you probably want querySourceFeatures?

@lbud
Copy link
Contributor

lbud commented Mar 13, 2017

@nitins1@tristen is right in that you can use querySourceFeatures to dig into the data added to a GL map.

Alternatively, you can look for that dataset's TileJSON — in this case, at https://api.mapbox.com/v4/mapbox.82pkq93d.json?secure&access_token=<your access token>
which contains this field:

  "vector_layers": [
    {
      "description": "",
      "fields": {
        "COUNTY": "String",
        "FIPS": "Number",
        "median-income": "Number",
        "population": "Number"
      },
      "id": "original",
      "maxzoom": 22,
      "minzoom": 0,
      "source": "mapbox.82pkq93d",
      "source_name": "counties"
    }
  ],

@nitins1
Copy link

nitins1 commented Mar 14, 2017

@tristen @lbud Thank you both for your responses! So I understand that I can use querySourceFeatures to return an array of objects that match a given filter. But after looking into the dataset's tileJSON, it doesn't seem like this data source has any information about states or counties relating to a state. Is there a data source/another walkthrough example with state data?

edit: I think "FIPS" is some sort of code for states? https://gist.github.com/wavded/1250983/bf7c1c08f7b1596ca10822baeb8049d7350b0a4b

edit again: Yep, FIPS corresponds to states and I got it working. I wanted to highlight only the currently selected county. Thank you both for your help!
map.setFilter('counties-highlighted', [ "all", ['==', 'COUNTY', feature.properties.COUNTY], ['==', 'FIPS', feature.properties.FIPS] ]);

one last edit: The FIPS code data that I posted earlier is only half right. Although each state's FIPS code is a two digit number, each county's FIPS property in the dataset starts with those two digits but is a five digit number. In my case, maryland FIPS code is 24 but each county's FIPS property was 24001, 24014, and the like. Baltimore city was an outlier being in the 24500 range with a FIPS code of 24510. I'm not sure how to select a state's worth of counties since the filters don't have any "starts with" type of operators. I had to use in and !in and included each county's FIPS code as a membership filter.

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

Successfully merging this pull request may close these issues.

4 participants