Merge pull request #175 from elemoine/control
Simplify control architecture
This commit is contained in:
@@ -42,12 +42,13 @@ var domMap = new ol.Map({
|
|||||||
view: view
|
view: view
|
||||||
});
|
});
|
||||||
|
|
||||||
domMap.getControls().push(new ol.control.MousePosition({
|
var domMousePosition = new ol.control.MousePosition({
|
||||||
coordinateFormat: ol.Coordinate.toStringHDMS,
|
coordinateFormat: ol.Coordinate.toStringHDMS,
|
||||||
projection: ol.Projection.getFromCode('EPSG:4326'),
|
projection: ol.Projection.getFromCode('EPSG:4326'),
|
||||||
target: document.getElementById('domMousePosition'),
|
target: document.getElementById('domMousePosition'),
|
||||||
undefinedHTML: ' '
|
undefinedHTML: ' '
|
||||||
}));
|
});
|
||||||
|
domMousePosition.setMap(domMap);
|
||||||
|
|
||||||
var webglMap = new ol.Map({
|
var webglMap = new ol.Map({
|
||||||
renderer: ol.RendererHint.WEBGL,
|
renderer: ol.RendererHint.WEBGL,
|
||||||
@@ -58,12 +59,13 @@ if (webglMap !== null) {
|
|||||||
webglMap.bindTo('view', domMap);
|
webglMap.bindTo('view', domMap);
|
||||||
}
|
}
|
||||||
|
|
||||||
webglMap.getControls().push(new ol.control.MousePosition({
|
var webglMousePosition = new ol.control.MousePosition({
|
||||||
coordinateFormat: ol.Coordinate.toStringHDMS,
|
coordinateFormat: ol.Coordinate.toStringHDMS,
|
||||||
projection: ol.Projection.getFromCode('EPSG:4326'),
|
projection: ol.Projection.getFromCode('EPSG:4326'),
|
||||||
target: document.getElementById('webglMousePosition'),
|
target: document.getElementById('webglMousePosition'),
|
||||||
undefinedHTML: ' '
|
undefinedHTML: ' '
|
||||||
}));
|
});
|
||||||
|
webglMousePosition.setMap(webglMap);
|
||||||
|
|
||||||
var canvasMap = new ol.Map({
|
var canvasMap = new ol.Map({
|
||||||
renderer: ol.RendererHint.CANVAS,
|
renderer: ol.RendererHint.CANVAS,
|
||||||
@@ -74,12 +76,13 @@ if (canvasMap !== null) {
|
|||||||
canvasMap.bindTo('view', domMap);
|
canvasMap.bindTo('view', domMap);
|
||||||
}
|
}
|
||||||
|
|
||||||
canvasMap.getControls().push(new ol.control.MousePosition({
|
var canvasMousePosition = new ol.control.MousePosition({
|
||||||
coordinateFormat: ol.Coordinate.toStringHDMS,
|
coordinateFormat: ol.Coordinate.toStringHDMS,
|
||||||
projection: ol.Projection.getFromCode('EPSG:4326'),
|
projection: ol.Projection.getFromCode('EPSG:4326'),
|
||||||
target: document.getElementById('canvasMousePosition'),
|
target: document.getElementById('canvasMousePosition'),
|
||||||
undefinedHtml: ' '
|
undefinedHtml: ' '
|
||||||
}));
|
});
|
||||||
|
canvasMousePosition.setMap(canvasMap);
|
||||||
|
|
||||||
var keyboardInteraction = new ol.interaction.Keyboard();
|
var keyboardInteraction = new ol.interaction.Keyboard();
|
||||||
keyboardInteraction.addCallback('0', function() {
|
keyboardInteraction.addCallback('0', function() {
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
@exportObjectLiteral ol.MapOptions
|
@exportObjectLiteral ol.MapOptions
|
||||||
@exportObjectLiteralProperty ol.MapOptions.controls ol.Collection|undefined
|
@exportObjectLiteralProperty ol.MapOptions.attributionControl boolean|undefined
|
||||||
@exportObjectLiteralProperty ol.MapOptions.doubleClickZoom boolean|undefined
|
@exportObjectLiteralProperty ol.MapOptions.doubleClickZoom boolean|undefined
|
||||||
@exportObjectLiteralProperty ol.MapOptions.dragPan boolean|undefined
|
@exportObjectLiteralProperty ol.MapOptions.dragPan boolean|undefined
|
||||||
@exportObjectLiteralProperty ol.MapOptions.interactions ol.Collection|undefined
|
@exportObjectLiteralProperty ol.MapOptions.interactions ol.Collection|undefined
|
||||||
@@ -13,6 +13,7 @@
|
|||||||
@exportObjectLiteralProperty ol.MapOptions.shiftDragZoom boolean|undefined
|
@exportObjectLiteralProperty ol.MapOptions.shiftDragZoom boolean|undefined
|
||||||
@exportObjectLiteralProperty ol.MapOptions.target Element|string
|
@exportObjectLiteralProperty ol.MapOptions.target Element|string
|
||||||
@exportObjectLiteralProperty ol.MapOptions.view ol.IView|undefined
|
@exportObjectLiteralProperty ol.MapOptions.view ol.IView|undefined
|
||||||
|
@exportObjectLiteralProperty ol.MapOptions.zoomControl boolean|undefined
|
||||||
@exportObjectLiteralProperty ol.MapOptions.zoomDelta number|undefined
|
@exportObjectLiteralProperty ol.MapOptions.zoomDelta number|undefined
|
||||||
|
|
||||||
@exportObjectLiteral ol.View2DOptions
|
@exportObjectLiteral ol.View2DOptions
|
||||||
|
|||||||
@@ -1,2 +1,3 @@
|
|||||||
@exportClass ol.control.Attribution ol.control.AttributionOptions
|
@exportClass ol.control.Attribution ol.control.AttributionOptions
|
||||||
|
@exportProperty ol.control.Attribution.prototype.setMap
|
||||||
|
|
||||||
|
|||||||
@@ -1,2 +1,3 @@
|
|||||||
@exportClass ol.control.MousePosition ol.control.MousePositionOptions
|
@exportClass ol.control.MousePosition ol.control.MousePositionOptions
|
||||||
|
@exportProperty ol.control.MousePosition.prototype.setMap
|
||||||
|
|
||||||
|
|||||||
@@ -1,2 +1,2 @@
|
|||||||
@exportClass ol.control.Zoom ol.control.ZoomOptions
|
@exportClass ol.control.Zoom ol.control.ZoomOptions
|
||||||
|
@exportProperty ol.control.Zoom.prototype.setMap
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
@exportClass ol.Map ol.MapOptions
|
@exportClass ol.Map ol.MapOptions
|
||||||
@exportProperty ol.Map.prototype.addPreRenderFunction
|
@exportProperty ol.Map.prototype.addPreRenderFunction
|
||||||
@exportProperty ol.Map.prototype.addPreRenderFunctions
|
@exportProperty ol.Map.prototype.addPreRenderFunctions
|
||||||
@exportProperty ol.Map.prototype.getControls
|
|
||||||
@exportProperty ol.Map.prototype.getInteractions
|
@exportProperty ol.Map.prototype.getInteractions
|
||||||
|
|
||||||
@exportSymbol ol.RendererHint
|
@exportSymbol ol.RendererHint
|
||||||
|
|||||||
@@ -22,8 +22,6 @@ goog.require('goog.events.MouseWheelHandler');
|
|||||||
goog.require('goog.events.MouseWheelHandler.EventType');
|
goog.require('goog.events.MouseWheelHandler.EventType');
|
||||||
goog.require('ol.BrowserFeature');
|
goog.require('ol.BrowserFeature');
|
||||||
goog.require('ol.Collection');
|
goog.require('ol.Collection');
|
||||||
goog.require('ol.CollectionEvent');
|
|
||||||
goog.require('ol.CollectionEventType');
|
|
||||||
goog.require('ol.Color');
|
goog.require('ol.Color');
|
||||||
goog.require('ol.Coordinate');
|
goog.require('ol.Coordinate');
|
||||||
goog.require('ol.Extent');
|
goog.require('ol.Extent');
|
||||||
@@ -230,17 +228,6 @@ ol.Map = function(mapOptions) {
|
|||||||
this.handleBrowserEvent, false, this);
|
this.handleBrowserEvent, false, this);
|
||||||
this.registerDisposable(mouseWheelHandler);
|
this.registerDisposable(mouseWheelHandler);
|
||||||
|
|
||||||
/**
|
|
||||||
* @type {ol.Collection}
|
|
||||||
* @private
|
|
||||||
*/
|
|
||||||
this.controls_ = mapOptionsInternal.controls;
|
|
||||||
|
|
||||||
goog.events.listen(this.controls_, ol.CollectionEventType.ADD,
|
|
||||||
this.handleControlsAdd_, false, this);
|
|
||||||
goog.events.listen(this.controls_, ol.CollectionEventType.REMOVE,
|
|
||||||
this.handleControlsRemove_, false, this);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @type {ol.Collection}
|
* @type {ol.Collection}
|
||||||
* @private
|
* @private
|
||||||
@@ -299,7 +286,9 @@ ol.Map = function(mapOptions) {
|
|||||||
// this gives the map an initial size
|
// this gives the map an initial size
|
||||||
this.handleBrowserWindowResize();
|
this.handleBrowserWindowResize();
|
||||||
|
|
||||||
this.controls_.forEach(
|
/** @type {Array.<ol.control.Control>} */
|
||||||
|
var controls = mapOptionsInternal.controls;
|
||||||
|
goog.array.forEach(controls,
|
||||||
/**
|
/**
|
||||||
* @param {ol.control.Control} control Control.
|
* @param {ol.control.Control} control Control.
|
||||||
*/
|
*/
|
||||||
@@ -387,14 +376,6 @@ ol.Map.prototype.getTarget = function() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return {ol.Collection} Controls.
|
|
||||||
*/
|
|
||||||
ol.Map.prototype.getControls = function() {
|
|
||||||
return this.controls_;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {ol.Pixel} pixel Pixel.
|
* @param {ol.Pixel} pixel Pixel.
|
||||||
* @return {ol.Coordinate} Coordinate.
|
* @return {ol.Coordinate} Coordinate.
|
||||||
@@ -522,26 +503,6 @@ ol.Map.prototype.handleBrowserEvent = function(browserEvent, opt_type) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param {ol.CollectionEvent} collectionEvent Collection event.
|
|
||||||
* @private
|
|
||||||
*/
|
|
||||||
ol.Map.prototype.handleControlsAdd_ = function(collectionEvent) {
|
|
||||||
var control = /** @type {ol.control.Control} */ (collectionEvent.elem);
|
|
||||||
control.setMap(this);
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param {ol.CollectionEvent} collectionEvent Collection event.
|
|
||||||
* @private
|
|
||||||
*/
|
|
||||||
ol.Map.prototype.handleControlsRemove_ = function(collectionEvent) {
|
|
||||||
var control = /** @type {ol.control.Control} */ (collectionEvent.elem);
|
|
||||||
control.setMap(null);
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {ol.MapBrowserEvent} mapBrowserEvent The event to handle.
|
* @param {ol.MapBrowserEvent} mapBrowserEvent The event to handle.
|
||||||
*/
|
*/
|
||||||
@@ -848,7 +809,7 @@ ol.Map.prototype.withFrozenRendering = function(f, opt_obj) {
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @typedef {{controls: ol.Collection,
|
* @typedef {{controls: Array.<ol.control.Control>,
|
||||||
* interactions: ol.Collection,
|
* interactions: ol.Collection,
|
||||||
* rendererConstructor:
|
* rendererConstructor:
|
||||||
* function(new: ol.renderer.Map, Element, ol.Map),
|
* function(new: ol.renderer.Map, Element, ol.Map),
|
||||||
@@ -914,14 +875,9 @@ ol.Map.createOptionsInternal = function(mapOptions) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @type {ol.Collection}
|
* @type {Array.<ol.control.Control>}
|
||||||
*/
|
*/
|
||||||
var controls;
|
var controls = ol.Map.createControls_(mapOptions);
|
||||||
if (goog.isDef(mapOptions.controls)) {
|
|
||||||
controls = mapOptions.controls;
|
|
||||||
} else {
|
|
||||||
controls = ol.Map.createControls_(mapOptions);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @type {ol.Collection}
|
* @type {ol.Collection}
|
||||||
@@ -952,22 +908,29 @@ ol.Map.createOptionsInternal = function(mapOptions) {
|
|||||||
/**
|
/**
|
||||||
* @private
|
* @private
|
||||||
* @param {ol.MapOptions} mapOptions Map options.
|
* @param {ol.MapOptions} mapOptions Map options.
|
||||||
* @return {ol.Collection} Controls.
|
* @return {Array.<ol.control.Control>} Controls.
|
||||||
*/
|
*/
|
||||||
ol.Map.createControls_ = function(mapOptions) {
|
ol.Map.createControls_ = function(mapOptions) {
|
||||||
|
/** @type {Array.<ol.control.Control>} */
|
||||||
|
var controls = [];
|
||||||
|
|
||||||
var controls = new ol.Collection();
|
var attributionControl = goog.isDef(mapOptions.attributionControl) ?
|
||||||
|
mapOptions.attributionControl : true;
|
||||||
|
if (attributionControl) {
|
||||||
controls.push(new ol.control.Attribution({}));
|
controls.push(new ol.control.Attribution({}));
|
||||||
|
}
|
||||||
|
|
||||||
|
var zoomControl = goog.isDef(mapOptions.zoomControl) ?
|
||||||
|
mapOptions.zoomControl : true;
|
||||||
|
if (zoomControl) {
|
||||||
var zoomDelta = goog.isDef(mapOptions.zoomDelta) ?
|
var zoomDelta = goog.isDef(mapOptions.zoomDelta) ?
|
||||||
mapOptions.zoomDelta : 4;
|
mapOptions.zoomDelta : 4;
|
||||||
controls.push(new ol.control.Zoom({
|
controls.push(new ol.control.Zoom({
|
||||||
delta: zoomDelta
|
delta: zoomDelta
|
||||||
}));
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
return controls;
|
return controls;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user