Final jshinting without remorse

This commit is contained in:
mourner 2011-12-09 16:51:31 +02:00
parent b03f6eff07
commit a9720fcb43
65 changed files with 405 additions and 401 deletions

View File

@ -1,3 +0,0 @@
@echo off
jshint ../src --config jshintrc.json

View File

@ -1,5 +1,5 @@
L.Control.Attribution = L.Class.extend({
onAdd: function(map) {
onAdd: function (map) {
this._container = L.DomUtil.create('div', 'leaflet-control-attribution');
L.DomEvent.disableClickPropagation(this._container);
this._map = map;
@ -8,20 +8,20 @@ L.Control.Attribution = L.Class.extend({
this._update();
},
getPosition: function() {
getPosition: function () {
return L.Control.Position.BOTTOM_RIGHT;
},
getContainer: function() {
getContainer: function () {
return this._container;
},
setPrefix: function(prefix) {
setPrefix: function (prefix) {
this._prefix = prefix;
this._update();
},
addAttribution: function(text) {
addAttribution: function (text) {
if (!text) {
return;
}
@ -29,7 +29,7 @@ L.Control.Attribution = L.Class.extend({
this._update();
},
removeAttribution: function(text) {
removeAttribution: function (text) {
if (!text) {
return;
}
@ -37,7 +37,7 @@ L.Control.Attribution = L.Class.extend({
this._update();
},
_update: function() {
_update: function () {
if (!this._map) {
return;
}

View File

@ -4,7 +4,7 @@ L.Control.Layers = L.Class.extend({
collapsed: !L.Browser.touch
},
initialize: function(baseLayers, overlays, options) {
initialize: function (baseLayers, overlays, options) {
L.Util.setOptions(this, options);
this._layers = {};
@ -22,41 +22,41 @@ L.Control.Layers = L.Class.extend({
}
},
onAdd: function(map) {
onAdd: function (map) {
this._map = map;
this._initLayout();
this._update();
},
getContainer: function() {
getContainer: function () {
return this._container;
},
getPosition: function() {
getPosition: function () {
return L.Control.Position.TOP_RIGHT;
},
addBaseLayer: function(layer, name) {
addBaseLayer: function (layer, name) {
this._addLayer(layer, name);
this._update();
return this;
},
addOverlay: function(layer, name) {
addOverlay: function (layer, name) {
this._addLayer(layer, name, true);
this._update();
return this;
},
removeLayer: function(layer) {
removeLayer: function (layer) {
var id = L.Util.stamp(layer);
delete this._layers[id];
this._update();
return this;
},
_initLayout: function() {
_initLayout: function () {
this._container = L.DomUtil.create('div', 'leaflet-control-layers');
L.DomEvent.disableClickPropagation(this._container);
@ -86,7 +86,7 @@ L.Control.Layers = L.Class.extend({
this._container.appendChild(this._form);
},
_addLayer: function(layer, name, overlay) {
_addLayer: function (layer, name, overlay) {
var id = L.Util.stamp(layer);
this._layers[id] = {
layer: layer,
@ -95,7 +95,7 @@ L.Control.Layers = L.Class.extend({
};
},
_update: function() {
_update: function () {
if (!this._container) { return; }
this._baseLayersList.innerHTML = '';
@ -116,7 +116,7 @@ L.Control.Layers = L.Class.extend({
this._separator.style.display = (overlaysPresent && baseLayersPresent ? '' : 'none');
},
_addItem: function(obj, onclick) {
_addItem: function (obj, onclick) {
var label = document.createElement('label');
var input = document.createElement('input');
@ -138,7 +138,7 @@ L.Control.Layers = L.Class.extend({
container.appendChild(label);
},
_onInputClick: function() {
_onInputClick: function () {
var i, input, obj,
inputs = this._form.getElementsByTagName('input'),
inputsLen = inputs.length;
@ -155,11 +155,11 @@ L.Control.Layers = L.Class.extend({
}
},
_expand: function() {
_expand: function () {
L.DomUtil.addClass(this._container, 'leaflet-control-layers-expanded');
},
_collapse: function() {
_collapse: function () {
this._container.className = this._container.className.replace(' leaflet-control-layers-expanded', '');
}
});

View File

@ -1,6 +1,6 @@
L.Control.Zoom = L.Class.extend({
onAdd: function(map) {
onAdd: function (map) {
this._map = map;
this._container = L.DomUtil.create('div', 'leaflet-control-zoom');
@ -13,15 +13,15 @@ L.Control.Zoom = L.Class.extend({
this._container.appendChild(this._zoomOutButton);
},
getContainer: function() {
getContainer: function () {
return this._container;
},
getPosition: function() {
getPosition: function () {
return L.Control.Position.TOP_LEFT;
},
_createButton: function(title, className, fn, context) {
_createButton: function (title, className, fn, context) {
var link = document.createElement('a');
link.href = '#';
link.title = title;

View File

@ -1,4 +1,4 @@
(function() {
(function () {
var ua = navigator.userAgent.toLowerCase(),
ie = !!window.ActiveXObject,
webkit = ua.indexOf("webkit") !== -1,
@ -22,7 +22,7 @@
mobileOpera: mobile && opera,
mobile: mobile,
touch: (function() {
touch: (function () {
var touchSupported = false,
startName = 'ontouchstart';

View File

@ -2,19 +2,19 @@
* Class powers the OOP facilities of the library. Thanks to John Resig and Dean Edwards for inspiration!
*/
L.Class = function() {};
L.Class = function () {};
L.Class.extend = function(/*Object*/ props) /*-> Class*/ {
L.Class.extend = function (/*Object*/ props) /*-> Class*/ {
// extended class with the new prototype
var NewClass = function() {
var NewClass = function () {
if (this.initialize) {
this.initialize.apply(this, arguments);
}
};
// instantiate class without calling constructor
var F = function() {};
var F = function () {};
F.prototype = this.prototype;
var proto = new F();
@ -58,7 +58,7 @@ L.Class.extend = function(/*Object*/ props) /*-> Class*/ {
NewClass.extend = L.Class.extend;
// method for adding properties to prototype
NewClass.include = function(props) {
NewClass.include = function (props) {
L.Util.extend(this.prototype, props);
};

View File

@ -5,7 +5,7 @@
L.Mixin = {};
L.Mixin.Events = {
addEventListener: function(/*String*/ type, /*Function*/ fn, /*(optional) Object*/ context) {
addEventListener: function (/*String*/ type, /*Function*/ fn, /*(optional) Object*/ context) {
var events = this._leaflet_events = this._leaflet_events || {};
events[type] = events[type] || [];
events[type].push({
@ -15,12 +15,12 @@ L.Mixin.Events = {
return this;
},
hasEventListeners: function(/*String*/ type) /*-> Boolean*/ {
hasEventListeners: function (/*String*/ type) /*-> Boolean*/ {
var k = '_leaflet_events';
return (k in this) && (type in this[k]) && (this[k][type].length > 0);
},
removeEventListener: function(/*String*/ type, /*Function*/ fn, /*(optional) Object*/ context) {
removeEventListener: function (/*String*/ type, /*Function*/ fn, /*(optional) Object*/ context) {
if (!this.hasEventListeners(type)) { return this; }
for (var i = 0, events = this._leaflet_events, len = events[type].length; i < len; i++) {
@ -35,7 +35,7 @@ L.Mixin.Events = {
return this;
},
fireEvent: function(/*String*/ type, /*(optional) Object*/ data) {
fireEvent: function (/*String*/ type, /*(optional) Object*/ data) {
if (!this.hasEventListeners(type)) { return; }
var event = L.Util.extend({

View File

@ -3,7 +3,7 @@
*/
L.Util = {
extend: function(/*Object*/ dest) /*-> Object*/ { // merge src properties into dest
extend: function (/*Object*/ dest) /*-> Object*/ { // merge src properties into dest
var sources = Array.prototype.slice.call(arguments, 1);
for (var j = 0, len = sources.length, src; j < len; j++) {
src = sources[j] || {};
@ -16,21 +16,21 @@ L.Util = {
return dest;
},
bind: function(/*Function*/ fn, /*Object*/ obj) /*-> Object*/ {
return function() {
bind: function (/*Function*/ fn, /*Object*/ obj) /*-> Object*/ {
return function () {
return fn.apply(obj, arguments);
};
},
stamp: (function() {
stamp: (function () {
var lastId = 0, key = '_leaflet_id';
return function(/*Object*/ obj) {
return function (/*Object*/ obj) {
obj[key] = obj[key] || ++lastId;
return obj[key];
};
}()),
requestAnimFrame: (function() {
requestAnimFrame: (function () {
function timeoutDefer(callback) {
window.setTimeout(callback, 1000 / 60);
}
@ -42,7 +42,7 @@ L.Util = {
window.msRequestAnimationFrame ||
timeoutDefer;
return function(callback, context, immediate, contextEl) {
return function (callback, context, immediate, contextEl) {
callback = context ? L.Util.bind(callback, context) : callback;
if (immediate && requestFn === timeoutDefer) {
callback();
@ -52,16 +52,16 @@ L.Util = {
};
}()),
limitExecByInterval: function(fn, time, context) {
limitExecByInterval: function (fn, time, context) {
var lock, execOnUnlock, args;
function exec(){
function exec() {
lock = false;
if (execOnUnlock) {
args.callee.apply(context, args);
execOnUnlock = false;
}
}
return function() {
return function () {
args = arguments;
if (!lock) {
lock = true;
@ -73,18 +73,18 @@ L.Util = {
};
},
falseFn: function() { return false; },
falseFn: function () { return false; },
formatNum: function(num, digits) {
formatNum: function (num, digits) {
var pow = Math.pow(10, digits || 5);
return Math.round(num * pow) / pow;
},
setOptions: function(obj, options) {
setOptions: function (obj, options) {
obj.options = L.Util.extend({}, obj.options, options);
},
getParamString: function(obj) {
getParamString: function (obj) {
var params = [];
for (var i in obj) {
if (obj.hasOwnProperty(i)) {

View File

@ -1,6 +1,6 @@
L.Util.extend(L.DomEvent, {
// inspired by Zepto touch code by Thomas Fuchs
addDoubleTapListener: function(obj, handler, id) {
addDoubleTapListener: function (obj, handler, id) {
var last,
doubleTap = false,
delay = 250,
@ -35,7 +35,7 @@ L.Util.extend(L.DomEvent, {
obj.addEventListener(touchend, onTouchEnd, false);
},
removeDoubleTapListener: function(obj, id) {
removeDoubleTapListener: function (obj, id) {
var pre = '_leaflet_';
obj.removeEventListener(obj, obj[pre + 'touchstart' + id], false);
obj.removeEventListener(obj, obj[pre + 'touchend' + id], false);

View File

@ -4,7 +4,7 @@
L.DomEvent = {
/* inpired by John Resig, Dean Edwards and YUI addEvent implementations */
addListener: function(/*HTMLElement*/ obj, /*String*/ type, /*Function*/ fn, /*Object*/ context) {
addListener: function (/*HTMLElement*/ obj, /*String*/ type, /*Function*/ fn, /*Object*/ context) {
var id = L.Util.stamp(fn),
key = '_leaflet_' + type + id;
@ -25,7 +25,7 @@ L.DomEvent = {
} else if ((type === 'mouseenter') || (type === 'mouseleave')) {
var originalHandler = handler,
newType = (type === 'mouseenter' ? 'mouseover' : 'mouseout');
handler = function(e) {
handler = function (e) {
if (!L.DomEvent._checkMouse(obj, e)) {
return;
}
@ -42,7 +42,7 @@ L.DomEvent = {
obj[key] = handler;
},
removeListener: function(/*HTMLElement*/ obj, /*String*/ type, /*Function*/ fn) {
removeListener: function (/*HTMLElement*/ obj, /*String*/ type, /*Function*/ fn) {
var id = L.Util.stamp(fn),
key = '_leaflet_' + type + id,
handler = obj[key];
@ -66,7 +66,7 @@ L.DomEvent = {
obj[key] = null;
},
_checkMouse: function(el, e) {
_checkMouse: function (el, e) {
var related = e.relatedTarget;
if (!related) {
@ -77,13 +77,15 @@ L.DomEvent = {
while (related && (related !== el)) {
related = related.parentNode;
}
} catch(err) { return false; }
} catch (err) {
return false;
}
return (related !== el);
},
/*jshint noarg:false */ // evil magic for IE
_getEvent: function() {
_getEvent: function () {
var e = window.event;
if (!e) {
var caller = arguments.callee.caller;
@ -99,7 +101,7 @@ L.DomEvent = {
},
/*jshint noarg:false */
stopPropagation: function(/*Event*/ e) {
stopPropagation: function (/*Event*/ e) {
if (e.stopPropagation) {
e.stopPropagation();
} else {
@ -107,13 +109,13 @@ L.DomEvent = {
}
},
disableClickPropagation: function(/*HTMLElement*/ el) {
disableClickPropagation: function (/*HTMLElement*/ el) {
L.DomEvent.addListener(el, 'mousedown', L.DomEvent.stopPropagation);
L.DomEvent.addListener(el, 'click', L.DomEvent.stopPropagation);
L.DomEvent.addListener(el, 'dblclick', L.DomEvent.stopPropagation);
},
preventDefault: function(/*Event*/ e) {
preventDefault: function (/*Event*/ e) {
if (e.preventDefault) {
e.preventDefault();
} else {
@ -121,12 +123,12 @@ L.DomEvent = {
}
},
stop: function(e) {
stop: function (e) {
L.DomEvent.preventDefault(e);
L.DomEvent.stopPropagation(e);
},
getMousePosition: function(e, container) {
getMousePosition: function (e, container) {
var x = e.pageX ? e.pageX : e.clientX +
document.body.scrollLeft + document.documentElement.scrollLeft,
y = e.pageY ? e.pageY : e.clientY +
@ -136,11 +138,15 @@ L.DomEvent = {
pos.subtract(L.DomUtil.getViewportOffset(container)) : pos);
},
getWheelDelta: function(e) {
getWheelDelta: function (e) {
var delta = 0;
if (e.wheelDelta) { delta = e.wheelDelta/120; }
if (e.detail) { delta = -e.detail/3; }
return delta;
if (e.wheelDelta) {
delta = e.wheelDelta / 120;
}
if (e.detail) {
delta = -e.detail / 3;
}
return delta;
}
};

View File

@ -3,11 +3,11 @@
*/
L.DomUtil = {
get: function(id) {
get: function (id) {
return (typeof id === 'string' ? document.getElementById(id) : id);
},
getStyle: function(el, style) {
getStyle: function (el, style) {
var value = el.style[style];
if (!value && el.currentStyle) {
value = el.currentStyle[style];
@ -19,7 +19,7 @@ L.DomUtil = {
return (value === 'auto' ? null : value);
},
getViewportOffset: function(element) {
getViewportOffset: function (element) {
var top = 0,
left = 0,
el = element,
@ -52,7 +52,7 @@ L.DomUtil = {
return new L.Point(left, top);
},
create: function(tagName, className, container) {
create: function (tagName, className, container) {
var el = document.createElement(tagName);
el.className = className;
if (container) {
@ -61,7 +61,7 @@ L.DomUtil = {
return el;
},
disableTextSelection: function() {
disableTextSelection: function () {
if (document.selection && document.selection.empty) {
document.selection.empty();
}
@ -71,24 +71,24 @@ L.DomUtil = {
}
},
enableTextSelection: function() {
enableTextSelection: function () {
document.onselectstart = this._onselectstart;
this._onselectstart = null;
},
hasClass: function(el, name) {
hasClass: function (el, name) {
return (el.className.length > 0) &&
new RegExp("(^|\\s)" + name + "(\\s|$)").test(el.className);
},
addClass: function(el, name) {
addClass: function (el, name) {
if (!L.DomUtil.hasClass(el, name)) {
el.className += (el.className ? ' ' : '') + name;
}
},
removeClass: function(el, name) {
el.className = el.className.replace(/(\S+)\s*/g, function(w, match) {
removeClass: function (el, name) {
el.className = el.className.replace(/(\S+)\s*/g, function (w, match) {
if (match === name) {
return '';
}
@ -96,7 +96,7 @@ L.DomUtil = {
}).replace(/^\s+/, '');
},
setOpacity: function(el, value) {
setOpacity: function (el, value) {
if (L.Browser.ie) {
el.style.filter = 'alpha(opacity=' + Math.round(value * 100) + ')';
} else {
@ -106,7 +106,7 @@ L.DomUtil = {
//TODO refactor away this ugly translate/position mess
testProp: function(props) {
testProp: function (props) {
var style = document.documentElement.style;
for (var i = 0; i < props.length; i++) {
@ -117,13 +117,13 @@ L.DomUtil = {
return false;
},
getTranslateString: function(point) {
getTranslateString: function (point) {
return L.DomUtil.TRANSLATE_OPEN +
point.x + 'px,' + point.y + 'px' +
L.DomUtil.TRANSLATE_CLOSE;
},
getScaleString: function(scale, origin) {
getScaleString: function (scale, origin) {
var preTranslateStr = L.DomUtil.getTranslateString(origin),
scaleStr = ' scale(' + scale + ') ',
postTranslateStr = L.DomUtil.getTranslateString(origin.multiplyBy(-1));
@ -131,7 +131,7 @@ L.DomUtil = {
return preTranslateStr + scaleStr + postTranslateStr;
},
setPosition: function(el, point) {
setPosition: function (el, point) {
el._leaflet_pos = point;
if (L.Browser.webkit) {
el.style[L.DomUtil.TRANSFORM] = L.DomUtil.getTranslateString(point);
@ -141,7 +141,7 @@ L.DomUtil = {
}
},
getPosition: function(el) {
getPosition: function (el) {
return el._leaflet_pos;
}
};

View File

@ -12,24 +12,24 @@ L.Draggable = L.Class.extend({
TAP_TOLERANCE: 15
},
initialize: function(element, dragStartTarget) {
initialize: function (element, dragStartTarget) {
this._element = element;
this._dragStartTarget = dragStartTarget || element;
},
enable: function() {
enable: function () {
if (this._enabled) { return; }
L.DomEvent.addListener(this._dragStartTarget, L.Draggable.START, this._onDown, this);
this._enabled = true;
},
disable: function() {
disable: function () {
if (!this._enabled) { return; }
L.DomEvent.removeListener(this._dragStartTarget, L.Draggable.START, this._onDown);
this._enabled = false;
},
_onDown: function(e) {
_onDown: function (e) {
if ((!L.Browser.touch && e.shiftKey) || ((e.which !== 1) && (e.button !== 1) && !e.touches)) { return; }
if (e.touches && e.touches.length > 1) { return; }
@ -58,7 +58,7 @@ L.Draggable = L.Class.extend({
L.DomEvent.addListener(document, L.Draggable.END, this._onUp, this);
},
_onMove: function(e) {
_onMove: function (e) {
if (e.touches && e.touches.length > 1) { return; }
L.DomEvent.preventDefault(e);
@ -77,13 +77,13 @@ L.Draggable = L.Class.extend({
L.Util.requestAnimFrame(this._updatePosition, this, true, this._dragStartTarget);
},
_updatePosition: function() {
_updatePosition: function () {
this.fire('predrag');
L.DomUtil.setPosition(this._element, this._newPos);
this.fire('drag');
},
_onUp: function(e) {
_onUp: function (e) {
if (e.changedTouches) {
var first = e.changedTouches[0],
el = first.target,
@ -112,16 +112,16 @@ L.Draggable = L.Class.extend({
this._moving = false;
},
_setMovingCursor: function() {
_setMovingCursor: function () {
this._bodyCursor = document.body.style.cursor;
document.body.style.cursor = 'move';
},
_restoreCursor: function() {
_restoreCursor: function () {
document.body.style.cursor = this._bodyCursor;
},
_simulateEvent: function(type, e) {
_simulateEvent: function (type, e) {
var simulatedEvent = document.createEvent('MouseEvents');
simulatedEvent.initMouseEvent(

View File

@ -4,7 +4,7 @@
*/
L.Transition = L.Transition.extend({
statics: (function() {
statics: (function () {
var transition = L.DomUtil.TRANSITION,
transitionEnd = (transition === 'webkitTransition' || transition === 'OTransition' ?
transition + 'End' : 'transitionend');
@ -29,7 +29,7 @@ L.Transition = L.Transition.extend({
fakeStepInterval: 100
},
initialize: function(/*HTMLElement*/ el, /*Object*/ options) {
initialize: function (/*HTMLElement*/ el, /*Object*/ options) {
this._el = el;
L.Util.setOptions(this, options);
@ -37,7 +37,7 @@ L.Transition = L.Transition.extend({
this._onFakeStep = L.Util.bind(this._onFakeStep, this);
},
run: function(/*Object*/ props) {
run: function (/*Object*/ props) {
var prop,
propsList = [],
customProp = L.Transition.CUSTOM_PROPS_PROPERTIES;
@ -77,16 +77,16 @@ L.Transition = L.Transition.extend({
function replaceFn(w) { return '-' + w.toLowerCase(); }
return function(str) {
return function (str) {
return str.replace(re, replaceFn);
};
}()),
_onFakeStep: function() {
_onFakeStep: function () {
this.fire('step');
},
_onTransitionEnd: function() {
_onTransitionEnd: function () {
if (this._inProgress) {
this._inProgress = false;
clearInterval(this._timer);

View File

@ -5,7 +5,7 @@
L.Transition = L.Transition.NATIVE ? L.Transition : L.Transition.extend({
statics: {
getTime: Date.now || function() { return +new Date(); },
getTime: Date.now || function () { return +new Date(); },
TIMER: true,
@ -29,7 +29,7 @@ L.Transition = L.Transition.NATIVE ? L.Transition : L.Transition.extend({
fps: 50
},
initialize: function(el, options) {
initialize: function (el, options) {
this._el = el;
L.Util.extend(this.options, options);
@ -44,7 +44,7 @@ L.Transition = L.Transition.NATIVE ? L.Transition : L.Transition.extend({
this._interval = Math.round(1000 / this.options.fps);
},
run: function(props) {
run: function (props) {
this._props = {};
var getters = L.Transition.CUSTOM_PROPS_GETTERS,
@ -72,7 +72,7 @@ L.Transition = L.Transition.NATIVE ? L.Transition : L.Transition.extend({
this._startTime = L.Transition.getTime();
},
_step: function() {
_step: function () {
var time = L.Transition.getTime(),
elapsed = time - this._startTime,
duration = this.options.duration * 1000;
@ -85,7 +85,7 @@ L.Transition = L.Transition.NATIVE ? L.Transition : L.Transition.extend({
}
},
_runFrame: function(percentComplete) {
_runFrame: function (percentComplete) {
var setters = L.Transition.CUSTOM_PROPS_SETTERS,
prop, p, value;
@ -104,12 +104,12 @@ L.Transition = L.Transition.NATIVE ? L.Transition : L.Transition.extend({
this.fire('step');
},
_complete: function() {
_complete: function () {
clearInterval(this._timer);
this.fire('end');
},
_cubicBezier: function(t) {
_cubicBezier: function (t) {
var a = Math.pow(1 - t, 3),
b = 3 * Math.pow(1 - t, 2) * t,
c = 3 * (1 - t) * Math.pow(t, 2),

View File

@ -7,7 +7,7 @@ L.Transition = L.Class.extend({
//TODO transform custom attr
},
implemented: function() {
implemented: function () {
return L.Transition.NATIVE || L.Transition.TIMER;
}
},
@ -17,7 +17,7 @@ L.Transition = L.Class.extend({
duration: 0.5
},
_setProperty: function(prop, value) {
_setProperty: function (prop, value) {
var setters = L.Transition.CUSTOM_PROPS_SETTERS;
if (prop in setters) {
setters[prop](this._el, value);

View File

@ -2,7 +2,7 @@
CM.LatLng represents a geographical point with latitude and longtitude coordinates.
*/
L.LatLng = function(/*Number*/ rawLat, /*Number*/ rawLng, /*Boolean*/ noWrap) {
L.LatLng = function (/*Number*/ rawLat, /*Number*/ rawLng, /*Boolean*/ noWrap) {
var lat = parseFloat(rawLat),
lng = parseFloat(rawLng);
@ -27,14 +27,14 @@ L.Util.extend(L.LatLng, {
});
L.LatLng.prototype = {
equals: function(/*LatLng*/ obj) {
equals: function (/*LatLng*/ obj) {
if (!(obj instanceof L.LatLng)) { return false; }
var margin = Math.max(Math.abs(this.lat - obj.lat), Math.abs(this.lng - obj.lng));
return margin <= L.LatLng.MAX_MARGIN;
},
toString: function() {
toString: function () {
return 'LatLng(' +
L.Util.formatNum(this.lat) + ', ' +
L.Util.formatNum(this.lng) + ')';

View File

@ -3,7 +3,7 @@
*/
L.LatLngBounds = L.Class.extend({
initialize: function(southWest, northEast) { // (LatLng, LatLng) or (LatLng[])
initialize: function (southWest, northEast) { // (LatLng, LatLng) or (LatLng[])
if (!southWest) {
return;
}
@ -14,7 +14,7 @@ L.LatLngBounds = L.Class.extend({
},
// extend the bounds to contain the given point
extend: function(/*LatLng*/ latlng) {
extend: function (/*LatLng*/ latlng) {
if (!this._southWest && !this._northEast) {
this._southWest = new L.LatLng(latlng.lat, latlng.lng);
this._northEast = new L.LatLng(latlng.lat, latlng.lng);
@ -26,25 +26,25 @@ L.LatLngBounds = L.Class.extend({
}
},
getCenter: function() /*-> LatLng*/ {
getCenter: function () /*-> LatLng*/ {
return new L.LatLng(
(this._southWest.lat + this._northEast.lat) / 2,
(this._southWest.lng + this._northEast.lng) / 2);
},
getSouthWest: function() { return this._southWest; },
getSouthWest: function () { return this._southWest; },
getNorthEast: function() { return this._northEast; },
getNorthEast: function () { return this._northEast; },
getNorthWest: function() {
getNorthWest: function () {
return new L.LatLng(this._northEast.lat, this._southWest.lng);
},
getSouthEast: function() {
getSouthEast: function () {
return new L.LatLng(this._southWest.lat, this._northEast.lng);
},
contains: function(/*LatLngBounds or LatLng*/ obj) /*-> Boolean*/ {
contains: function (/*LatLngBounds or LatLng*/ obj) /*-> Boolean*/ {
var sw = this._southWest,
ne = this._northEast,
sw2, ne2;
@ -60,7 +60,7 @@ L.LatLngBounds = L.Class.extend({
(sw2.lng >= sw.lng) && (ne2.lng <= ne.lng);
},
toBBoxString: function() {
toBBoxString: function () {
var sw = this._southWest,
ne = this._northEast;
return [sw.lng, sw.lat, ne.lng, ne.lat].join(',');

View File

@ -3,11 +3,11 @@ L.CRS.EPSG3395 = L.Util.extend({}, L.CRS, {
code: 'EPSG:3395',
projection: L.Projection.Mercator,
transformation: (function() {
transformation: (function () {
var m = L.Projection.Mercator,
r = m.R_MAJOR,
r2 = m.R_MINOR;
return new L.Transformation(0.5/(Math.PI * r), 0.5, -0.5/(Math.PI * r2), 0.5);
return new L.Transformation(0.5 / (Math.PI * r), 0.5, -0.5 / (Math.PI * r2), 0.5);
}())
});

View File

@ -3,9 +3,9 @@ L.CRS.EPSG3857 = L.Util.extend({}, L.CRS, {
code: 'EPSG:3857',
projection: L.Projection.SphericalMercator,
transformation: new L.Transformation(0.5/Math.PI, 0.5, -0.5/Math.PI, 0.5),
transformation: new L.Transformation(0.5 / Math.PI, 0.5, -0.5 / Math.PI, 0.5),
project: function(/*LatLng*/ latlng)/*-> Point*/ {
project: function (/*LatLng*/ latlng)/*-> Point*/ {
var projectedPoint = this.projection.project(latlng),
earthRadius = 6378137;
return projectedPoint.multiplyBy(earthRadius);

View File

@ -3,5 +3,5 @@ L.CRS.EPSG4326 = L.Util.extend({}, L.CRS, {
code: 'EPSG:4326',
projection: L.Projection.LonLat,
transformation: new L.Transformation(1/360, 0.5, -1/360, 0.5)
transformation: new L.Transformation(1 / 360, 0.5, -1 / 360, 0.5)
});

View File

@ -1,17 +1,17 @@
L.CRS = {
latLngToPoint: function(/*LatLng*/ latlng, /*Number*/ scale)/*-> Point*/ {
latLngToPoint: function (/*LatLng*/ latlng, /*Number*/ scale)/*-> Point*/ {
var projectedPoint = this.projection.project(latlng);
return this.transformation._transform(projectedPoint, scale);
},
pointToLatLng: function(/*Point*/ point, /*Number*/ scale, /*(optional) Boolean*/ unbounded)/*-> LatLng*/ {
pointToLatLng: function (/*Point*/ point, /*Number*/ scale, /*(optional) Boolean*/ unbounded)/*-> LatLng*/ {
var untransformedPoint = this.transformation.untransform(point, scale);
return this.projection.unproject(untransformedPoint, unbounded);
//TODO get rid of 'unbounded' everywhere
},
project: function(latlng) {
project: function (latlng) {
return this.projection.project(latlng);
}
};

View File

@ -1,10 +1,10 @@
L.Projection.LonLat = {
project: function(latlng) {
project: function (latlng) {
return new L.Point(latlng.lng, latlng.lat);
},
unproject: function(point, unbounded) {
unproject: function (point, unbounded) {
return new L.LatLng(point.y, point.x, unbounded);
}
};

View File

@ -5,7 +5,7 @@ L.Projection.Mercator = {
R_MINOR: 6356752.3142,
R_MAJOR: 6378137,
project: function(/*LatLng*/ latlng) /*-> Point*/ {
project: function (/*LatLng*/ latlng) /*-> Point*/ {
var d = L.LatLng.DEG_TO_RAD,
max = this.MAX_LATITUDE,
lat = Math.max(Math.min(max, latlng.lat), -max),
@ -16,7 +16,7 @@ L.Projection.Mercator = {
eccent = Math.sqrt(1.0 - tmp * tmp),
con = eccent * Math.sin(y);
con = Math.pow((1 - con)/(1 + con), eccent * 0.5);
con = Math.pow((1 - con) / (1 + con), eccent * 0.5);
var ts = Math.tan(0.5 * ((Math.PI * 0.5) - y)) / con;
y = -r * Math.log(ts);
@ -24,14 +24,14 @@ L.Projection.Mercator = {
return new L.Point(x, y);
},
unproject: function(/*Point*/ point, /*Boolean*/ unbounded) /*-> LatLng*/ {
unproject: function (/*Point*/ point, /*Boolean*/ unbounded) /*-> LatLng*/ {
var d = L.LatLng.RAD_TO_DEG,
r = this.R_MAJOR,
lng = point.x * d / r,
tmp = this.R_MINOR / r,
eccent = Math.sqrt(1 - (tmp * tmp)),
ts = Math.exp(- point.y / r),
phi = Math.PI/2 - 2 * Math.atan(ts),
phi = (Math.PI / 2) - 2 * Math.atan(ts),
numIter = 15,
tol = 1e-7,
i = numIter,
@ -40,7 +40,7 @@ L.Projection.Mercator = {
while ((Math.abs(dphi) > tol) && (--i > 0)) {
con = eccent * Math.sin(phi);
dphi = Math.PI/2 - 2 * Math.atan(ts * Math.pow((1.0 - con)/(1.0 + con), 0.5 * eccent)) - phi;
dphi = (Math.PI / 2) - 2 * Math.atan(ts * Math.pow((1.0 - con) / (1.0 + con), 0.5 * eccent)) - phi;
phi += dphi;
}

View File

@ -2,21 +2,21 @@
L.Projection.SphericalMercator = {
MAX_LATITUDE: 85.0511287798,
project: function(/*LatLng*/ latlng) /*-> Point*/ {
project: function (/*LatLng*/ latlng) /*-> Point*/ {
var d = L.LatLng.DEG_TO_RAD,
max = this.MAX_LATITUDE,
lat = Math.max(Math.min(max, latlng.lat), -max),
x = latlng.lng * d,
y = lat * d;
y = Math.log(Math.tan(Math.PI/4 + y/2));
y = Math.log(Math.tan((Math.PI / 4) + (y / 2)));
return new L.Point(x, y);
},
unproject: function(/*Point*/ point, /*Boolean*/ unbounded) /*-> LatLng*/ {
unproject: function (/*Point*/ point, /*Boolean*/ unbounded) /*-> LatLng*/ {
var d = L.LatLng.RAD_TO_DEG,
lng = point.x * d,
lat = (2 * Math.atan(Math.exp(point.y)) - Math.PI/2) * d;
lat = (2 * Math.atan(Math.exp(point.y)) - (Math.PI / 2)) * d;
return new L.LatLng(lat, lng, unbounded);
}

View File

@ -3,7 +3,7 @@
*/
L.Bounds = L.Class.extend({
initialize: function(min, max) { //(Point, Point) or Point[]
initialize: function (min, max) { //(Point, Point) or Point[]
if (!min) {
return;
}
@ -14,7 +14,7 @@ L.Bounds = L.Class.extend({
},
// extend the bounds to contain the given point
extend: function(/*Point*/ point) {
extend: function (/*Point*/ point) {
if (!this.min && !this.max) {
this.min = new L.Point(point.x, point.y);
this.max = new L.Point(point.x, point.y);
@ -26,13 +26,13 @@ L.Bounds = L.Class.extend({
}
},
getCenter: function(round)/*->Point*/ {
getCenter: function (round)/*->Point*/ {
return new L.Point(
(this.min.x + this.max.x) / 2,
(this.min.y + this.max.y) / 2, round);
},
contains: function(/*Bounds or Point*/ obj)/*->Boolean*/ {
contains: function (/*Bounds or Point*/ obj)/*->Boolean*/ {
var min, max;
if (obj instanceof L.Bounds) {

View File

@ -8,7 +8,7 @@ L.LineUtil = {
// Simplify polyline with vertex reduction and Douglas-Peucker simplification.
// Improves rendering performance dramatically by lessening the number of points to draw.
simplify: function(/*Point[]*/ points, /*Number*/ tolerance) {
simplify: function (/*Point[]*/ points, /*Number*/ tolerance) {
if (!tolerance || !points.length) {
return points.slice();
}
@ -23,18 +23,18 @@ L.LineUtil = {
},
// distance from a point to a segment between two points
pointToSegmentDistance: function(/*Point*/ p, /*Point*/ p1, /*Point*/ p2) {
pointToSegmentDistance: function (/*Point*/ p, /*Point*/ p1, /*Point*/ p2) {
return Math.sqrt(this._sqPointToSegmentDist(p, p1, p2));
},
closestPointOnSegment: function(/*Point*/ p, /*Point*/ p1, /*Point*/ p2) {
closestPointOnSegment: function (/*Point*/ p, /*Point*/ p1, /*Point*/ p2) {
var point = this._sqClosestPointOnSegment(p, p1, p2);
point.distance = Math.sqrt(point._sqDist);
return point;
},
// Douglas-Peucker simplification, see http://en.wikipedia.org/wiki/Douglas-Peucker_algorithm
simplifyDP: function(points, tol) {
simplifyDP: function (points, tol) {
var maxDist2 = 0,
index = 0,
t2 = tol * tol,
@ -69,7 +69,7 @@ L.LineUtil = {
},
// reduce points that are too close to each other to a single point
reducePoints: function(points, tol) {
reducePoints: function (points, tol) {
var reducedPoints = [points[0]],
t2 = tol * tol;
@ -91,7 +91,7 @@ L.LineUtil = {
// Cohen-Sutherland line clipping algorithm.
// Used to avoid rendering parts of a polyline that are not currently visible.
clipSegment: function(a, b, bounds, useLastCode) {
clipSegment: function (a, b, bounds, useLastCode) {
var min = bounds.min,
max = bounds.max;
@ -125,7 +125,7 @@ L.LineUtil = {
}
},
_getEdgeIntersection: function(a, b, code, bounds) {
_getEdgeIntersection: function (a, b, code, bounds) {
var dx = b.x - a.x,
dy = b.y - a.y,
min = bounds.min,
@ -135,14 +135,14 @@ L.LineUtil = {
return new L.Point(a.x + dx * (max.y - a.y) / dy, max.y);
} else if (code & 4) { // bottom
return new L.Point(a.x + dx * (min.y - a.y) / dy, min.y);
} else if (code & 2){ // right
} else if (code & 2) { // right
return new L.Point(max.x, a.y + dy * (max.x - a.x) / dx);
} else if (code & 1) { // left
return new L.Point(min.x, a.y + dy * (min.x - a.x) / dx);
}
},
_getBitCode: function(/*Point*/ p, bounds) {
_getBitCode: function (/*Point*/ p, bounds) {
var code = 0;
if (p.x < bounds.min.x) { // left
@ -162,14 +162,14 @@ L.LineUtil = {
/*jshint bitwise:true */
// square distance (to avoid unnecessary Math.sqrt calls)
_sqDist: function(p1, p2) {
_sqDist: function (p1, p2) {
var dx = p2.x - p1.x,
dy = p2.y - p1.y;
return dx * dx + dy * dy;
},
// return closest point on segment with attribute _sqDist - square distance to segment
_sqClosestPointOnSegment: function(p, p1, p2) {
_sqClosestPointOnSegment: function (p, p1, p2) {
var x2 = p2.x - p1.x,
y2 = p2.y - p1.y,
apoint = p1;
@ -188,7 +188,7 @@ L.LineUtil = {
},
// distance from a point to a segment between two points
_sqPointToSegmentDist: function(p, p1, p2) {
_sqPointToSegmentDist: function (p, p1, p2) {
return this._sqClosestPointOnSegment(p, p1, p2)._sqDist;
}
};

View File

@ -2,63 +2,63 @@
* L.Point represents a point with x and y coordinates.
*/
L.Point = function(/*Number*/ x, /*Number*/ y, /*Boolean*/ round) {
L.Point = function (/*Number*/ x, /*Number*/ y, /*Boolean*/ round) {
this.x = (round ? Math.round(x) : x);
this.y = (round ? Math.round(y) : y);
};
L.Point.prototype = {
add: function(point) {
add: function (point) {
return this.clone()._add(point);
},
_add: function(point) {
_add: function (point) {
this.x += point.x;
this.y += point.y;
return this;
},
subtract: function(point) {
subtract: function (point) {
return this.clone()._subtract(point);
},
// destructive subtract (faster)
_subtract: function(point) {
_subtract: function (point) {
this.x -= point.x;
this.y -= point.y;
return this;
},
divideBy: function(num, round) {
return new L.Point(this.x/num, this.y/num, round);
divideBy: function (num, round) {
return new L.Point(this.x / num, this.y / num, round);
},
multiplyBy: function(num) {
multiplyBy: function (num) {
return new L.Point(this.x * num, this.y * num);
},
distanceTo: function(point) {
distanceTo: function (point) {
var x = point.x - this.x,
y = point.y - this.y;
return Math.sqrt(x*x + y*y);
return Math.sqrt(x * x + y * y);
},
round: function() {
round: function () {
return this.clone()._round();
},
// destructive round
_round: function() {
_round: function () {
this.x = Math.round(this.x);
this.y = Math.round(this.y);
return this;
},
clone: function() {
clone: function () {
return new L.Point(this.x, this.y);
},
toString: function() {
toString: function () {
return 'Point(' +
L.Util.formatNum(this.x) + ', ' +
L.Util.formatNum(this.y) + ')';

View File

@ -10,7 +10,7 @@ L.PolyUtil = {};
* Sutherland-Hodgeman polygon clipping algorithm.
* Used to avoid rendering parts of a polygon that are not currently visible.
*/
L.PolyUtil.clipPolygon = function(points, bounds) {
L.PolyUtil.clipPolygon = function (points, bounds) {
var min = bounds.min,
max = bounds.max,
clippedPoints,

View File

@ -3,29 +3,29 @@
*/
L.Transformation = L.Class.extend({
initialize: function(/*Number*/ a, /*Number*/ b, /*Number*/ c, /*Number*/ d) {
initialize: function (/*Number*/ a, /*Number*/ b, /*Number*/ c, /*Number*/ d) {
this._a = a;
this._b = b;
this._c = c;
this._d = d;
},
transform: function(point, scale) {
transform: function (point, scale) {
return this._transform(point.clone(), scale);
},
// destructive transform (faster)
_transform: function(/*Point*/ point, /*Number*/ scale) /*-> Point*/ {
_transform: function (/*Point*/ point, /*Number*/ scale) /*-> Point*/ {
scale = scale || 1;
point.x = scale * (this._a * point.x + this._b);
point.y = scale * (this._c * point.y + this._d);
return point;
},
untransform: function(/*Point*/ point, /*Number*/ scale) /*-> Point*/ {
untransform: function (/*Point*/ point, /*Number*/ scale) /*-> Point*/ {
scale = scale || 1;
return new L.Point(
(point.x/scale - this._b) / this._a,
(point.y/scale - this._d) / this._c);
(point.x / scale - this._b) / this._a,
(point.y / scale - this._d) / this._c);
}
});

View File

@ -3,19 +3,19 @@
*/
L.Handler.DoubleClickZoom = L.Handler.extend({
enable: function() {
enable: function () {
if (this._enabled) { return; }
this._map.on('dblclick', this._onDoubleClick, this._map);
this._enabled = true;
},
disable: function() {
disable: function () {
if (!this._enabled) { return; }
this._map.off('dblclick', this._onDoubleClick, this._map);
this._enabled = false;
},
_onDoubleClick: function(e) {
_onDoubleClick: function (e) {
this.setView(e.latlng, this._zoom + 1);
}
});

View File

@ -3,11 +3,11 @@
*/
L.Handler = L.Class.extend({
initialize: function(map) {
initialize: function (map) {
this._map = map;
},
enabled: function() {
enabled: function () {
return !!this._enabled;
}
});

View File

@ -4,7 +4,7 @@
L.Handler.MapDrag = L.Handler.extend({
enable: function() {
enable: function () {
if (this._enabled) { return; }
if (!this._draggable) {
this._draggable = new L.Draggable(this._map._mapPane, this._map._container);
@ -24,34 +24,34 @@ L.Handler.MapDrag = L.Handler.extend({
this._enabled = true;
},
disable: function() {
disable: function () {
if (!this._enabled) { return; }
this._draggable.disable();
this._enabled = false;
},
moved: function() {
moved: function () {
return this._draggable && this._draggable._moved;
},
_onDragStart: function() {
_onDragStart: function () {
this._map.fire('movestart');
this._map.fire('dragstart');
},
_onDrag: function() {
_onDrag: function () {
this._map.fire('move');
this._map.fire('drag');
},
_onViewReset: function() {
_onViewReset: function () {
var pxCenter = this._map.getSize().divideBy(2),
pxWorldCenter = this._map.latLngToLayerPoint(new L.LatLng(0,0));
pxWorldCenter = this._map.latLngToLayerPoint(new L.LatLng(0, 0));
this._initialWorldOffset = pxWorldCenter.subtract(pxCenter);
},
_onPreDrag: function() {
_onPreDrag: function () {
var map = this._map,
worldWidth = map.options.scale(map.getZoom()),
halfWidth = Math.round(worldWidth / 2),
@ -64,7 +64,7 @@ L.Handler.MapDrag = L.Handler.extend({
this._draggable._newPos.x = newX;
},
_onDragEnd: function() {
_onDragEnd: function () {
var map = this._map;
map.fire('moveend');

View File

@ -3,11 +3,11 @@
*/
L.Handler.MarkerDrag = L.Handler.extend({
initialize: function(marker) {
initialize: function (marker) {
this._marker = marker;
},
enable: function() {
enable: function () {
if (this._enabled) { return; }
if (!this._draggable) {
this._draggable = new L.Draggable(this._marker._icon, this._marker._icon);
@ -19,24 +19,24 @@ L.Handler.MarkerDrag = L.Handler.extend({
this._enabled = true;
},
disable: function() {
disable: function () {
if (!this._enabled) { return; }
this._draggable.disable();
this._enabled = false;
},
moved: function() {
moved: function () {
return this._draggable && this._draggable._moved;
},
_onDragStart: function(e) {
_onDragStart: function (e) {
this._marker.closePopup();
this._marker.fire('movestart');
this._marker.fire('dragstart');
},
_onDrag: function(e) {
_onDrag: function (e) {
// update shadow position
var iconPos = L.DomUtil.getPosition(this._marker._icon);
if (this._marker._shadow) {
@ -49,7 +49,7 @@ L.Handler.MarkerDrag = L.Handler.extend({
this._marker.fire('drag');
},
_onDragEnd: function() {
_onDragEnd: function () {
this._marker.fire('moveend');
this._marker.fire('dragend');
}

View File

@ -3,20 +3,20 @@
*/
L.Handler.ScrollWheelZoom = L.Handler.extend({
enable: function() {
enable: function () {
if (this._enabled) { return; }
L.DomEvent.addListener(this._map._container, 'mousewheel', this._onWheelScroll, this);
this._delta = 0;
this._enabled = true;
},
disable: function() {
disable: function () {
if (!this._enabled) { return; }
L.DomEvent.removeListener(this._map._container, 'mousewheel', this._onWheelScroll);
this._enabled = false;
},
_onWheelScroll: function(e) {
_onWheelScroll: function (e) {
var delta = L.DomEvent.getWheelDelta(e);
this._delta += delta;
this._lastMousePos = this._map.mouseEventToContainerPoint(e);
@ -27,7 +27,7 @@ L.Handler.ScrollWheelZoom = L.Handler.extend({
L.DomEvent.preventDefault(e);
},
_performZoom: function() {
_performZoom: function () {
var delta = Math.round(this._delta),
zoom = this._map.getZoom();
@ -44,7 +44,7 @@ L.Handler.ScrollWheelZoom = L.Handler.extend({
this._map.setView(newCenter, newZoom);
},
_getCenterForScrollWheelZoom: function(mousePos, delta) {
_getCenterForScrollWheelZoom: function (mousePos, delta) {
var centerPoint = this._map.getPixelBounds().getCenter(),
viewHalf = this._map.getSize().divideBy(2),
centerOffset = mousePos.subtract(viewHalf).multiplyBy(1 - Math.pow(2, -delta)),

View File

@ -3,13 +3,13 @@
*/
L.Handler.ShiftDragZoom = L.Handler.extend({
initialize: function(map) {
initialize: function (map) {
this._map = map;
this._container = map._container;
this._pane = map._panes.overlayPane;
},
enable: function() {
enable: function () {
if (this._enabled) { return; }
L.DomEvent.addListener(this._container, 'mousedown', this._onMouseDown, this);
@ -17,7 +17,7 @@ L.Handler.ShiftDragZoom = L.Handler.extend({
this._enabled = true;
},
disable: function() {
disable: function () {
if (!this._enabled) { return; }
L.DomEvent.removeListener(this._container, 'mousedown', this._onMouseDown);
@ -25,7 +25,7 @@ L.Handler.ShiftDragZoom = L.Handler.extend({
this._enabled = false;
},
_onMouseDown: function(e) {
_onMouseDown: function (e) {
if (!e.shiftKey || ((e.which !== 1) && (e.button !== 1))) { return false; }
L.DomUtil.disableTextSelection();
@ -44,7 +44,7 @@ L.Handler.ShiftDragZoom = L.Handler.extend({
L.DomEvent.preventDefault(e);
},
_onMouseMove: function(e) {
_onMouseMove: function (e) {
var layerPoint = this._map.mouseEventToLayerPoint(e),
dx = layerPoint.x - this._startLayerPoint.x,
dy = layerPoint.y - this._startLayerPoint.y;
@ -59,7 +59,7 @@ L.Handler.ShiftDragZoom = L.Handler.extend({
this._box.style.height = (Math.abs(dy) - 4) + 'px';
},
_onMouseUp: function(e) {
_onMouseUp: function (e) {
this._pane.removeChild(this._box);
this._container.style.cursor = '';

View File

@ -3,19 +3,19 @@
*/
L.Handler.TouchZoom = L.Handler.extend({
enable: function() {
enable: function () {
if (!L.Browser.touch || this._enabled) { return; }
L.DomEvent.addListener(this._map._container, 'touchstart', this._onTouchStart, this);
this._enabled = true;
},
disable: function() {
disable: function () {
if (!this._enabled) { return; }
L.DomEvent.removeListener(this._map._container, 'touchstart', this._onTouchStart, this);
this._enabled = false;
},
_onTouchStart: function(e) {
_onTouchStart: function (e) {
if (!e.touches || e.touches.length !== 2 || this._map._animatingZoom) { return; }
var p1 = this._map.mouseEventToLayerPoint(e.touches[0]),
@ -37,7 +37,7 @@ L.Handler.TouchZoom = L.Handler.extend({
L.DomEvent.preventDefault(e);
},
_onTouchMove: function(e) {
_onTouchMove: function (e) {
if (!e.touches || e.touches.length !== 2) { return; }
if (!this._moved) {
@ -63,12 +63,12 @@ L.Handler.TouchZoom = L.Handler.extend({
L.DomEvent.preventDefault(e);
},
_onTouchEnd: function(e) {
_onTouchEnd: function (e) {
if (!this._moved || !this._zooming) { return; }
this._zooming = false;
var oldZoom = this._map.getZoom(),
floatZoomDelta = Math.log(this._scale)/Math.LN2,
floatZoomDelta = Math.log(this._scale) / Math.LN2,
roundZoomDelta = (floatZoomDelta > 0 ? Math.ceil(floatZoomDelta) : Math.floor(floatZoomDelta)),
zoom = this._map._limitZoom(oldZoom + roundZoomDelta),
zoomDelta = zoom - oldZoom,

View File

@ -5,7 +5,7 @@
L.FeatureGroup = L.LayerGroup.extend({
includes: L.Mixin.Events,
addLayer: function(layer) {
addLayer: function (layer) {
this._initEvents(layer);
L.LayerGroup.prototype.addLayer.call(this, layer);
@ -14,7 +14,7 @@ L.FeatureGroup = L.LayerGroup.extend({
}
},
bindPopup: function(content) {
bindPopup: function (content) {
this._popupContent = content;
for (var i in this._layers) {
@ -26,13 +26,13 @@ L.FeatureGroup = L.LayerGroup.extend({
_events: ['click', 'dblclick', 'mouseover', 'mouseout'],
_initEvents: function(layer) {
_initEvents: function (layer) {
for (var i = 0, len = this._events.length; i < len; i++) {
layer.on(this._events[i], this._propagateEvent, this);
}
},
_propagateEvent: function(e) {
_propagateEvent: function (e) {
e.layer = e.target;
e.target = this;
this.fire(e.type, e);

View File

@ -1,6 +1,6 @@
L.GeoJSON = L.FeatureGroup.extend({
initialize: function(geojson, options) {
initialize: function (geojson, options) {
L.Util.setOptions(this, options);
this._geojson = geojson;
this._layers = {};
@ -10,7 +10,7 @@ L.GeoJSON = L.FeatureGroup.extend({
}
},
addGeoJSON: function(geojson) {
addGeoJSON: function (geojson) {
if (geojson.features) {
for (var i = 0, len = geojson.features.length; i < len; i++) {
this.addGeoJSON(geojson.features[i]);
@ -35,7 +35,7 @@ L.GeoJSON = L.FeatureGroup.extend({
});
L.Util.extend(L.GeoJSON, {
geometryToLayer: function(geometry, pointToLayer) {
geometryToLayer: function (geometry, pointToLayer) {
var coords = geometry.coordinates,
latlng, latlngs,
i, len,
@ -83,13 +83,13 @@ L.Util.extend(L.GeoJSON, {
}
},
coordsToLatLng: function(/*Array*/ coords, /*Boolean*/ reverse)/*: LatLng*/ {
coordsToLatLng: function (/*Array*/ coords, /*Boolean*/ reverse)/*: LatLng*/ {
var lat = parseFloat(coords[reverse ? 0 : 1]),
lng = parseFloat(coords[reverse ? 1 : 0]);
return new L.LatLng(lat, lng);
},
coordsToLatLngs: function(/*Array*/ coords, /*Number*/ levelsDeep, /*Boolean*/ reverse)/*: Array*/ {
coordsToLatLngs: function (/*Array*/ coords, /*Number*/ levelsDeep, /*Boolean*/ reverse)/*: Array*/ {
var latlng, latlngs = [],
i, len = coords.length;

View File

@ -1,12 +1,12 @@
L.ImageOverlay = L.Class.extend({
includes: L.Mixin.Events,
initialize: function(/*String*/ url, /*LatLngBounds*/ bounds) {
initialize: function (/*String*/ url, /*LatLngBounds*/ bounds) {
this._url = url;
this._bounds = bounds;
},
onAdd: function(map) {
onAdd: function (map) {
this._map = map;
if (!this._image) {
@ -19,12 +19,12 @@ L.ImageOverlay = L.Class.extend({
this._reset();
},
onRemove: function(map) {
onRemove: function (map) {
map.getPanes().overlayPane.removeChild(this._image);
map.off('viewreset', this._reset, this);
},
_initImage: function() {
_initImage: function () {
this._image = L.DomUtil.create('img', 'leaflet-image-layer');
this._image.style.visibility = 'hidden';
@ -40,7 +40,7 @@ L.ImageOverlay = L.Class.extend({
});
},
_reset: function() {
_reset: function () {
var topLeft = this._map.latLngToLayerPoint(this._bounds.getNorthWest()),
bottomRight = this._map.latLngToLayerPoint(this._bounds.getSouthEast()),
size = bottomRight.subtract(topLeft);
@ -51,7 +51,7 @@ L.ImageOverlay = L.Class.extend({
this._image.style.height = size.y + 'px';
},
_onImageLoad: function() {
_onImageLoad: function () {
this.style.visibility = '';
//TODO fire layerload
}

View File

@ -3,7 +3,7 @@
*/
L.LayerGroup = L.Class.extend({
initialize: function(layers) {
initialize: function (layers) {
this._layers = {};
if (layers) {
@ -13,7 +13,7 @@ L.LayerGroup = L.Class.extend({
}
},
addLayer: function(layer) {
addLayer: function (layer) {
var id = L.Util.stamp(layer);
this._layers[id] = layer;
@ -23,7 +23,7 @@ L.LayerGroup = L.Class.extend({
return this;
},
removeLayer: function(layer) {
removeLayer: function (layer) {
var id = L.Util.stamp(layer);
delete this._layers[id];
@ -33,22 +33,22 @@ L.LayerGroup = L.Class.extend({
return this;
},
clearLayers: function() {
clearLayers: function () {
this._iterateLayers(this.removeLayer, this);
return this;
},
onAdd: function(map) {
onAdd: function (map) {
this._map = map;
this._iterateLayers(map.addLayer, map);
},
onRemove: function(map) {
onRemove: function (map) {
this._iterateLayers(map.removeLayer, map);
delete this._map;
},
_iterateLayers: function(method, context) {
_iterateLayers: function (method, context) {
for (var i in this._layers) {
if (this._layers.hasOwnProperty(i)) {
method.call(context, this._layers[i]);

View File

@ -11,11 +11,11 @@ L.Popup = L.Class.extend({
autoPanPadding: new L.Point(5, 5)
},
initialize: function(options) {
initialize: function (options) {
L.Util.setOptions(this, options);
},
onAdd: function(map) {
onAdd: function (map) {
this._map = map;
if (!this._container) {
this._initLayout();
@ -36,7 +36,7 @@ L.Popup = L.Class.extend({
this._opened = true;
},
onRemove: function(map) {
onRemove: function (map) {
map._panes.popupPane.removeChild(this._container);
map.off('viewreset', this._updatePosition, this);
map.off('click', this._close, this);
@ -46,7 +46,7 @@ L.Popup = L.Class.extend({
this._opened = false;
},
setLatLng: function(latlng) {
setLatLng: function (latlng) {
this._latlng = latlng;
if (this._opened) {
this._update();
@ -54,7 +54,7 @@ L.Popup = L.Class.extend({
return this;
},
setContent: function(content) {
setContent: function (content) {
this._content = content;
if (this._opened) {
this._update();
@ -62,13 +62,13 @@ L.Popup = L.Class.extend({
return this;
},
_close: function() {
_close: function () {
if (this._opened) {
this._map.removeLayer(this);
}
},
_initLayout: function() {
_initLayout: function () {
this._container = L.DomUtil.create('div', 'leaflet-popup');
if (this.options.closeButton) {
@ -85,7 +85,7 @@ L.Popup = L.Class.extend({
this._tip = L.DomUtil.create('div', 'leaflet-popup-tip', this._tipContainer);
},
_update: function() {
_update: function () {
this._container.style.visibility = 'hidden';
this._updateContent();
@ -97,7 +97,7 @@ L.Popup = L.Class.extend({
this._adjustPan();
},
_updateContent: function() {
_updateContent: function () {
if (!this._content) {
return;
}
@ -110,29 +110,30 @@ L.Popup = L.Class.extend({
}
},
_updateLayout: function() {
_updateLayout: function () {
this._container.style.width = '';
this._container.style.whiteSpace = 'nowrap';
var width = this._container.offsetWidth;
this._container.style.width = (width > this.options.maxWidth ? this.options.maxWidth : (width < this.options.minWidth ? this.options.minWidth : width ) ) + 'px';
this._container.style.width = (width > this.options.maxWidth ?
this.options.maxWidth : (width < this.options.minWidth ? this.options.minWidth : width)) + 'px';
this._container.style.whiteSpace = '';
this._containerWidth = this._container.offsetWidth;
},
_updatePosition: function() {
_updatePosition: function () {
var pos = this._map.latLngToLayerPoint(this._latlng);
this._containerBottom = -pos.y - this.options.offset.y;
this._containerLeft = pos.x - Math.round(this._containerWidth/2) + this.options.offset.x;
this._containerLeft = pos.x - Math.round(this._containerWidth / 2) + this.options.offset.x;
this._container.style.bottom = this._containerBottom + 'px';
this._container.style.left = this._containerLeft + 'px';
},
_adjustPan: function() {
_adjustPan: function () {
if (!this.options.autoPan) { return; }
var containerHeight = this._container.offsetHeight,
@ -162,7 +163,7 @@ L.Popup = L.Class.extend({
}
},
_onCloseButtonClick: function(e) {
_onCloseButtonClick: function (e) {
this._close();
L.DomEvent.stop(e);
}

View File

@ -8,21 +8,21 @@ L.Icon = L.Class.extend({
iconAnchor: new L.Point(13, 41),
popupAnchor: new L.Point(0, -33),
initialize: function(iconUrl) {
initialize: function (iconUrl) {
if (iconUrl) {
this.iconUrl = iconUrl;
}
},
createIcon: function() {
createIcon: function () {
return this._createIcon('icon');
},
createShadow: function() {
createShadow: function () {
return this._createIcon('shadow');
},
_createIcon: function(name) {
_createIcon: function (name) {
var size = this[name + 'Size'],
src = this[name + 'Url'],
img = this._createImg(src);
@ -42,7 +42,7 @@ L.Icon = L.Class.extend({
return img;
},
_createImg: function(src) {
_createImg: function (src) {
var el;
if (!L.Browser.ie6) {
el = document.createElement('img');

View File

@ -3,21 +3,21 @@
*/
L.Marker.include({
openPopup: function() {
openPopup: function () {
this._popup.setLatLng(this._latlng);
this._map.openPopup(this._popup);
return this;
},
closePopup: function() {
closePopup: function () {
if (this._popup) {
this._popup._close();
}
return this;
},
bindPopup: function(content, options) {
bindPopup: function (content, options) {
options = L.Util.extend({offset: this.options.icon.popupAnchor}, options);
if (!this._popup) {
@ -30,7 +30,7 @@ L.Marker.include({
return this;
},
unbindPopup: function() {
unbindPopup: function () {
if (this._popup) {
this._popup = null;
this.off('click', this.openPopup);

View File

@ -13,12 +13,12 @@ L.Marker = L.Class.extend({
draggable: false
},
initialize: function(latlng, options) {
initialize: function (latlng, options) {
L.Util.setOptions(this, options);
this._latlng = latlng;
},
onAdd: function(map) {
onAdd: function (map) {
this._map = map;
this._initIcon();
@ -27,7 +27,7 @@ L.Marker = L.Class.extend({
this._reset();
},
onRemove: function(map) {
onRemove: function (map) {
this._removeIcon();
this._map = null;
@ -40,18 +40,18 @@ L.Marker = L.Class.extend({
map.off('viewreset', this._reset, this);
},
getLatLng: function() {
getLatLng: function () {
return this._latlng;
},
setLatLng: function(latlng) {
setLatLng: function (latlng) {
this._latlng = latlng;
if (this._icon) {
this._reset();
}
},
setIcon: function(icon) {
setIcon: function (icon) {
if (this._map) {
this._removeIcon();
}
@ -64,7 +64,7 @@ L.Marker = L.Class.extend({
}
},
_initIcon: function() {
_initIcon: function () {
if (!this._icon) {
this._icon = this.options.icon.createIcon();
@ -84,7 +84,7 @@ L.Marker = L.Class.extend({
}
},
_removeIcon: function() {
_removeIcon: function () {
this._map._panes.markerPane.removeChild(this._icon);
if (this._shadow) {
this._map._panes.shadowPane.removeChild(this._shadow);
@ -92,7 +92,7 @@ L.Marker = L.Class.extend({
this._icon = this._shadow = null;
},
_reset: function() {
_reset: function () {
var pos = this._map.latLngToLayerPoint(this._latlng).round();
L.DomUtil.setPosition(this._icon, pos);
@ -103,7 +103,7 @@ L.Marker = L.Class.extend({
this._icon.style.zIndex = pos.y;
},
_initInteraction: function() {
_initInteraction: function () {
if (this.options.clickable) {
this._icon.className += ' leaflet-clickable';
@ -124,13 +124,13 @@ L.Marker = L.Class.extend({
}
},
_onMouseClick: function(e) {
_onMouseClick: function (e) {
L.DomEvent.stopPropagation(e);
if (this.dragging && this.dragging.moved()) { return; }
this.fire(e.type);
},
_fireMouseEvent: function(e) {
_fireMouseEvent: function (e) {
this.fire(e.type);
L.DomEvent.stopPropagation(e);
}

View File

@ -3,11 +3,11 @@ L.TileLayer.Canvas = L.TileLayer.extend({
async: false
},
initialize: function(options) {
initialize: function (options) {
L.Util.setOptions(this, options);
},
_createTileProto: function() {
_createTileProto: function () {
this._canvasProto = L.DomUtil.create('canvas', 'leaflet-tile');
var tileSize = this.options.tileSize;
@ -15,13 +15,13 @@ L.TileLayer.Canvas = L.TileLayer.extend({
this._canvasProto.height = tileSize;
},
_createTile: function() {
_createTile: function () {
var tile = this._canvasProto.cloneNode(false);
tile.onselectstart = tile.onmousemove = L.Util.falseFn;
return tile;
},
_loadTile: function(tile, tilePoint, zoom) {
_loadTile: function (tile, tilePoint, zoom) {
tile._layer = this;
this.drawTile(tile, tilePoint, zoom);
@ -31,11 +31,11 @@ L.TileLayer.Canvas = L.TileLayer.extend({
}
},
drawTile: function(tile, tilePoint, zoom) {
drawTile: function (tile, tilePoint, zoom) {
// override with rendering code
},
tileDrawn: function(tile) {
tileDrawn: function (tile) {
this._tileOnLoad.call(tile);
}
});

View File

@ -9,7 +9,7 @@ L.TileLayer.WMS = L.TileLayer.extend({
transparent: false
},
initialize: function(/*String*/ url, /*Object*/ options) {
initialize: function (/*String*/ url, /*Object*/ options) {
this._url = url;
this.wmsParams = L.Util.extend({}, this.defaultWmsParams);
@ -25,14 +25,14 @@ L.TileLayer.WMS = L.TileLayer.extend({
L.Util.setOptions(this, options);
},
onAdd: function(map) {
onAdd: function (map) {
var projectionKey = (parseFloat(this.wmsParams.version) >= 1.3 ? 'crs' : 'srs');
this.wmsParams[projectionKey] = map.options.crs.code;
L.TileLayer.prototype.onAdd.call(this, map);
},
getTileUrl: function(/*Point*/ tilePoint, /*Number*/ zoom)/*-> String*/ {
getTileUrl: function (/*Point*/ tilePoint, /*Number*/ zoom)/*-> String*/ {
var tileSize = this.options.tileSize,
nwPoint = tilePoint.multiplyBy(tileSize),
sePoint = nwPoint.add(new L.Point(tileSize, tileSize)),

View File

@ -22,7 +22,7 @@ L.TileLayer = L.Class.extend({
updateWhenIdle: L.Browser.mobile
},
initialize: function(url, options, urlParams) {
initialize: function (url, options, urlParams) {
L.Util.setOptions(this, options);
this._url = url;
@ -33,7 +33,7 @@ L.TileLayer = L.Class.extend({
}
},
onAdd: function(map, insertAtTheBottom) {
onAdd: function (map, insertAtTheBottom) {
this._map = map;
this._insertAtTheBottom = insertAtTheBottom;
@ -57,7 +57,7 @@ L.TileLayer = L.Class.extend({
this._update();
},
onRemove: function(map) {
onRemove: function (map) {
this._map.getPanes().tilePane.removeChild(this._container);
this._container = null;
@ -70,11 +70,11 @@ L.TileLayer = L.Class.extend({
}
},
getAttribution: function() {
getAttribution: function () {
return this.options.attribution;
},
setOpacity: function(opacity) {
setOpacity: function (opacity) {
this.options.opacity = opacity;
this._setOpacity(opacity);
@ -89,13 +89,13 @@ L.TileLayer = L.Class.extend({
}
},
_setOpacity: function(opacity) {
_setOpacity: function (opacity) {
if (opacity < 1) {
L.DomUtil.setOpacity(this._container, opacity);
}
},
_initContainer: function() {
_initContainer: function () {
var tilePane = this._map.getPanes().tilePane,
first = tilePane.firstChild;
@ -112,11 +112,11 @@ L.TileLayer = L.Class.extend({
}
},
_resetCallback: function(e) {
_resetCallback: function (e) {
this._reset(e.hard);
},
_reset: function(clearOldContainer) {
_reset: function (clearOldContainer) {
var key;
for (key in this._tiles) {
if (this._tiles.hasOwnProperty(key)) {
@ -131,7 +131,7 @@ L.TileLayer = L.Class.extend({
this._initContainer();
},
_update: function() {
_update: function () {
var bounds = this._map.getPixelBounds(),
tileSize = this.options.tileSize;
@ -150,7 +150,7 @@ L.TileLayer = L.Class.extend({
}
},
_addTilesFromCenterOut: function(bounds) {
_addTilesFromCenterOut: function (bounds) {
var queue = [],
center = bounds.getCenter();
@ -162,7 +162,7 @@ L.TileLayer = L.Class.extend({
}
// load tiles in order of their distance to center
queue.sort(function(a, b) {
queue.sort(function (a, b) {
return a.distanceTo(center) - b.distanceTo(center);
});
@ -176,7 +176,7 @@ L.TileLayer = L.Class.extend({
this._container.appendChild(fragment);
},
_removeOtherTiles: function(bounds) {
_removeOtherTiles: function (bounds) {
var kArr, x, y, key, tile;
for (key in this._tiles) {
@ -203,7 +203,7 @@ L.TileLayer = L.Class.extend({
}
},
_addTile: function(tilePoint, container) {
_addTile: function (tilePoint, container) {
var tilePos = this._getTilePos(tilePoint),
zoom = this._map.getZoom(),
key = tilePoint.x + ':' + tilePoint.y,
@ -239,7 +239,7 @@ L.TileLayer = L.Class.extend({
container.appendChild(tile);
},
_getTilePos: function(tilePoint) {
_getTilePos: function (tilePoint) {
var origin = this._map.getPixelOrigin(),
tileSize = this.options.tileSize;
@ -248,7 +248,7 @@ L.TileLayer = L.Class.extend({
// image-specific code (override to implement e.g. Canvas or SVG tile layer)
getTileUrl: function(tilePoint, zoom) {
getTileUrl: function (tilePoint, zoom) {
var subdomains = this.options.subdomains,
s = this.options.subdomains[(tilePoint.x + tilePoint.y) % subdomains.length];
@ -260,7 +260,7 @@ L.TileLayer = L.Class.extend({
}, this._urlParams));
},
_createTileProto: function() {
_createTileProto: function () {
this._tileImg = L.DomUtil.create('img', 'leaflet-tile');
this._tileImg.galleryimg = 'no';
@ -269,20 +269,20 @@ L.TileLayer = L.Class.extend({
this._tileImg.style.height = tileSize + 'px';
},
_createTile: function() {
_createTile: function () {
var tile = this._tileImg.cloneNode(false);
tile.onselectstart = tile.onmousemove = L.Util.falseFn;
return tile;
},
_loadTile: function(tile, tilePoint, zoom) {
_loadTile: function (tile, tilePoint, zoom) {
tile._layer = this;
tile.onload = this._tileOnLoad;
tile.onerror = this._tileOnError;
tile.src = this.getTileUrl(tilePoint, zoom);
},
_tileOnLoad: function(e) {
_tileOnLoad: function (e) {
var layer = this._layer;
this.className += ' leaflet-tile-loaded';
@ -295,7 +295,7 @@ L.TileLayer = L.Class.extend({
}
},
_tileOnError: function(e) {
_tileOnError: function (e) {
var layer = this._layer;
layer.fire('tileerror', {tile: this, url: this.src});

View File

@ -3,7 +3,7 @@
*/
L.Circle = L.Path.extend({
initialize: function(latlng, radius, options) {
initialize: function (latlng, radius, options) {
L.Path.prototype.initialize.call(this, options);
this._latlng = latlng;
@ -14,19 +14,19 @@ L.Circle = L.Path.extend({
fill: true
},
setLatLng: function(latlng) {
setLatLng: function (latlng) {
this._latlng = latlng;
this._redraw();
return this;
},
setRadius: function(radius) {
setRadius: function (radius) {
this._mRadius = radius;
this._redraw();
return this;
},
projectLatlngs: function() {
projectLatlngs: function () {
var equatorLength = 40075017,
hLength = equatorLength * Math.cos(L.LatLng.DEG_TO_RAD * this._latlng.lat);
@ -38,7 +38,7 @@ L.Circle = L.Path.extend({
this._radius = Math.round(this._point.x - point2.x);
},
getPathString: function() {
getPathString: function () {
var p = this._point,
r = this._radius;
@ -55,7 +55,7 @@ L.Circle = L.Path.extend({
}
},
_checkIfEmpty: function() {
_checkIfEmpty: function () {
var vp = this._map._pathViewport,
r = this._radius,
p = this._point;

View File

@ -8,16 +8,16 @@ L.CircleMarker = L.Circle.extend({
weight: 2
},
initialize: function(latlng, options) {
initialize: function (latlng, options) {
L.Circle.prototype.initialize.call(this, latlng, null, options);
this._radius = this.options.radius;
},
projectLatlngs: function() {
projectLatlngs: function () {
this._point = this._map.latLngToLayerPoint(this._latlng);
},
setRadius: function(radius) {
setRadius: function (radius) {
this._radius = radius;
this._redraw();
return this;

View File

@ -2,16 +2,16 @@
* Contains L.MultiPolyline and L.MultiPolygon layers.
*/
(function() {
(function () {
function createMulti(Klass) {
return L.FeatureGroup.extend({
initialize: function(latlngs, options) {
initialize: function (latlngs, options) {
this._layers = {};
this._options = options;
this.setLatLngs(latlngs);
},
setStyle: function(style) {
setStyle: function (style) {
for (var i in this._layers) {
if (this._layers.hasOwnProperty(i) && this._layers[i].setStyle) {
this._layers[i].setStyle(style);
@ -19,10 +19,10 @@
}
},
setLatLngs: function(latlngs) {
setLatLngs: function (latlngs) {
var i = 0, len = latlngs.length;
this._iterateLayers(function(layer) {
this._iterateLayers(function (layer) {
if (i < len) {
layer.setLatLngs(latlngs[i++]);
} else {

View File

@ -3,7 +3,7 @@
*/
L.Path.include({
bindPopup: function(content, options) {
bindPopup: function (content, options) {
if (!this._popup || this._popup.options !== options) {
this._popup = new L.Popup(options);
}
@ -17,7 +17,7 @@ L.Path.include({
return this;
},
_openPopup: function(e) {
_openPopup: function (e) {
this._popup.setLatLng(e.latlng);
this._map.openPopup(this._popup);
}

View File

@ -5,22 +5,22 @@ L.Browser.svg = !!(document.createElementNS && document.createElementNS(L.Path.S
L.Path = L.Path.extend({
statics: {
SVG: L.Browser.svg,
_createElement: function(name) {
_createElement: function (name) {
return document.createElementNS(L.Path.SVG_NS, name);
}
},
getPathString: function() {
getPathString: function () {
// form path string here
},
_initElements: function() {
_initElements: function () {
this._map._initPathRoot();
this._initPath();
this._initStyle();
},
_initPath: function() {
_initPath: function () {
this._container = L.Path._createElement('g');
this._path = L.Path._createElement('path');
@ -29,7 +29,7 @@ L.Path = L.Path.extend({
this._map._pathRoot.appendChild(this._container);
},
_initStyle: function() {
_initStyle: function () {
if (this.options.stroke) {
this._path.setAttribute('stroke-linejoin', 'round');
this._path.setAttribute('stroke-linecap', 'round');
@ -42,7 +42,7 @@ L.Path = L.Path.extend({
this._updateStyle();
},
_updateStyle: function() {
_updateStyle: function () {
if (this.options.stroke) {
this._path.setAttribute('stroke', this.options.color);
this._path.setAttribute('stroke-opacity', this.options.opacity);
@ -54,7 +54,7 @@ L.Path = L.Path.extend({
}
},
_updatePath: function() {
_updatePath: function () {
var str = this.getPathString();
if (!str) {
// fix webkit empty string parsing bug
@ -64,7 +64,7 @@ L.Path = L.Path.extend({
},
// TODO remove duplication with L.Map
_initEvents: function() {
_initEvents: function () {
if (this.options.clickable) {
if (!L.Browser.vml) {
this._path.setAttribute('class', 'leaflet-clickable');
@ -79,12 +79,12 @@ L.Path = L.Path.extend({
}
},
_onMouseClick: function(e) {
_onMouseClick: function (e) {
if (this._map.dragging && this._map.dragging.moved()) { return; }
this._fireMouseEvent(e);
},
_fireMouseEvent: function(e) {
_fireMouseEvent: function (e) {
if (!this.hasEventListeners(e.type)) { return; }
this.fire(e.type, {
latlng: this._map.mouseEventToLatLng(e),
@ -95,7 +95,7 @@ L.Path = L.Path.extend({
});
L.Map.include({
_initPathRoot: function() {
_initPathRoot: function () {
if (!this._pathRoot) {
this._pathRoot = L.Path._createElement('svg');
this._panes.overlayPane.appendChild(this._pathRoot);
@ -105,7 +105,7 @@ L.Map.include({
}
},
_updateSvgViewport: function() {
_updateSvgViewport: function () {
this._updatePathViewport();
var vp = this._pathViewport,

View File

@ -3,7 +3,7 @@
* Thanks to Dmitry Baranovsky and his Raphael library for inspiration!
*/
L.Browser.vml = (function() {
L.Browser.vml = (function () {
var d = document.createElement('div'), s;
d.innerHTML = '<v:shape adj="1"/>';
s = d.firstChild;
@ -16,21 +16,21 @@ L.Path = L.Browser.svg || !L.Browser.vml ? L.Path : L.Path.extend({
statics: {
VML: true,
CLIP_PADDING: 0.02,
_createElement: (function() {
_createElement: (function () {
try {
document.namespaces.add('lvml', 'urn:schemas-microsoft-com:vml');
return function(name) {
return function (name) {
return document.createElement('<lvml:' + name + ' class="lvml">');
};
} catch (e) {
return function(name) {
return function (name) {
return document.createElement('<' + name + ' xmlns="urn:schemas-microsoft.com:vml" class="lvml">');
};
}
}())
},
_initPath: function() {
_initPath: function () {
this._container = L.Path._createElement('shape');
this._container.className += ' leaflet-vml-shape' +
(this.options.clickable ? ' leaflet-clickable' : '');
@ -42,7 +42,7 @@ L.Path = L.Browser.svg || !L.Browser.vml ? L.Path : L.Path.extend({
this._map._pathRoot.appendChild(this._container);
},
_initStyle: function() {
_initStyle: function () {
if (this.options.stroke) {
this._stroke = L.Path._createElement('stroke');
this._stroke.endcap = 'round';
@ -60,7 +60,7 @@ L.Path = L.Browser.svg || !L.Browser.vml ? L.Path : L.Path.extend({
this._updateStyle();
},
_updateStyle: function() {
_updateStyle: function () {
if (this.options.stroke) {
this._stroke.weight = this.options.weight + 'px';
this._stroke.color = this.options.color;
@ -72,7 +72,7 @@ L.Path = L.Browser.svg || !L.Browser.vml ? L.Path : L.Path.extend({
}
},
_updatePath: function() {
_updatePath: function () {
this._container.style.display = 'none';
this._path.v = this.getPathString() + ' '; // the space fixes IE empty path string bug
this._container.style.display = '';
@ -80,7 +80,7 @@ L.Path = L.Browser.svg || !L.Browser.vml ? L.Path : L.Path.extend({
});
L.Map.include(L.Browser.svg || !L.Browser.vml ? {} : {
_initPathRoot: function() {
_initPathRoot: function () {
if (!this._pathRoot) {
this._pathRoot = document.createElement('div');
this._pathRoot.className = 'leaflet-vml-container';

View File

@ -27,11 +27,11 @@ L.Path = L.Class.extend({
updateOnMoveEnd: true
},
initialize: function(options) {
initialize: function (options) {
L.Util.setOptions(this, options);
},
onAdd: function(map) {
onAdd: function (map) {
this._map = map;
this._initElements();
@ -45,7 +45,7 @@ L.Path = L.Class.extend({
map.on(this._updateTrigger, this._updatePath, this);
},
onRemove: function(map) {
onRemove: function (map) {
this._map = null;
map._pathRoot.removeChild(this._container);
@ -54,11 +54,11 @@ L.Path = L.Class.extend({
map.off(this._updateTrigger, this._updatePath, this);
},
projectLatlngs: function() {
projectLatlngs: function () {
// do all projection stuff here
},
setStyle: function(style) {
setStyle: function (style) {
L.Util.setOptions(this, style);
if (this._container) {
this._updateStyle();
@ -66,7 +66,7 @@ L.Path = L.Class.extend({
return this;
},
_redraw: function() {
_redraw: function () {
if (this._map) {
this.projectLatlngs();
this._updatePath();
@ -75,7 +75,7 @@ L.Path = L.Class.extend({
});
L.Map.include({
_updatePathViewport: function() {
_updatePathViewport: function () {
var p = L.Path.CLIP_PADDING,
size = this.getSize(),
//TODO this._map._getMapPanePos()

View File

@ -7,7 +7,7 @@ L.Polygon = L.Polyline.extend({
fill: true
},
initialize: function(latlngs, options) {
initialize: function (latlngs, options) {
L.Polyline.prototype.initialize.call(this, latlngs, options);
if (latlngs[0] instanceof Array) {
@ -16,7 +16,7 @@ L.Polygon = L.Polyline.extend({
}
},
projectLatlngs: function() {
projectLatlngs: function () {
L.Polyline.prototype.projectLatlngs.call(this);
// project polygon holes points
@ -30,13 +30,13 @@ L.Polygon = L.Polyline.extend({
for (var i = 0, len = this._holes.length, hole; i < len; i++) {
this._holePoints[i] = [];
for(var j = 0, len2 = this._holes[i].length; j < len2; j++) {
for (var j = 0, len2 = this._holes[i].length; j < len2; j++) {
this._holePoints[i][j] = this._map.latLngToLayerPoint(this._holes[i][j]);
}
}
},
_clipPoints: function() {
_clipPoints: function () {
var points = this._originalPoints,
newParts = [];
@ -57,7 +57,7 @@ L.Polygon = L.Polyline.extend({
this._parts = newParts;
},
_getPathPartStr: function(points) {
_getPathPartStr: function (points) {
var str = L.Polyline.prototype._getPathPartStr.call(this, points);
return str + (L.Browser.svg ? 'z' : 'x');
}

View File

@ -1,6 +1,6 @@
L.Polyline = L.Path.extend({
initialize: function(latlngs, options) {
initialize: function (latlngs, options) {
L.Path.prototype.initialize.call(this, options);
this._latlngs = latlngs;
},
@ -14,7 +14,7 @@ L.Polyline = L.Path.extend({
updateOnMoveEnd: true
},
projectLatlngs: function() {
projectLatlngs: function () {
this._originalPoints = [];
for (var i = 0, len = this._latlngs.length; i < len; i++) {
@ -22,42 +22,42 @@ L.Polyline = L.Path.extend({
}
},
getPathString: function() {
getPathString: function () {
for (var i = 0, len = this._parts.length, str = ''; i < len; i++) {
str += this._getPathPartStr(this._parts[i]);
}
return str;
},
getLatLngs: function() {
getLatLngs: function () {
return this._latlngs;
},
setLatLngs: function(latlngs) {
setLatLngs: function (latlngs) {
this._latlngs = latlngs;
this._redraw();
return this;
},
addLatLng: function(latlng) {
addLatLng: function (latlng) {
this._latlngs.push(latlng);
this._redraw();
return this;
},
spliceLatLngs: function(index, howMany) {
spliceLatLngs: function (index, howMany) {
var removed = [].splice.apply(this._latlngs, arguments);
this._redraw();
return removed;
},
closestLayerPoint: function(p) {
closestLayerPoint: function (p) {
var minDistance = Infinity, parts = this._parts, p1, p2, minPoint = null;
for (var j = 0, jLen = parts.length; j < jLen; j++) {
var points = parts[j];
for (var i = 1, len = points.length; i < len; i++) {
p1 = points[i-1];
p1 = points[i - 1];
p2 = points[i];
var point = L.LineUtil._sqClosestPointOnSegment(p, p1, p2);
if (point._sqDist < minDistance) {
@ -72,7 +72,7 @@ L.Polyline = L.Path.extend({
return minPoint;
},
getBounds: function() {
getBounds: function () {
var b = new L.LatLngBounds();
var latLngs = this.getLatLngs();
for (var i = 0, len = latLngs.length; i < len; i++) {
@ -81,7 +81,7 @@ L.Polyline = L.Path.extend({
return b;
},
_getPathPartStr: function(points) {
_getPathPartStr: function (points) {
var round = L.Path.VML;
for (var j = 0, len2 = points.length, str = '', p; j < len2; j++) {
@ -94,7 +94,7 @@ L.Polyline = L.Path.extend({
return str;
},
_clipPoints: function() {
_clipPoints: function () {
var points = this._originalPoints,
len = points.length,
i, k, segment;
@ -111,7 +111,7 @@ L.Polyline = L.Path.extend({
lu = L.LineUtil;
for (i = 0, k = 0; i < len - 1; i++) {
segment = lu.clipSegment(points[i], points[i+1], vp, i);
segment = lu.clipSegment(points[i], points[i + 1], vp, i);
if (!segment) {
continue;
}
@ -120,7 +120,7 @@ L.Polyline = L.Path.extend({
parts[k].push(segment[0]);
// if segment goes out of screen, or it's the last one, it's the end of the line part
if ((segment[1] !== points[i+1]) || (i === len - 2)) {
if ((segment[1] !== points[i + 1]) || (i === len - 2)) {
parts[k].push(segment[1]);
k++;
}
@ -128,7 +128,7 @@ L.Polyline = L.Path.extend({
},
// simplify each clipped part of the polyline
_simplifyPoints: function() {
_simplifyPoints: function () {
var parts = this._parts,
lu = L.LineUtil;
@ -137,7 +137,7 @@ L.Polyline = L.Path.extend({
}
},
_updatePath: function() {
_updatePath: function () {
this._clipPoints();
this._simplifyPoints();

View File

@ -3,13 +3,13 @@
*/
L.Circle.include(!L.Path.CANVAS ? {} : {
_drawPath: function() {
_drawPath: function () {
var p = this._point;
this._ctx.beginPath();
this._ctx.arc(p.x, p.y, this._radius, 0, Math.PI * 2);
},
_containsPoint: function(p) {
_containsPoint: function (p) {
var center = this._point,
w2 = this.options.stroke ? this.options.weight / 2 : 0;

View File

@ -2,7 +2,7 @@
* Vector rendering for all browsers that support canvas.
*/
L.Browser.canvas = (function() {
L.Browser.canvas = (function () {
return !!document.createElement('canvas').getContext;
}());
@ -17,12 +17,12 @@ L.Path = (L.Path.SVG && !window.L_PREFER_CANVAS) || !L.Browser.canvas ? L.Path :
updateOnMoveEnd: true
},
_initElements: function() {
_initElements: function () {
this._map._initPathRoot();
this._ctx = this._map._canvasCtx;
},
_updateStyle: function() {
_updateStyle: function () {
if (this.options.stroke) {
this._ctx.lineWidth = this.options.weight;
this._ctx.strokeStyle = this.options.color;
@ -32,7 +32,7 @@ L.Path = (L.Path.SVG && !window.L_PREFER_CANVAS) || !L.Browser.canvas ? L.Path :
}
},
_drawPath: function() {
_drawPath: function () {
var i, j, len, len2, point, drawMethod;
this._ctx.beginPath();
@ -51,11 +51,11 @@ L.Path = (L.Path.SVG && !window.L_PREFER_CANVAS) || !L.Browser.canvas ? L.Path :
}
},
_checkIfEmpty: function() {
_checkIfEmpty: function () {
return !this._parts.length;
},
_updatePath: function() {
_updatePath: function () {
if (this._checkIfEmpty()) { return; }
this._drawPath();
@ -86,7 +86,7 @@ L.Path = (L.Path.SVG && !window.L_PREFER_CANVAS) || !L.Browser.canvas ? L.Path :
// TODO optimization: 1 fill/stroke for all features with equal style instead of 1 for each feature
},
_initEvents: function() {
_initEvents: function () {
if (this.options.clickable) {
// TODO hand cursor
// TODO mouseover, mouseout, dblclick
@ -94,13 +94,13 @@ L.Path = (L.Path.SVG && !window.L_PREFER_CANVAS) || !L.Browser.canvas ? L.Path :
}
},
_onClick: function(e) {
_onClick: function (e) {
if (this._containsPoint(e.layerPoint)) {
this.fire('click', e);
}
},
onRemove: function(map) {
onRemove: function (map) {
map.off('viewreset', this._projectLatlngs, this);
map.off(this._updateTrigger, this._updatePath, this);
map.fire(this._updateTrigger);
@ -108,7 +108,7 @@ L.Path = (L.Path.SVG && !window.L_PREFER_CANVAS) || !L.Browser.canvas ? L.Path :
});
L.Map.include((L.Path.SVG && !window.L_PREFER_CANVAS) || !L.Browser.canvas ? {} : {
_initPathRoot: function() {
_initPathRoot: function () {
var root = this._pathRoot,
ctx;
@ -127,7 +127,7 @@ L.Map.include((L.Path.SVG && !window.L_PREFER_CANVAS) || !L.Browser.canvas ? {}
}
},
_updateCanvasViewport: function() {
_updateCanvasViewport: function () {
this._updatePathViewport();
var vp = this._pathViewport,

View File

@ -1,6 +1,6 @@
L.Polygon.include(!L.Path.CANVAS ? {} : {
_containsPoint: function(p) {
_containsPoint: function (p) {
var inside = false,
part, p1, p2,
i, j, k,

View File

@ -1,6 +1,6 @@
L.Polyline.include(!L.Path.CANVAS ? {} : {
_containsPoint: function(p, closed) {
_containsPoint: function (p, closed) {
var i, j, k, len, len2, dist, part,
w = this.options.weight / 2;

View File

@ -1,5 +1,5 @@
L.Map.include({
addControl: function(control) {
addControl: function (control) {
control.onAdd(this);
var pos = control.getPosition(),
@ -16,7 +16,7 @@ L.Map.include({
return this;
},
removeControl: function(control) {
removeControl: function (control) {
var pos = control.getPosition(),
corner = this._controlCorners[pos],
container = control.getContainer();
@ -29,7 +29,7 @@ L.Map.include({
return this;
},
_initControlPos: function() {
_initControlPos: function () {
var corners = this._controlCorners = {},
classPart = 'leaflet-',
top = classPart + 'top',

View File

@ -3,7 +3,7 @@
*/
L.Map.include({
locate: function(/*Object*/ options) {
locate: function (/*Object*/ options) {
this._locationOptions = options = L.Util.extend({
watch: false,
@ -32,13 +32,13 @@ L.Map.include({
return this;
},
stopLocate: function() {
stopLocate: function () {
if (navigator.geolocation) {
navigator.geolocation.clearWatch(this._locationWatchId);
}
},
locateAndSetView: function(maxZoom, options) {
locateAndSetView: function (maxZoom, options) {
options = L.Util.extend({
maxZoom: maxZoom || Infinity,
setView: true
@ -46,7 +46,7 @@ L.Map.include({
return this.locate(options);
},
_handleGeolocationError: function(error) {
_handleGeolocationError: function (error) {
var c = error.code,
message = (c === 1 ? "permission denied" :
(c === 2 ? "position unavailable" : "timeout"));
@ -61,7 +61,7 @@ L.Map.include({
});
},
_handleGeolocationResponse: function(pos) {
_handleGeolocationResponse: function (pos) {
var latAccuracy = 180 * pos.coords.accuracy / 4e7,
lngAccuracy = latAccuracy * 2,
lat = pos.coords.latitude,

View File

@ -1,5 +1,5 @@
L.Map.include(!(L.Transition && L.Transition.implemented()) ? {} : {
setView: function(center, zoom, forceReset) {
setView: function (center, zoom, forceReset) {
zoom = this._limitZoom(zoom);
var zoomChanged = (this._zoom !== zoom);
@ -23,7 +23,7 @@ L.Map.include(!(L.Transition && L.Transition.implemented()) ? {} : {
return this;
},
panBy: function(offset) {
panBy: function (offset) {
if (!(offset.x || offset.y)) { return this; }
if (!this._panTransition) {
@ -41,15 +41,15 @@ L.Map.include(!(L.Transition && L.Transition.implemented()) ? {} : {
return this;
},
_onPanTransitionStep: function() {
_onPanTransitionStep: function () {
this.fire('move');
},
_onPanTransitionEnd: function() {
_onPanTransitionEnd: function () {
this.fire('moveend');
},
_panByIfClose: function(offset) {
_panByIfClose: function (offset) {
if (this._offsetIsWithinView(offset)) {
this.panBy(offset);
return true;
@ -57,7 +57,7 @@ L.Map.include(!(L.Transition && L.Transition.implemented()) ? {} : {
return false;
},
_offsetIsWithinView: function(offset, multiplyFactor) {
_offsetIsWithinView: function (offset, multiplyFactor) {
var m = multiplyFactor || 1,
size = this.getSize();
return (Math.abs(offset.x) <= size.x * m) &&

View File

@ -1,12 +1,12 @@
L.Map.include({
openPopup: function(popup) {
openPopup: function (popup) {
this.closePopup();
this._popup = popup;
return this.addLayer(popup);
},
closePopup: function() {
closePopup: function () {
if (this._popup) {
this.removeLayer(this._popup);
}