diff --git a/Makefile b/Makefile
index b9e9df4e14..edd10287c4 100644
--- a/Makefile
+++ b/Makefile
@@ -20,7 +20,6 @@ GSLINT_EXCLUDES= \
src/ol/control/Control.js \
src/ol/control/Navigation.js \
src/ol/control/Zoom.js \
- src/ol/coord/AccessorInterface.js \
src/ol/event/Drag.js \
src/ol/event/Events.js \
src/ol/event/ISequence.js \
@@ -34,17 +33,12 @@ GSLINT_EXCLUDES= \
src/ol/geom/MultiPoint.js \
src/ol/geom/Point.js \
src/ol/handler/Drag.js \
- src/ol/layer/OSM.js \
- src/ol/layer/TileLayer.js \
src/ol/layer/WMS.js \
- src/ol/layer/XYZ.js \
- src/ol/Loc.js \
src/ol/Popup.js \
src/ol/renderer/Composite.js \
src/ol/renderer/LayerRenderer.js \
src/ol/renderer/MapRenderer.js \
- src/ol/renderer/TileLayerRenderer.js \
- src/ol/renderer/WebGL.js
+ src/ol/renderer/TileLayerRenderer.js
comma := ,
empty :=
space := $(empty) $(empty)
diff --git a/src/ol/Loc.js b/src/ol/Loc.js
deleted file mode 100644
index 035ffa933a..0000000000
--- a/src/ol/Loc.js
+++ /dev/null
@@ -1,147 +0,0 @@
-goog.provide('ol.Loc');
-
-goog.require('ol.Projection');
-
-
-
-/**
- * @export
- * @constructor
- * @param {number} x X.
- * @param {number} y Y.
- * @param {number=} opt_z Z.
- * @param {ol.Projection=} opt_projection Projection.
- */
-ol.Loc = function(x, y, opt_z, opt_projection) {
-
- /**
- * @private
- * @type {number}
- */
- this.x_ = x;
-
- /**
- * @private
- * @type {number}
- */
- this.y_ = y;
-
- /**
- * @private
- * @type {number|undefined}
- */
- this.z_ = opt_z;
-
- /**
- * @private
- * @type {ol.Projection}
- */
- this.projection_ = goog.isDef(opt_projection) ? opt_projection : null;
-
-};
-
-
-/**
- * @return {ol.Projection|undefined} Projection.
- */
-ol.Loc.prototype.getProjection = function() {
- return this.projection_;
-};
-
-
-/**
- * @return {number} X.
- */
-ol.Loc.prototype.getX = function() {
- return this.x_;
-};
-
-
-/**
- * @return {number} Y.
- */
-ol.Loc.prototype.getY = function() {
- return this.y_;
-};
-
-
-/**
- * @return {number|undefined} Z.
- */
-ol.Loc.prototype.getZ = function() {
- return this.z_;
-};
-
-
-/**
- * @param {ol.Projection} projection Projection.
- */
-ol.Loc.prototype.setProjection = function(projection) {
- this.projection_ = projection;
-};
-
-
-/**
- * @param {number} x X.
- */
-ol.Loc.prototype.setX = function(x) {
- this.x_ = x;
-};
-
-
-/**
- * @param {number} y Y.
- */
-ol.Loc.prototype.setY = function(y) {
- this.y_ = y;
-};
-
-
-/**
- * @param {number|undefined} z Z.
- */
-ol.Loc.prototype.setZ = function(z) {
- this.z_ = z;
-};
-
-/**
- * Transform this location to a new location given a projection object.
- *
- * @param {ol.Projection} proj The destination projection.
- * @returns {ol.Loc}
- */
-ol.Loc.prototype.doTransform = function(proj) {
- var point = {'x': this.x_, 'y': this.y_};
- var sourceProj = this.projection_;
- if (!goog.isDefAndNotNull(sourceProj)) {
- throw new Error("Cannot transform a location without a source projection.");
- }
- ol.Projection.transform(point, sourceProj, proj);
- return new ol.Loc(point['x'], point['y'], this.z_, proj);
-};
-
-/**
- * Adds the passed x, y(, z) delta to a new location.
- *
- * @param {number} x
- * @param {number} y
- * @param {number=} opt_z
- * @returns {ol.Loc}
- */
-ol.Loc.prototype.add = function(x, y, opt_z) {
- var newZ;
- if (goog.isDef(this.z_)) {
- newZ = (opt_z || 0) + this.z_;
- }
- return new ol.Loc(this.x_ + x, this.y_ + y, newZ, this.projection_);
-};
-
-/**
- * Clean up.
- * @export
- */
-ol.Loc.prototype.destroy = function() {
- for (var key in this) {
- delete this[key];
- }
-};
diff --git a/src/ol/layer/OSM.js b/src/ol/layer/OSM.js
deleted file mode 100644
index b628e3119d..0000000000
--- a/src/ol/layer/OSM.js
+++ /dev/null
@@ -1,21 +0,0 @@
-goog.provide('ol.layer.OSM');
-
-goog.require('ol.layer.XYZ');
-
-/**
- * Class for OSM layers.
- *
- * @export
- * @constructor
- * @extends {ol.layer.XYZ}
- */
-ol.layer.OSM = function() {
-
- //TODO Is this attribution still correct?
- /** @inheritDoc */
- this.attribution_ = "Data CC-By-SA by OpenStreetMap";
-
- goog.base(this, 'http://a.tile.openstreetmap.org/{z}/{x}/{y}.png');
-};
-
-goog.inherits(ol.layer.OSM, ol.layer.XYZ);
diff --git a/src/ol/layer/TileLayer.js b/src/ol/layer/TileLayer.js
deleted file mode 100644
index 0b2bc7cc1e..0000000000
--- a/src/ol/layer/TileLayer.js
+++ /dev/null
@@ -1,490 +0,0 @@
-goog.provide('ol.layer.TileLayer');
-
-goog.require('ol.error');
-goog.require('ol.layer.Layer');
-goog.require('ol.Tile');
-goog.require('ol.TileCache');
-
-/**
- * @constructor
- * @extends {ol.layer.Layer}
- */
-ol.layer.TileLayer = function() {
-
- /**
- * @private
- * @type {string|undefined}
- */
- this.url_ = undefined;
-
- /**
- * @protected
- * @type {ol.Projection}
- */
- this.projection_ = null;
-
- /**
- * @private
- * @type {ol.Bounds}
- */
- this.extent_ = null;
-
- /**
- * @protected
- * @type {number}
- */
- this.tileWidth_ = 256;
-
- /**
- * @protected
- * @type {number}
- */
- this.tileHeight_ = 256;
-
- /**
- * @protected
- * @type {function(new:ol.Tile, string, ol.Bounds=)}
- */
- this.Tile = ol.Tile.createConstructor(this.tileWidth_, this.tileHeight_);
-
- /**
- * @protected
- * @type {number|undefined}
- */
- this.tileOriginX_ = undefined;
-
- /**
- * @protected
- * @type {number|undefined}
- */
- this.tileOriginY_ = undefined;
-
- /**
- * @private
- * @type {string}
- */
- this.tileOriginCorner_ = 'tl';
-
- /**
- * @private
- * @type {number|undefined}
- */
- this.maxResolution_ = undefined;
-
- /**
- * @private
- * @type {boolean}
- */
- this.xRight_ = true;
-
- /**
- * @private
- * @type {boolean}
- */
- this.yDown_ = true;
-
- /**
- * @private
- * @type {number|undefined}
- */
- this.numZoomLevels_ = undefined;
-
- /**
- * @protected
- * @type {Array.}
- */
- this.resolutions_ = null;
-
- /**
- * @private
- * @type {ol.TileCache}
- */
- this.cache_ = new ol.TileCache();
-
-};
-
-goog.inherits(ol.layer.TileLayer, ol.layer.Layer);
-
-/**
- * @protected
- * @param {number} x
- * @param {number} y
- * @param {number} z
- * @return {string}
- */
-ol.layer.TileLayer.prototype.getTileUrl = function(x, y, z) {
- // overridden by subclasses
-};
-
-/**
- * @return {string|undefined} The layer URL.
- */
-ol.layer.TileLayer.prototype.getUrl = function() {
- return this.url_;
-};
-
-/**
- * @return {boolean} The tile index increases from left to right.
- */
-ol.layer.TileLayer.prototype.getXRight = function() {
- return this.xRight_;
-};
-
-/**
- * @return {boolean} The tile index increases from top to bottom.
- */
-ol.layer.TileLayer.prototype.getYDown = function() {
- return this.yDown_;
-};
-
-/**
- * @param {boolean} right The tile index increases from left to right.
- */
-ol.layer.TileLayer.prototype.setXRight = function(right) {
- this.xRight_ = right;
-};
-
-/**
- * @param {boolean} down The tile index increases from top to bottom.
- */
-ol.layer.TileLayer.prototype.setYDown = function(down) {
- this.yDown_ = down;
-};
-
-/**
- * Get layer extent. Return null if the layer has no extent
- * and no projection.
- * @return {ol.UnreferencedBounds}
- */
-ol.layer.TileLayer.prototype.getExtent = function() {
- if (!goog.isNull(this.extent_)) {
- return this.extent_;
- }
- if (!goog.isNull(this.projection_)) {
- return this.projection_.getExtent();
- }
- return null;
-};
-
-/**
- * Get tile size.
- * @return {Array.}
- */
-ol.layer.TileLayer.prototype.getTileSize = function() {
- return [this.tileWidth_, this.tileHeight_];
-};
-
-/**
- * Get tile origin.
- * @return {Array.}
- */
-ol.layer.TileLayer.prototype.getTileOrigin = function() {
- if (goog.isDef(this.tileOriginX_) &&
- goog.isDef(this.tileOriginY_)) {
- return [this.tileOriginX_, this.tileOriginY_];
- }
- var errmsg = 'Cannot calculate tile origin; ';
- if (goog.isDef(this.tileOriginCorner_)) {
- var extent = this.getExtent();
- if (!goog.isNull(extent)) {
- var tileOriginX, tileOriginY;
- switch (this.tileOriginCorner_) {
- case "tl":
- tileOriginX = extent.getMinX();
- tileOriginY = extent.getMaxY();
- break;
- case "tr":
- tileOriginX = extent.getMaxX();
- tileOriginY = extent.getMaxY();
- break;
- case "bl":
- tileOriginX = extent.getMinX();
- tileOriginY = extent.getMinY();
- break;
- case "br":
- tileOriginX = extent.getMaxX();
- tileOriginY = extent.getMinY();
- break;
- default:
- errmsg += 'tileOriginCorner value is incorrect.';
- ol.error(errmsg);
- }
- return [tileOriginX, tileOriginY];
- }
- errmsg += 'layer has no extent.';
- ol.error(errmsg);
- }
- errmsg += 'layer has no tileOriginCorner.';
- ol.error(errmsg);
- return null;
-};
-
-/**
- * Get max resolution. Return undefined if the layer has no maxResolution,
- * and no extent from which maxResolution could be derived.
- * @return {number|undefined}
- */
-ol.layer.TileLayer.prototype.getMaxResolution = function() {
- if (!goog.isDef(this.maxResolution_)) {
- var extent = this.getExtent();
- if (!goog.isNull(extent)) {
- this.maxResolution_ = Math.max(
- (extent.getMaxX() - extent.getMinX()) / this.tileWidth_,
- (extent.getMaxY() - extent.getMinY()) / this.tileHeight_);
- }
- }
- return this.maxResolution_;
-};
-
-/**
- * Get the number of the zoom levels.
- * @return {number|undefined}
- */
-ol.layer.TileLayer.prototype.getNumZoomLevels = function() {
- return this.numZoomLevels_;
-};
-
-/**
- * Get layer resolutions. Return null if the layer has no resolutions.
- * @return {Array.}
- */
-ol.layer.TileLayer.prototype.getResolutions = function() {
- if (goog.isNull(this.resolutions_)) {
- var maxResolution = this.getMaxResolution(),
- numZoomLevels = this.getNumZoomLevels();
- if (goog.isDef(maxResolution) && goog.isDef(numZoomLevels)) {
- this.resolutions_ = [];
- for (var i = 0; i < numZoomLevels; i++) {
- this.resolutions_[i] = maxResolution / Math.pow(2, i);
- }
- }
- }
- return this.resolutions_;
-};
-
-/**
- * Set the layer URL.
- * @param {string} url
- */
-ol.layer.TileLayer.prototype.setUrl = function(url) {
- this.url_ = url;
-};
-
-/**
- * Set layer projection.
- * @param {ol.Projection} projection
- */
-ol.layer.TileLayer.prototype.setProjection = function(projection) {
- this.projection_ = projection;
-};
-
-/**
- * Set layer extent.
- * @param {ol.Bounds} extent
- */
-ol.layer.TileLayer.prototype.setExtent = function(extent) {
- this.extent_ = extent;
-};
-
-/**
- * Set tile origin.
- * @param {number} tileOriginX
- * @param {number} tileOriginY
- */
-ol.layer.TileLayer.prototype.setTileOrigin = function(tileOriginX, tileOriginY) {
- this.tileOriginX_ = tileOriginX;
- this.tileOriginY_ = tileOriginY;
-};
-
-/**
- * Set tile origin corner.
- * @param {string} tileOriginCorner
- */
-ol.layer.TileLayer.prototype.setTileOriginCorner = function(tileOriginCorner) {
- this.tileOriginCorner_ = tileOriginCorner;
-};
-
-/**
- * Set maximum resolution.
- * @param {number} maxResolution
- */
-ol.layer.TileLayer.prototype.setMaxResolution = function(maxResolution) {
- this.maxResolution_ = maxResolution;
-};
-
-/**
- * Set the number of zoom levels.
- * @param {number} numZoomLevels
- */
-ol.layer.TileLayer.prototype.setNumZoomLevels = function(numZoomLevels) {
- this.numZoomLevels_ = numZoomLevels;
-};
-
-/**
- * Set resolutions for the layer.
- * @param {Array.} resolutions
- */
-ol.layer.TileLayer.prototype.setResolutions = function(resolutions) {
- this.resolutions_ = resolutions;
-};
-
-/**
- * Get a tile from the cache, or create a tile and add to
- * the cache.
- * @param url {string}
- * @param bounds {ol.Bounds}
- */
-ol.layer.TileLayer.prototype.getTile = function(url, bounds) {
- var tile = this.cache_.get(url);
- if (!goog.isDef(tile)) {
- tile = new this.Tile(url, bounds);
- this.cache_.set(tile.getUrl(), tile);
- }
- return tile;
-};
-
-/**
- * Get a tile from the cache, or create a tile and add to
- * the cache.
- * @param {number} x
- * @param {number} y
- * @param {number} z
- */
-ol.layer.TileLayer.prototype.getTileForXYZ = function(x, y, z) {
- if (!this.validXY(x, y, z)) {
- return null;
- }
- var tileUrl = this.getTileUrl(x, y, z);
- var tile = this.cache_.get(tileUrl);
- if (!goog.isDef(tile)) {
- tile = new this.Tile(tileUrl);
- this.cache_.set(tileUrl, tile);
- }
- return tile;
-};
-
-/**
- * Determine if the tile x/y/z intersects the layer extent. Always
- * return true if the layer has no extent.
- * @param {number} x
- * @param {number} y
- * @param {number} z
- * @return {boolean}
- */
-ol.layer.TileLayer.prototype.validXY = function(x, y, z) {
- var extent = this.getExtent();
- if (goog.isNull(extent)) {
- return true;
- }
- var extentMinX = extent.getMinX(),
- extentMinY = extent.getMinY(),
- extentMaxX = extent.getMaxX(),
- extentMaxY = extent.getMaxY();
- var tileOrigin = this.getTileOrigin(),
- tileOriginX = tileOrigin[0],
- tileOriginY = tileOrigin[1];
- var resolution = this.getResolutions()[z];
- var tileWidth = this.tileWidth_ * resolution,
- tileHeight = this.tileHeight_ * resolution;
- var minX, maxX;
- if (this.xRight_) {
- minX = Math.floor((extentMinX - tileOriginX) / tileWidth);
- maxX = Math.ceil((extentMaxX - tileOriginX) / tileWidth) - 1;
- } else {
- minX = Math.floor((tileOriginX - extentMaxX) / tileWidth);
- maxX = Math.ceil((tileOriginX - extentMinX) / tileWidth) - 1;
- }
- var minY, maxY;
- if (this.yDown_) {
- minY = Math.floor((tileOriginY - extentMaxY) / tileHeight);
- maxY = Math.ceil((tileOriginY - extentMinY) / tileHeight) - 1;
- } else {
- minY = Math.floor((extentMinY - tileOriginY) / tileHeight);
- maxY = Math.ceil((extentMaxY - tileOriginY) / tileHeight) - 1;
- }
- return x >= minX && x <= maxX && y >= minY && y <= maxY;
-};
-
-/**
- * Get data from the layer. This is the layer's main API function.
- * @param {ol.Bounds} bounds
- * @param {number} resolution
- */
-ol.layer.TileLayer.prototype.getData = function(bounds, resolution) {
- var me = this,
- zoomAndRes = me.getZoomAndRes(resolution),
- zoom = zoomAndRes[0];
- resolution = zoomAndRes[1];
-
- // define some values used for the actual tiling
- var boundsMinX = bounds.getMinX(),
- boundsMaxX = bounds.getMaxX(),
- boundsMinY = bounds.getMinY(),
- boundsMaxY = bounds.getMaxY(),
- tileWidth = me.tileWidth_,
- tileHeight = me.tileHeight_,
- tileOrigin = me.getTileOrigin(),
- tileOriginX = tileOrigin[0],
- tileOriginY = tileOrigin[1],
- tileWidthGeo = tileWidth * resolution,
- tileHeightGeo = tileHeight * resolution;
-
- // make sure we don't create tiles outside the layer extent
- var extent = this.getExtent();
- if (extent) {
- boundsMinX = Math.max(boundsMinX, extent.getMinX());
- boundsMaxX = Math.min(boundsMaxX, extent.getMaxX());
- boundsMinY = Math.max(boundsMinY, extent.getMinY());
- boundsMaxY = Math.min(boundsMaxY, extent.getMaxY());
- }
-
- var offsetX = Math.floor(
- (boundsMinX - tileOriginX) / tileWidthGeo),
- offsetY = Math.floor(
- (tileOriginY - boundsMaxY) / tileHeightGeo),
- gridLeft = tileOriginX + tileWidthGeo * offsetX,
- gridTop = tileOriginY - tileHeightGeo * offsetY;
-
- // now tile
- var tiles = [],
- tile,
- url,
- tileBottom, tileRight, tileBounds;
- for (var y=0, tileTop=gridTop; tileTop > boundsMinY;
- ++y, tileTop-=tileHeightGeo) {
- tiles[y] = [];
- tileBottom = tileTop - tileHeightGeo;
- for (var x=0, tileLeft=gridLeft; tileLeft < boundsMaxX;
- ++x, tileLeft+=tileWidthGeo) {
- tileRight = tileLeft + tileWidthGeo;
- tileBounds = new ol.Bounds(tileLeft, tileBottom,
- tileRight, tileTop, this.projection_);
- url = this.getTileUrl(offsetX + x, offsetY + y, zoom);
- tile = this.getTile(url, tileBounds);
- tiles[y][x] = tile;
- }
- }
-
- return new ol.TileSet(tiles, tileWidth, tileHeight, resolution);
-};
-
-/**
- * Get the zoom level (z) and layer resolution for the given resolution.
- * @param {number} resolution
- * @return {Array.}
- */
-ol.layer.TileLayer.prototype.getZoomAndRes = function(resolution) {
- var delta = Number.POSITIVE_INFINITY,
- currentDelta,
- resolutions = this.getResolutions(),
- zoom;
- for (var i=resolutions.length-1; i>=0; --i) {
- currentDelta = Math.abs(resolutions[i] - resolution);
- if (currentDelta > delta) {
- break;
- }
- delta = currentDelta;
- }
- zoom = i + 1;
- return [zoom, resolutions[zoom]];
-};
diff --git a/src/ol/layer/XYZ.js b/src/ol/layer/XYZ.js
deleted file mode 100644
index 4a1c16fe86..0000000000
--- a/src/ol/layer/XYZ.js
+++ /dev/null
@@ -1,35 +0,0 @@
-goog.provide('ol.layer.XYZ');
-
-goog.require('ol.layer.TileLayer');
-goog.require('ol.Projection');
-goog.require('ol.TileSet');
-
-/**
- * Class for XYZ layers.
- *
- * @export
- * @constructor
- * @extends {ol.layer.TileLayer}
- * @param {string} url URL template. E.g.
- * http://a.tile.openstreetmap.org/{z}/{x}/{y}.png.
- */
-ol.layer.XYZ = function(url) {
-
- goog.base(this);
-
- this.setUrl(url);
- this.setProjection(new ol.Projection("EPSG:3857"));
- this.setNumZoomLevels(22);
-};
-
-goog.inherits(ol.layer.XYZ, ol.layer.TileLayer);
-
-/**
- * @inheritDoc
- */
-ol.layer.XYZ.prototype.getTileUrl = function(x, y, z) {
- var base = this.getUrl();
- return base.replace('{x}', x + '')
- .replace('{y}', y + '')
- .replace('{z}', z + '');
-};
diff --git a/src/ol/renderer/WebGL.js b/src/ol/renderer/WebGL.js
deleted file mode 100644
index ff86f4584e..0000000000
--- a/src/ol/renderer/WebGL.js
+++ /dev/null
@@ -1,273 +0,0 @@
-/**
- * @fileoverview WebGL based MapRenderer drawing all the supplied layers in OpenGL
- */
-
-goog.provide('ol.renderer.WebGL');
-
-goog.require('ol.renderer.MapRenderer');
-goog.require('ol.layer.Layer');
-goog.require('ol.Loc');
-
-goog.require('goog.array');
-goog.require('goog.asserts');
-goog.require('goog.vec.Mat4');
-goog.require('goog.webgl');
-
-/**
- * Initialization of the native WebGL renderer (canvas, context, layers)
- * @constructor
- * @param {!Element} container
- * @extends {ol.renderer.MapRenderer}
- */
-ol.renderer.WebGL = function(container) {
-
- /**
- * @private
- * @type {!Element}
- */
- this.canvas_ = goog.dom.createDom('canvas', 'ol-renderer-webgl-canvas'); // Suppose to have: style: 'width:100%;height:100%;'
-
- /**
- * @private
- * @type {WebGLRenderingContext}
- */
- this.gl_ = (this.canvas_.getContext('experimental-webgl', {
- 'alpha': false,
- 'depth': false,
- 'antialias': true,
- 'stencil': false,
- 'preserveDrawingBuffer': false
- }));
- goog.asserts.assert(!goog.isNull(this.gl_), "The WebGL is not supported on your browser. Check http://get.webgl.org/");
-
- goog.dom.append(container, this.canvas_);
-
- goog.base(this, container);
-
- /**
- * @private
- * @type {Object.}
- */
- this.textureCache_ = {};
-
- var gl = this.gl_;
-
- var clearColor = [0, 0, 0]; // hardcoded background color
- gl.clearColor(clearColor[0], clearColor[1], clearColor[2], 1);
- gl.disable(goog.webgl.DEPTH_TEST);
- gl.disable(goog.webgl.SCISSOR_TEST);
- gl.disable(goog.webgl.CULL_FACE);
-
- var fragmentShader = gl.createShader(goog.webgl.FRAGMENT_SHADER);
- gl.shaderSource(fragmentShader, [
- 'precision mediump float;',
- '',
- 'uniform sampler2D uTexture;',
- '',
- 'varying vec2 vTexCoord;',
- '',
- 'void main(void) {',
- ' gl_FragColor = vec4(vec3(texture2D(uTexture, vTexCoord)), 1.);',
- '}'
- ].join('\n'));
- gl.compileShader(fragmentShader);
- if (!gl.getShaderParameter(fragmentShader, goog.webgl.COMPILE_STATUS)) {
- window.console.log(gl.getShaderInfoLog(fragmentShader));
- goog.asserts.assert(gl.getShaderParameter(fragmentShader, goog.webgl.COMPILE_STATUS));
- }
-
- var vertexShader = gl.createShader(goog.webgl.VERTEX_SHADER);
- gl.shaderSource(vertexShader, [
- 'attribute vec2 aPosition;',
- 'attribute vec2 aTexCoord;',
- '',
- 'uniform mat4 uMVPMatrix;',
- '',
- 'varying vec2 vTexCoord;',
- '',
- 'void main(void) {',
- ' gl_Position = uMVPMatrix * vec4(aPosition, 0.0, 1.0);',
- ' vTexCoord = aTexCoord;',
- '}'
- ].join('\n'));
- if (!gl.getShaderParameter(vertexShader, goog.webgl.COMPILE_STATUS)) {
- window.console.log(gl.getShaderInfoLog(vertexShader));
- goog.asserts.assert(gl.getShaderParameter(vertexShader, goog.webgl.COMPILE_STATUS));
- }
-
- var program = gl.createProgram();
- gl.attachShader(program, fragmentShader);
- gl.attachShader(program, vertexShader);
- gl.linkProgram(program);
- if (!gl.getProgramParameter(program, goog.webgl.LINK_STATUS)) {
- window.console.log(gl.getProgramInfoLog(program));
- goog.asserts.assert(gl.getProgramParameter(program, goog.webgl.LINK_STATUS));
- }
-
- this.mvpMatrixLocation_ = gl.getUniformLocation(program, 'uMVPMatrix');
- this.textureLocation_ = gl.getUniformLocation(program, 'uTexture');
-
- var texCoordBuffer = gl.createBuffer();
- gl.bindBuffer(goog.webgl.ARRAY_BUFFER, texCoordBuffer);
- gl.bufferData(goog.webgl.ARRAY_BUFFER, new Float32Array([0, 1, 1, 1, 0, 0, 1, 0]), goog.webgl.STATIC_DRAW);
- var texCoordLocation = gl.getAttributeLocation(program, 'aTexCoord');
- gl.enableVertexAttribArray(texCoordLocation);
- gl.vertexAttribPointer(texCoordLocation, 2, goog.webgl.FLOAT, false, 0, 0);
- gl.bindBuffer(goog.webgl.ARRAY_BUFFER, null);
-
- this.positionLocation_ = gl.getAttributeLocation(program, 'aPosition');
- gl.enableVertexAttribArray(this.positionLocation_);
- this.positionBuffer_ = gl.createBuffer();
-
-};
-
-goog.inherits(ol.renderer.WebGL, ol.renderer.MapRenderer);
-
-
-/**
- * Determine if this renderer type is supported in this environment.
- * A static method.
- * @returns {boolean} This renderer is supported.
- */
-ol.renderer.WebGL.isSupported = function() {
- return !goog.isNull( goog.dom.createDom('canvas').getContext('experimental-webgl') );
-};
-
-
-/**
- * @param {ol.Tile} tile Tile.
- * @protected
- */
-ol.renderer.WebGL.prototype.bindTexture = function(tile) {
- var gl = this.gl_;
- var url = tile.getUrl();
- if (url in this.textureCache_) {
- gl.bindTexture(gl.TEXTURE_2D, this.textureCache_[url]);
- } else {
- var texture = gl.createTexture();
- gl.bindTexture(goog.webgl.TEXTURE_2D, texture);
- gl.texImage2D(goog.webgl.TEXTURE_2D, 0, goog.webgl.RGBA, goog.webgl.RGBA, goog.webgl.UNSIGNED_BYTE, tile.getImg());
- gl.texParameteri(goog.webgl.TEXTURE_2D, goog.webgl.TEXTURE_MAG_FILTER, goog.webgl.LINEAR);
- gl.texParameteri(goog.webgl.TEXTURE_2D, goog.webgl.TEXTURE_MIN_FILTER, goog.webgl.LINEAR);
- this.textureCache_[url] = texture;
- }
-};
-
-
-/**
- * @param {ol.Tile} tile Tile.
- * @protected
- */
-ol.renderer.WebGL.prototype.handleTileLoad = function(tile) {
- this.redraw();
-};
-
-
-/**
- * @param {ol.Tile} tile Tile.
- * @protected
- */
-ol.renderer.WebGL.prototype.handleTileDestroy = function(tile) {
- var gl = this.gl_;
- var url = tile.getUrl();
- if (url in this.textureCache_) {
- gl.deleteTexture(this.textureCache_[url]);
- delete this.textureCache_[url];
- }
-};
-
-
-/**
- * @inheritDoc
- */
-ol.renderer.WebGL.prototype.draw = function(layers, center, resolution, animate) {
-
- var gl = this.gl_;
-
- var width = this.canvas_.width;
- var height = this.canvas_.height;
-
- var bounds = new ol.Bounds(
- center.getX() - width * resolution / 2,
- center.getY() - height * resolution / 2,
- center.getX() + width * resolution / 2,
- center.getY() + height * resolution / 2,
- center.getProjection());
-
- /** @type {goog.vec.Mat4.Type} */
- var cameraMatrix;
- goog.vec.Mat4.makeIdentity(cameraMatrix);
- goog.vec.Mat4.scale(cameraMatrix, resolution, resolution, 1);
- goog.vec.Mat4.translate(cameraMatrix, -center.getX(), -center.getY(), 0);
-
- /** @type {goog.vec.Mat4.Type} */
- var positionToViewportMatrix;
- goog.vec.Mat4.makeIdentity(positionToViewportMatrix);
- goog.vec.Mat4.scale(positionToViewportMatrix, 1 / width, 1 / height, 1);
- goog.vec.Mat4.multMat(positionToViewportMatrix, cameraMatrix, positionToViewportMatrix);
-
- /** @type {goog.vec.Mat4.Type} */
- var viewportToPositionMatrix;
- var inverted = goog.vec.Mat4.invert(positionToViewportMatrix, viewportToPositionMatrix);
- goog.asserts.assert(inverted);
-
- /** @type {goog.vec.Mat4.Type} */
- var targetPixelToPositionMatrix;
- goog.vec.Mat4.makeIdentity(targetPixelToPositionMatrix);
- goog.vec.Mat4.translate(targetPixelToPositionMatrix, -1, 1, 0);
- goog.vec.Mat4.scale(targetPixelToPositionMatrix, 2 / width, -2 / height, 1);
- goog.vec.Mat4.multMat(viewportToPositionMatrix, targetPixelToPositionMatrix, targetPixelToPositionMatrix);
-
- gl.clear(goog.webgl.COLOR_BUFFER_BIT);
- gl.bindBuffer(goog.webgl.ARRAY_BUFFER, this.positionBuffer_);
- gl.uniform1i(this.textureLocation_, 0);
- gl.uniformMatrix4fv(this.positionLocation_, false, positionToViewportMatrix);
-
- goog.array.forEach(layers, function(layer) {
- if (!(layer instanceof ol.layer.TileLayer)) {
- return;
- }
- var tileLayer = /** @type {ol.layer.TileLayer} */ (layer);
- var tileSet = layer.getData(bounds, resolution);
- var tiles = tileSet.getTiles();
- var i, j, row, tile, tileBounds, positions, texture;
- for (i = 0; i < tiles.length; ++i) {
- row = tiles[i];
- for (j = 0; j < row.length; ++j) {
- tile = row[j];
- if (!tile.isLoaded()) {
- if (!tile.isLoading()) {
- tile.register('load', this.handleTileLoad, this);
- tile.register('destroy', this.handleTileDestroy, this);
- tile.load();
- }
- continue;
- }
- tileBounds = tile.getBounds();
- positions = [
- tileBounds.getMinX(), tileBounds.getMinY(),
- tileBounds.getMaxX(), tileBounds.getMinY(),
- tileBounds.getMinX(), tileBounds.getMaxY(),
- tileBounds.getMaxX(), tileBounds.getMaxY()
- ];
- gl.bufferData(goog.webgl.ARRAY_BUFFER, new Float32Array(positions), goog.webgl.DYNAMIC_DRAW);
- gl.vertexAttribPointer(this.positionLocation_, 2, goog.webgl.FLOAT, false, 0, 0);
- this.bindTexture(tile);
- gl.drawArrays(goog.webgl.TRIANGLES, 0, 4);
- }
- }
- }, this);
-
- this.renderedLayers_ = layers;
- this.renderedCenter_ = center;
- this.renderedResolution_ = resolution;
- this.renderedAnimate_ = animate;
-
-};
-
-
-/**
- */
-ol.renderer.WebGL.prototype.redraw = function() {
- this.draw(this.renderedLayers_, this.renderedCenter_, this.renderedResolution_, this.renderedAnimate_);
-};