We’re introducing runtime styling in the upcoming release of our Android SDK. Runtime styling gives developers a new level of customization and a toolbox to design experiences directly in their code. Now you can adjust the color of a map to the local time of day, change text labels based on localization settings on the device, or use a heat-map to change the color of buildings on the fly.
While we’re polishing the final release, here’s a preview of some of the magic available in our current beta.
Runtime styling allows you to add, remove, or modify map layers on the fly, offering new ways to present data on a map. For this demo, we mapped out the interior of The White House, saved in a GeoJSON file. Here’s how you add the data as a source to the map and create a layer from the data:
// Load in the GeoJSON file and add as a new source.indoorBuildingSource=newGeoJsonSource("indoor-building",<loadGeoJSONhere>);mapboxMap.addSource(indoorBuildingSource);FillLayerindoorBuildingLayer=newFillLayer("indoor-building-fill","indoor-building").withProperties(fillColor(Color.parseColor("#eeeeee")),// Function.zoom is used here to fade out the indoor layer if zoom level is beyond 16. Only// necessary to show the indoor map at high zoom levels.fillOpacity(Function.zoom(0.8f,stop(17,fillOpacity(1f)),stop(16.5f,fillOpacity(0.5f)),stop(16,fillOpacity(0f)))));map.addLayer(indoorBuildingLayer);
Now add different data sources for each floor level to modify the map whenever a user selects a different floor:
Highlight map features
This example lets the user explore parks, hotels and attractions in Los Angeles.
Runtime styling allows you to customize the look of existing layers in the map style. To keep the map neat and informative, users simply toggle the layers they are interested in. The pulsing animation of a layer being toggled on or off is the result of using a ValueAnimator, typically used in Android: