Merge branch 'master' of https://github.com/msaspence/Leaflet into msaspence-master

This commit is contained in:
mourner 2011-04-11 22:46:32 +03:00
commit b22349c1c0
7 changed files with 105 additions and 8 deletions

View File

@ -24,6 +24,9 @@ L.Class.extend = function(/*Object*/ props) /*-> Class*/ {
// add superclass access
proto.superclass = this.prototype;
// add class name
//proto.className = props;
// mix static properties into the class
if (props.statics) {
L.Util.extend(NewClass, props.statics);

View File

@ -35,6 +35,19 @@ L.DomEvent = {
obj[key] = null;
},
fireEvent: function (/*HTMLElement*/ obj, /*String*/ type) {
if (document.createEventObject){
// dispatch for IE
var evt = document.createEventObject();
return obj.fireEvent('on'+type,evt)
} else{
// dispatch for firefox + others
var evt = document.createEvent("HTMLEvents");
evt.initEvent(type, true, true ); // event type,bubbling,cancelable
return !obj.dispatchEvent(evt);
}
},
_getEvent: function()/*->Event*/ {
var e = window.event;
if (!e) {
@ -84,8 +97,8 @@ L.DomEvent = {
getWheelDelta: function(e) {
var delta = 0;
if (e.wheelDelta) { delta = e.wheelDelta/120; }
if (e.detail) { delta = -e.detail/3; }
return delta;
if (e.detail) { delta = -e.detail/3; }
return delta;
}
};

View File

@ -3,8 +3,13 @@
*/
L.Handler = L.Class.extend({
initialize: function(map) {
this._map = map;
initialize: function(handlee) {
// not sure this is the best name for this property
this._handlee = handlee;
// this ensures map handles looking for ._map can still find it
// I would remove this and change them but with out full test coverage
// am worried I will break something
this._map = handlee;
},
enabled: function() {

View File

@ -3,6 +3,7 @@
*/
L.Handler.MapDrag = L.Handler.extend({
enable: function() {
if (this._enabled) { return; }
if (!this._draggable) {

51
src/handler/MarkerDrag.js Normal file
View File

@ -0,0 +1,51 @@
/*
* L.Handler.MarkerDrag is used internally by L.Marker to make the markers draggable.
*/
L.Handler.MarkerDrag = L.Handler.extend({
enable: function() {
if (this._enabled) { return; }
if (!this._draggable) {
this._draggable = new L.Draggable(this._handlee._icon, this._handlee._icon);
this._draggable.on('dragstart', this._onDragStart, this);
this._draggable.on('drag', this._onDrag, this);
this._draggable.on('dragend', this._onDragEnd, this);
}
this._draggable.enable();
this._enabled = true;
},
disable: function() {
if (!this._enabled) { return; }
this._draggable.disable();
this._enabled = false;
},
moved: function() {
return this._draggable._moved;
},
_onDragStart: function(e) {
this._handlee.fire('movestart',this);
this._handlee.fire('dragstart',"hello");
this._dragStartShadowPos = L.DomUtil.getPosition(this._handlee._shadow);
},
_onDrag: function(e) {
// update shadow position
var newShadowPos = this._dragStartShadowPos.add(e.target._offset);
L.DomUtil.setPosition(this._handlee._shadow, newShadowPos);
this._handlee.fire('move',this);
this._handlee.fire('drag',this);
},
_onDragEnd: function() {
this._handlee.fire('moveend',this);
this._handlee.fire('dragend',this);
}
});

View File

@ -4,16 +4,18 @@
L.Marker = L.Class.extend({
includes: L.Mixin.Events,
options: {
icon: new L.Icon(),
clickable: true
clickable: true,
draggable: false
},
initialize: function(latlng, options) {
L.Util.setOptions(this, options);
this._latlng = latlng;
this._latlng = latlng;
},
onAdd: function(map) {
@ -44,7 +46,8 @@ L.Marker = L.Class.extend({
},
getLatLng: function() {
return this._latlng;
var pos = L.DomUtil.getPosition(this._icon);
return this._map.layerPointToLatLng(pos);
},
_reset: function() {
@ -57,16 +60,35 @@ L.Marker = L.Class.extend({
},
_initInteraction: function() {
if (this.options.clickable) {
this._icon.className += ' leaflet-clickable';
L.DomEvent.addListener(this._icon, 'mousedown', this._fireMouseEvent, this);
L.DomEvent.addListener(this._icon, 'click', this._fireMouseEvent, this);
L.DomEvent.addListener(this._icon, 'dblclick', this._fireMouseEvent, this);
}
var handlers = {
draggable: L.Handler.MarkerDrag
}
for (var i in handlers) {
if (handlers.hasOwnProperty(i) && handlers[i]) {
this[i] = new handlers[i](this);
if (this.options[i]) this[i].enable();
}
}
},
_fireMouseEvent: function(e) {
this.fire(e.type);
L.DomEvent.stopPropagation(e);
}
},
moved: function() {
return this._draggable._moved;
},
});

View File

@ -3,6 +3,7 @@
*/
L.Map = L.Class.extend({
includes: L.Mixin.Events,
options: {
@ -129,6 +130,7 @@ L.Map = L.Class.extend({
this.on('load', onMapLoad, this);
}
}
return this;
},