Merge branch 'master' of github.com:openlayers/ol3
This commit is contained in:
@@ -132,6 +132,6 @@ ol.geom.LineString.prototype.remove = function(vertices){
|
||||
this.removeVertex(v);
|
||||
return true;
|
||||
}, this);
|
||||
|
||||
|
||||
return this;
|
||||
};
|
||||
|
||||
@@ -2,8 +2,8 @@ goog.provide("ol");
|
||||
|
||||
goog.require('ol.base');
|
||||
goog.require('ol.bounds');
|
||||
goog.require('ol.control.Control');
|
||||
goog.require('ol.control.Navigation');
|
||||
goog.require('ol.control.Zoom');
|
||||
goog.require('ol.event.Drag');
|
||||
goog.require('ol.event.Events');
|
||||
goog.require("ol.map");
|
||||
|
||||
@@ -108,8 +108,6 @@ ol.Map = function() {
|
||||
*/
|
||||
this.container_ = null;
|
||||
|
||||
this.setControls(ol.Map.DEFAULT_CONTROLS);
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -136,7 +134,7 @@ ol.Map.DEFAULT_TILE_SIZE = 256;
|
||||
@const
|
||||
@type {Array.<string>}
|
||||
*/
|
||||
ol.Map.DEFAULT_CONTROLS = ["navigation"];
|
||||
ol.Map.DEFAULT_CONTROLS = ["navigation", "zoom"];
|
||||
|
||||
/**
|
||||
* @return {ol.Loc} Location.
|
||||
@@ -355,9 +353,19 @@ ol.Map.prototype.setMaxRes = function(res) {
|
||||
* @param {Element} container the container to render the map to
|
||||
*/
|
||||
ol.Map.prototype.setContainer = function(container) {
|
||||
this.events_.setElement(container);
|
||||
this.container_ = container;
|
||||
this.setViewport();
|
||||
this.createRenderer();
|
||||
//TODO Controls could be set earlier, but we need to deal with content that
|
||||
// controls place on overlays.
|
||||
this.setControls(ol.Map.DEFAULT_CONTROLS);
|
||||
};
|
||||
|
||||
/**
|
||||
* @return {Element}
|
||||
*/
|
||||
ol.Map.prototype.getViewport = function() {
|
||||
return this.viewport_;
|
||||
};
|
||||
|
||||
ol.Map.prototype.setViewport = function() {
|
||||
@@ -367,9 +375,21 @@ ol.Map.prototype.setViewport = function() {
|
||||
this.staticOverlay_ = goog.dom.createDom('div', 'ol-overlay-static');
|
||||
goog.dom.append(this.viewport_, this.mapOverlay_, this.staticOverlay_);
|
||||
}
|
||||
this.events_.setElement(this.viewport_);
|
||||
goog.dom.appendChild(this.container_, this.viewport_);
|
||||
};
|
||||
|
||||
ol.Map.prototype.createRenderer = function() {
|
||||
/*var registeredRenderers = ol.renderer.RENDERER_MAP,
|
||||
candidate;
|
||||
for (var r in registeredRenderers) {
|
||||
if (registeredRenderers[r].isSupported()) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
this.renderer_ = new registeredRenderers[r](this.viewport_);*/
|
||||
};
|
||||
|
||||
/**
|
||||
* @return {ol.event.Events} the events instance for this map
|
||||
*/
|
||||
@@ -385,6 +405,14 @@ ol.Map.prototype.moveByPx = function(dx, dy) {
|
||||
// call moveByPx on renderers
|
||||
};
|
||||
|
||||
ol.Map.prototype.zoomIn = function() {
|
||||
this.setZoom(this.zoom_++);
|
||||
};
|
||||
|
||||
ol.Map.prototype.zoomOut = function() {
|
||||
this.setZoom(this.zoom_--);
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {ol.geom.Point} loc the location being requested
|
||||
* @returns {Array} the position of the location in pixel space
|
||||
|
||||
@@ -9,13 +9,7 @@ goog.require('goog.structs.LinkedMap');
|
||||
* @param {number=} opt_size
|
||||
*/
|
||||
ol.TileCache = function(opt_size) {
|
||||
/**
|
||||
* @constant
|
||||
* @type {number}
|
||||
*/
|
||||
this.size_ = opt_size || 100;
|
||||
|
||||
goog.base(this, 1, true /* cache mode */);
|
||||
goog.base(this, opt_size || 100, true /* cache mode */);
|
||||
};
|
||||
|
||||
goog.inherits(ol.TileCache, goog.structs.LinkedMap);
|
||||
|
||||
@@ -42,10 +42,11 @@ ol.control.Navigation.prototype.deactivate = function() {
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {ol.event.DragEvent} evt
|
||||
* @param {Object} evt
|
||||
*/
|
||||
ol.control.Navigation.prototype.moveMap = function(evt) {
|
||||
this.getMap().moveByPx(evt.dx, evt.dy);
|
||||
return false;
|
||||
};
|
||||
|
||||
ol.control.addControl('navigation', ol.control.Navigation);
|
||||
103
src/ol/control/Zoom.js
Normal file
103
src/ol/control/Zoom.js
Normal file
@@ -0,0 +1,103 @@
|
||||
goog.provide('ol.control.Zoom');
|
||||
|
||||
goog.require('ol.control.Control');
|
||||
goog.require('goog.dom');
|
||||
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @extends {ol.control.Control}
|
||||
* @param {boolean|undefined} opt_autoActivate
|
||||
*/
|
||||
ol.control.Zoom = function(opt_autoActivate) {
|
||||
|
||||
goog.base(this, opt_autoActivate);
|
||||
|
||||
/**
|
||||
* Activate this control when it is added to a map. Default is true.
|
||||
*
|
||||
* @type {boolean} autoActivate
|
||||
*/
|
||||
this.autoActivate_ =
|
||||
goog.isDef(opt_autoActivate) ? opt_autoActivate : true;
|
||||
|
||||
};
|
||||
goog.inherits(ol.control.Zoom, ol.control.Control);
|
||||
|
||||
/**
|
||||
* @param {ol.Map} map
|
||||
*/
|
||||
ol.control.Zoom.prototype.setMap = function(map) {
|
||||
goog.base(this, 'setMap', map);
|
||||
var container = goog.dom.createDom('div', ol.control.Zoom.RES.CLS);
|
||||
var inButton = goog.dom.createDom(
|
||||
'div', ol.control.Zoom.RES.IN_CLS,
|
||||
goog.dom.createDom('a', {'href': '#zoomIn'})
|
||||
);
|
||||
goog.dom.setTextContent(
|
||||
/** @type {Element} */ (inButton.firstChild),
|
||||
ol.control.Zoom.RES.IN_TEXT
|
||||
);
|
||||
var outButton = goog.dom.createDom(
|
||||
'div', ol.control.Zoom.RES.OUT_CLS,
|
||||
goog.dom.createDom('a', {'href': '#zoomOut'})
|
||||
);
|
||||
goog.dom.setTextContent(
|
||||
/** @type {Element} */ (outButton.firstChild),
|
||||
ol.control.Zoom.RES.OUT_TEXT
|
||||
);
|
||||
goog.dom.append(container, inButton, outButton);
|
||||
|
||||
var viewport = /** @type {Node} */ map.getViewport();
|
||||
if (goog.isDefAndNotNull(viewport)) {
|
||||
goog.dom.append(viewport, container);
|
||||
}
|
||||
};
|
||||
|
||||
/** @inheritDoc */
|
||||
ol.control.Zoom.prototype.activate = function() {
|
||||
var active = goog.base(this, 'activate');
|
||||
if (active) {
|
||||
this.getMap().getEvents().register("click", this.handle, this);
|
||||
}
|
||||
return active;
|
||||
};
|
||||
|
||||
/** @inheritDoc */
|
||||
ol.control.Zoom.prototype.deactivate = function() {
|
||||
var inactive = goog.base(this, 'deactivate');
|
||||
if (inactive) {
|
||||
this.getMap().getEvents().unregister("click", this.handle, this);
|
||||
}
|
||||
return inactive;
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {Event} evt
|
||||
*/
|
||||
ol.control.Zoom.prototype.handle = function(evt) {
|
||||
var target = /** @type {Node} */ (evt.target),
|
||||
handled = false;
|
||||
if (goog.dom.getAncestorByClass(target, ol.control.Zoom.RES.IN_CLS)) {
|
||||
this.getMap().zoomIn();
|
||||
handled = true;
|
||||
} else
|
||||
if (goog.dom.getAncestorByClass(target, ol.control.Zoom.RES.OUT_CLS)) {
|
||||
this.getMap().zoomOut();
|
||||
handled = true;
|
||||
}
|
||||
if (handled) {
|
||||
evt.preventDefault();
|
||||
}
|
||||
return !handled;
|
||||
};
|
||||
|
||||
ol.control.addControl('zoom', ol.control.Zoom);
|
||||
|
||||
ol.control.Zoom.RES = {
|
||||
CLS: 'ol-control-zoom',
|
||||
IN_CLS: 'ol-control-zoom-in',
|
||||
OUT_CLS: 'ol-control-zoom-out',
|
||||
IN_TEXT: '+',
|
||||
OUT_TEXT: '\u2013'
|
||||
};
|
||||
@@ -1,5 +1,4 @@
|
||||
goog.provide('ol.event.Drag');
|
||||
goog.provide('ol.event.DragEvent');
|
||||
|
||||
goog.require('ol.event.ISequence');
|
||||
goog.require('ol.event.Events');
|
||||
@@ -52,67 +51,38 @@ ol.event.Drag.prototype.dispatchEvent = function(e) {
|
||||
} else if (e.type === goog.fx.Dragger.EventType.END) {
|
||||
e.type = ol.event.Drag.EventType.DRAGEND;
|
||||
}
|
||||
e.target = e.browserEvent.target;
|
||||
e.dx = e.clientX - this.previousX_;
|
||||
e.dy = e.clientY - this.previousY_;
|
||||
}
|
||||
this.target_.dispatchEvent(/** @type {Event} */ (e));
|
||||
this.target_.triggerEvent(e.type, /** @type {Object} (e.type) */ (e));
|
||||
return goog.base(this, 'dispatchEvent', e);
|
||||
};
|
||||
|
||||
/** @inheritDoc */
|
||||
ol.event.Drag.prototype.startDrag = function(e) {
|
||||
goog.base(this, 'startDrag', e);
|
||||
this.previousX_ = e.clientX;
|
||||
this.previousY_ = e.clientY;
|
||||
goog.base(this, 'startDrag', e);
|
||||
};
|
||||
|
||||
/** @inheritDoc */
|
||||
ol.event.Drag.prototype.doDrag = function(e, x, y, dragFromScroll) {
|
||||
e.dx = e.clientX - this.previousX_;
|
||||
e.dy = e.clientX - this.previousY_;
|
||||
goog.base(this, 'doDrag', e, x, y, dragFromScroll);
|
||||
};
|
||||
|
||||
/** @override */
|
||||
ol.event.Drag.prototype.doDrag = function(e, x, y, dragFromScroll) {
|
||||
goog.base(this, 'doDrag', e, x, y, dragFromScroll);
|
||||
this.previousX_ = e.clientX;
|
||||
this.previousY_ = e.clientY;
|
||||
};
|
||||
|
||||
/** @inheritDoc */
|
||||
ol.event.Drag.prototype.defaultAction = function(x, y) {};
|
||||
|
||||
/** @inheritDoc */
|
||||
ol.event.Drag.prototype.destroy = ol.event.Drag.prototype.dispose;
|
||||
|
||||
|
||||
ol.event.addSequenceProvider('drag', ol.event.Drag);
|
||||
|
||||
|
||||
/**
|
||||
* Object representing a drag event
|
||||
*
|
||||
* @param {string} type Event type.
|
||||
* @param {goog.fx.Dragger} dragobj Drag object initiating event.
|
||||
* @param {number} clientX X-coordinate relative to the viewport.
|
||||
* @param {number} clientY Y-coordinate relative to the viewport.
|
||||
* @param {goog.events.BrowserEvent} browserEvent Object representing the
|
||||
* browser event that caused this drag event.
|
||||
* @constructor
|
||||
* @extends {goog.fx.DragEvent}
|
||||
*/
|
||||
ol.event.DragEvent = function(type, dragobj, clientX, clientY, browserEvent) {
|
||||
|
||||
goog.base(this, type, dragobj, clientX, clientY, browserEvent);
|
||||
|
||||
/**
|
||||
* The move delta in X direction since the previous drag event
|
||||
*
|
||||
* @type {number}
|
||||
*/
|
||||
this.dx = 0;
|
||||
|
||||
/**
|
||||
* The move delta in Y direction since the previous drag event
|
||||
*
|
||||
* @type {number}
|
||||
*/
|
||||
this.dy = 0;
|
||||
};
|
||||
goog.inherits(ol.event.DragEvent, goog.fx.DragEvent);
|
||||
|
||||
|
||||
/**
|
||||
* @type {Object.<string, string>}
|
||||
*/
|
||||
|
||||
@@ -136,7 +136,7 @@ ol.event.Events.prototype.setElement = function(element) {
|
||||
for (t in types) {
|
||||
// register the event cross-browser
|
||||
goog.events.unlisten(
|
||||
this.element_, types[t], this.dispatchEvent, true, this
|
||||
this.element_, types[t], this.handleBrowserEvent, true, this
|
||||
);
|
||||
}
|
||||
this.destroySequences();
|
||||
@@ -148,7 +148,7 @@ ol.event.Events.prototype.setElement = function(element) {
|
||||
for (t in types) {
|
||||
// register the event cross-browser
|
||||
goog.events.listen(
|
||||
element, types[t], this.dispatchEvent, true, this
|
||||
element, types[t], this.handleBrowserEvent, true, this
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -243,15 +243,14 @@ ol.event.Events.prototype.triggerEvent = function(type, opt_evt) {
|
||||
};
|
||||
|
||||
/**
|
||||
* Basically just a wrapper to the parent's dispatchEvent() function, but takes
|
||||
* care to set a property 'xy' on the event with the current mouse position and
|
||||
* normalize clientX and clientY for multi-touch events.
|
||||
* Prepares browser events before they are dispatched. This takes care to set a
|
||||
* property 'xy' on the event with the current pointer position (if
|
||||
* {@code includeXY} is set to true), and normalizes clientX and clientY for
|
||||
* multi-touch events.
|
||||
*
|
||||
* @param {Event} evt Event object.
|
||||
* @return {boolean} If anyone called preventDefault on the event object (or
|
||||
* if any of the handlers returns false this will also return false.
|
||||
*/
|
||||
ol.event.Events.prototype.dispatchEvent = function(evt) {
|
||||
ol.event.Events.prototype.handleBrowserEvent = function(evt) {
|
||||
var type = evt.type,
|
||||
listeners = goog.events.getListeners(this.element_, type, false)
|
||||
.concat(goog.events.getListeners(this.element_, type, true));
|
||||
@@ -276,7 +275,7 @@ ol.event.Events.prototype.dispatchEvent = function(evt) {
|
||||
evt.xy = goog.style.getRelativePosition(evt, this.element_);
|
||||
}
|
||||
}
|
||||
return goog.base(this, 'dispatchEvent', evt);
|
||||
this.triggerEvent(evt.type, evt);
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@@ -4,10 +4,10 @@ goog.provide('ol.event.ISequence');
|
||||
* Interface for event sequences. Event sequences map sequences of native
|
||||
* browser events to high level events that the sequence provides.
|
||||
*
|
||||
* Implementations are expected to call dispatchEvent on the {@code target} to
|
||||
* to fire their high level events.
|
||||
* Implementations are expected to call {@code triggerEvent} on the
|
||||
* {@code target} to to fire their high level events.
|
||||
*
|
||||
* Implementations can expect the {@code target}'s {@code getElement()} method
|
||||
* Implementations can expect the {@code target}'s {@code getElement} method
|
||||
* to return an {Element} at construction time.
|
||||
*
|
||||
* @interface
|
||||
|
||||
Reference in New Issue
Block a user