The map now has a viewport and can render to a container.

This commit is contained in:
ahocevar
2012-06-21 18:56:48 +02:00
parent 8f90db58dc
commit e9e5fd27dc
3 changed files with 34 additions and 2 deletions

View File

@@ -1 +1,2 @@
.ol-renderer-webgl-canvas { width:100%;height:100%; } .ol-viewport { width:100%; height:100%; position:relative; left:0; top:0; }
.ol-renderer-webgl-canvas { width:100%; height:100%; }

View File

@@ -18,7 +18,7 @@ ol.MapLike;
* @param {ol.MapLike=} opt_arg Argument. * @param {ol.MapLike=} opt_arg Argument.
* @return {ol.Map} Map. * @return {ol.Map} Map.
*/ */
ol.map = function(opt_arg){ ol.map = function(opt_arg) {
/** @type {ol.Loc|undefined} */ /** @type {ol.Loc|undefined} */
var center; var center;
@@ -36,6 +36,8 @@ ol.map = function(opt_arg){
var maxRes; var maxRes;
/** @type {Array.<number>|undefined} */ /** @type {Array.<number>|undefined} */
var resolutions; var resolutions;
/** @type {Element|string|undefined} */
var el;
/** @type {Array|undefined} */ /** @type {Array|undefined} */
var layers; var layers;
/** @type {Array|undefined} */ /** @type {Array|undefined} */
@@ -54,6 +56,7 @@ ol.map = function(opt_arg){
maxExtent = opt_arg['maxExtent']; maxExtent = opt_arg['maxExtent'];
maxRes = opt_arg['maxRes']; maxRes = opt_arg['maxRes'];
resolutions = opt_arg['resolutions']; resolutions = opt_arg['resolutions'];
el = opt_arg['el'];
layers = opt_arg['layers']; layers = opt_arg['layers'];
controls = opt_arg['controls']; controls = opt_arg['controls'];
} }
@@ -63,6 +66,9 @@ ol.map = function(opt_arg){
} }
var map = new ol.Map(); var map = new ol.Map();
if (goog.isDef(el)) {
map.el(el);
}
if (goog.isDef(center)) { if (goog.isDef(center)) {
map.setCenter(ol.loc(center)); map.setCenter(ol.loc(center));
} }
@@ -244,3 +250,12 @@ ol.Map.prototype.maxRes = function(opt_arg) {
ol.Map.prototype.getResForZoom = function(arg) { ol.Map.prototype.getResForZoom = function(arg) {
return this.getResolutionForZoom(arg); return this.getResolutionForZoom(arg);
}; };
/**
* @param {string|Element} arg Render the map to a container
* @returns {ol.Map}
*/
ol.Map.prototype.el = function(arg) {
this.setContainer(goog.dom.getElement(arg));
return this;
};

View File

@@ -74,6 +74,12 @@ ol.Map = function() {
*/ */
this.maxRes_ = undefined; this.maxRes_ = undefined;
/**
* @private
* @type {Element}
*/
this.viewport_ = null;
/** /**
* @private * @private
* @type {ol.event.Events} * @type {ol.event.Events}
@@ -332,6 +338,16 @@ ol.Map.prototype.setMaxRes = function(res) {
ol.Map.prototype.setContainer = function(container) { ol.Map.prototype.setContainer = function(container) {
this.events_.setElement(container); this.events_.setElement(container);
this.container_ = container; this.container_ = container;
this.setViewport();
};
ol.Map.prototype.setViewport = function() {
if (!this.viewport_) {
this.viewport_ = goog.dom.createDom(
'div', 'ol-viewport'
);
goog.dom.appendChild(this.container_, this.viewport_);
}
}; };
/** /**