Add overlay-related methods to ol.Map
This commit is contained in:
@@ -47,6 +47,8 @@
|
|||||||
* Controls initially added to the map.
|
* Controls initially added to the map.
|
||||||
* @property {ol.Collection|undefined} interactions Interactions.
|
* @property {ol.Collection|undefined} interactions Interactions.
|
||||||
* @property {Array.<ol.layer.LayerBase>|ol.Collection|undefined} layers Layers.
|
* @property {Array.<ol.layer.LayerBase>|ol.Collection|undefined} layers Layers.
|
||||||
|
* @property {ol.Collection|Array.<ol.Overlay>|undefined} overlays
|
||||||
|
* Overlays initially added to the map.
|
||||||
* @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|undefined} target The container for the map.
|
* @property {Element|string|undefined} target The container for the map.
|
||||||
|
|||||||
@@ -1,15 +1,18 @@
|
|||||||
@exportClass ol.Map ol.MapOptions
|
@exportClass ol.Map ol.MapOptions
|
||||||
@exportProperty ol.Map.prototype.addControl
|
@exportProperty ol.Map.prototype.addControl
|
||||||
@exportProperty ol.Map.prototype.addLayer
|
@exportProperty ol.Map.prototype.addLayer
|
||||||
|
@exportProperty ol.Map.prototype.addOverlay
|
||||||
@exportProperty ol.Map.prototype.addPreRenderFunction
|
@exportProperty ol.Map.prototype.addPreRenderFunction
|
||||||
@exportProperty ol.Map.prototype.addPreRenderFunctions
|
@exportProperty ol.Map.prototype.addPreRenderFunctions
|
||||||
@exportProperty ol.Map.prototype.getFeatureInfo
|
@exportProperty ol.Map.prototype.getFeatureInfo
|
||||||
@exportProperty ol.Map.prototype.getFeatures
|
@exportProperty ol.Map.prototype.getFeatures
|
||||||
@exportProperty ol.Map.prototype.getInteractions
|
@exportProperty ol.Map.prototype.getInteractions
|
||||||
@exportProperty ol.Map.prototype.getLayers
|
@exportProperty ol.Map.prototype.getLayers
|
||||||
|
@exportProperty ol.Map.prototype.getOverlays
|
||||||
@exportProperty ol.Map.prototype.getRenderer
|
@exportProperty ol.Map.prototype.getRenderer
|
||||||
@exportProperty ol.Map.prototype.removeControl
|
@exportProperty ol.Map.prototype.removeControl
|
||||||
@exportProperty ol.Map.prototype.removeLayer
|
@exportProperty ol.Map.prototype.removeLayer
|
||||||
|
@exportProperty ol.Map.prototype.removeOverlay
|
||||||
@exportProperty ol.Map.prototype.updateSize
|
@exportProperty ol.Map.prototype.updateSize
|
||||||
|
|
||||||
@exportSymbol ol.RendererHint
|
@exportSymbol ol.RendererHint
|
||||||
|
|||||||
@@ -264,6 +264,12 @@ ol.Map = function(options) {
|
|||||||
*/
|
*/
|
||||||
this.interactions_ = optionsInternal.interactions;
|
this.interactions_ = optionsInternal.interactions;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @type {ol.Collection}
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
|
this.overlays_ = optionsInternal.overlays;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @type {ol.renderer.Map}
|
* @type {ol.renderer.Map}
|
||||||
* @private
|
* @private
|
||||||
@@ -334,6 +340,14 @@ ol.Map = function(options) {
|
|||||||
control.setMap(this);
|
control.setMap(this);
|
||||||
}, this);
|
}, this);
|
||||||
|
|
||||||
|
this.overlays_.forEach(
|
||||||
|
/**
|
||||||
|
* @param {ol.Overlay} overlay Overlay.
|
||||||
|
*/
|
||||||
|
function(overlay) {
|
||||||
|
overlay.setMap(this);
|
||||||
|
}, this);
|
||||||
|
|
||||||
};
|
};
|
||||||
goog.inherits(ol.Map, ol.Object);
|
goog.inherits(ol.Map, ol.Object);
|
||||||
|
|
||||||
@@ -361,6 +375,18 @@ ol.Map.prototype.addLayer = function(layer) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add the given overlay to the map.
|
||||||
|
* @param {ol.Overlay} overlay Overlay.
|
||||||
|
*/
|
||||||
|
ol.Map.prototype.addOverlay = function(overlay) {
|
||||||
|
var overlays = this.getOverlays();
|
||||||
|
goog.asserts.assert(goog.isDef(overlays));
|
||||||
|
overlays.push(overlay);
|
||||||
|
overlay.setMap(this);
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a prerender function. This can be used for attaching animations to
|
* Add a prerender function. This can be used for attaching animations to
|
||||||
* be performed before setting the map's center. The {@link ol.animation}
|
* be performed before setting the map's center. The {@link ol.animation}
|
||||||
@@ -459,6 +485,14 @@ ol.Map.prototype.getControls = function() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return {ol.Collection} Overlays.
|
||||||
|
*/
|
||||||
|
ol.Map.prototype.getOverlays = function() {
|
||||||
|
return this.overlays_;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get feature information for a pixel on the map.
|
* Get feature information for a pixel on the map.
|
||||||
*
|
*
|
||||||
@@ -854,6 +888,23 @@ ol.Map.prototype.removeLayer = function(layer) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove the given overlay from the map.
|
||||||
|
* @param {ol.Overlay} overlay Overlay.
|
||||||
|
* @return {ol.Overlay|undefined} The removed overlay of undefined
|
||||||
|
* if the overlay was not found.
|
||||||
|
*/
|
||||||
|
ol.Map.prototype.removeOverlay = function(overlay) {
|
||||||
|
var overlays = this.getOverlays();
|
||||||
|
goog.asserts.assert(goog.isDef(overlays));
|
||||||
|
if (goog.isDef(overlays.remove(overlay))) {
|
||||||
|
overlay.setMap(null);
|
||||||
|
return overlay;
|
||||||
|
}
|
||||||
|
return undefined;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {number} time Time.
|
* @param {number} time Time.
|
||||||
* @private
|
* @private
|
||||||
@@ -1042,6 +1093,7 @@ ol.Map.prototype.withFrozenRendering = function(f, opt_obj) {
|
|||||||
/**
|
/**
|
||||||
* @typedef {{controls: ol.Collection,
|
* @typedef {{controls: ol.Collection,
|
||||||
* interactions: ol.Collection,
|
* interactions: ol.Collection,
|
||||||
|
* overlays: ol.Collection,
|
||||||
* rendererConstructor:
|
* rendererConstructor:
|
||||||
* function(new: ol.renderer.Map, Element, ol.Map),
|
* function(new: ol.renderer.Map, Element, ol.Map),
|
||||||
* values: Object.<string, *>}}
|
* values: Object.<string, *>}}
|
||||||
@@ -1123,9 +1175,22 @@ 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();
|
||||||
|
|
||||||
|
var overlays;
|
||||||
|
if (goog.isDef(options.overlays)) {
|
||||||
|
if (goog.isArray(options.overlays)) {
|
||||||
|
overlays = new ol.Collection(goog.array.clone(options.overlays));
|
||||||
|
} else {
|
||||||
|
goog.asserts.assertInstanceof(options.overlays, ol.Collection);
|
||||||
|
overlays = options.overlays;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
overlays = new ol.Collection();
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
controls: controls,
|
controls: controls,
|
||||||
interactions: interactions,
|
interactions: interactions,
|
||||||
|
overlays: overlays,
|
||||||
rendererConstructor: rendererConstructor,
|
rendererConstructor: rendererConstructor,
|
||||||
values: values
|
values: values
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user