Code coverage report for src/Toolbar.Popup.js

Statements: 100% (29 / 29)      Branches: 50% (1 / 2)      Functions: 100% (6 / 6)      Lines: 100% (29 / 29)      Ignored: none     

All files » src/ » Toolbar.Popup.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92    1                   5           5                 2 2   2   2   2       1   1   1       1   1       2                     2 4 4 4     2     2 2   2     2 2 2     2 2       1 1    
// A convenience class for built-in popup toolbars.
 
L.Toolbar.Popup = L.Toolbar.extend({
	statics: {
		baseClass: 'leaflet-popup-toolbar ' + L.Toolbar.baseClass
	},
 
	options: {
		anchor: [0, 0]
	},
 
	initialize: function(latlng, options) {
		L.Toolbar.prototype.initialize.call(this, options);
 
		/* 
		 * Developers can't pass a DivIcon in the options for L.Toolbar.Popup
		 * (the use of DivIcons is an implementation detail which may change).
		 */
		this._marker = new L.Marker(latlng, {
			icon : new L.DivIcon({
				className: this.options.className,
				iconAnchor: [0, 0]
			})
		});
	},
 
	onAdd: function(map) {
		this._map = map;
		this._marker.addTo(map);
 
		L.Toolbar.prototype.onAdd.call(this, map);
 
		this.appendToContainer(this._marker._icon);
 
		this._setStyles();
	},
 
	onRemove: function(map) {
		map.removeLayer(this._marker);
 
		L.Toolbar.prototype.onRemove.call(this, map);
 
		delete this._map;
	},
 
	setLatLng: function(latlng) {
		this._marker.setLatLng(latlng);
 
		return this;
	},
 
	_setStyles: function() {
		var container = this._container,
			toolbar = this._ul,
			anchor = L.point(this.options.anchor),
			icons = toolbar.querySelectorAll('.leaflet-toolbar-icon'),
			buttonHeights = [],
			toolbarWidth = 0,
			toolbarHeight,
			tipSize,
			tipAnchor;
 
		/* Calculate the dimensions of the toolbar. */
		for (var i = 0, l = icons.length; i < l; i++) {
			Eif (icons[i].parentNode.parentNode === toolbar) {
				buttonHeights.push(parseInt(L.DomUtil.getStyle(icons[i], 'height'), 10));
				toolbarWidth += Math.ceil(parseFloat(L.DomUtil.getStyle(icons[i], 'width')));
			}
		}
		toolbar.style.width = toolbarWidth + 'px';
 
		/* Create and place the toolbar tip. */
		this._tipContainer = L.DomUtil.create('div', 'leaflet-toolbar-tip-container', container);
		this._tipContainer.style.width = toolbarWidth + 'px';
 
		this._tip = L.DomUtil.create('div', 'leaflet-toolbar-tip', this._tipContainer);
 
		/* Set the tipAnchor point. */
		toolbarHeight = Math.max.apply(undefined, buttonHeights);
		tipSize = parseInt(L.DomUtil.getStyle(this._tip, 'width'), 10);
		tipAnchor = new L.Point(toolbarWidth/2, toolbarHeight + 0.7071*tipSize);
 
		/* The anchor option allows app developers to adjust the toolbar's position. */
		container.style.marginLeft = (anchor.x - tipAnchor.x) + 'px';
		container.style.marginTop = (anchor.y - tipAnchor.y) + 'px';
	}
});
 
L.toolbar.popup = function(options) {
    return new L.Toolbar.Popup(options);
};