Leaflet smoothFactor test
Displays 12 spirals of different smoothFactor values.
by Bateman
HTML
<script src="http://cdn.leafletjs.com/leaflet-0.7.2/leaflet.js"></script>
<link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet-0.7.2/leaflet.css">
<div id="map"></div>
CSS
html, body, #map {
height: 100%;
width:100%;
padding:0px;
margin:0px;
background: white;
}
JavaScript
/////////////////////////////////////////////////////////////////////////////////////////////
//setting up the map//
/////////////////////////////////////////////////////////////////////////////////////////////
// set center coordinates
var centerlat = 34.05;
var centerlon = -118.25;
// set default zoom level
var zoomLevel = 10;
// initialize map
var map = L.map('map').setView([centerlat, centerlon], zoomLevel);
// set source for map tiles
ATTR = '© <a href="http://openstreetmap.org">OpenStreetMap</a> contributors, ' +
'<a href="http://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a> | ' +
'© <a href="http://cartodb.com/attributions">CartoDB</a>';
CDB_URL = 'http://{s}.basemaps.cartocdn.com/light_all/{z}/{x}/{y}.png';
// add tiles to map
L.tileLayer(CDB_URL, {attribution: ATTR}).addTo(map);
/////////////////////////////////////////////////////////////////////////////////////////////
//generating spirals and adding them to the map//
/////////////////////////////////////////////////////////////////////////////////////////////
var spiralsteps = 200;
//create 12 spirals of different smoothFactors, rotated about the map center point
for (var i = 0; i < 12; ++i) {
var ang = Math.PI * i / 6;
spiral = make_spiral(spiralsteps, [centerlat, centerlon], ang, 0.01, 0.05, 0.985);
smoo = 0.1 * Math.pow(1.6185, i);
L.polyline(spiral, {
smoothFactor: smoo
}).on('click', onSpiralClick).addTo(map);
}
//change popup content based on smoothing parameters
function onSpiralClick(e) {
var rpts = 0;
for (var i in e.target._parts) {
rpts = rpts + e.target._parts[i].length;
}
e.target.bindPopup('smoothFactor : ' + Math.round(10 * e.target.options.smoothFactor) / 10 + '<br /> Rendering ' + rpts + ' / ' + e.target._originalPoints.length + ' original vertices.').openPopup(e.latlng);
}
/////////////////////////////////////////////////////////////////////////////////////////////
//functions for creating synthetic...