diff --git a/CHANGELOG.md b/CHANGELOG.md index aed68805..ad69edde 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,16 +7,18 @@ Leaflet Changelog An in-progress version being developed on the master branch. -### Major features +### Notable new features * Added **polyline and polygon editing**. [#174](https://github.com/CloudMade/Leaflet/issues/174) * Added `DivIcon` class that easily allows you to create lightweight div-based markers. + * Added `Rectangle` vector layer (by [@JasonSanford](https://github.com/JasonSanford)). [#504](https://github.com/CloudMade/Leaflet/pull/504) ### Improvements #### Usabiliy improvements * Drag-panning now works even when there are markers in the starting point (helps on maps with lots of markers). [#506](https://github.com/CloudMade/Leaflet/issues/506) + * Improved panning performance even more (there are no wasted frames now). * Slightly improved default popup styling. #### Breaking API changes @@ -33,6 +35,7 @@ An in-progress version being developed on the master branch. * Added `Icon` `className` option to assign a custom class to an icon. * Added `Icon` `shadowOffset` option to set the position of shadow relative to the icon. * Made all `Icon` options except `iconUrl` optional (if not specified, they'll be chosen automatically or implemented using CSS). Anchor is centered by default (if size is specified), and otherwise can be set through CSS using negative margins. + * Added `originalEvent` property to `MouseEvent` (by [@k4](https://github.com/k4)). [#521](https://github.com/CloudMade/Leaflet/pull/521) * Added `Circle` `getBounds` method. [#440](https://github.com/CloudMade/Leaflet/issues/440) * Added `Marker` `opacity` option. * Added public `redraw` method to vector layers (useful if you manipulate their `LatLng` points directly). diff --git a/debug/leaflet-include.js b/debug/leaflet-include.js index ac7b693f..1ab5a1a8 100644 --- a/debug/leaflet-include.js +++ b/debug/leaflet-include.js @@ -76,6 +76,7 @@ 'layer/vector/Polyline.Edit.js', 'layer/vector/canvas/Polyline.Canvas.js', 'layer/vector/Polygon.js', + 'layer/vector/Rectangle.js', 'layer/vector/canvas/Polygon.Canvas.js', 'layer/vector/MultiPoly.js', 'layer/vector/Circle.js', diff --git a/debug/vector/rectangle.html b/debug/vector/rectangle.html new file mode 100644 index 00000000..2e508ef0 --- /dev/null +++ b/debug/vector/rectangle.html @@ -0,0 +1,53 @@ + + + + Leaflet debug page + + + + + + + + + + +
+ + + + + \ No newline at end of file diff --git a/src/control/Control.Zoom.js b/src/control/Control.Zoom.js index ddf28f40..52a2c185 100644 --- a/src/control/Control.Zoom.js +++ b/src/control/Control.Zoom.js @@ -1,4 +1,3 @@ - L.Control.Zoom = L.Control.extend({ options: { position: 'topleft' @@ -6,25 +5,23 @@ L.Control.Zoom = L.Control.extend({ onAdd: function (map) { var className = 'leaflet-control-zoom', - container = L.DomUtil.create('div', className), - zoomInButton = this._createButton('Zoom in', className + '-in', map.zoomIn, map), - zoomOutButton = this._createButton('Zoom out', className + '-out', map.zoomOut, map); - - container.appendChild(zoomInButton); - container.appendChild(zoomOutButton); + container = L.DomUtil.create('div', className); + + this._createButton('Zoom in', className + '-in', container, map.zoomIn, map); + this._createButton('Zoom out', className + '-out', container, map.zoomOut, map); return container; }, - _createButton: function (title, className, fn, context) { - var link = document.createElement('a'); + _createButton: function (title, className, container, fn, context) { + var link = L.DomUtil.create('a', className, container); link.href = '#'; link.title = title; - link.className = className; - L.DomEvent.addListener(link, 'click', L.DomEvent.stopPropagation); - L.DomEvent.addListener(link, 'click', L.DomEvent.preventDefault); - L.DomEvent.addListener(link, 'click', fn, context); + L.DomEvent + .addListener(link, 'click', L.DomEvent.stopPropagation) + .addListener(link, 'click', L.DomEvent.preventDefault) + .addListener(link, 'click', fn, context); return link; } diff --git a/src/core/Util.js b/src/core/Util.js index 337d405f..75e8ea0e 100644 --- a/src/core/Util.js +++ b/src/core/Util.js @@ -30,6 +30,9 @@ L.Util = { }; }()), + + // TODO refactor: remove repetition + requestAnimFrame: (function () { function timeoutDefer(callback) { window.setTimeout(callback, 1000 / 60); @@ -47,11 +50,24 @@ L.Util = { if (immediate && requestFn === timeoutDefer) { callback(); } else { - requestFn(callback, contextEl); + return requestFn.call(window, callback, contextEl); } }; }()), + cancelAnimFrame: (function () { + var requestFn = window.cancelAnimationFrame || + window.webkitCancelRequestAnimationFrame || + window.mozCancelRequestAnimationFrame || + window.oCancelRequestAnimationFrame || + window.msCancelRequestAnimationFrame || + clearTimeout; + + return function (handle) { + return requestFn.call(window, handle); + } + }()), + limitExecByInterval: function (fn, time, context) { var lock, execOnUnlock, args; function exec() { diff --git a/src/dom/DomEvent.js b/src/dom/DomEvent.js index 5006a777..3240c54b 100644 --- a/src/dom/DomEvent.js +++ b/src/dom/DomEvent.js @@ -9,7 +9,7 @@ L.DomEvent = { key = '_leaflet_' + type + id; if (obj[key]) { - return; + return this; } var handler = function (e) { diff --git a/src/dom/Draggable.js b/src/dom/Draggable.js index 36e9ff7a..927eed14 100644 --- a/src/dom/Draggable.js +++ b/src/dom/Draggable.js @@ -90,7 +90,8 @@ L.Draggable = L.Class.extend({ var newPoint = new L.Point(first.clientX, first.clientY); this._newPos = this._startPos.add(newPoint).subtract(this._startPoint); - L.Util.requestAnimFrame(this._updatePosition, this, true, this._dragStartTarget); + L.Util.cancelAnimFrame(this._animRequest); + this._animRequest = L.Util.requestAnimFrame(this._updatePosition, this, true, this._dragStartTarget); }, _updatePosition: function () { diff --git a/src/layer/vector/Path.SVG.js b/src/layer/vector/Path.SVG.js index 947e109e..65e178b2 100644 --- a/src/layer/vector/Path.SVG.js +++ b/src/layer/vector/Path.SVG.js @@ -106,7 +106,8 @@ L.Path = L.Path.extend({ this.fire(e.type, { latlng: latlng, layerPoint: layerPoint, - containerPoint: containerPoint + containerPoint: containerPoint, + originalEvent: e }); L.DomEvent.stopPropagation(e); diff --git a/src/layer/vector/Rectangle.js b/src/layer/vector/Rectangle.js new file mode 100644 index 00000000..57c73d00 --- /dev/null +++ b/src/layer/vector/Rectangle.js @@ -0,0 +1,23 @@ +/* + * L.Rectangle extends Polygon and creates a rectangle when passed at LatLngBounds + */ + +L.Rectangle = L.Polygon.extend({ + initialize: function (latLngBounds, options) { + L.Polygon.prototype.initialize.call(this, this._boundsToLatLngs(latLngBounds), options); + }, + + setBounds: function (latLngBounds) { + this.setLatLngs(this._boundsToLatLngs(latLngBounds)); + }, + + _boundsToLatLngs: function (latLngBounds) { + return [ + latLngBounds.getSouthWest(), + latLngBounds.getNorthWest(), + latLngBounds.getNorthEast(), + latLngBounds.getSouthEast(), + latLngBounds.getSouthWest() + ]; + } +}); diff --git a/src/map/Map.js b/src/map/Map.js index d81b6fc3..42ddfee2 100644 --- a/src/map/Map.js +++ b/src/map/Map.js @@ -597,7 +597,8 @@ L.Map = L.Class.extend({ this.fire(type, { latlng: latlng, layerPoint: layerPoint, - containerPoint: containerPoint + containerPoint: containerPoint, + originalEvent: e }); },