Merge branch 'master' of github.com:openlayers/ol3 into vector
This commit is contained in:
@@ -70,6 +70,12 @@ Proj4js.Proj.prototype.title;
|
|||||||
Proj4js.Proj.prototype.units;
|
Proj4js.Proj.prototype.units;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @type {string}
|
||||||
|
*/
|
||||||
|
Proj4js.Proj.prototype.srsCode;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @nosideeffects
|
* @nosideeffects
|
||||||
* @param {Proj4js.Proj} source
|
* @param {Proj4js.Proj} source
|
||||||
|
|||||||
@@ -410,7 +410,12 @@ ol.projection.getProj4jsProjectionFromCode_ = function(code) {
|
|||||||
var proj4jsProjection = proj4jsProjections[code];
|
var proj4jsProjection = proj4jsProjections[code];
|
||||||
if (!goog.isDef(proj4jsProjection)) {
|
if (!goog.isDef(proj4jsProjection)) {
|
||||||
var proj4jsProj = new Proj4js.Proj(code);
|
var proj4jsProj = new Proj4js.Proj(code);
|
||||||
proj4jsProjection = new ol.Proj4jsProjection_(code, proj4jsProj);
|
var srsCode = proj4jsProj.srsCode;
|
||||||
|
proj4jsProjection = proj4jsProjections[srsCode];
|
||||||
|
if (!goog.isDef(proj4jsProjection)) {
|
||||||
|
proj4jsProjection = new ol.Proj4jsProjection_(srsCode, proj4jsProj);
|
||||||
|
proj4jsProjections[srsCode] = proj4jsProjection;
|
||||||
|
}
|
||||||
proj4jsProjections[code] = proj4jsProjection;
|
proj4jsProjections[code] = proj4jsProjection;
|
||||||
}
|
}
|
||||||
return proj4jsProjection;
|
return proj4jsProjection;
|
||||||
|
|||||||
@@ -158,8 +158,7 @@ ol.renderer.canvas.TileLayer.prototype.renderFrame =
|
|||||||
|
|
||||||
tileState = tile.getState();
|
tileState = tile.getState();
|
||||||
if (tileState == ol.TileState.IDLE) {
|
if (tileState == ol.TileState.IDLE) {
|
||||||
goog.events.listenOnce(tile, goog.events.EventType.CHANGE,
|
this.listenToTileChange(tile);
|
||||||
this.handleTileChange, false, this);
|
|
||||||
this.updateWantedTiles(frameState.wantedTiles, tileSource, tileCoord);
|
this.updateWantedTiles(frameState.wantedTiles, tileSource, tileCoord);
|
||||||
tileCenter = tileGrid.getTileCoordCenter(tileCoord);
|
tileCenter = tileGrid.getTileCoordCenter(tileCoord);
|
||||||
frameState.tileQueue.enqueue(tile, tileSourceKey, tileCenter);
|
frameState.tileQueue.enqueue(tile, tileSourceKey, tileCenter);
|
||||||
|
|||||||
@@ -116,8 +116,7 @@ ol.renderer.dom.TileLayer.prototype.renderFrame =
|
|||||||
|
|
||||||
tileState = tile.getState();
|
tileState = tile.getState();
|
||||||
if (tileState == ol.TileState.IDLE) {
|
if (tileState == ol.TileState.IDLE) {
|
||||||
goog.events.listenOnce(tile, goog.events.EventType.CHANGE,
|
this.listenToTileChange(tile);
|
||||||
this.handleTileChange, false, this);
|
|
||||||
this.updateWantedTiles(frameState.wantedTiles, tileSource, tileCoord);
|
this.updateWantedTiles(frameState.wantedTiles, tileSource, tileCoord);
|
||||||
tileCenter = tileGrid.getTileCoordCenter(tileCoord);
|
tileCenter = tileGrid.getTileCoordCenter(tileCoord);
|
||||||
frameState.tileQueue.enqueue(tile, tileSourceKey, tileCenter);
|
frameState.tileQueue.enqueue(tile, tileSourceKey, tileCenter);
|
||||||
|
|||||||
@@ -40,6 +40,12 @@ ol.renderer.Layer = function(mapRenderer, layer) {
|
|||||||
*/
|
*/
|
||||||
this.layer_ = layer;
|
this.layer_ = layer;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @protected
|
||||||
|
* @type {Object.<string, boolean>}
|
||||||
|
*/
|
||||||
|
this.observedTileKeys = {};
|
||||||
|
|
||||||
goog.events.listen(this.layer_,
|
goog.events.listen(this.layer_,
|
||||||
ol.Object.getChangedEventType(ol.layer.LayerProperty.BRIGHTNESS),
|
ol.Object.getChangedEventType(ol.layer.LayerProperty.BRIGHTNESS),
|
||||||
this.handleLayerBrightnessChange, false, this);
|
this.handleLayerBrightnessChange, false, this);
|
||||||
@@ -167,13 +173,29 @@ ol.renderer.Layer.prototype.handleLayerVisibleChange = function() {
|
|||||||
/**
|
/**
|
||||||
* Handle changes in tile state.
|
* Handle changes in tile state.
|
||||||
* @param {goog.events.Event} event Tile change event.
|
* @param {goog.events.Event} event Tile change event.
|
||||||
* @protected
|
* @private
|
||||||
*/
|
*/
|
||||||
ol.renderer.Layer.prototype.handleTileChange = function(event) {
|
ol.renderer.Layer.prototype.handleTileChange_ = function(event) {
|
||||||
var tile = /** @type {ol.Tile} */ (event.target);
|
var tile = /** @type {ol.Tile} */ (event.target);
|
||||||
if (tile.getState() === ol.TileState.LOADED) {
|
if (tile.getState() === ol.TileState.LOADED) {
|
||||||
this.getMap().requestRenderFrame();
|
this.getMap().requestRenderFrame();
|
||||||
}
|
}
|
||||||
|
delete this.observedTileKeys[tile.getKey()];
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Listen once to tileKey, le change event.
|
||||||
|
* @param {ol.Tile} tile Tile.
|
||||||
|
* @protected
|
||||||
|
*/
|
||||||
|
ol.renderer.Layer.prototype.listenToTileChange = function(tile) {
|
||||||
|
var tileKey = tile.getKey();
|
||||||
|
if (!(tileKey in this.observedTileKeys)) {
|
||||||
|
this.observedTileKeys[tileKey] = true;
|
||||||
|
goog.events.listenOnce(tile, goog.events.EventType.CHANGE,
|
||||||
|
this.handleTileChange_, false, this);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -391,8 +391,7 @@ ol.renderer.webgl.TileLayer.prototype.renderFrame =
|
|||||||
|
|
||||||
tileState = tile.getState();
|
tileState = tile.getState();
|
||||||
if (tileState == ol.TileState.IDLE) {
|
if (tileState == ol.TileState.IDLE) {
|
||||||
goog.events.listenOnce(tile, goog.events.EventType.CHANGE,
|
this.listenToTileChange(tile);
|
||||||
this.handleTileChange, false, this);
|
|
||||||
this.updateWantedTiles(frameState.wantedTiles, tileSource, tileCoord);
|
this.updateWantedTiles(frameState.wantedTiles, tileSource, tileCoord);
|
||||||
tileCenter = tileGrid.getTileCoordCenter(tileCoord);
|
tileCenter = tileGrid.getTileCoordCenter(tileCoord);
|
||||||
frameState.tileQueue.enqueue(tile, tileSourceKey, tileCenter);
|
frameState.tileQueue.enqueue(tile, tileSourceKey, tileCenter);
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
// FIXME should inQueue be private?
|
||||||
|
|
||||||
goog.provide('ol.Tile');
|
goog.provide('ol.Tile');
|
||||||
goog.provide('ol.TileState');
|
goog.provide('ol.TileState');
|
||||||
|
|
||||||
@@ -28,6 +30,13 @@ ol.Tile = function(tileCoord) {
|
|||||||
|
|
||||||
goog.base(this);
|
goog.base(this);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A count incremented each time the tile is inQueue in a tile queue,
|
||||||
|
* and decremented each time the tile is dequeued from a tile queue.
|
||||||
|
* @type {number}
|
||||||
|
*/
|
||||||
|
this.inQueue = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @type {ol.TileCoord}
|
* @type {ol.TileCoord}
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -89,6 +89,8 @@ ol.TileQueue.prototype.dequeue_ = function() {
|
|||||||
}
|
}
|
||||||
var tileKey = tile.getKey();
|
var tileKey = tile.getKey();
|
||||||
delete this.queuedTileKeys_[tileKey];
|
delete this.queuedTileKeys_[tileKey];
|
||||||
|
tile.inQueue--;
|
||||||
|
goog.asserts.assert(tile.inQueue >= 0);
|
||||||
return tile;
|
return tile;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -110,6 +112,8 @@ ol.TileQueue.prototype.enqueue = function(tile, tileSourceKey, tileCenter) {
|
|||||||
this.heap_.push([priority, tile, tileSourceKey, tileCenter]);
|
this.heap_.push([priority, tile, tileSourceKey, tileCenter]);
|
||||||
this.queuedTileKeys_[tileKey] = true;
|
this.queuedTileKeys_[tileKey] = true;
|
||||||
this.siftDown_(0, this.heap_.length - 1);
|
this.siftDown_(0, this.heap_.length - 1);
|
||||||
|
tile.inQueue++;
|
||||||
|
goog.asserts.assert(tile.inQueue > 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -246,6 +250,11 @@ ol.TileQueue.prototype.reprioritize = function() {
|
|||||||
if (priority == ol.TileQueue.DROP) {
|
if (priority == ol.TileQueue.DROP) {
|
||||||
tileKey = tile.getKey();
|
tileKey = tile.getKey();
|
||||||
delete this.queuedTileKeys_[tileKey];
|
delete this.queuedTileKeys_[tileKey];
|
||||||
|
tile.inQueue--;
|
||||||
|
goog.asserts.assert(tile.inQueue >= 0);
|
||||||
|
if (tile.inQueue === 0) {
|
||||||
|
goog.events.removeAll(tile);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
node[0] = priority;
|
node[0] = priority;
|
||||||
heap[n++] = node;
|
heap[n++] = node;
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
/**
|
/**
|
||||||
Jasmine Reporter that outputs test results to the browser console.
|
Jasmine Reporter that outputs test results to the browser console.
|
||||||
Useful for running in a headless environment such as PhantomJs, ZombieJs etc.
|
Useful for running in a headless environment such as PhantomJs, ZombieJs etc.
|
||||||
|
|
||||||
Usage:
|
Usage:
|
||||||
// From your html file that loads jasmine:
|
// From your html file that loads jasmine:
|
||||||
jasmine.getEnv().addReporter(new jasmine.ConsoleReporter());
|
jasmine.getEnv().addReporter(new jasmine.ConsoleReporter());
|
||||||
jasmine.getEnv().execute();
|
jasmine.getEnv().execute();
|
||||||
*/
|
*/
|
||||||
@@ -13,17 +13,17 @@
|
|||||||
throw "jasmine library isn't loaded!";
|
throw "jasmine library isn't loaded!";
|
||||||
}
|
}
|
||||||
|
|
||||||
var ANSI = {}
|
var ANSI = {};
|
||||||
ANSI.color_map = {
|
ANSI.color_map = {
|
||||||
"green" : 32,
|
"green" : 32,
|
||||||
"red" : 31
|
"red" : 31
|
||||||
}
|
};
|
||||||
|
|
||||||
ANSI.colorize_text = function(text, color) {
|
ANSI.colorize_text = function(text, color) {
|
||||||
var color_code = this.color_map[color];
|
var color_code = this.color_map[color];
|
||||||
return "\033[" + color_code + "m" + text + "\033[0m";
|
return "\033[" + color_code + "m" + text + "\033[0m";
|
||||||
}
|
};
|
||||||
|
|
||||||
var ConsoleReporter = function() {
|
var ConsoleReporter = function() {
|
||||||
if (!console || !console.log) { throw "console isn't present!"; }
|
if (!console || !console.log) { throw "console isn't present!"; }
|
||||||
this.status = this.statuses.stopped;
|
this.status = this.statuses.stopped;
|
||||||
@@ -79,24 +79,81 @@
|
|||||||
var resultText = spec.suite.description + " : " + spec.description;
|
var resultText = spec.suite.description + " : " + spec.description;
|
||||||
this.log(resultText, "red");
|
this.log(resultText, "red");
|
||||||
|
|
||||||
var items = spec.results().getItems()
|
var items = spec.results().getItems();
|
||||||
for (var i = 0; i < items.length; i++) {
|
for (var i = 0; i < items.length; i++) {
|
||||||
var trace = items[i].trace.stack || items[i].trace;
|
var trace = items[i].trace.stack || items[i].trace;
|
||||||
this.log(trace, "red");
|
this.log(trace, "red");
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Will hold the title of the current 'group'.
|
||||||
|
*/
|
||||||
|
proto.lastTitle = "";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Pads given string up to a target length with a given character on either
|
||||||
|
* the left or right side.
|
||||||
|
*/
|
||||||
|
proto.pad = function(string, len, char, side){
|
||||||
|
var str = string + "",
|
||||||
|
whichSide = side || 'left',
|
||||||
|
buff = "",
|
||||||
|
padChar = char || " ",
|
||||||
|
padded = "",
|
||||||
|
iterEnd = len - str.length;
|
||||||
|
|
||||||
|
while(buff.length < iterEnd) {
|
||||||
|
buff += padChar;
|
||||||
|
}
|
||||||
|
if (side === 'left') {
|
||||||
|
padded = buff + str;
|
||||||
|
} else {
|
||||||
|
padded = str + buff;
|
||||||
|
}
|
||||||
|
// we still need a substring when we are called with e.g. " . " as char.
|
||||||
|
return padded.substring(0, len);
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Pads given string up to a target length with a given character on the right
|
||||||
|
* side.
|
||||||
|
*/
|
||||||
|
proto.padRight = function(str, len, char){
|
||||||
|
return this.pad(str, len, char, 'right');
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Pads given string up to a target length with a given character on the right
|
||||||
|
* side.
|
||||||
|
*/
|
||||||
|
proto.padLeft = function(str, len, char){
|
||||||
|
return this.pad(str, len, char, 'left');
|
||||||
|
};
|
||||||
|
|
||||||
proto.reportSuiteResults = function(suite) {
|
proto.reportSuiteResults = function(suite) {
|
||||||
if (!suite.parentSuite) { return; }
|
if (!suite.parentSuite) { return; }
|
||||||
|
// determine title from full name (wo/ own description)
|
||||||
|
var title = suite.getFullName().replace(new RegExp(suite.description + "$"), "");
|
||||||
|
if (this.lastTitle !== title) {
|
||||||
|
// when title differs, we have a new 'group'
|
||||||
|
this.log("\n" + title);
|
||||||
|
}
|
||||||
|
// always set current title
|
||||||
|
this.lastTitle = title;
|
||||||
|
|
||||||
var results = suite.results();
|
var results = suite.results();
|
||||||
var failed = results.totalCount - results.passedCount;
|
var failed = results.totalCount - results.passedCount;
|
||||||
var color = (failed > 0)? "red" : "green";
|
var color = (failed > 0) ? "red" : "green";
|
||||||
this.log(suite.description + ": " + results.passedCount + " of " + results.totalCount + " passed.", color);
|
var logStr = " " + this.padRight(suite.description + " ", 60, '.') +
|
||||||
|
this.padLeft(results.passedCount, 4) + "/" +
|
||||||
|
this.padRight(results.totalCount, 4) + " ok";
|
||||||
|
this.log(logStr, color);
|
||||||
};
|
};
|
||||||
|
|
||||||
proto.log = function(str, color) {
|
proto.log = function(str, color) {
|
||||||
var text = (color != undefined)? ANSI.colorize_text(str, color) : str;
|
var text = (color)? ANSI.colorize_text(str, color) : str;
|
||||||
console.log(text)
|
console.log(text);
|
||||||
};
|
};
|
||||||
|
|
||||||
jasmine.ConsoleReporter = ConsoleReporter;
|
jasmine.ConsoleReporter = ConsoleReporter;
|
||||||
|
|||||||
@@ -144,6 +144,22 @@ describe('ol.projection', function() {
|
|||||||
expect(point.y).toRoughlyEqual(200146.976, 1);
|
expect(point.y).toRoughlyEqual(200146.976, 1);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('caches the new Proj4js projections given their srsCode', function() {
|
||||||
|
Proj4js.defs['EPSG:21781'] =
|
||||||
|
'+proj=somerc +lat_0=46.95240555555556 +lon_0=7.439583333333333 ' +
|
||||||
|
'+k_0=1 +x_0=600000 +y_0=200000 +ellps=bessel ' +
|
||||||
|
'+towgs84=674.374,15.056,405.346,0,0,0,0 +units=m +no_defs';
|
||||||
|
var code = 'urn:ogc:def:crs:EPSG:21781';
|
||||||
|
var srsCode = 'EPSG:21781';
|
||||||
|
var proj = ol.projection.getFromCode(code);
|
||||||
|
expect(ol.projection.proj4jsProjections_.hasOwnProperty(code))
|
||||||
|
.toBeTruthy();
|
||||||
|
expect(ol.projection.proj4jsProjections_.hasOwnProperty(srsCode))
|
||||||
|
.toBeTruthy();
|
||||||
|
var proj2 = ol.projection.getFromCode(srsCode);
|
||||||
|
expect(proj2).toBe(proj);
|
||||||
|
});
|
||||||
|
|
||||||
it('numerically estimates point scale at the equator', function() {
|
it('numerically estimates point scale at the equator', function() {
|
||||||
var googleProjection = ol.projection.getFromCode('GOOGLE');
|
var googleProjection = ol.projection.getFromCode('GOOGLE');
|
||||||
expect(googleProjection.getPointResolution(1, new ol.Coordinate(0, 0))).
|
expect(googleProjection.getPointResolution(1, new ol.Coordinate(0, 0))).
|
||||||
|
|||||||
@@ -21,13 +21,20 @@ describe('ol.TileQueue', function() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function addRandomPriorityTiles(tq, num) {
|
function addRandomPriorityTiles(tq, num) {
|
||||||
|
var tiles = [];
|
||||||
var i, tile, priority;
|
var i, tile, priority;
|
||||||
for (i = 0; i < num; i++) {
|
for (i = 0; i < num; i++) {
|
||||||
tile = new ol.Tile();
|
tile = new ol.Tile();
|
||||||
|
tile.toDrop = (i % 2 === 0) ? true : false;
|
||||||
|
goog.events.listen(tile, goog.events.EventType.CHANGE,
|
||||||
|
goog.nullFunction);
|
||||||
priority = Math.floor(Math.random() * 100);
|
priority = Math.floor(Math.random() * 100);
|
||||||
tq.heap_.push([priority, tile, '', new ol.Coordinate(0, 0)]);
|
tq.heap_.push([priority, tile, '', new ol.Coordinate(0, 0)]);
|
||||||
tq.queuedTileKeys_[tile.getKey()] = true;
|
tq.queuedTileKeys_[tile.getKey()] = true;
|
||||||
|
tile.inQueue++;
|
||||||
|
tiles.push(tile);
|
||||||
}
|
}
|
||||||
|
return tiles;
|
||||||
}
|
}
|
||||||
|
|
||||||
describe('heapify', function() {
|
describe('heapify', function() {
|
||||||
@@ -45,16 +52,15 @@ describe('ol.TileQueue', function() {
|
|||||||
it('does reprioritize the array', function() {
|
it('does reprioritize the array', function() {
|
||||||
|
|
||||||
var tq = new ol.TileQueue(function() {});
|
var tq = new ol.TileQueue(function() {});
|
||||||
addRandomPriorityTiles(tq, 100);
|
var tiles = addRandomPriorityTiles(tq, 100);
|
||||||
|
|
||||||
tq.heapify_();
|
tq.heapify_();
|
||||||
|
|
||||||
// now reprioritize, changing the priority of 50 tiles and removing the
|
// now reprioritize, changing the priority of 50 tiles and removing the
|
||||||
// rest
|
// rest
|
||||||
|
|
||||||
var i = 0;
|
tq.tilePriorityFunction_ = function(tile) {
|
||||||
tq.tilePriorityFunction_ = function() {
|
if (tile.toDrop) {
|
||||||
if ((i++) % 2 === 0) {
|
|
||||||
return ol.TileQueue.DROP;
|
return ol.TileQueue.DROP;
|
||||||
}
|
}
|
||||||
return Math.floor(Math.random() * 100);
|
return Math.floor(Math.random() * 100);
|
||||||
@@ -64,10 +70,23 @@ describe('ol.TileQueue', function() {
|
|||||||
expect(tq.heap_.length).toEqual(50);
|
expect(tq.heap_.length).toEqual(50);
|
||||||
expect(isHeap(tq)).toBeTruthy();
|
expect(isHeap(tq)).toBeTruthy();
|
||||||
|
|
||||||
|
var i, tile;
|
||||||
|
for (i = 0; i < tiles.length; ++i) {
|
||||||
|
tile = tiles[i];
|
||||||
|
var hasListener = goog.events.hasListener(tile);
|
||||||
|
if (tile.toDrop) {
|
||||||
|
expect(hasListener).toBeFalsy();
|
||||||
|
} else {
|
||||||
|
expect(hasListener).toBeTruthy();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
goog.require('goog.events');
|
||||||
|
goog.require('goog.events.EventType');
|
||||||
goog.require('ol.Coordinate');
|
goog.require('ol.Coordinate');
|
||||||
goog.require('ol.Tile');
|
goog.require('ol.Tile');
|
||||||
goog.require('ol.TileQueue');
|
goog.require('ol.TileQueue');
|
||||||
|
|||||||
Reference in New Issue
Block a user