maptastik
2/10/2017 - 8:57 PM

Tangram Choropleth: Final

Tangram Choropleth: Final

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <title>TangramJS - Mixing with raster tiles</title>
    <meta name="viewport" content="initial-scale=1,maximum-scale=1,user-scalable=no" />
    <link rel="stylesheet" href="https://unpkg.com/leaflet@1.0.3/dist/leaflet.css" />
    <style>
        body {
            margin: 0;
            padding: 0;
        }
        #map {
            position: absolute;
            top: 0;
            bottom: 0;
            width: 100%;
        }
    </style>
</head>

<body>
    <div id="map"></div>
    <script src="https://unpkg.com/leaflet@1.0.3/dist/leaflet.js"></script>
    <script src="https://unpkg.com/tangram/dist/tangram.min.js"></script>
    <script>
        var kentucky = [37.857507, -85.632935]
        var map = L.map('map', {
          center: kentucky,
          zoom: 7,
        });

        var layer = Tangram.leafletLayer({
          scene: 'scene.yaml'
        }).addTo(map);

        // ADD LABELS TO CUSTOM PANE
        map.createPane('labels');
        map.getPane('labels').style.zIndex = 650;

        var labels = L.tileLayer('http://{s}.basemaps.cartocdn.com/light_only_labels/{z}/{x}/{y}.png', {
        	attribution: '&copy; <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a> &copy; <a href="http://cartodb.com/attributions">CartoDB</a>',
        	subdomains: 'abcd',
            pane: 'labels',
        	maxZoom: 19
        }).addTo(map);

    </script>
</body>

</html>
sources:
    counties:
        type: GeoJSON
        url: https://gist.githubusercontent.com/maptastik/df8e483d5ac1c6cae3dc4a7c02ea9039/raw/9cd46849bddcfa90aab240772a12275408d6d8d0/kyCounties.geojson
    carto_nolabel:
        type: Raster
        url: http://a.basemaps.cartocdn.com/light_nolabels/{z}/{x}/{y}.png
styles:
  _alpha_polygons:
    base: polygons
    blend: multiply
layers:
    basemap:
      data: {source: carto_nolabel}
      draw:
        raster:
          order: 0
    counties:
        data: {source: counties}
        draw:
            lines:
                color: '#000000'
                width: 1px
                order: 1
            polygons:
                style: _alpha_polygons
                order: 1
                color: |
                    function() {
                        var cat = feature.CH00_10;
                        var color = cat >= 5 ? '#2196F3' :
                                    cat < 5 && cat >= 1 ? '#90CAF9':
                                    cat < 1 && cat > -1 ? '#FFFDE7':
                                    cat <= -1 && cat > -5 ? '#ef9a9a':
                                    cat <= -5 ? '#f44336':
                                    '#000'
                        return color;
                      }