Initial port of Control.js and Navigation.js.
This also adds an Events instance to the map, so the Navigation control can register events on the map. Tests still missing.
This commit is contained in:
@@ -2,6 +2,8 @@ goog.provide('ol.Map');
|
||||
|
||||
goog.require('ol.Loc');
|
||||
goog.require('ol.Projection');
|
||||
goog.require('ol.event');
|
||||
goog.require('ol.event.Events');
|
||||
|
||||
|
||||
|
||||
@@ -53,6 +55,12 @@ ol.Map = function() {
|
||||
*/
|
||||
this.layers_ = null;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {Array}
|
||||
*/
|
||||
this.controls_ = null;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {ol.UnreferencedBounds}
|
||||
@@ -64,7 +72,21 @@ ol.Map = function() {
|
||||
* @type {number|undefined}
|
||||
*/
|
||||
this.maxRes_ = undefined;
|
||||
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {ol.event.Events}
|
||||
*/
|
||||
this.events_ = new ol.event.Events(
|
||||
this, undefined, true, [ol.event.drag()]
|
||||
);
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {Element}
|
||||
*/
|
||||
this.container_ = null;
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -151,6 +173,14 @@ ol.Map.prototype.getLayers = function() {
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @return {Array.<ol.control.Control>}
|
||||
*/
|
||||
ol.Map.prototype.getControls = function() {
|
||||
return this.controls_;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @return {ol.UnreferencedBounds} the maxExtent for the map
|
||||
*/
|
||||
@@ -257,6 +287,18 @@ ol.Map.prototype.setLayers = function(layers) {
|
||||
this.layers_ = layers;
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {Array.<ol.control.Control>} controls
|
||||
*/
|
||||
ol.Map.prototype.setControls = function(controls) {
|
||||
if (!this.controls_) {
|
||||
for (var i=0, ii=controls.length; i<ii; ++i) {
|
||||
controls[i].setMap(this);
|
||||
}
|
||||
this.controls_ = controls;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {ol.UnreferencedBounds} extent the maxExtent for the map
|
||||
*/
|
||||
@@ -271,6 +313,29 @@ ol.Map.prototype.setMaxRes = function(res) {
|
||||
this.maxRes_ = res;
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {Element} container the container to render the map to
|
||||
*/
|
||||
ol.Map.prototype.setContainer = function(container) {
|
||||
this.events_.setElement(container);
|
||||
this.container_ = container;
|
||||
};
|
||||
|
||||
/**
|
||||
* @return {ol.event.Events} the events instance for this map
|
||||
*/
|
||||
ol.Map.prototype.getEvents = function() {
|
||||
return this.events_;
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {number} dx pixels to move in x direction
|
||||
* @param {number} dy pixels to move in x direction
|
||||
*/
|
||||
ol.Map.prototype.moveByPx = function(dx, dy) {
|
||||
// call moveByPx on renderers
|
||||
};
|
||||
|
||||
/**
|
||||
* @export
|
||||
*/
|
||||
|
||||
66
src/ol/control/Control.js
Normal file
66
src/ol/control/Control.js
Normal file
@@ -0,0 +1,66 @@
|
||||
goog.provide('ol.control.Control');
|
||||
|
||||
goog.require('ol.Map');
|
||||
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @param {boolean|undefined} opt_autoActivate
|
||||
*/
|
||||
ol.control.Control = function(opt_autoActivate) {
|
||||
|
||||
/**
|
||||
* @type {ol.Map} map
|
||||
* @private
|
||||
*/
|
||||
this.map_ = null;
|
||||
|
||||
/**
|
||||
* @type {boolean} active
|
||||
* @private
|
||||
*/
|
||||
this.active_ = false;
|
||||
|
||||
/**
|
||||
* Activate this control when it is added to a map. Default is false.
|
||||
*
|
||||
* @type {boolean} autoActivate
|
||||
*/
|
||||
this.autoActivate_ =
|
||||
goog.isDef(opt_autoActivate) ? opt_autoActivate : false;
|
||||
};
|
||||
|
||||
/**
|
||||
* @return {ol.Map} getMap
|
||||
*/
|
||||
ol.control.Control.prototype.getMap = function() {
|
||||
return this.map_;
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {ol.Map} map
|
||||
*/
|
||||
ol.control.Control.prototype.setMap = function(map) {
|
||||
this.map_ = map;
|
||||
if (this.autoActivate_) {
|
||||
this.activate();
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @return {boolean}
|
||||
*/
|
||||
ol.control.Control.prototype.activate = function() {
|
||||
var returnValue = !this.active_;
|
||||
this.active_ = true;
|
||||
return returnValue;
|
||||
};
|
||||
|
||||
/**
|
||||
* @return {boolean}
|
||||
*/
|
||||
ol.control.Control.prototype.deactivate = function() {
|
||||
var returnValue = this.active_;
|
||||
this.active_ = true;
|
||||
return returnValue;
|
||||
};
|
||||
49
src/ol/control/Navigation.js
Normal file
49
src/ol/control/Navigation.js
Normal file
@@ -0,0 +1,49 @@
|
||||
goog.provide('ol.control.Navigation');
|
||||
|
||||
goog.require('ol.control.Control');
|
||||
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @extends ol.control.Control
|
||||
* @param {boolean|undefined} opt_autoActivate
|
||||
*/
|
||||
ol.control.Navigation = 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.Navigation, ol.control.Control);
|
||||
|
||||
/** @inheritDoc */
|
||||
ol.control.Navigation.prototype.activate = function() {
|
||||
var active = goog.base(this, 'activate');
|
||||
if (active) {
|
||||
this.getMap().getEvents().register("drag", this.moveMap, this);
|
||||
}
|
||||
return active;
|
||||
};
|
||||
|
||||
/** @inheritDoc */
|
||||
ol.control.Navigation.prototype.deactivate = function() {
|
||||
var inactive = goog.base(this, 'deactivate');
|
||||
if (inactive) {
|
||||
this.getMap().getEvents().unregister("drag", this.moveMap, this);
|
||||
}
|
||||
return inactive;
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {Event} evt
|
||||
*/
|
||||
ol.control.Navigation.prototype.moveMap = function(evt) {
|
||||
this.getMap().moveByPx(evt.dx, evt.xy);
|
||||
};
|
||||
Reference in New Issue
Block a user