Scaled Markers

Scaling circles based on GeoJSON properties
Select all
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
<title>Scaled Markers</title>
  
  <meta name='viewport' content='width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no' />
  <script src='//api.tiles.mapbox.com/mapbox.js/v1.5.0/mapbox.js'></script>
  <link href='//api.tiles.mapbox.com/mapbox.js/v1.5.0/mapbox.css' rel='stylesheet' />
  
  <style>
    body { margin:0; padding:0; }
    #map { position:absolute; top:0; bottom:0; width:100%; }
  </style>
</head>
<body>
<div id='map'></div>
<script>
var map = L.mapbox.map('map', 'examples.map-9ijuk24y')
    .setView([24, 122], 7);

// GeoJSON data: see http://geojson.org/ for the full description of this format.
//
// In these lines, we create some random points. This, of course, you can change:
// instead, your data can be hardcoded as a Javascript object, or pulled in
// from an external file with AJAX, or loaded from MapBox automatically.
var geoJsonData = {
  type: "FeatureCollection",
  features: []
};
for (var i = 0; i < 30; i++) {
    geoJsonData.features.push({
        type: 'Feature',
        properties: {
            // the important part is here: that each feature has some property
            // that we refer to later on, in `pointToLayer`, that determines
            // the size of the scaled circle
            count: Math.random() * 20
        },
        geometry: {
            type: 'Point',
            coordinates: [120 + Math.random() * 2, 23 + Math.random() * 2]
        }
    });
}

var geoJson = L.geoJson(geoJsonData, {
    pointToLayer: function(feature, latlng) {
        return L.circleMarker(latlng, {
            // here we use the `count` property in GeoJSON verbatim: if it's
            // to small or two large, we can use basic math in Javascript to
            // adjust it so that it fits the map better.
            radius: feature.properties.count
        })
    }
}).addTo(map);
</script>
The code and documentation to mapbox.js is hosted on GitHub where you can contribute changes and improvements.