\r
getScaleString: function (scale, origin) {\r
\r
- var preTranslateStr = L.DomUtil.getTranslateString(origin),\r
- scaleStr = ' scale(' + scale + ') ',\r
- postTranslateStr = L.DomUtil.getTranslateString(origin.multiplyBy(-1));\r
+ var preTranslateStr = L.DomUtil.getTranslateString(origin.add(origin.multiplyBy(-1 * scale))),\r
+ scaleStr = ' scale(' + scale + ') ';\r
\r
- return preTranslateStr + scaleStr + postTranslateStr;\r
+ return preTranslateStr + scaleStr;\r
},\r
\r
setPosition: function (el, point, disable3D) { // (HTMLElement, Point[, Boolean])\r
layer.on('load', this._onTileLayerLoad, this);\r
}\r
\r
- var onMapLoad = function () {\r
+ this.whenReady(function () {\r
layer.onAdd(this);\r
this.fire('layeradd', {layer: layer});\r
- };\r
-\r
- if (this._loaded) {\r
- onMapLoad.call(this);\r
- } else {\r
- this.on('load', onMapLoad, this);\r
- }\r
+ }, this);\r
\r
return this;\r
},\r
}\r
},\r
\r
+ whenReady: function (callback, context) {\r
+ if (this._loaded) {\r
+ callback.call(context || this, this);\r
+ } else {\r
+ this.on('load', callback, context);\r
+ }\r
+ return this;\r
+ },\r
+\r
\r
// private methods for getting map state\r
\r
onRemove: function (map) {\r
this._removeIcon();\r
\r
- // TODO move to Marker.Popup.js\r
- if (this.closePopup) {\r
- this.closePopup();\r
- }\r
+ this.fire('remove');\r
\r
map.off({\r
'viewreset': this.update,\r
\r
this.update();\r
\r
- if (this._popup) {\r
- this._popup.setLatLng(latlng);\r
- }\r
+ this.fire('move', { latlng: this._latlng });\r
},\r
\r
setZIndexOffset: function (offset) {\r
options = L.Util.extend({offset: anchor}, options);\r
\r
if (!this._popup) {\r
- this.on('click', this.openPopup, this);\r
+ this\r
+ .on('click', this.openPopup, this)\r
+ .on('remove', this.closePopup, this)\r
+ .on('move', this._movePopup, this);\r
}\r
\r
this._popup = new L.Popup(options, this)\r
unbindPopup: function () {\r
if (this._popup) {\r
this._popup = null;\r
- this.off('click', this.openPopup);\r
+ this\r
+ .off('click', this.openPopup)\r
+ .off('remove', this.closePopup)\r
+ .off('move', this._movePopup);\r
}\r
return this;\r
+ },\r
+\r
+ _movePopup: function (e) {\r
+ this._popup.setLatLng(e.latlng);\r
}\r
});\r
this._fill = null;\r
}\r
\r
+ this.fire('remove');\r
+\r
map.off({\r
'viewreset': this.projectLatlngs,\r
'moveend': this._updatePath\r
}\r
\r
this._fireMouseEvent(e);\r
-\r
- if (this.hasEventListeners(e.type)) {\r
- L.DomEvent.stopPropagation(e);\r
- }\r
},\r
\r
_fireMouseEvent: function (e) {\r
return;\r
}\r
\r
- if (e.type === 'contextmenu') {\r
- L.DomEvent.preventDefault(e);\r
- }\r
-\r
var map = this._map,\r
containerPoint = map.mouseEventToContainerPoint(e),\r
layerPoint = map.containerPointToLayerPoint(containerPoint),\r
containerPoint: containerPoint,\r
originalEvent: e\r
});\r
+\r
+ if (e.type === 'contextmenu') {\r
+ L.DomEvent.preventDefault(e);\r
+ }\r
+ L.DomEvent.stopPropagation(e);\r
}\r
});\r
\r
\r
this._popup.setContent(content);\r
\r
- if (!this._openPopupAdded) {\r
- this.on('click', this._openPopup, this);\r
- this._openPopupAdded = true;\r
+ if (!this._popupHandlersAdded) {\r
+ this\r
+ .on('click', this._openPopup, this)\r
+ .on('remove', this._closePopup, this);\r
+ this._popupHandlersAdded = true;\r
}\r
\r
return this;\r
},\r
\r
+ unbindPopup: function () {\r
+ if (this._popup) {\r
+ this._popup = null;\r
+ this\r
+ .off('click', this.openPopup)\r
+ .off('remove', this.closePopup);\r
+ }\r
+ return this;\r
+ },\r
+\r
openPopup: function (latlng) {\r
\r
if (this._popup) {\r
_openPopup: function (e) {\r
this._popup.setLatLng(e.latlng);\r
this._map.openPopup(this._popup);\r
+ },\r
+\r
+ _closePopup: function () {\r
+ this._popup._close();\r
}\r
});\r
},
_onDrag: function (e) {
+ var marker = this._marker,
+ shadow = marker._shadow,
+ iconPos = L.DomUtil.getPosition(marker._icon),
+ latlng = marker._map.layerPointToLatLng(iconPos);
+
// update shadow position
- var iconPos = L.DomUtil.getPosition(this._marker._icon);
- if (this._marker._shadow) {
- L.DomUtil.setPosition(this._marker._shadow, iconPos);
+ if (shadow) {
+ L.DomUtil.setPosition(shadow, iconPos);
}
- this._marker._latlng = this._marker._map.layerPointToLatLng(iconPos);
+ marker._latlng = latlng;
- this._marker
- .fire('move')
+ marker
+ .fire('move', { latlng: latlng })
.fire('drag');
},
this._addScales(options, className, container);
map.on(options.updateWhenIdle ? 'moveend' : 'move', this._update, this);
- this._update();
+ map.whenReady(this._update, this);
return container;
},
_onInputClick: function () {\r
var i, input, obj,\r
inputs = this._form.getElementsByTagName('input'),\r
- inputsLen = inputs.length;\r
+ inputsLen = inputs.length,\r
+ baseLayer;\r
\r
for (i = 0; i < inputsLen; i++) {\r
input = inputs[i];\r
obj = this._layers[input.layerId];\r
\r
- if (input.checked) {\r
- this._map.addLayer(obj.layer, !obj.overlay);\r
- } else {\r
+ if (input.checked && !this._map.hasLayer(obj.layer)) {\r
+ this._map.addLayer(obj.layer);\r
+ if (!obj.overlay) {\r
+ baseLayer = obj.layer;\r
+ }\r
+ } else if (!input.checked && this._map.hasLayer(obj.layer)) {\r
this._map.removeLayer(obj.layer);\r
}\r
}\r
+\r
+ if (baseLayer) {\r
+ this._map.fire('baselayerchange', {layer: baseLayer});\r
+ }\r
},\r
\r
_expand: function () {\r
clearTimeout(this._clearTileBgTimer);
- //dumb FireFox hack, I have no idea why this magic zero translate fixes the scale transition problem
- if (L.Browser.gecko || window.opera || L.Browser.ie3d) {
- tileBg.style[transform] += ' translate(0,0)';
- }
-
L.Util.falseFn(tileBg.offsetWidth); //hack to make sure transform is updated before running animation
var scaleStr = L.DomUtil.getScaleString(scale, origin),