diff --git a/package.json b/package.json index 207e85250..a94f9ffd7 100644 --- a/package.json +++ b/package.json @@ -54,7 +54,7 @@ "happen": "0.1.3", "html5shiv": "^3.7.2", "image-size": "0.3.5", - "leaflet": "git://github.com/Leaflet/Leaflet.git#1bb1b5a3f8307b4460211f340281b764a24a13cc", + "leaflet": "git://github.com/2gis/Leaflet.git#6998a11da56a796a8bbee34f00705e264ec41ff8", "less": "^2.4.0", "lodash": "^2.4.1", "map-stream": "0.1.0", diff --git a/src/DGCustomization/src/DGCustomization.js b/src/DGCustomization/src/DGCustomization.js index c5850305f..41eb943ad 100644 --- a/src/DGCustomization/src/DGCustomization.js +++ b/src/DGCustomization/src/DGCustomization.js @@ -26,3 +26,7 @@ DG.setOptions = L.setOptions = DG.Util.setOptions = function (obj, options) { return utilSetOptions.call(this, obj, options); }; + +DG.Layer.mergeOptions({ + nonBubblingEvents: ['click', 'dblclick', 'mouseover', 'mouseout', 'contextmenu'] +}); diff --git a/src/DGCustomization/src/DGMap.js b/src/DGCustomization/src/DGMap.js index 99a813b8c..e07fea846 100644 --- a/src/DGCustomization/src/DGMap.js +++ b/src/DGCustomization/src/DGMap.js @@ -25,6 +25,10 @@ DG.Map.include({ this.setMaxBounds(options.maxBounds); } + if (options.zoom !== undefined) { + this._zoom = this._limitZoom(options.zoom); + } + this._handlers = []; this._layers = {}; @@ -181,30 +185,68 @@ DG.Map.include({ // Add prepreclick event before preclick than geoclicker can track popup state // https://github.com/2gis/mapsapi/pull/96 - _fireDOMEvent: function (target, e, type) { - if (!target.listens(type, true) && (type !== 'click' || !target.listens('preclick', true))) { return; } + _handleDOMEvent: function (e) { + if (!this._loaded || L.DomEvent._skipped(e)) { return; } + + // find the layer the event is propagating from and its parents + var type = e.type === 'keypress' && e.keyCode === 13 ? 'click' : e.type; + + if (e.type === 'click') { + // Fire a synthetic 'preclick' event which propagates up (mainly for closing popups). + var synthPrePre = L.Util.extend({}, e); + synthPrePre.type = 'prepreclick'; + this._handleDOMEvent(synthPrePre); + + var synth = L.Util.extend({}, e); + synth.type = 'preclick'; + this._handleDOMEvent(synth); + } + + if (type === 'mousedown') { + // prevents outline when clicking on keyboard-focusable element + L.DomUtil.preventOutline(e.target || e.srcElement); + } - if (type === 'contextmenu') { + this._fireDOMEvent(e, type); + }, + + _fireDOMEvent: function (e, type, targets) { + + var isHover = type === 'mouseover' || type === 'mouseout'; + targets = (targets || []).concat(this._findEventTargets(e.target || e.srcElement, type, !isHover)); + + if (!targets.length) { + targets = [this]; + + // special case for map mouseover/mouseout events so that they're actually mouseenter/mouseleave + if (isHover && !L.DomEvent._checkMouse(this._container, e)) { return; } + } else if (type === 'contextmenu') { + // we only want to call preventDefault when targets listen to it. L.DomEvent.preventDefault(e); } + var target = targets[0]; + // prevents firing click after you just dragged an object - if (e.type === 'click' && !e._simulated && this._draggableMoved(target)) { return; } + if ((e.type === 'click' || e.type === 'preclick' || e.type === 'prepreclick') && !e._simulated && this._draggableMoved(target)) { return; } var data = { originalEvent: e }; + if (e.type !== 'keypress') { - data.containerPoint = target instanceof L.Marker ? - this.latLngToContainerPoint(target.getLatLng()) : this.mouseEventToContainerPoint(e); + var isMarker = target instanceof L.Marker; + data.containerPoint = isMarker ? + this.latLngToContainerPoint(target.getLatLng()) : this.mouseEventToContainerPoint(e); data.layerPoint = this.containerPointToLayerPoint(data.containerPoint); - data.latlng = this.layerPointToLatLng(data.layerPoint); + data.latlng = isMarker ? target.getLatLng() : this.layerPointToLatLng(data.layerPoint); } - if (type === 'click') { - target.fire('prepreclick', data, true); - target.fire('preclick', data, true); + + for (var i = 0; i < targets.length; i++) { + targets[i].fire(type, data, true); + if (data.originalEvent._stopped + || (targets[i].options.nonBubblingEvents && L.Util.indexOf(targets[i].options.nonBubblingEvents, type) !== -1)) { return; } } - target.fire(type, data, true); } }); diff --git a/src/DGCustomization/test/GridLayerSpec.js b/src/DGCustomization/test/GridLayerSpec.js index 8cc05a92f..af3cf3867 100644 --- a/src/DGCustomization/test/GridLayerSpec.js +++ b/src/DGCustomization/test/GridLayerSpec.js @@ -57,14 +57,14 @@ describe('GridLayer', function () { } expect(loaded).to.eql({ - '144:44': [0, 0], - '400:44': [1, 0], - '144:300': [0, 1], - '400:300': [1, 1], - '-112:44': [1, 0], - '656:44': [0, 0], - '-112:300': [1, 1], - '656:300': [0, 1] + '144:0': [0, 0], + '400:0': [1, 0], + '144:256': [0, 1], + '400:256': [1, 1], + '-112:0': [1, 0], + '656:0': [0, 0], + '-112:256': [1, 1], + '656:256': [0, 1] }); }); diff --git a/src/DGMeta/src/DGMeta.Layer.js b/src/DGMeta/src/DGMeta.Layer.js index d8fd1d44d..bc093d010 100644 --- a/src/DGMeta/src/DGMeta.Layer.js +++ b/src/DGMeta/src/DGMeta.Layer.js @@ -67,7 +67,7 @@ DG.Meta.Layer = DG.Layer.extend({ _removeAllTiles: DG.GridLayer.prototype._removeAllTiles, _getZoomForUrl: DG.TileLayer.prototype._getZoomForUrl, - _getTileSize: DG.TileLayer.prototype._getTileSize, + getTileSize: DG.TileLayer.prototype.getTileSize, _isValidTile: DG.GridLayer.prototype._isValidTile, _wrapCoords: DG.GridLayer.prototype._wrapCoords, _resetView: DG.GridLayer.prototype._resetView, @@ -77,10 +77,10 @@ DG.Meta.Layer = DG.Layer.extend({ _domEvents: { mousemove: function (event) { // (MouseEvent) - var tileSize = this._getTileSize(), + var tileSize = this.getTileSize(), layerPoint = this._map.mouseEventToLayerPoint(event), tileOriginPoint = this._map.getPixelOrigin().add(layerPoint), - tileCoord = tileOriginPoint.divideBy(tileSize).floor(), + tileCoord = tileOriginPoint.unscaleBy(tileSize).floor(), mouseTileOffset, tileKey, hoveredObject, @@ -95,7 +95,7 @@ DG.Meta.Layer = DG.Layer.extend({ this._wrapCoords(tileCoord); tileCoord.z = this._getZoomForUrl(); - tileCoord.key = tileSize; + tileCoord.key = tileSize.x + 'x' + tileSize.y; tileKey = this._origin.getTileKey(tileCoord); if (tileKey !== this._currentTile) { @@ -106,7 +106,7 @@ DG.Meta.Layer = DG.Layer.extend({ if (this._currentTileData === false) { this._currentTileData = this._origin.getTileData(tileCoord); } else { - mouseTileOffset = DG.point(tileOriginPoint.x % tileSize, tileOriginPoint.y % tileSize); + mouseTileOffset = DG.point(tileOriginPoint.x % tileSize.x, tileOriginPoint.y % tileSize.y); hoveredObject = this._getHoveredObject(tileCoord, mouseTileOffset); if (this._hoveredEntity !== hoveredObject) { diff --git a/src/DGMeta/test/DGMetaSpec.js b/src/DGMeta/test/DGMetaSpec.js index 2b268c258..02cdc7934 100644 --- a/src/DGMeta/test/DGMetaSpec.js +++ b/src/DGMeta/test/DGMetaSpec.js @@ -55,7 +55,7 @@ describe('DGMeta', function () { }); it('should click on map', function () { - origin.setTileData('78713:43453:17:256', demoData); + origin.setTileData('78713:43453:17:256x256', demoData); spy = sinon.spy(); meta.addTo(map); @@ -71,7 +71,7 @@ describe('DGMeta', function () { it('getTileData should NOT call ajax and return false', function () { var data; - data = origin.getTileData('124:12:42:256'); + data = origin.getTileData('124:12:42:256x256'); expect(data).to.not.be.ok(); //ajax should not be called since empty url provided @@ -81,9 +81,9 @@ describe('DGMeta', function () { it('flush should clear cache', function () { var chain, data; - origin.setTileData({x: 124, y: 12, z: 42, key: 256}, demoData); + origin.setTileData({x: 124, y: 12, z: 42, key: '256x256'}, demoData); chain = origin.flush(); - data = origin.getTileData({x: 124, y: 12, z: 42, key: 256}); + data = origin.getTileData({x: 124, y: 12, z: 42, key: '256x256'}); expect(data).to.not.be.ok(); // check for returning this @@ -98,7 +98,7 @@ describe('DGMeta', function () { data, chain; chain = origin.setURL('http://demo/data'); - data = origin.getTileData({x: 124, y: 12, z: 42, key: 256}); + data = origin.getTileData({x: 124, y: 12, z: 42, key: '256x256'}); expect(data).to.not.be.ok(); expect(ajaxSpy.callCount).to.be.eql(1); @@ -126,7 +126,7 @@ describe('DGMeta', function () { var data; origin.setURL('http://demo/data'); - data = origin.getTileData({x: 124, y: 12, z: 42, key: 256}); + data = origin.getTileData({x: 124, y: 12, z: 42, key: '256x256'}); expect(data).to.not.be.ok(); expect(ajaxSpy.callCount).to.be.eql(1); @@ -135,9 +135,9 @@ describe('DGMeta', function () { it('setTileData by object key should write and cache tileData', function () { var chain, data; - chain = origin.setTileData({x: 124, y: 12, z: 42, key: 256}, demoData); + chain = origin.setTileData({x: 124, y: 12, z: 42, key: '256x256'}, demoData); - data = origin.getTileData({x: 124, y: 12, z: 42, key: 256}); + data = origin.getTileData({x: 124, y: 12, z: 42, key: '256x256'}); expect(data).to.be.a('object'); expect(ajaxSpy.callCount).to.be.eql(0); // check for returning this @@ -147,9 +147,9 @@ describe('DGMeta', function () { it('setTileData by string key should write and cache tileData', function () { var chain, data; - chain = origin.setTileData('124:12:42:256', demoData); + chain = origin.setTileData('124:12:42:256x256', demoData); - data = origin.getTileData({x: 124, y: 12, z: 42, key: 256}); + data = origin.getTileData({x: 124, y: 12, z: 42, key: '256x256'}); expect(data).to.be.a('object'); expect(ajaxSpy.callCount).to.be.eql(0); // check for returning this @@ -159,9 +159,9 @@ describe('DGMeta', function () { it('getTileKey should string tileKey representation', function () { var tileKey; - tileKey = origin.getTileKey({x: 124, y: 12, z: 42, key: 256}); + tileKey = origin.getTileKey({x: 124, y: 12, z: 42, key: '256x256'}); - expect(tileKey).to.be.eql('124:12:42:256'); + expect(tileKey).to.be.eql('124:12:42:256x256'); }); }); }); diff --git a/src/DGPoi/src/DGPoi.js b/src/DGPoi/src/DGPoi.js index 6b122cd9d..0ecc4d003 100644 --- a/src/DGPoi/src/DGPoi.js +++ b/src/DGPoi/src/DGPoi.js @@ -43,7 +43,7 @@ DG.Poi = DG.Handler.extend({ _processData : function (data, coord) { var map = this._map, - tileOriginPoint = coord.multiplyBy(this._metaLayer._getTileSize()); + tileOriginPoint = coord.scaleBy(this._metaLayer.getTileSize()); if (data.responseText === '') { return []; diff --git a/src/DGProjectDetector/test/ProjectDetectorInSpec.js b/src/DGProjectDetector/test/ProjectDetectorInSpec.js index e10eac6b9..46e77b54d 100644 --- a/src/DGProjectDetector/test/ProjectDetectorInSpec.js +++ b/src/DGProjectDetector/test/ProjectDetectorInSpec.js @@ -238,21 +238,21 @@ describe('DG.ProjectDetectorIn', function () { map.setView(project1, maxZoom); expect(map.fitWorld()).to.be(map); - expect(map.getZoom()).to.be(0); + expect(map.getZoom()).to.be(1); }); it('fire from min zoom', function () { map.setView(project1, 0); expect(map.fitWorld()).to.be(map); - expect(map.getZoom()).to.be(0); + expect(map.getZoom()).to.be(1); }); it('fire after min zoom 15', function () { map.setZoom(15); expect(map.fitWorld()).to.be(map); - expect(map.getZoom()).to.be(0); + expect(map.getZoom()).to.be(1); }); }); diff --git a/src/DGProjectDetector/test/ProjectDetectorOutOfWorldSpec.js b/src/DGProjectDetector/test/ProjectDetectorOutOfWorldSpec.js index 60a1ca002..45271ef3d 100644 --- a/src/DGProjectDetector/test/ProjectDetectorOutOfWorldSpec.js +++ b/src/DGProjectDetector/test/ProjectDetectorOutOfWorldSpec.js @@ -238,21 +238,21 @@ describe('DG.ProjectDetectorOut', function () { map.setView(project1, maxZoom); expect(map.fitWorld()).to.be(map); - expect(map.getZoom()).to.be(0); + expect(map.getZoom()).to.be(1); }); it('fire from min zoom', function () { map.setView(project1, 0); expect(map.fitWorld()).to.be(map); - expect(map.getZoom()).to.be(0); + expect(map.getZoom()).to.be(1); }); it('fire after min zoom 15', function () { map.setZoom(15); expect(map.fitWorld()).to.be(map); - expect(map.getZoom()).to.be(0); + expect(map.getZoom()).to.be(1); }); }); diff --git a/src/DGProjectDetector/test/ProjectDetectorUnderSpec.js b/src/DGProjectDetector/test/ProjectDetectorUnderSpec.js index 9245f4576..d6df66439 100644 --- a/src/DGProjectDetector/test/ProjectDetectorUnderSpec.js +++ b/src/DGProjectDetector/test/ProjectDetectorUnderSpec.js @@ -238,21 +238,21 @@ describe('DG.ProjectDetectorUnder', function () { map.setView(project1, maxZoom); expect(map.fitWorld()).to.be(map); - expect(map.getZoom()).to.be(0); + expect(map.getZoom()).to.be(1); }); it('fire from min zoom', function () { map.setView(project1, 0); expect(map.fitWorld()).to.be(map); - expect(map.getZoom()).to.be(0); + expect(map.getZoom()).to.be(1); }); it('fire after min zoom 15', function () { map.setZoom(15); expect(map.fitWorld()).to.be(map); - expect(map.getZoom()).to.be(0); + expect(map.getZoom()).to.be(1); }); }); diff --git a/src/DGRuler/skin/basic/less/dg-ruler.less b/src/DGRuler/skin/basic/less/dg-ruler.less index f73580c95..76fd15b6d 100644 --- a/src/DGRuler/skin/basic/less/dg-ruler.less +++ b/src/DGRuler/skin/basic/less/dg-ruler.less @@ -2,7 +2,7 @@ position: absolute; top: 0; left: 0; - z-index: 4; + z-index: 400; -webkit-tap-highlight-color: rgba(0,0,0,0); } .dg-ruler__label-spacer { diff --git a/src/DGTraffic/src/DGTraffic.js b/src/DGTraffic/src/DGTraffic.js index 495353820..13b38ba51 100644 --- a/src/DGTraffic/src/DGTraffic.js +++ b/src/DGTraffic/src/DGTraffic.js @@ -116,7 +116,7 @@ DG.Traffic = DG.TileLayer.extend({ _processData: function (trafficData, coord) { var map = this._map, - tileOriginPoint = coord.multiplyBy(this._getTileSize()), + tileOriginPoint = coord.scaleBy(this.getTileSize()), hints = {}; if (!DG.Util.isArray(trafficData)) { // TODO remove