var scale_factory_cache = {}; function scale_factory(feature) { var dim = Math.round(+feature.properties.Burglary / 100); if (!scale_factory_cache[dim]) { var c = document.createElement('canvas'); c.width = dim; c.height = dim; var ctx = c.getContext('2d'); ctx.fillStyle = 'rgba(142, 179, 219, 0.5)'; ctx.strokeStyle = '#3F71A7'; ctx.beginPath(); ctx.arc(dim/2, dim/2, dim/Math.PI, 0, Math.PI*2, true); ctx.closePath(); ctx.fill(); ctx.stroke(); scale_factory_cache[dim] = c.toDataURL(); } var el = document.createElement('img'); el.width = dim; el.height = dim; el.src = scale_factory_cache[dim]; el.style.cssText = 'width:' + dim + 'px;' + 'height:' + dim + 'px;' + 'margin-left:' + (-dim/2) + 'px;' + 'margin-top:' + (-dim/2) + 'px;' + 'position:absolute'; return el; }