/* Leaflet.AwesomeNumberMarkers, a plugin that adds number markers for Leaflet http://leafletjs.com https://github.com/zahidul-islam Modified: SVG-based markers to support multi-digit numbers */ /*global L*/ (function (){ "use strict"; // Color map for marker fill colors var MARKER_COLORS = { red: '#d63e2a', darkred: '#a23336', lightred: '#ff8e7f', orange: '#f69730', beige: '#ffcb92', green: '#72b026', darkgreen: '#728224', lightgreen: '#bbf970', blue: '#38aadd', darkblue: '#00649f', lightblue: '#8adaff', purple: '#d152b8', darkpurple: '#5b396b', pink: '#ff91ea', cadetblue: '#436978', white: '#fbfbfb', gray: '#575757', lightgray: '#a3a3a3', black: '#303030' }; L.AwesomeNumberMarkers = L.Icon.extend({ options: { iconSize: [35, 45], iconAnchor: [17, 42], popupAnchor: [1, -32], className: 'awesome-number-marker', icon: 'home', markerColor: 'blue', numberColor: 'white', number: '' }, createIcon: function () { var div = document.createElement('div'), options = this.options; var num = String(options.number); var isMultiDigit = num.length > 1; // Widen marker for multi-digit numbers var w = isMultiDigit ? Math.max(35, 20 + num.length * 10) : 35; var h = 45; var cx = w / 2; // Tip of the pin var tipY = h; // Circle center and radius var cr = 14; var cy = cr + 1; // Build SVG pin shape var fillColor = MARKER_COLORS[options.markerColor] || MARKER_COLORS.blue; var textColor = options.numberColor || 'white'; var fontSize = isMultiDigit ? 12 : 14; var svg = '' + '' + '' + '' + '' + '' + '' + num + ''; div.innerHTML = svg; div.style.width = w + 'px'; div.style.height = h + 'px'; div.className = options.className; // Update icon size and anchor for this instance var anchor = L.point(Math.round(w / 2), 42); div.style.marginLeft = (-anchor.x) + 'px'; div.style.marginTop = (-anchor.y) + 'px'; // Store actual size so Leaflet positions correctly this.options.iconSize = [w, h]; this.options.iconAnchor = [anchor.x, 42]; return div; }, createShadow: function () { return null; } }); }());