Detailed interpretation of Mapbox expressions

Friends who are new to mapbox will definitely be confused by expressions. Obviously conditional judgment or callback function can solve the problem. You must use expressions in mapbox. This is indeed more ex.

But now that we have encountered it, don’t be afraid. In this article, I will help you understand this so-called expression bit by bit.

First of all, from a macro perspective, we need to know why we use expressions. in mapbox. Expressions are usually used to simplify some if/else conditional judgments. An expression is usually one line of code. Automatic matching of conditions can be completed in just a few dozen characters. There is also an internal reason because Mapbox wants to maintain the unity of code styles between the JS side and the mobile SDK, which means that expressions were not used in JS at the beginning.

It should also be made clear that expressions are often used in the paint, layout, and filter attributes of layer objects. In addition, expressions can also be used in the process of assigning values ​​to these attributes. In addition, expressions can also be used in other layer parameters or Some expressions can also be used in some parameters of source. Some people will say that you can also use expressions when settingFilter. That's right, but doesn't setFilter also set a filter? Therefore, the expression is only used in certain attributes of the layer, and cannot be used in other places.

There are several types of mapbox expressions. They are mathematical calculations, logical judgments, data operations, and camera operations. Among them, camera expressions are easy to understand, but they are of little use. Data manipulation and logical expression are the top priority and need to be mastered.

For example, if your administrative district needs to attach the color of the administrative district based on a certain indicator. Similar to the following

 When you write a program, you will definitely think of judging this indicator through if/else. for example"

Guess you like

Origin blog.csdn.net/lz5211314121/article/details/131082717