Quantcast
Channel: maps for developers - Medium
Viewing all articles
Browse latest Browse all 2230

Introducing GL JS v1.9.0 and the “within” expression

$
0
0

By: Ryan Hamley

The latest GL JS release (v1.9.0) brings several new features, fixes for long-standing bugs with line-pattern, and updates to our CHANGELOG policy for contributors. Check out the demos below to see the new features, and view the changelog for a complete list of what’s new.

Know if data is within a boundary

The highlight of this release is the within expression, which allows developers to check whether or not a feature is in the bounds of a GeoJSON polygon. This enables styling point and line data differently if they’re fully within a polygon’s borders.

The example below demonstrates how to use the within expression to change the color of symbol layer features based on whether they’re fully contained within the green polygon covering Maine. The Augusta to Bangor route and labels are black because they’re inside the Maine polygon. The Concord to Boston route and labels are colored red because the expression sets red as the fallback value when the features are not contained within the Maine polygon.

Interactive demo: https://codepen.io/rsh412/pen/QWbxpba

Adjust the map center based on UI elements

Map padding options are now available to the camera methods Map#easeTo, Map#jumpTo, and Map#flyTo. This shifts the visual center of the map to match overlaid UI elements on your page, such as sidebars, headers, and footers. Different padding values can be specified for each side of the map for granular control.

Interactive demo: https://jsfiddle.net/eh6zt4dm/

queryRenderedFeatures now returns evaluated properties

The Map#queryRenderedFeatures method returns a list of visible features in a geographic area. Previously, when a feature used an expression, queryRenderedFeatures would return the expression as-is. With this update, queryRenderedFeatures will evaluate the expression and return the result, which makes debugging expressions easier and allows expressing the evaluated result within GL JS. This update also improved performance when queryRenderedFeatures evaluates many features at once.

1.8.0 - line-offset returns expression input (left). 1.9.0 - line-offset returns the evaluated value -14 (right).

These and other improvements are available today to give you more tools to customize your map visualizations on web and mobile in the Maps SDKs for iOS and Android. See our changelog for the complete list of updates. We’re excited to see what you build, share your projects with us on Twitter using #BuiltWithMapbox.

Ryan Hamley - Software Engineer - Mapbox | LinkedIn

Maps feature data from Mapbox and OpenStreetMap and their data partners.


Introducing GL JS v1.9.0 and the “within” expression was originally published in Points of interest on Medium, where people are continuing the conversation by highlighting and responding to this story.


Viewing all articles
Browse latest Browse all 2230

Trending Articles