Add map property "target"
This commit is contained in:
@@ -14,7 +14,7 @@
|
|||||||
* @property {Array.<ol.layer.Layer>|ol.Collection|undefined} layers Layers.
|
* @property {Array.<ol.layer.Layer>|ol.Collection|undefined} layers Layers.
|
||||||
* @property {ol.RendererHint|undefined} renderer Renderer.
|
* @property {ol.RendererHint|undefined} renderer Renderer.
|
||||||
* @property {Array.<ol.RendererHint>|undefined} renderers Renderers.
|
* @property {Array.<ol.RendererHint>|undefined} renderers Renderers.
|
||||||
* @property {Element|string} target The container for the map.
|
* @property {Element|string|undefined} target The container for the map.
|
||||||
* @property {ol.IView|undefined} view The map's view. Currently
|
* @property {ol.IView|undefined} view The map's view. Currently
|
||||||
* {@link ol.View2D} is available as view.
|
* {@link ol.View2D} is available as view.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -112,6 +112,7 @@ ol.MapProperty = {
|
|||||||
BACKGROUND_COLOR: 'backgroundColor',
|
BACKGROUND_COLOR: 'backgroundColor',
|
||||||
LAYERS: 'layers',
|
LAYERS: 'layers',
|
||||||
SIZE: 'size',
|
SIZE: 'size',
|
||||||
|
TARGET: 'target',
|
||||||
VIEW: 'view'
|
VIEW: 'view'
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -192,12 +193,6 @@ ol.Map = function(options) {
|
|||||||
*/
|
*/
|
||||||
this.dirty_ = false;
|
this.dirty_ = false;
|
||||||
|
|
||||||
/**
|
|
||||||
* @private
|
|
||||||
* @type {Element}
|
|
||||||
*/
|
|
||||||
this.target_ = optionsInternal.target;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @private
|
* @private
|
||||||
* @type {?number}
|
* @type {?number}
|
||||||
@@ -218,7 +213,6 @@ ol.Map = function(options) {
|
|||||||
if (ol.BrowserFeature.HAS_TOUCH) {
|
if (ol.BrowserFeature.HAS_TOUCH) {
|
||||||
this.viewport_.className = 'ol-touch';
|
this.viewport_.className = 'ol-touch';
|
||||||
}
|
}
|
||||||
goog.dom.appendChild(this.target_, this.viewport_);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @private
|
* @private
|
||||||
@@ -318,15 +312,16 @@ ol.Map = function(options) {
|
|||||||
this.handleViewChanged_, false, this);
|
this.handleViewChanged_, false, this);
|
||||||
goog.events.listen(this, ol.Object.getChangedEventType(ol.MapProperty.SIZE),
|
goog.events.listen(this, ol.Object.getChangedEventType(ol.MapProperty.SIZE),
|
||||||
this.handleSizeChanged_, false, this);
|
this.handleSizeChanged_, false, this);
|
||||||
|
goog.events.listen(this, ol.Object.getChangedEventType(ol.MapProperty.TARGET),
|
||||||
|
this.handleTargetChanged_, false, this);
|
||||||
goog.events.listen(
|
goog.events.listen(
|
||||||
this, ol.Object.getChangedEventType(ol.MapProperty.BACKGROUND_COLOR),
|
this, ol.Object.getChangedEventType(ol.MapProperty.BACKGROUND_COLOR),
|
||||||
this.handleBackgroundColorChanged_, false, this);
|
this.handleBackgroundColorChanged_, false, this);
|
||||||
|
|
||||||
|
// setValues will trigger the rendering of the map if the map
|
||||||
|
// is "defined" already.
|
||||||
this.setValues(optionsInternal.values);
|
this.setValues(optionsInternal.values);
|
||||||
|
|
||||||
// this gives the map an initial size
|
|
||||||
this.updateSize();
|
|
||||||
|
|
||||||
if (goog.isDef(optionsInternal.controls)) {
|
if (goog.isDef(optionsInternal.controls)) {
|
||||||
goog.array.forEach(optionsInternal.controls,
|
goog.array.forEach(optionsInternal.controls,
|
||||||
/**
|
/**
|
||||||
@@ -421,11 +416,15 @@ ol.Map.prototype.getRenderer = function() {
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return {Element} Container.
|
* @return {Element|undefined} Target.
|
||||||
*/
|
*/
|
||||||
ol.Map.prototype.getTarget = function() {
|
ol.Map.prototype.getTarget = function() {
|
||||||
return this.target_;
|
return /** @type {Element|undefined} */ (this.get(ol.MapProperty.TARGET));
|
||||||
};
|
};
|
||||||
|
goog.exportProperty(
|
||||||
|
ol.Map.prototype,
|
||||||
|
'getTarget',
|
||||||
|
ol.Map.prototype.getTarget);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -688,6 +687,22 @@ ol.Map.prototype.handleSizeChanged_ = function() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
|
ol.Map.prototype.handleTargetChanged_ = function() {
|
||||||
|
var target = this.getTarget();
|
||||||
|
if (!goog.isDef(target)) {
|
||||||
|
goog.dom.removeNode(this.viewport_);
|
||||||
|
} else {
|
||||||
|
goog.dom.appendChild(target, this.viewport_);
|
||||||
|
}
|
||||||
|
this.updateSize();
|
||||||
|
// updateSize calls setSize, so no need to call this.render
|
||||||
|
// ourselves here.
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
@@ -890,7 +905,7 @@ goog.exportProperty(
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {ol.Size} size Size.
|
* @param {ol.Size|undefined} size Size.
|
||||||
*/
|
*/
|
||||||
ol.Map.prototype.setSize = function(size) {
|
ol.Map.prototype.setSize = function(size) {
|
||||||
this.set(ol.MapProperty.SIZE, size);
|
this.set(ol.MapProperty.SIZE, size);
|
||||||
@@ -901,6 +916,18 @@ goog.exportProperty(
|
|||||||
ol.Map.prototype.setSize);
|
ol.Map.prototype.setSize);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {Element|undefined} target Target.
|
||||||
|
*/
|
||||||
|
ol.Map.prototype.setTarget = function(target) {
|
||||||
|
this.set(ol.MapProperty.TARGET, target);
|
||||||
|
};
|
||||||
|
goog.exportProperty(
|
||||||
|
ol.Map.prototype,
|
||||||
|
'setTarget',
|
||||||
|
ol.Map.prototype.setTarget);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {ol.IView} view View.
|
* @param {ol.IView} view View.
|
||||||
*/
|
*/
|
||||||
@@ -929,8 +956,13 @@ ol.Map.prototype.unfreezeRendering = function() {
|
|||||||
* third-party code changes the size of the map viewport.
|
* third-party code changes the size of the map viewport.
|
||||||
*/
|
*/
|
||||||
ol.Map.prototype.updateSize = function() {
|
ol.Map.prototype.updateSize = function() {
|
||||||
var size = goog.style.getSize(this.target_);
|
var target = this.getTarget();
|
||||||
this.setSize(new ol.Size(size.width, size.height));
|
if (goog.isDef(target)) {
|
||||||
|
var size = goog.style.getSize(target);
|
||||||
|
this.setSize(new ol.Size(size.width, size.height));
|
||||||
|
} else {
|
||||||
|
this.setSize(undefined);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -954,7 +986,6 @@ ol.Map.prototype.withFrozenRendering = function(f, opt_obj) {
|
|||||||
* interactions: ol.Collection,
|
* interactions: ol.Collection,
|
||||||
* rendererConstructor:
|
* rendererConstructor:
|
||||||
* function(new: ol.renderer.Map, Element, ol.Map),
|
* function(new: ol.renderer.Map, Element, ol.Map),
|
||||||
* target: Element,
|
|
||||||
* values: Object.<string, *>}}
|
* values: Object.<string, *>}}
|
||||||
*/
|
*/
|
||||||
ol.MapOptionsInternal;
|
ol.MapOptionsInternal;
|
||||||
@@ -984,6 +1015,10 @@ ol.Map.createOptionsInternal = function(options) {
|
|||||||
}
|
}
|
||||||
values[ol.MapProperty.LAYERS] = layers;
|
values[ol.MapProperty.LAYERS] = layers;
|
||||||
|
|
||||||
|
if (goog.isDef(options.target)) {
|
||||||
|
values[ol.MapProperty.TARGET] = goog.dom.getElement(options.target);
|
||||||
|
}
|
||||||
|
|
||||||
values[ol.MapProperty.VIEW] = goog.isDef(options.view) ?
|
values[ol.MapProperty.VIEW] = goog.isDef(options.view) ?
|
||||||
options.view : new ol.View2D();
|
options.view : new ol.View2D();
|
||||||
|
|
||||||
@@ -1032,16 +1067,10 @@ ol.Map.createOptionsInternal = function(options) {
|
|||||||
var interactions = goog.isDef(options.interactions) ?
|
var interactions = goog.isDef(options.interactions) ?
|
||||||
options.interactions : ol.interaction.defaults();
|
options.interactions : ol.interaction.defaults();
|
||||||
|
|
||||||
/**
|
|
||||||
* @type {Element}
|
|
||||||
*/
|
|
||||||
var target = goog.dom.getElement(options.target);
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
controls: controls,
|
controls: controls,
|
||||||
interactions: interactions,
|
interactions: interactions,
|
||||||
rendererConstructor: rendererConstructor,
|
rendererConstructor: rendererConstructor,
|
||||||
target: target,
|
|
||||||
values: values
|
values: values
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user