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 variable binding expression example #7317

Merged
merged 3 commits into from
Sep 24, 2018

Conversation

malwoodsantoro
Copy link
Contributor

This example uses let and var expressions to demonstrate variable binding syntax. To test this out locally, you'll need to replace the url to the GeoJSON with the raw data.

:)

@malwoodsantoro malwoodsantoro changed the title Add variable binding expression Add variable binding expression example Sep 21, 2018
Copy link
Contributor

@ryanhamley ryanhamley left a comment

Choose a reason for hiding this comment

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

I'm wondering if this is the best example for let and var. The code is almost identical to our choropleth example but with the added overhead of declaring the variable syntax. I agree with the goal of documenting how to use the variables though. @ChrisLoer thoughts?

@@ -0,0 +1,10 @@
/*---
title: Visualize population density
description: Using a [`varible binding expression`](/mapbox-gl-js/style-spec#expressions-variable-binding) to calculate and display population density.
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: variable is misspelled here

["linear"],
["var", "density"],
274,
["to-color", "#eff3ff"],
Copy link
Contributor

Choose a reason for hiding this comment

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

I think @ChrisLoer 's recent work makes the explicit cast to a color here unnecessary

Copy link
Contributor

Choose a reason for hiding this comment

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

I think the cast is necessary until #7301 has merged and is being used by the example page, right?

Copy link
Contributor

Choose a reason for hiding this comment

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

LOL, oh yeah. I was working on that. Fridays.

<script>
var map = new mapboxgl.Map({
container: 'map', // container id
style: 'mapbox://styles/mapbox/streets-v9', // stylesheet location
Copy link
Contributor

Choose a reason for hiding this comment

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

I have a personal vendetta against streets-v9 in examples. The flattened road labels are 🙅‍♂️

@ChrisLoer
Copy link
Contributor

The code is almost identical to our choropleth example but with the added overhead of declaring the variable syntax

🤔 Yeah I see your point although it seems like using let and var will always be part of accomplishing something else (hopefully with less duplication in the expression code). I guess this seems like a pretty reasonable choice to me.

@ryanhamley
Copy link
Contributor

I'm ok with it then. Just a couple little nits to clean up. I'll update the example to remove the explicit casts to color when I finish up the test in #7301

@malwoodsantoro malwoodsantoro merged commit b421b50 into mb-pages Sep 24, 2018
@malwoodsantoro malwoodsantoro deleted the var-binding-expression branch December 20, 2018 05:06
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