Merge branch 'master' of github.com:openlayers/ol3 into vector

This commit is contained in:
Tim Schaub
2013-02-20 10:18:09 -07:00
22 changed files with 1201 additions and 1123 deletions
+1 -1
View File
@@ -13,9 +13,9 @@
height: 100%; height: 100%;
} }
#log { #log {
height: 500px;
position: absolute; position: absolute;
top: 130px; top: 130px;
font-size: 12px;
} }
#text { #text {
position: absolute; position: absolute;
+14 -21
View File
@@ -1,26 +1,19 @@
goog.require('goog.debug.Console');
goog.require('goog.debug.DivConsole');
goog.require('goog.debug.Logger');
goog.require('goog.debug.Logger.Level');
goog.require('goog.json.Serializer');
goog.require('goog.net.XhrIo');
goog.require('ol.parser.ogc.WMSCapabilities'); goog.require('ol.parser.ogc.WMSCapabilities');
if (goog.DEBUG) {
goog.debug.Console.autoInstall();
goog.debug.Logger.getLogger('ol').setLevel(goog.debug.Logger.Level.INFO);
var logconsole = new goog.debug.DivConsole(goog.dom.getElement('log'));
logconsole.setCapturing(true);
}
var parser = new ol.parser.ogc.WMSCapabilities(), result; var parser = new ol.parser.ogc.WMSCapabilities(), result;
var url = '../test/spec/ol/parser/ogc/xml/wmscapabilities_v1_3_0/ogcsample.xml'; var url = '../test/spec/ol/parser/ogc/xml/wmscapabilities_v1_3_0/ogcsample.xml';
goog.net.XhrIo.send(url, function(e) {
var xhr = e.target; var xhr = new XMLHttpRequest();
result = parser.read(xhr.getResponseXml()); xhr.open('GET', url, true);
if (goog.DEBUG) {
var output = new goog.json.Serializer().serialize(result);
goog.debug.Logger.getLogger('ol').info(output); /**
* onload handler for the XHR request.
*/
xhr.onload = function() {
if (xhr.status == 200) {
result = parser.read(xhr.responseXML);
document.getElementById('log').innerHTML = window.JSON.stringify(result);
} }
}); };
xhr.send();
+40 -6
View File
@@ -31,7 +31,20 @@ and explore the `examples/` directory, for example by opening
<http://localhost:8000/examples/side-by-side.html>. <http://localhost:8000/examples/side-by-side.html>.
You can turn off compilation by appending `?mode=RAW` to the URL, for example You can turn off compilation by appending `?mode=RAW` to the URL, for example
<http://localhost:8000/examples/side-by-side.html?mode=RAW>. <http://localhost:8000/examples/side-by-side.html?mode=RAW>. (By default mode is `ADVANCED`.)
The examples can also be run against the `ol.js` standalone lib, without Plovr,
just like the examples [hosted](http://openlayers.github.com/ol3/master/examples/)
on GitHub. You will want to run the examples against the standalone lib to verify
that will work correctly when copied on GitHub (as GitHub pages). Start by executing
the `hostexamples` build target:
$ ./build.py hostexamples
This will build `ol.js` and `ol.css`, creates the examples index page, and copy everything to
`build/gh-pages/<branch_name>/`, where `<branch_name>` is the name of the local checked
out Git branch. You can now open the `build/gh-pages/<branch_name>examples` directory
in the browser, for example: <http://localhost:8000/build/gh-pages/master/examples/side-by-side.html>.
## Run tests ## Run tests
@@ -56,14 +69,35 @@ Then:
## Add examples ## Add examples
The examples are located in the `examples` directory. Adding a new example The examples are located in the `examples` directory. Adding a new example
implies creating two files in this directory, a `.html` file and `.js` file. implies creating two files in this directory, an `.html` file and a `.js` file.
See `examples/full-screen.html` and `examples/full-screen.js` for instance. See `examples/full-screen.html` and `examples/full-screen.js` for instance.
The `.html` file needs to include a script tag with The `.html` file needs to include a script tag with
`loader.js?id=<example_name>` as its `src`. For example, if the two files for `loader.js?id=<example_name>` as its `src`. For example, if the two files for
the examples are `myexample.js` and `myexample.html` then `id` should be set to the example are `myexample.js` and `myexample.html` then the script tag's `src`
`myexample` in the `loader.js` URL. should be set to `myexample`.
`build.py serve` should be stopped and restarted for the `build.py serve` should be stopped and restarted for the
`loader.js?id=<example_name>` script tag to refer to a valid URL. `build.py serve` `loader.js?id=<example_name>` script tag to refer to a valid URL. `build.py
triggers the `examples` target which creates Plovr JSON file for each example. serve` triggers the `examples` target which creates a Plovr JSON file for each
example.
A note on the use of the `goog` namespace in the examples:
Short story: the OL3 examples should not use the `goog` namespace, except
for `goog.require`.
Longer story:
We want that the OL3 examples work in multiple modes: with the standalone lib
(which has implications of the symbols and properties we export), with Plovr in
ADVANCED mode, and with Plovr in RAW (debug) mode.
Running the examples with Plovr makes it mandatory to declare dependencies with
`goog.require` statements. And for the examples to also run with the standalone
lib we [export](https://github.com/openlayers/ol3/blob/master/src/goog.exports)
`goog.require` as the null function.
Exporting `goog.require` has a side effect: it adds the `goog` namespace object
to the global object. This is why we can, for example, have `if (goog.DEBUG)`
statements in the code of the examples.
+2 -2
View File
@@ -93,7 +93,7 @@ goog.inherits(ol.Collection, ol.Object);
* Remove all elements from the collection. * Remove all elements from the collection.
*/ */
ol.Collection.prototype.clear = function() { ol.Collection.prototype.clear = function() {
while (this[ol.CollectionProperty.LENGTH]) { while (this.getLength() > 0) {
this.pop(); this.pop();
} }
}; };
@@ -187,7 +187,7 @@ ol.Collection.prototype.removeAt = function(index) {
* @param {*} elem Element. * @param {*} elem Element.
*/ */
ol.Collection.prototype.setAt = function(index, elem) { ol.Collection.prototype.setAt = function(index, elem) {
var n = this[ol.CollectionProperty.LENGTH]; var n = this.getLength();
if (index < n) { if (index < n) {
var prev = this.array_[index]; var prev = this.array_[index];
this.array_[index] = elem; this.array_[index] = elem;
+43 -19
View File
@@ -39,6 +39,13 @@ ol.ObjectProperty = {
*/ */
ol.Object = function(opt_values) { ol.Object = function(opt_values) {
goog.base(this); goog.base(this);
/**
* @private
* @type {Object.<string, *>}
*/
this.values_ = {};
if (goog.isDef(opt_values)) { if (goog.isDef(opt_values)) {
this.setValues(opt_values); this.setValues(opt_values);
} }
@@ -91,7 +98,8 @@ ol.Object.getAccessors = function(obj) {
* @return {string} Changed name. * @return {string} Changed name.
*/ */
ol.Object.getChangedEventType = function(key) { ol.Object.getChangedEventType = function(key) {
return ol.Object.changedEventTypeCache_[key] || return ol.Object.changedEventTypeCache_.hasOwnProperty(key) ?
ol.Object.changedEventTypeCache_[key] :
(ol.Object.changedEventTypeCache_[key] = key.toLowerCase() + '_changed'); (ol.Object.changedEventTypeCache_[key] = key.toLowerCase() + '_changed');
}; };
@@ -101,7 +109,8 @@ ol.Object.getChangedEventType = function(key) {
* @return {string} Getter name. * @return {string} Getter name.
*/ */
ol.Object.getGetterName = function(key) { ol.Object.getGetterName = function(key) {
return ol.Object.getterNameCache_[key] || return ol.Object.getterNameCache_.hasOwnProperty(key) ?
ol.Object.getterNameCache_[key] :
(ol.Object.getterNameCache_[key] = 'get' + ol.Object.capitalize(key)); (ol.Object.getterNameCache_[key] = 'get' + ol.Object.capitalize(key));
}; };
@@ -121,7 +130,8 @@ ol.Object.getListeners = function(obj) {
* @return {string} Setter name. * @return {string} Setter name.
*/ */
ol.Object.getSetterName = function(key) { ol.Object.getSetterName = function(key) {
return ol.Object.setterNameCache_[key] || return ol.Object.setterNameCache_.hasOwnProperty(key) ?
ol.Object.setterNameCache_[key] :
(ol.Object.setterNameCache_[key] = 'set' + ol.Object.capitalize(key)); (ol.Object.setterNameCache_[key] = 'set' + ol.Object.capitalize(key));
}; };
@@ -161,20 +171,34 @@ ol.Object.prototype.changed = goog.nullFunction;
* @return {*} Value. * @return {*} Value.
*/ */
ol.Object.prototype.get = function(key) { ol.Object.prototype.get = function(key) {
var value;
var accessors = ol.Object.getAccessors(this); var accessors = ol.Object.getAccessors(this);
if (goog.object.containsKey(accessors, key)) { if (accessors.hasOwnProperty(key)) {
var accessor = accessors[key]; var accessor = accessors[key];
var target = accessor.target; var target = accessor.target;
var targetKey = accessor.key; var targetKey = accessor.key;
var getterName = ol.Object.getGetterName(targetKey); var getterName = ol.Object.getGetterName(targetKey);
if (target[getterName]) { if (target[getterName]) {
return target[getterName](); value = target[getterName]();
} else { } else {
return target.get(targetKey); value = target.get(targetKey);
} }
} else { } else if (this.values_.hasOwnProperty(key)) {
return this[key]; value = this.values_[key];
} }
return value;
};
/**
* Get a list of object property names.
* @return {Array.<string>} List of property names.
*/
ol.Object.prototype.getKeys = function() {
var keys = goog.object.getKeys(ol.Object.getAccessors(this)).concat(
goog.object.getKeys(this.values_));
goog.array.removeDuplicates(keys);
return keys;
}; };
@@ -183,7 +207,7 @@ ol.Object.prototype.get = function(key) {
*/ */
ol.Object.prototype.notify = function(key) { ol.Object.prototype.notify = function(key) {
var accessors = ol.Object.getAccessors(this); var accessors = ol.Object.getAccessors(this);
if (goog.object.containsKey(accessors, key)) { if (accessors.hasOwnProperty(key)) {
var accessor = accessors[key]; var accessor = accessors[key];
var target = accessor.target; var target = accessor.target;
var targetKey = accessor.key; var targetKey = accessor.key;
@@ -211,7 +235,7 @@ ol.Object.prototype.notifyInternal_ = function(key) {
*/ */
ol.Object.prototype.set = function(key, value) { ol.Object.prototype.set = function(key, value) {
var accessors = ol.Object.getAccessors(this); var accessors = ol.Object.getAccessors(this);
if (goog.object.containsKey(accessors, key)) { if (accessors.hasOwnProperty(key)) {
var accessor = accessors[key]; var accessor = accessors[key];
var target = accessor.target; var target = accessor.target;
var targetKey = accessor.key; var targetKey = accessor.key;
@@ -222,7 +246,7 @@ ol.Object.prototype.set = function(key, value) {
target.set(targetKey, value); target.set(targetKey, value);
} }
} else { } else {
this[key] = value; this.values_[key] = value;
this.notifyInternal_(key); this.notifyInternal_(key);
} }
}; };
@@ -232,14 +256,16 @@ ol.Object.prototype.set = function(key, value) {
* @param {Object.<string, *>} options Options. * @param {Object.<string, *>} options Options.
*/ */
ol.Object.prototype.setOptions = function(options) { ol.Object.prototype.setOptions = function(options) {
goog.object.forEach(options, function(value, key) { var key, value, setterName;
var setterName = ol.Object.getSetterName(key); for (key in options) {
value = options[key];
setterName = ol.Object.getSetterName(key);
if (this[setterName]) { if (this[setterName]) {
this[setterName](value); this[setterName](value);
} else { } else {
this.set(key, value); this.set(key, value);
} }
}, this); }
}; };
@@ -261,7 +287,7 @@ ol.Object.prototype.unbind = function(key) {
var value = this.get(key); var value = this.get(key);
var accessors = ol.Object.getAccessors(this); var accessors = ol.Object.getAccessors(this);
delete accessors[key]; delete accessors[key];
this[key] = value; this.values_[key] = value;
} }
}; };
@@ -270,9 +296,7 @@ ol.Object.prototype.unbind = function(key) {
* Removes all bindings. * Removes all bindings.
*/ */
ol.Object.prototype.unbindAll = function() { ol.Object.prototype.unbindAll = function() {
var listeners = ol.Object.getListeners(this); for (var key in ol.Object.getListeners(this)) {
var keys = goog.object.getKeys(listeners);
goog.array.forEach(keys, function(key) {
this.unbind(key); this.unbind(key);
}, this); }
}; };
+113 -118
View File
@@ -19,17 +19,17 @@ ol.parser.ogc.WMSCapabilities_v1 = function() {
this.readChildNodes(node, obj['service']); this.readChildNodes(node, obj['service']);
}, },
'Name': function(node, obj) { 'Name': function(node, obj) {
obj.name = this.getChildValue(node); obj['name'] = this.getChildValue(node);
}, },
'Title': function(node, obj) { 'Title': function(node, obj) {
obj.title = this.getChildValue(node); obj['title'] = this.getChildValue(node);
}, },
'Abstract': function(node, obj) { 'Abstract': function(node, obj) {
obj['abstract'] = this.getChildValue(node); obj['abstract'] = this.getChildValue(node);
}, },
'BoundingBox': function(node, obj) { 'BoundingBox': function(node, obj) {
var bbox = {}; var bbox = {};
bbox.bbox = [ bbox['bbox'] = [
parseFloat(node.getAttribute('minx')), parseFloat(node.getAttribute('minx')),
parseFloat(node.getAttribute('miny')), parseFloat(node.getAttribute('miny')),
parseFloat(node.getAttribute('maxx')), parseFloat(node.getAttribute('maxx')),
@@ -40,96 +40,96 @@ ol.parser.ogc.WMSCapabilities_v1 = function() {
y: parseFloat(node.getAttribute('resy')) y: parseFloat(node.getAttribute('resy'))
}; };
if (! (isNaN(res.x) && isNaN(res.y))) { if (! (isNaN(res.x) && isNaN(res.y))) {
bbox.res = res; bbox['res'] = res;
} }
// return the bbox so that descendant classes can set the // return the bbox so that descendant classes can set the
// CRS and SRS and add it to the obj // CRS and SRS and add it to the obj
return bbox; return bbox;
}, },
'OnlineResource': function(node, obj) { 'OnlineResource': function(node, obj) {
obj.href = this.getAttributeNS(node, 'http://www.w3.org/1999/xlink', obj['href'] = this.getAttributeNS(node, 'http://www.w3.org/1999/xlink',
'href'); 'href');
}, },
'ContactInformation': function(node, obj) { 'ContactInformation': function(node, obj) {
obj.contactInformation = {}; obj['contactInformation'] = {};
this.readChildNodes(node, obj.contactInformation); this.readChildNodes(node, obj['contactInformation']);
}, },
'ContactPersonPrimary': function(node, obj) { 'ContactPersonPrimary': function(node, obj) {
obj.personPrimary = {}; obj['personPrimary'] = {};
this.readChildNodes(node, obj.personPrimary); this.readChildNodes(node, obj['personPrimary']);
}, },
'ContactPerson': function(node, obj) { 'ContactPerson': function(node, obj) {
obj.person = this.getChildValue(node); obj['person'] = this.getChildValue(node);
}, },
'ContactOrganization': function(node, obj) { 'ContactOrganization': function(node, obj) {
obj.organization = this.getChildValue(node); obj['organization'] = this.getChildValue(node);
}, },
'ContactPosition': function(node, obj) { 'ContactPosition': function(node, obj) {
obj.position = this.getChildValue(node); obj['position'] = this.getChildValue(node);
}, },
'ContactAddress': function(node, obj) { 'ContactAddress': function(node, obj) {
obj.contactAddress = {}; obj['contactAddress'] = {};
this.readChildNodes(node, obj.contactAddress); this.readChildNodes(node, obj['contactAddress']);
}, },
'AddressType': function(node, obj) { 'AddressType': function(node, obj) {
obj.type = this.getChildValue(node); obj['type'] = this.getChildValue(node);
}, },
'Address': function(node, obj) { 'Address': function(node, obj) {
obj.address = this.getChildValue(node); obj['address'] = this.getChildValue(node);
}, },
'City': function(node, obj) { 'City': function(node, obj) {
obj.city = this.getChildValue(node); obj['city'] = this.getChildValue(node);
}, },
'StateOrProvince': function(node, obj) { 'StateOrProvince': function(node, obj) {
obj.stateOrProvince = this.getChildValue(node); obj['stateOrProvince'] = this.getChildValue(node);
}, },
'PostCode': function(node, obj) { 'PostCode': function(node, obj) {
obj.postcode = this.getChildValue(node); obj['postcode'] = this.getChildValue(node);
}, },
'Country': function(node, obj) { 'Country': function(node, obj) {
obj.country = this.getChildValue(node); obj['country'] = this.getChildValue(node);
}, },
'ContactVoiceTelephone': function(node, obj) { 'ContactVoiceTelephone': function(node, obj) {
obj.phone = this.getChildValue(node); obj['phone'] = this.getChildValue(node);
}, },
'ContactFacsimileTelephone': function(node, obj) { 'ContactFacsimileTelephone': function(node, obj) {
obj.fax = this.getChildValue(node); obj['fax'] = this.getChildValue(node);
}, },
'ContactElectronicMailAddress': function(node, obj) { 'ContactElectronicMailAddress': function(node, obj) {
obj.email = this.getChildValue(node); obj['email'] = this.getChildValue(node);
}, },
'Fees': function(node, obj) { 'Fees': function(node, obj) {
var fees = this.getChildValue(node); var fees = this.getChildValue(node);
if (fees && fees.toLowerCase() != 'none') { if (fees && fees.toLowerCase() != 'none') {
obj.fees = fees; obj['fees'] = fees;
} }
}, },
'AccessConstraints': function(node, obj) { 'AccessConstraints': function(node, obj) {
var constraints = this.getChildValue(node); var constraints = this.getChildValue(node);
if (constraints && constraints.toLowerCase() != 'none') { if (constraints && constraints.toLowerCase() != 'none') {
obj.accessConstraints = constraints; obj['accessConstraints'] = constraints;
} }
}, },
'Capability': function(node, obj) { 'Capability': function(node, obj) {
obj.capability = { obj['capability'] = {};
nestedLayers: [], obj['capability']['nestedLayers'] = [];
layers: [] obj['capability']['layers'] = [];
}; this.readChildNodes(node, obj['capability']);
this.readChildNodes(node, obj.capability);
}, },
'Request': function(node, obj) { 'Request': function(node, obj) {
obj.request = {}; obj['request'] = {};
this.readChildNodes(node, obj.request); this.readChildNodes(node, obj['request']);
}, },
'GetCapabilities': function(node, obj) { 'GetCapabilities': function(node, obj) {
obj.getcapabilities = {formats: []}; obj['getcapabilities'] = {};
this.readChildNodes(node, obj.getcapabilities); obj['getcapabilities']['formats'] = [];
this.readChildNodes(node, obj['getcapabilities']);
}, },
'Format': function(node, obj) { 'Format': function(node, obj) {
if (goog.isArray(obj.formats)) { if (goog.isArray(obj['formats'])) {
obj.formats.push(this.getChildValue(node)); obj['formats'].push(this.getChildValue(node));
} else { } else {
obj.format = this.getChildValue(node); obj['format'] = this.getChildValue(node);
} }
}, },
'DCPType': function(node, obj) { 'DCPType': function(node, obj) {
@@ -139,37 +139,32 @@ ol.parser.ogc.WMSCapabilities_v1 = function() {
this.readChildNodes(node, obj); this.readChildNodes(node, obj);
}, },
'Get': function(node, obj) { 'Get': function(node, obj) {
obj.get = {}; obj['get'] = {};
this.readChildNodes(node, obj.get); this.readChildNodes(node, obj['get']);
// backwards compatibility
if (!obj.href) {
obj.href = obj.get.href;
}
}, },
'Post': function(node, obj) { 'Post': function(node, obj) {
obj.post = {}; obj['post'] = {};
this.readChildNodes(node, obj.post); this.readChildNodes(node, obj['post']);
// backwards compatibility
if (!obj.href) {
obj.href = obj.get.href;
}
}, },
'GetMap': function(node, obj) { 'GetMap': function(node, obj) {
obj.getmap = {formats: []}; obj['getmap'] = {};
this.readChildNodes(node, obj.getmap); obj['getmap']['formats'] = [];
this.readChildNodes(node, obj['getmap']);
}, },
'GetFeatureInfo': function(node, obj) { 'GetFeatureInfo': function(node, obj) {
obj.getfeatureinfo = {formats: []}; obj['getfeatureinfo'] = {};
this.readChildNodes(node, obj.getfeatureinfo); obj['getfeatureinfo']['formats'] = [];
this.readChildNodes(node, obj['getfeatureinfo']);
}, },
'Exception': function(node, obj) { 'Exception': function(node, obj) {
obj.exception = {formats: []}; obj['exception'] = {};
this.readChildNodes(node, obj.exception); obj['exception']['formats'] = [];
this.readChildNodes(node, obj['exception']);
}, },
'Layer': function(node, obj) { 'Layer': function(node, obj) {
var parentLayer, capability; var parentLayer, capability;
if (obj.capability) { if (obj['capability']) {
capability = obj.capability; capability = obj['capability'];
parentLayer = obj; parentLayer = obj;
} else { } else {
capability = obj; capability = obj;
@@ -188,113 +183,113 @@ ol.parser.ogc.WMSCapabilities_v1 = function() {
var fixedHeight = node.getAttribute('fixedHeight'); var fixedHeight = node.getAttribute('fixedHeight');
var parent = parentLayer || {}; var parent = parentLayer || {};
var layer = { var layer = {
nestedLayers: [], 'nestedLayers': [],
styles: parentLayer ? [].concat(parentLayer.styles) : [], 'styles': parentLayer ? [].concat(parentLayer['styles']) : [],
srs: {}, 'srs': {},
metadataURLs: [], 'metadataURLs': [],
bbox: {}, 'bbox': {},
llbbox: parent.llbbox, 'llbbox': parent['llbbox'],
dimensions: {}, 'dimensions': {},
authorityURLs: {}, 'authorityURLs': {},
identifiers: {}, 'identifiers': {},
keywords: [], 'keywords': [],
queryable: (queryable && queryable !== '') ? 'queryable': (queryable && queryable !== '') ?
(queryable === '1' || queryable === 'true') : (queryable === '1' || queryable === 'true') :
(parent.queryable || false), (parent['queryable'] || false),
cascaded: (cascaded !== null) ? parseInt(cascaded, 10) : 'cascaded': (cascaded !== null) ? parseInt(cascaded, 10) :
(parent.cascaded || 0), (parent['cascaded'] || 0),
opaque: opaque ? 'opaque': opaque ?
(opaque === '1' || opaque === 'true') : (opaque === '1' || opaque === 'true') :
(parent.opaque || false), (parent['opaque'] || false),
noSubsets: (noSubsets !== null) ? 'noSubsets': (noSubsets !== null) ?
(noSubsets === '1' || noSubsets === 'true') : (noSubsets === '1' || noSubsets === 'true') :
(parent.noSubsets || false), (parent['noSubsets'] || false),
fixedWidth: (fixedWidth !== null) ? 'fixedWidth': (fixedWidth !== null) ?
parseInt(fixedWidth, 10) : (parent.fixedWidth || 0), parseInt(fixedWidth, 10) : (parent['fixedWidth'] || 0),
fixedHeight: (fixedHeight !== null) ? 'fixedHeight': (fixedHeight !== null) ?
parseInt(fixedHeight, 10) : (parent.fixedHeight || 0), parseInt(fixedHeight, 10) : (parent['fixedHeight'] || 0),
minScale: parent.minScale, 'minScale': parent['minScale'],
maxScale: parent.maxScale, 'maxScale': parent['maxScale'],
attribution: parent.attribution 'attribution': parent['attribution']
}; };
if (parentLayer) { if (parentLayer) {
goog.object.extend(layer.srs, parent.srs); goog.object.extend(layer['srs'], parent['srs']);
goog.object.extend(layer.bbox, parent.bbox); goog.object.extend(layer['bbox'], parent['bbox']);
goog.object.extend(layer.dimensions, parent.dimensions); goog.object.extend(layer['dimensions'], parent['dimensions']);
goog.object.extend(layer.authorityURLs, parent.authorityURLs); goog.object.extend(layer['authorityURLs'], parent['authorityURLs']);
} }
obj.nestedLayers.push(layer); obj['nestedLayers'].push(layer);
layer.capability = capability; layer['capability'] = capability;
this.readChildNodes(node, layer); this.readChildNodes(node, layer);
delete layer.capability; delete layer['capability'];
if (layer.name) { if (layer['name']) {
var parts = layer.name.split(':'), var parts = layer['name'].split(':'),
request = capability.request, request = capability['request'],
gfi = request.getfeatureinfo; gfi = request['getfeatureinfo'];
if (parts.length > 0) { if (parts.length > 0) {
layer.prefix = parts[0]; layer['prefix'] = parts[0];
} }
capability.layers.push(layer); capability['layers'].push(layer);
if (layer.formats === undefined) { if (layer['formats'] === undefined) {
layer.formats = request.getmap.formats; layer['formats'] = request['getmap']['formats'];
} }
if (layer.infoFormats === undefined && gfi) { if (layer['infoFormats'] === undefined && gfi) {
layer.infoFormats = gfi.formats; layer['infoFormats'] = gfi['formats'];
} }
} }
}, },
'Attribution': function(node, obj) { 'Attribution': function(node, obj) {
obj.attribution = {}; obj['attribution'] = {};
this.readChildNodes(node, obj.attribution); this.readChildNodes(node, obj['attribution']);
}, },
'LogoURL': function(node, obj) { 'LogoURL': function(node, obj) {
obj.logo = { obj['logo'] = {
width: node.getAttribute('width'), 'width': node.getAttribute('width'),
height: node.getAttribute('height') 'height': node.getAttribute('height')
}; };
this.readChildNodes(node, obj.logo); this.readChildNodes(node, obj['logo']);
}, },
'Style': function(node, obj) { 'Style': function(node, obj) {
var style = {}; var style = {};
obj.styles.push(style); obj['styles'].push(style);
this.readChildNodes(node, style); this.readChildNodes(node, style);
}, },
'LegendURL': function(node, obj) { 'LegendURL': function(node, obj) {
var legend = { var legend = {
width: node.getAttribute('width'), 'width': node.getAttribute('width'),
height: node.getAttribute('height') 'height': node.getAttribute('height')
}; };
obj.legend = legend; obj['legend'] = legend;
this.readChildNodes(node, legend); this.readChildNodes(node, legend);
}, },
'MetadataURL': function(node, obj) { 'MetadataURL': function(node, obj) {
var metadataURL = {type: node.getAttribute('type')}; var metadataURL = {'type': node.getAttribute('type')};
obj.metadataURLs.push(metadataURL); obj['metadataURLs'].push(metadataURL);
this.readChildNodes(node, metadataURL); this.readChildNodes(node, metadataURL);
}, },
'DataURL': function(node, obj) { 'DataURL': function(node, obj) {
obj.dataURL = {}; obj['dataURL'] = {};
this.readChildNodes(node, obj.dataURL); this.readChildNodes(node, obj['dataURL']);
}, },
'FeatureListURL': function(node, obj) { 'FeatureListURL': function(node, obj) {
obj.featureListURL = {}; obj['featureListURL'] = {};
this.readChildNodes(node, obj.featureListURL); this.readChildNodes(node, obj['featureListURL']);
}, },
'AuthorityURL': function(node, obj) { 'AuthorityURL': function(node, obj) {
var name = node.getAttribute('name'); var name = node.getAttribute('name');
var authority = {}; var authority = {};
this.readChildNodes(node, authority); this.readChildNodes(node, authority);
obj.authorityURLs[name] = authority.href; obj['authorityURLs'][name] = authority['href'];
}, },
'Identifier': function(node, obj) { 'Identifier': function(node, obj) {
var authority = node.getAttribute('authority'); var authority = node.getAttribute('authority');
obj.identifiers[authority] = this.getChildValue(node); obj['identifiers'][authority] = this.getChildValue(node);
}, },
'KeywordList': function(node, obj) { 'KeywordList': function(node, obj) {
this.readChildNodes(node, obj); this.readChildNodes(node, obj);
}, },
'SRS': function(node, obj) { 'SRS': function(node, obj) {
obj.srs[this.getChildValue(node)] = true; obj['srs'][this.getChildValue(node)] = true;
} }
} }
}; };
+29 -29
View File
@@ -15,37 +15,37 @@ ol.parser.ogc.WMSCapabilities_v1_1 = function() {
this.readChildNodes(node, obj); this.readChildNodes(node, obj);
}, },
'Keyword': function(node, obj) { 'Keyword': function(node, obj) {
if (obj.keywords) { if (obj['keywords']) {
obj.keywords.push({value: this.getChildValue(node)}); obj['keywords'].push({'value': this.getChildValue(node)});
} }
}, },
'DescribeLayer': function(node, obj) { 'DescribeLayer': function(node, obj) {
obj.describelayer = {formats: []}; obj['describelayer'] = {'formats': []};
this.readChildNodes(node, obj.describelayer); this.readChildNodes(node, obj['describelayer']);
}, },
'GetLegendGraphic': function(node, obj) { 'GetLegendGraphic': function(node, obj) {
obj.getlegendgraphic = {formats: []}; obj['getlegendgraphic'] = {'formats': []};
this.readChildNodes(node, obj.getlegendgraphic); this.readChildNodes(node, obj['getlegendgraphic']);
}, },
'GetStyles': function(node, obj) { 'GetStyles': function(node, obj) {
obj.getstyles = {formats: []}; obj['getstyles'] = {'formats': []};
this.readChildNodes(node, obj.getstyles); this.readChildNodes(node, obj['getstyles']);
}, },
'PutStyles': function(node, obj) { 'PutStyles': function(node, obj) {
obj.putstyles = {formats: []}; obj['putstyles'] = {'formats': []};
this.readChildNodes(node, obj.putstyles); this.readChildNodes(node, obj['putstyles']);
}, },
'UserDefinedSymbolization': function(node, obj) { 'UserDefinedSymbolization': function(node, obj) {
var userSymbols = { var userSymbols = {
supportSLD: parseInt(node.getAttribute('SupportSLD'), 10) == 1, 'supportSLD': parseInt(node.getAttribute('SupportSLD'), 10) == 1,
userLayer: parseInt(node.getAttribute('UserLayer'), 10) == 1, 'userLayer': parseInt(node.getAttribute('UserLayer'), 10) == 1,
userStyle: parseInt(node.getAttribute('UserStyle'), 10) == 1, 'userStyle': parseInt(node.getAttribute('UserStyle'), 10) == 1,
remoteWFS: parseInt(node.getAttribute('RemoteWFS'), 10) == 1 'remoteWFS': parseInt(node.getAttribute('RemoteWFS'), 10) == 1
}; };
obj.userSymbols = userSymbols; obj['userSymbols'] = userSymbols;
}, },
'LatLonBoundingBox': function(node, obj) { 'LatLonBoundingBox': function(node, obj) {
obj.llbbox = [ obj['llbbox'] = [
parseFloat(node.getAttribute('minx')), parseFloat(node.getAttribute('minx')),
parseFloat(node.getAttribute('miny')), parseFloat(node.getAttribute('miny')),
parseFloat(node.getAttribute('maxx')), parseFloat(node.getAttribute('maxx')),
@@ -54,8 +54,8 @@ ol.parser.ogc.WMSCapabilities_v1_1 = function() {
}, },
'BoundingBox': function(node, obj) { 'BoundingBox': function(node, obj) {
var bbox = bboxreader.apply(this, arguments); var bbox = bboxreader.apply(this, arguments);
bbox.srs = node.getAttribute('SRS'); bbox['srs'] = node.getAttribute('SRS');
obj.bbox[bbox.srs] = bbox; obj['bbox'][bbox['srs']] = bbox;
}, },
'ScaleHint': function(node, obj) { 'ScaleHint': function(node, obj) {
var min = parseFloat(node.getAttribute('min')); var min = parseFloat(node.getAttribute('min'));
@@ -64,33 +64,33 @@ ol.parser.ogc.WMSCapabilities_v1_1 = function() {
var dpi = (25.4 / 0.28); var dpi = (25.4 / 0.28);
var ipm = 39.37; var ipm = 39.37;
if (min !== 0) { if (min !== 0) {
obj.maxScale = parseFloat((min / rad2) * ipm * dpi); obj['maxScale'] = parseFloat((min / rad2) * ipm * dpi);
} }
if (max != Number.POSITIVE_INFINITY) { if (max != Number.POSITIVE_INFINITY) {
obj.minScale = parseFloat((max / rad2) * ipm * dpi); obj['minScale'] = parseFloat((max / rad2) * ipm * dpi);
} }
}, },
'Dimension': function(node, obj) { 'Dimension': function(node, obj) {
var name = node.getAttribute('name').toLowerCase(); var name = node.getAttribute('name').toLowerCase();
var dim = { var dim = {
name: name, 'name': name,
units: node.getAttribute('units'), 'units': node.getAttribute('units'),
unitsymbol: node.getAttribute('unitSymbol') 'unitsymbol': node.getAttribute('unitSymbol')
}; };
obj.dimensions[dim.name] = dim; obj['dimensions'][dim.name] = dim;
}, },
'Extent': function(node, obj) { 'Extent': function(node, obj) {
var name = node.getAttribute('name').toLowerCase(); var name = node.getAttribute('name').toLowerCase();
if (name in obj['dimensions']) { if (name in obj['dimensions']) {
var extent = obj.dimensions[name]; var extent = obj['dimensions'][name];
extent.nearestVal = extent['nearestVal'] =
node.getAttribute('nearestValue') === '1'; node.getAttribute('nearestValue') === '1';
extent.multipleVal = extent['multipleVal'] =
node.getAttribute('multipleValues') === '1'; node.getAttribute('multipleValues') === '1';
extent.current = node.getAttribute('current') === '1'; extent['current'] = node.getAttribute('current') === '1';
extent['default'] = node.getAttribute('default') || ''; extent['default'] = node.getAttribute('default') || '';
var values = this.getChildValue(node); var values = this.getChildValue(node);
extent.values = values.split(','); extent['values'] = values.split(',');
} }
} }
}); });
+1 -1
View File
@@ -15,7 +15,7 @@ ol.parser.ogc.WMSCapabilities_v1_1_0 = function() {
var srs = this.getChildValue(node); var srs = this.getChildValue(node);
var values = srs.split(/ +/); var values = srs.split(/ +/);
for (var i = 0, len = values.length; i < len; i++) { for (var i = 0, len = values.length; i < len; i++) {
obj.srs[values[i]] = true; obj['srs'][values[i]] = true;
} }
} }
}); });
+1 -1
View File
@@ -12,7 +12,7 @@ ol.parser.ogc.WMSCapabilities_v1_1_1 = function() {
this.version = '1.1.1'; this.version = '1.1.1';
goog.object.extend(this.readers['http://www.opengis.net/wms'], { goog.object.extend(this.readers['http://www.opengis.net/wms'], {
'SRS': function(node, obj) { 'SRS': function(node, obj) {
obj.srs[this.getChildValue(node)] = true; obj['srs'][this.getChildValue(node)] = true;
} }
}); });
}; };
@@ -12,11 +12,11 @@ ol.parser.ogc.WMSCapabilities_v1_1_1_WMSC = function() {
this.profile = 'WMSC'; this.profile = 'WMSC';
goog.object.extend(this.readers['http://www.opengis.net/wms'], { goog.object.extend(this.readers['http://www.opengis.net/wms'], {
'VendorSpecificCapabilities': function(node, obj) { 'VendorSpecificCapabilities': function(node, obj) {
obj.vendorSpecific = {tileSets: []}; obj['vendorSpecific'] = {'tileSets': []};
this.readChildNodes(node, obj.vendorSpecific); this.readChildNodes(node, obj['vendorSpecific']);
}, },
'TileSet': function(node, vendorSpecific) { 'TileSet': function(node, vendorSpecific) {
var tileset = {srs: {}, bbox: {}, resolutions: []}; var tileset = {'srs': {}, 'bbox': {}, 'resolutions': []};
this.readChildNodes(node, tileset); this.readChildNodes(node, tileset);
vendorSpecific.tileSets.push(tileset); vendorSpecific.tileSets.push(tileset);
}, },
@@ -24,21 +24,21 @@ ol.parser.ogc.WMSCapabilities_v1_1_1_WMSC = function() {
var res = this.getChildValue(node).split(' '); var res = this.getChildValue(node).split(' ');
for (var i = 0, len = res.length; i < len; i++) { for (var i = 0, len = res.length; i < len; i++) {
if (res[i] !== '') { if (res[i] !== '') {
tileset.resolutions.push(parseFloat(res[i])); tileset['resolutions'].push(parseFloat(res[i]));
} }
} }
}, },
'Width': function(node, tileset) { 'Width': function(node, tileset) {
tileset.width = parseInt(this.getChildValue(node), 10); tileset['width'] = parseInt(this.getChildValue(node), 10);
}, },
'Height': function(node, tileset) { 'Height': function(node, tileset) {
tileset.height = parseInt(this.getChildValue(node), 10); tileset['height'] = parseInt(this.getChildValue(node), 10);
}, },
'Layers': function(node, tileset) { 'Layers': function(node, tileset) {
tileset.layers = this.getChildValue(node); tileset['layers'] = this.getChildValue(node);
}, },
'Styles': function(node, tileset) { 'Styles': function(node, tileset) {
tileset.styles = this.getChildValue(node); tileset['styles'] = this.getChildValue(node);
} }
}); });
}; };
+23 -23
View File
@@ -15,18 +15,18 @@ ol.parser.ogc.WMSCapabilities_v1_3_0 = function() {
this.readChildNodes(node, obj); this.readChildNodes(node, obj);
}, },
'LayerLimit': function(node, obj) { 'LayerLimit': function(node, obj) {
obj.layerLimit = parseInt(this.getChildValue(node), 10); obj['layerLimit'] = parseInt(this.getChildValue(node), 10);
}, },
'MaxWidth': function(node, obj) { 'MaxWidth': function(node, obj) {
obj.maxWidth = parseInt(this.getChildValue(node), 10); obj['maxWidth'] = parseInt(this.getChildValue(node), 10);
}, },
'MaxHeight': function(node, obj) { 'MaxHeight': function(node, obj) {
obj.maxHeight = parseInt(this.getChildValue(node), 10); obj['maxHeight'] = parseInt(this.getChildValue(node), 10);
}, },
'BoundingBox': function(node, obj) { 'BoundingBox': function(node, obj) {
var bbox = bboxreader.apply(this, arguments); var bbox = bboxreader.apply(this, arguments);
bbox.srs = node.getAttribute('CRS'); bbox['srs'] = node.getAttribute('CRS');
obj.bbox[bbox.srs] = bbox; obj['bbox'][bbox['srs']] = bbox;
}, },
'CRS': function(node, obj) { 'CRS': function(node, obj) {
// CRS is the synonym of SRS // CRS is the synonym of SRS
@@ -34,8 +34,8 @@ ol.parser.ogc.WMSCapabilities_v1_3_0 = function() {
}, },
'EX_GeographicBoundingBox': function(node, obj) { 'EX_GeographicBoundingBox': function(node, obj) {
// replacement of LatLonBoundingBox // replacement of LatLonBoundingBox
obj.llbbox = []; obj['llbbox'] = [];
this.readChildNodes(node, obj.llbbox); this.readChildNodes(node, obj['llbbox']);
}, },
'westBoundLongitude': function(node, obj) { 'westBoundLongitude': function(node, obj) {
obj[0] = this.getChildValue(node); obj[0] = this.getChildValue(node);
@@ -50,10 +50,10 @@ ol.parser.ogc.WMSCapabilities_v1_3_0 = function() {
obj[3] = this.getChildValue(node); obj[3] = this.getChildValue(node);
}, },
'MinScaleDenominator': function(node, obj) { 'MinScaleDenominator': function(node, obj) {
obj.maxScale = parseFloat(this.getChildValue(node)).toPrecision(16); obj['maxScale'] = parseFloat(this.getChildValue(node)).toPrecision(16);
}, },
'MaxScaleDenominator': function(node, obj) { 'MaxScaleDenominator': function(node, obj) {
obj.minScale = parseFloat(this.getChildValue(node)).toPrecision(16); obj['minScale'] = parseFloat(this.getChildValue(node)).toPrecision(16);
}, },
'Dimension': function(node, obj) { 'Dimension': function(node, obj) {
// dimension has extra attributes: default, multipleValues, // dimension has extra attributes: default, multipleValues,
@@ -61,27 +61,27 @@ ol.parser.ogc.WMSCapabilities_v1_3_0 = function() {
// also contains the values. // also contains the values.
var name = node.getAttribute('name').toLowerCase(); var name = node.getAttribute('name').toLowerCase();
var dim = { var dim = {
name: name, 'name': name,
units: node.getAttribute('units'), 'units': node.getAttribute('units'),
unitsymbol: node.getAttribute('unitSymbol'), 'unitsymbol': node.getAttribute('unitSymbol'),
nearestVal: node.getAttribute('nearestValue') === '1', 'nearestVal': node.getAttribute('nearestValue') === '1',
multipleVal: node.getAttribute('multipleValues') === '1', 'multipleVal': node.getAttribute('multipleValues') === '1',
'default': node.getAttribute('default') || '', 'default': node.getAttribute('default') || '',
current: node.getAttribute('current') === '1', 'current': node.getAttribute('current') === '1',
values: this.getChildValue(node).split(',') 'values': this.getChildValue(node).split(',')
}; };
// Theoretically there can be more dimensions with the same // Theoretically there can be more dimensions with the same
// name, but with a different unit. Until we meet such a case, // name, but with a different unit. Until we meet such a case,
// let's just keep the same structure as the WMS 1.1 // let's just keep the same structure as the WMS 1.1
// GetCapabilities parser uses. We will store the last // GetCapabilities parser uses. We will store the last
// one encountered. // one encountered.
obj.dimensions[dim.name] = dim; obj['dimensions'][dim['name']] = dim;
}, },
'Keyword': function(node, obj) { 'Keyword': function(node, obj) {
var keyword = {value: this.getChildValue(node), var keyword = {'value': this.getChildValue(node),
vocabulary: node.getAttribute('vocabulary')}; 'vocabulary': node.getAttribute('vocabulary')};
if (obj.keywords) { if (obj['keywords']) {
obj.keywords.push(keyword); obj['keywords'].push(keyword);
} }
} }
}); });
@@ -91,9 +91,9 @@ ol.parser.ogc.WMSCapabilities_v1_3_0 = function() {
readers.UserDefinedSymbolization.apply(this, arguments); readers.UserDefinedSymbolization.apply(this, arguments);
// add the two extra attributes // add the two extra attributes
var value = node.getAttribute('InlineFeature'); var value = node.getAttribute('InlineFeature');
obj['userSymbols'].inlineFeature = parseInt(value, 10) == 1; obj['userSymbols']['inlineFeature'] = parseInt(value, 10) == 1;
value = node.getAttribute('RemoteWCS'); value = node.getAttribute('RemoteWCS');
obj['userSymbols'].remoteWCS = parseInt(value, 10) == 1; obj['userSymbols']['remoteWCS'] = parseInt(value, 10) == 1;
}, },
'DescribeLayer': function(node, obj) { 'DescribeLayer': function(node, obj) {
var readers = this.readers['http://www.opengis.net/wms']; var readers = this.readers['http://www.opengis.net/wms'];
@@ -129,30 +129,11 @@ ol.renderer.canvas.TileLayer.prototype.renderFrame =
var tilesToDrawByZ = {}; var tilesToDrawByZ = {};
tilesToDrawByZ[z] = {}; tilesToDrawByZ[z] = {};
var findInterimTiles = function(z, tileRange) { function isLoaded(tile) {
// FIXME this could be more efficient about filling partial holes return !goog.isNull(tile) && tile.getState() == ol.TileState.LOADED;
var fullyCovered = true;
var tile, tileCoord, tileCoordKey, x, y;
for (x = tileRange.minX; x <= tileRange.maxX; ++x) {
for (y = tileRange.minY; y <= tileRange.maxY; ++y) {
tileCoord = new ol.TileCoord(z, x, y);
tileCoordKey = tileCoord.toString();
if (tilesToDrawByZ[z] && tilesToDrawByZ[z][tileCoordKey]) {
return;
} }
tile = tileSource.getTile(tileCoord); var findLoadedTiles = goog.bind(tileSource.findLoadedTiles, tileSource,
if (!goog.isNull(tile) && tile.getState() == ol.TileState.LOADED) { tilesToDrawByZ, isLoaded);
if (!tilesToDrawByZ[z]) {
tilesToDrawByZ[z] = {};
}
tilesToDrawByZ[z][tileCoordKey] = tile;
} else {
fullyCovered = false;
}
}
}
return fullyCovered;
};
var allTilesLoaded = true; var allTilesLoaded = true;
var tile, tileCenter, tileCoord, tileState, x, y; var tile, tileCenter, tileCoord, tileState, x, y;
@@ -180,7 +161,7 @@ ol.renderer.canvas.TileLayer.prototype.renderFrame =
} }
allTilesLoaded = false; allTilesLoaded = false;
tileGrid.forEachTileCoordParentTileRange(tileCoord, findInterimTiles); tileGrid.forEachTileCoordParentTileRange(tileCoord, findLoadedTiles);
} }
} }
+5 -24
View File
@@ -93,30 +93,11 @@ ol.renderer.dom.TileLayer.prototype.renderFrame =
var tilesToDrawByZ = {}; var tilesToDrawByZ = {};
tilesToDrawByZ[z] = {}; tilesToDrawByZ[z] = {};
var findInterimTiles = function(z, tileRange) { function isLoaded(tile) {
// FIXME this could be more efficient about filling partial holes return !goog.isNull(tile) && tile.getState() == ol.TileState.LOADED;
var fullyCovered = true;
var tile, tileCoord, tileCoordKey, x, y;
for (x = tileRange.minX; x <= tileRange.maxX; ++x) {
for (y = tileRange.minY; y <= tileRange.maxY; ++y) {
tileCoord = new ol.TileCoord(z, x, y);
tileCoordKey = tileCoord.toString();
if (tilesToDrawByZ[z] && tilesToDrawByZ[z][tileCoordKey]) {
return;
} }
tile = tileSource.getTile(tileCoord); var findLoadedTiles = goog.bind(tileSource.findLoadedTiles, tileSource,
if (!goog.isNull(tile) && tile.getState() == ol.TileState.LOADED) { tilesToDrawByZ, isLoaded);
if (!tilesToDrawByZ[z]) {
tilesToDrawByZ[z] = {};
}
tilesToDrawByZ[z][tileCoordKey] = tile;
} else {
fullyCovered = false;
}
}
}
return fullyCovered;
};
var allTilesLoaded = true; var allTilesLoaded = true;
var tile, tileCenter, tileCoord, tileState, x, y; var tile, tileCenter, tileCoord, tileState, x, y;
@@ -144,7 +125,7 @@ ol.renderer.dom.TileLayer.prototype.renderFrame =
} }
allTilesLoaded = false; allTilesLoaded = false;
tileGrid.forEachTileCoordParentTileRange(tileCoord, findInterimTiles); tileGrid.forEachTileCoordParentTileRange(tileCoord, findLoadedTiles);
} }
@@ -365,32 +365,12 @@ ol.renderer.webgl.TileLayer.prototype.renderFrame =
var tilesToDrawByZ = {}; var tilesToDrawByZ = {};
tilesToDrawByZ[z] = {}; tilesToDrawByZ[z] = {};
var findInterimTiles = function(z, tileRange) { function isLoaded(tile) {
// FIXME this could be more efficient about filling partial holes return !goog.isNull(tile) && tile.getState() == ol.TileState.LOADED &&
var fullyCovered = true; mapRenderer.isTileTextureLoaded(tile);
var tile, tileCoord, tileCoordKey, x, y;
for (x = tileRange.minX; x <= tileRange.maxX; ++x) {
for (y = tileRange.minY; y <= tileRange.maxY; ++y) {
tileCoord = new ol.TileCoord(z, x, y);
tileCoordKey = tileCoord.toString();
if (tilesToDrawByZ[z] && tilesToDrawByZ[z][tileCoordKey]) {
return;
} }
tile = tileSource.getTile(tileCoord); var findLoadedTiles = goog.bind(tileSource.findLoadedTiles, tileSource,
if (!goog.isNull(tile) && tilesToDrawByZ, isLoaded);
tile.getState() == ol.TileState.LOADED &&
mapRenderer.isTileTextureLoaded(tile)) {
if (!tilesToDrawByZ[z]) {
tilesToDrawByZ[z] = {};
}
tilesToDrawByZ[z][tileCoordKey] = tile;
} else {
fullyCovered = false;
}
}
}
return fullyCovered;
};
var tilesToLoad = new goog.structs.PriorityQueue(); var tilesToLoad = new goog.structs.PriorityQueue();
@@ -428,7 +408,7 @@ ol.renderer.webgl.TileLayer.prototype.renderFrame =
} }
allTilesLoaded = false; allTilesLoaded = false;
tileGrid.forEachTileCoordParentTileRange(tileCoord, findInterimTiles); tileGrid.forEachTileCoordParentTileRange(tileCoord, findLoadedTiles);
} }
+40
View File
@@ -58,6 +58,46 @@ ol.source.TileSource.prototype.canExpireCache = goog.functions.FALSE;
ol.source.TileSource.prototype.expireCache = goog.abstractMethod; ol.source.TileSource.prototype.expireCache = goog.abstractMethod;
/**
* Look for loaded tiles over a given tile range and zoom level. Adds
* properties to the provided lookup representing key/tile pairs for already
* loaded tiles.
*
* @param {Object.<number, Object.<string, ol.Tile>>} loadedTilesByZ A lookup of
* loaded tiles by zoom level.
* @param {function(ol.Tile): boolean} isLoaded A function to determine if a
* tile is fully loaded.
* @param {number} z Zoom level.
* @param {ol.TileRange} tileRange Tile range.
* @return {boolean} The tile range is fully covered with loaded tiles.
*/
ol.source.TileSource.prototype.findLoadedTiles = function(loadedTilesByZ,
isLoaded, z, tileRange) {
// FIXME this could be more efficient about filling partial holes
var fullyCovered = true;
var tile, tileCoord, tileCoordKey, x, y;
for (x = tileRange.minX; x <= tileRange.maxX; ++x) {
for (y = tileRange.minY; y <= tileRange.maxY; ++y) {
tileCoord = new ol.TileCoord(z, x, y);
tileCoordKey = tileCoord.toString();
if (loadedTilesByZ[z] && loadedTilesByZ[z][tileCoordKey]) {
continue;
}
tile = this.getTile(tileCoord);
if (isLoaded(tile)) {
if (!loadedTilesByZ[z]) {
loadedTilesByZ[z] = {};
}
loadedTilesByZ[z][tileCoordKey] = tile;
} else {
fullyCovered = false;
}
}
}
return fullyCovered;
};
/** /**
* @inheritDoc * @inheritDoc
*/ */
+2
View File
@@ -23,6 +23,8 @@ ol.ViewHint = {
*/ */
ol.View = function() { ol.View = function() {
goog.base(this);
/** /**
* @private * @private
* @type {Array.<number>} * @type {Array.<number>}
+88 -2
View File
@@ -34,6 +34,54 @@ describe('ol.Object', function() {
}); });
}); });
describe('#get()', function() {
it('does not return values that are not explicitly set', function() {
var o = new ol.Object();
expect(o.get('constructor')).toBeUndefined();
expect(o.get('hasOwnProperty')).toBeUndefined();
expect(o.get('isPrototypeOf')).toBeUndefined();
expect(o.get('propertyIsEnumerable')).toBeUndefined();
expect(o.get('toLocaleString')).toBeUndefined();
expect(o.get('toString')).toBeUndefined();
expect(o.get('valueOf')).toBeUndefined();
});
});
describe('#set()', function() {
it('can be used with arbitrary names', function() {
var o = new ol.Object();
o.set('set', 'sat');
expect(o.get('set')).toBe('sat');
o.set('get', 'got');
expect(o.get('get')).toBe('got');
o.set('toString', 'string');
expect(o.get('toString')).toBe('string');
expect(typeof o.toString).toBe('function');
});
});
describe('#getKeys()', function() {
it('returns property names set at construction', function() {
var o = new ol.Object({
prop1: 'val1',
prop2: 'val2',
toString: 'string',
get: 'foo'
});
var keys = o.getKeys();
expect(keys.length).toBe(4);
expect(keys.sort()).toEqual(['get', 'prop1', 'prop2', 'toString']);
});
});
describe('setValues', function() { describe('setValues', function() {
it('sets multiple values at once', function() { it('sets multiple values at once', function() {
@@ -43,6 +91,9 @@ describe('ol.Object', function() {
}); });
expect(o.get('k1')).toEqual(1); expect(o.get('k1')).toEqual(1);
expect(o.get('k2')).toEqual(2); expect(o.get('k2')).toEqual(2);
var keys = o.getKeys().sort();
expect(keys).toEqual(['k1', 'k2']);
}); });
}); });
@@ -99,6 +150,9 @@ describe('ol.Object', function() {
it('dispatches events to object', function() { it('dispatches events to object', function() {
o.set('k', 1); o.set('k', 1);
expect(listener1).toHaveBeenCalled(); expect(listener1).toHaveBeenCalled();
expect(o.getKeys()).toEqual(['k']);
expect(o2.getKeys()).toEqual(['k']);
}); });
it('dispatches generic change events to object', function() { it('dispatches generic change events to object', function() {
@@ -114,6 +168,9 @@ describe('ol.Object', function() {
it('dispatches events to object bound to', function() { it('dispatches events to object bound to', function() {
o2.set('k', 2); o2.set('k', 2);
expect(listener1).toHaveBeenCalled(); expect(listener1).toHaveBeenCalled();
expect(o.getKeys()).toEqual(['k']);
expect(o2.getKeys()).toEqual(['k']);
}); });
it('dispatches generic change events to object bound to', function() { it('dispatches generic change events to object bound to', function() {
@@ -137,6 +194,9 @@ describe('ol.Object', function() {
o2.bindTo('k', o); o2.bindTo('k', o);
expect(o.get('k')).toEqual(1); expect(o.get('k')).toEqual(1);
expect(o2.get('k')).toEqual(1); expect(o2.get('k')).toEqual(1);
expect(o.getKeys()).toEqual(['k']);
expect(o2.getKeys()).toEqual(['k']);
}); });
}); });
@@ -147,6 +207,9 @@ describe('ol.Object', function() {
o.set('k', 1); o.set('k', 1);
expect(o.get('k')).toEqual(1); expect(o.get('k')).toEqual(1);
expect(o2.get('k')).toEqual(1); expect(o2.get('k')).toEqual(1);
expect(o.getKeys()).toEqual(['k']);
expect(o2.getKeys()).toEqual(['k']);
}); });
}); });
@@ -239,6 +302,9 @@ describe('ol.Object', function() {
expect(o2.get('k1')).toBeUndefined(); expect(o2.get('k1')).toBeUndefined();
expect(listener1).toHaveBeenCalled(); expect(listener1).toHaveBeenCalled();
expect(listener2).toHaveBeenCalled(); expect(listener2).toHaveBeenCalled();
expect(o.getKeys()).toEqual(['k1']);
expect(o2.getKeys()).toEqual(['k2']);
}); });
}); });
@@ -257,6 +323,10 @@ describe('ol.Object', function() {
expect(o.get('k1')).toEqual(1); expect(o.get('k1')).toEqual(1);
expect(o2.get('k2')).toEqual(1); expect(o2.get('k2')).toEqual(1);
expect(o3.get('k3')).toEqual(1); expect(o3.get('k3')).toEqual(1);
expect(o.getKeys()).toEqual(['k1']);
expect(o2.getKeys()).toEqual(['k2']);
expect(o3.getKeys()).toEqual(['k3']);
}); });
describe('backward', function() { describe('backward', function() {
@@ -266,6 +336,10 @@ describe('ol.Object', function() {
expect(o.get('k1')).toEqual(1); expect(o.get('k1')).toEqual(1);
expect(o2.get('k2')).toEqual(1); expect(o2.get('k2')).toEqual(1);
expect(o3.get('k3')).toEqual(1); expect(o3.get('k3')).toEqual(1);
expect(o.getKeys()).toEqual(['k1']);
expect(o2.getKeys()).toEqual(['k2']);
expect(o3.getKeys()).toEqual(['k3']);
}); });
}); });
}); });
@@ -309,7 +383,7 @@ describe('ol.Object', function() {
describe('setter', function() { describe('setter', function() {
beforeEach(function() { beforeEach(function() {
o.setX = function(x) { o.setX = function(x) {
this.x = x; this.set('x', x);
}; };
spyOn(o, 'setX').andCallThrough(); spyOn(o, 'setX').andCallThrough();
}); });
@@ -319,6 +393,8 @@ describe('ol.Object', function() {
o.set('x', 1); o.set('x', 1);
expect(o.get('x')).toEqual(1); expect(o.get('x')).toEqual(1);
expect(o.setX).not.toHaveBeenCalled(); expect(o.setX).not.toHaveBeenCalled();
expect(o.getKeys()).toEqual(['x']);
}); });
}); });
@@ -327,8 +403,11 @@ describe('ol.Object', function() {
var o2 = new ol.Object(); var o2 = new ol.Object();
o2.bindTo('x', o); o2.bindTo('x', o);
o2.set('x', 1); o2.set('x', 1);
expect(o.get('x')).toEqual(1);
expect(o.setX).toHaveBeenCalled(); expect(o.setX).toHaveBeenCalled();
expect(o.get('x')).toEqual(1);
expect(o.getKeys()).toEqual(['x']);
expect(o2.getKeys()).toEqual(['x']);
}); });
}); });
}); });
@@ -354,6 +433,9 @@ describe('ol.Object', function() {
o2.bindTo('x', o); o2.bindTo('x', o);
expect(o2.get('x')).toEqual(1); expect(o2.get('x')).toEqual(1);
expect(o.getX).toHaveBeenCalled(); expect(o.getX).toHaveBeenCalled();
expect(o.getKeys()).toEqual([]);
expect(o2.getKeys()).toEqual(['x']);
}); });
}); });
}); });
@@ -368,6 +450,8 @@ describe('ol.Object', function() {
it('sets the property', function() { it('sets the property', function() {
var o = new ol.Object({k: 1}); var o = new ol.Object({k: 1});
expect(o.get('k')).toEqual(1); expect(o.get('k')).toEqual(1);
expect(o.getKeys()).toEqual(['k']);
}); });
}); });
@@ -385,6 +469,8 @@ describe('ol.Object', function() {
o.set('K', 1); o.set('K', 1);
expect(listener1).toHaveBeenCalled(); expect(listener1).toHaveBeenCalled();
expect(listener2).not.toHaveBeenCalled(); expect(listener2).not.toHaveBeenCalled();
expect(o.getKeys()).toEqual(['K']);
}); });
}); });
}); });
+23 -28
View File
@@ -5,14 +5,20 @@ describe('ol.parser.ogc.exceptionreport', function() {
var parser = new ol.parser.ogc.ExceptionReport(); var parser = new ol.parser.ogc.ExceptionReport();
describe('test read exception', function() { describe('test read exception', function() {
it('OCG WMS 1.3.0 exceptions', function() {
var result, exceptions; var result, exceptions;
runs(function() {
var url = 'spec/ol/parser/ogc/xml/exceptionreport/wms1_3_0.xml'; var url = 'spec/ol/parser/ogc/xml/exceptionreport/wms1_3_0.xml';
goog.net.XhrIo.send(url, function(e) { goog.net.XhrIo.send(url, function(e) {
var xhr = e.target; var xhr = e.target;
result = parser.read(xhr.getResponseXml()); result = parser.read(xhr.getResponseXml());
exceptions = result.exceptionReport.exceptions; exceptions = result.exceptionReport.exceptions;
}); });
it('OCG WMS 1.3.0 exceptions', function() { });
waitsFor(function() {
return (result !== undefined);
}, 'XHR timeout', 1000);
runs(function() {
expect(exceptions.length).toBe(4); expect(exceptions.length).toBe(4);
var str = 'Plain text message about an error.'; var str = 'Plain text message about an error.';
expect(goog.string.trim(exceptions[0].text)).toBe(str); expect(goog.string.trim(exceptions[0].text)).toBe(str);
@@ -33,9 +39,9 @@ describe('ol.parser.ogc.exceptionreport', function() {
expect(goog.string.trim(exceptions[3].text), str); expect(goog.string.trim(exceptions[3].text), str);
}); });
}); });
it('test read exception OWSCommon 1.0.0', function() {
describe('test read exception OWSCommon 1.0.0', function() {
var result, report, exception; var result, report, exception;
runs(function() {
var url = 'spec/ol/parser/ogc/xml/exceptionreport/ows1_0_0.xml'; var url = 'spec/ol/parser/ogc/xml/exceptionreport/ows1_0_0.xml';
goog.net.XhrIo.send(url, function(e) { goog.net.XhrIo.send(url, function(e) {
var xhr = e.target; var xhr = e.target;
@@ -43,30 +49,24 @@ describe('ol.parser.ogc.exceptionreport', function() {
report = result.exceptionReport; report = result.exceptionReport;
exception = report.exceptions[0]; exception = report.exceptions[0];
}); });
it('Version parsed correctly', function() { });
waitsFor(function() {
return (result !== undefined);
}, 'XHR timeout', 1000);
runs(function() {
expect(report.version).toEqual('1.0.0'); expect(report.version).toEqual('1.0.0');
});
it('Language parsed correctly', function() {
expect(report.language).toEqual('en'); expect(report.language).toEqual('en');
});
it('exceptionCode properly parsed', function() {
expect(exception.code).toEqual('InvalidParameterValue'); expect(exception.code).toEqual('InvalidParameterValue');
});
it('locator properly parsed', function() {
expect(exception.locator).toEqual('foo'); expect(exception.locator).toEqual('foo');
});
it('ExceptionText correctly parsed', function() {
var msg = 'Update error: Error occured updating features'; var msg = 'Update error: Error occured updating features';
expect(exception.texts[0]).toEqual(msg); expect(exception.texts[0]).toEqual(msg);
}); msg = 'Second exception line';
it('Second ExceptionText correctly parsed', function() {
var msg = 'Second exception line';
expect(exception.texts[1]).toEqual(msg); expect(exception.texts[1]).toEqual(msg);
}); });
}); });
it('test read exception OWSCommon 1.1.0', function() {
describe('test read exception OWSCommon 1.1.0', function() {
var result, report, exception; var result, report, exception;
runs(function() {
var url = 'spec/ol/parser/ogc/xml/exceptionreport/ows1_1_0.xml'; var url = 'spec/ol/parser/ogc/xml/exceptionreport/ows1_1_0.xml';
goog.net.XhrIo.send(url, function(e) { goog.net.XhrIo.send(url, function(e) {
var xhr = e.target; var xhr = e.target;
@@ -74,27 +74,22 @@ describe('ol.parser.ogc.exceptionreport', function() {
report = result.exceptionReport; report = result.exceptionReport;
exception = report.exceptions[0]; exception = report.exceptions[0];
}); });
it('Version parsed correctly', function() { });
waitsFor(function() {
return (result !== undefined);
}, 'XHR timeout', 1000);
runs(function() {
expect(report.version).toEqual('1.1.0'); expect(report.version).toEqual('1.1.0');
});
it('Language parsed correctly', function() {
expect(report.language).toEqual('en'); expect(report.language).toEqual('en');
});
it('exceptionCode properly parsed', function() {
expect(exception.code).toEqual('InvalidParameterValue'); expect(exception.code).toEqual('InvalidParameterValue');
});
it('locator properly parsed', function() {
expect(exception.locator).toEqual('foo'); expect(exception.locator).toEqual('foo');
});
it('ExceptionText correctly parsed', function() {
var msg = 'Update error: Error occured updating features'; var msg = 'Update error: Error occured updating features';
expect(exception.texts[0]).toEqual(msg); expect(exception.texts[0]).toEqual(msg);
});
it('Second ExceptionText correctly parsed', function() {
expect(exception.texts[1]).toEqual('Second exception line'); expect(exception.texts[1]).toEqual('Second exception line');
}); });
}); });
}); });
});
goog.require('goog.net.XhrIo'); goog.require('goog.net.XhrIo');
goog.require('goog.string'); goog.require('goog.string');
@@ -5,20 +5,30 @@ describe('ol.parser.ogc.wmscapabilities_v1_1_1', function() {
var parser = new ol.parser.ogc.WMSCapabilities(); var parser = new ol.parser.ogc.WMSCapabilities();
describe('test read exception', function() { describe('test read exception', function() {
var obj, url; it('Error reported correctly', function() {
url = 'spec/ol/parser/ogc/xml/wmscapabilities_v1_1_1/exceptionsample.xml'; var obj;
runs(function() {
var url = 'spec/ol/parser/ogc/xml/wmscapabilities_v1_1_1/' +
'exceptionsample.xml';
goog.net.XhrIo.send(url, function(e) { goog.net.XhrIo.send(url, function(e) {
var xhr = e.target; var xhr = e.target;
obj = parser.read(xhr.getResponseXml()); obj = parser.read(xhr.getResponseXml());
}); });
it('Error reported correctly', function() { });
waitsFor(function() {
return (obj !== undefined);
}, 'XHR timeout', 1000);
runs(function() {
expect(!!obj.error).toBeTruthy(); expect(!!obj.error).toBeTruthy();
}); });
}); });
});
describe('test read', function() { describe('test read', function() {
var obj, capability, getmap, describelayer, getfeatureinfo, layer, url; it('Test read', function() {
url = 'spec/ol/parser/ogc/xml/wmscapabilities_v1_1_1/gssample.xml'; var obj, capability, getmap, describelayer, getfeatureinfo, layer;
runs(function() {
var url = 'spec/ol/parser/ogc/xml/wmscapabilities_v1_1_1/gssample.xml';
goog.net.XhrIo.send(url, function(e) { goog.net.XhrIo.send(url, function(e) {
var xhr = e.target; var xhr = e.target;
obj = parser.read(xhr.getResponseXml()); obj = parser.read(xhr.getResponseXml());
@@ -28,95 +38,54 @@ describe('ol.parser.ogc.wmscapabilities_v1_1_1', function() {
getfeatureinfo = capability.request.getfeatureinfo; getfeatureinfo = capability.request.getfeatureinfo;
layer = capability.layers[2]; layer = capability.layers[2];
}); });
it('object contains capability property', function() { });
waitsFor(function() {
return (obj !== undefined);
}, 'XHR timeout', 1000);
runs(function() {
expect(capability).toBeTruthy(); expect(capability).toBeTruthy();
});
it('getmap formats parsed', function() {
expect(getmap.formats.length).toEqual(28); expect(getmap.formats.length).toEqual(28);
}); var get = 'http://publicus.opengeo.org:80/geoserver/wms?SERVICE=WMS&';
it('getmap href parsed', function() { expect(getmap.get.href).toEqual(get);
var url = 'http://publicus.opengeo.org:80/geoserver/wms?SERVICE=WMS&';
expect(getmap.href).toEqual(url);
});
it('getmap.get.href parsed', function() {
expect(getmap.get.href).toEqual(getmap.href);
});
it('getmap.post not available', function() {
expect(getmap.post).toBeUndefined(); expect(getmap.post).toBeUndefined();
}); get = 'http://publicus.opengeo.org:80/geoserver/wms?SERVICE=WMS&';
it('describelayer href parsed', function() { expect(describelayer.get.href).toEqual(get);
var url = 'http://publicus.opengeo.org:80/geoserver/wms?SERVICE=WMS&';
expect(describelayer.href).toEqual(url);
});
it('describelayer.get.href parsed', function() {
expect(describelayer.get.href).toEqual(describelayer.href);
});
it('describelayer.post not available', function() {
expect(describelayer.post).toBeUndefined(); expect(describelayer.post).toBeUndefined();
}); get = 'http://publicus.opengeo.org:80/geoserver/wms?SERVICE=WMS&';
it('getfeatureinfo href parsed', function() { expect(getfeatureinfo.get.href).toEqual(get);
var url = 'http://publicus.opengeo.org:80/geoserver/wms?SERVICE=WMS&'; var post = 'http://publicus.opengeo.org:80/geoserver/wms?SERVICE=WMS&';
expect(getfeatureinfo.href).toEqual(url); expect(getfeatureinfo.post.href).toEqual(post);
});
it('getmap.get.href parsed', function() {
expect(getfeatureinfo.get.href).toEqual(getfeatureinfo.href);
});
it('getfeatureinfo.post set correctly', function() {
var url = 'http://publicus.opengeo.org:80/geoserver/wms?SERVICE=WMS&';
expect(getfeatureinfo.post.href).toEqual(url);
});
it('layers parsed', function() {
expect(capability.layers).toBeTruthy(); expect(capability.layers).toBeTruthy();
});
it('correct number of layers parsed', function() {
expect(capability.layers.length).toEqual(22); expect(capability.layers.length).toEqual(22);
}); var infoFormats = ['text/plain', 'text/html',
it('infoFormats set on layer', function() { 'application/vnd.ogc.gml'];
var infoFormats = ['text/plain', 'text/html', 'application/vnd.ogc.gml'];
expect(layer.infoFormats).toEqual(infoFormats); expect(layer.infoFormats).toEqual(infoFormats);
});
it('[2] correct layer name', function() {
expect(layer.name).toEqual('tiger:tiger_roads'); expect(layer.name).toEqual('tiger:tiger_roads');
});
it('[2] correct layer prefix', function() {
expect(layer.prefix).toEqual('tiger'); expect(layer.prefix).toEqual('tiger');
});
it('[2] correct layer title', function() {
expect(layer.title).toEqual('Manhattan (NY) roads'); expect(layer.title).toEqual('Manhattan (NY) roads');
});
it('[2] correct layer abstract', function() {
var abstr = 'Highly simplified road layout of Manhattan in New York..'; var abstr = 'Highly simplified road layout of Manhattan in New York..';
expect(layer['abstract']).toEqual(abstr); expect(layer['abstract']).toEqual(abstr);
});
it('[2] correct layer bbox', function() {
var bbox = [-74.08769307536667, 40.660618924633326, var bbox = [-74.08769307536667, 40.660618924633326,
-73.84653192463333, 40.90178007536667]; -73.84653192463333, 40.90178007536667];
expect(layer.llbbox).toEqual(bbox); expect(layer.llbbox).toEqual(bbox);
});
it('[2] correct styles length', function() {
expect(layer.styles.length).toEqual(1); expect(layer.styles.length).toEqual(1);
});
it('[2] correct style name', function() {
expect(layer.styles[0].name).toEqual('tiger_roads'); expect(layer.styles[0].name).toEqual('tiger_roads');
}); var legend = 'http://publicus.opengeo.org:80/geoserver/wms/' +
it('[2] correct legend url', function() {
var url = 'http://publicus.opengeo.org:80/geoserver/wms/' +
'GetLegendGraphic?VERSION=1.0.0&FORMAT=image/png&WIDTH=20&' + 'GetLegendGraphic?VERSION=1.0.0&FORMAT=image/png&WIDTH=20&' +
'HEIGHT=20&LAYER=tiger:tiger_roads'; 'HEIGHT=20&LAYER=tiger:tiger_roads';
expect(layer.styles[0].legend.href).toEqual(url); expect(layer.styles[0].legend.href).toEqual(legend);
});
it('[2] correct legend format', function() {
expect(layer.styles[0].legend.format).toEqual('image/png'); expect(layer.styles[0].legend.format).toEqual('image/png');
});
it('[2] correct queryable attribute', function() {
expect(layer.queryable).toBeTruthy(); expect(layer.queryable).toBeTruthy();
}); });
}); });
});
describe('test layers', function() { describe('test layers', function() {
it('Test layers', function() {
var obj, capability, layers = {}, rootlayer, identifiers, authorities; var obj, capability, layers = {}, rootlayer, identifiers, authorities;
var featurelist, url; var featurelist;
url = 'spec/ol/parser/ogc/xml/wmscapabilities_v1_1_1/ogcsample.xml'; runs(function() {
var url = 'spec/ol/parser/ogc/xml/wmscapabilities_v1_1_1/ogcsample.xml';
goog.net.XhrIo.send(url, function(e) { goog.net.XhrIo.send(url, function(e) {
var xhr = e.target; var xhr = e.target;
obj = parser.read(xhr.getResponseXml()); obj = parser.read(xhr.getResponseXml());
@@ -131,85 +100,50 @@ describe('ol.parser.ogc.wmscapabilities_v1_1_1', function() {
authorities = layers['ROADS_RIVERS'].authorityURLs; authorities = layers['ROADS_RIVERS'].authorityURLs;
featurelist = layers['ROADS_RIVERS'].featureListURL; featurelist = layers['ROADS_RIVERS'].featureListURL;
}); });
it('SRS parsed correctly for root layer', function() {
expect(rootlayer.srs).toEqual({'EPSG:4326': true});
}); });
it('Inheritance of SRS handled correctly when adding SRSes', function() { waitsFor(function() {
return (obj !== undefined);
}, 'XHR timeout', 1000);
runs(function() {
expect(rootlayer.srs).toEqual({'EPSG:4326': true});
var srs = {'EPSG:4326': true, 'EPSG:26986': true}; var srs = {'EPSG:4326': true, 'EPSG:26986': true};
expect(layers['ROADS_RIVERS'].srs).toEqual(srs); expect(layers['ROADS_RIVERS'].srs).toEqual(srs);
});
var msg = 'Inheritance of SRS handled correctly when redeclaring an ' +
'inherited SRS';
it(msg, function() {
expect(layers['Temperature'].srs).toEqual({'EPSG:4326': true}); expect(layers['Temperature'].srs).toEqual({'EPSG:4326': true});
});
it('Correct bbox and res from BoundingBox', function() {
var bbox = layers['ROADS_RIVERS'].bbox['EPSG:26986']; var bbox = layers['ROADS_RIVERS'].bbox['EPSG:26986'];
expect(bbox.bbox).toEqual([189000, 834000, 285000, 962000]); expect(bbox.bbox).toEqual([189000, 834000, 285000, 962000]);
expect(bbox.res).toEqual({x: 1, y: 1}); expect(bbox.res).toEqual({x: 1, y: 1});
});
it('Correct bbox and res from BoundingBox (override)', function() {
bbox = layers['ROADS_RIVERS'].bbox['EPSG:4326']; bbox = layers['ROADS_RIVERS'].bbox['EPSG:4326'];
expect(bbox.bbox).toEqual([-71.63, 41.75, -70.78, 42.90]); expect(bbox.bbox).toEqual([-71.63, 41.75, -70.78, 42.90]);
expect(bbox.res).toEqual({x: 0.01, y: 0.01}); expect(bbox.res).toEqual({x: 0.01, y: 0.01});
});
it('Correctly inherited bbox and resolution', function() {
bbox = layers['ROADS_1M'].bbox['EPSG:26986']; bbox = layers['ROADS_1M'].bbox['EPSG:26986'];
expect(bbox.bbox).toEqual([189000, 834000, 285000, 962000]); expect(bbox.bbox).toEqual([189000, 834000, 285000, 962000]);
expect(bbox.res).toEqual({x: 1, y: 1}); expect(bbox.res).toEqual({x: 1, y: 1});
});
it('got identifiers from layer ROADS_RIVERS', function() {
expect(identifiers).toBeTruthy(); expect(identifiers).toBeTruthy();
});
it('authority attribute from Identifiers parsed correctly', function() {
expect('DIF_ID' in identifiers).toBeTruthy(); expect('DIF_ID' in identifiers).toBeTruthy();
});
it('Identifier value parsed correctly', function() {
expect(identifiers['DIF_ID']).toEqual('123456'); expect(identifiers['DIF_ID']).toEqual('123456');
});
it('AuthorityURLs parsed and inherited correctly', function() {
expect('DIF_ID' in authorities).toBeTruthy(); expect('DIF_ID' in authorities).toBeTruthy();
});
it('OnlineResource in AuthorityURLs parsed correctly', function() {
var url = 'http://gcmd.gsfc.nasa.gov/difguide/whatisadif.html'; var url = 'http://gcmd.gsfc.nasa.gov/difguide/whatisadif.html';
expect(authorities['DIF_ID']).toEqual(url); expect(authorities['DIF_ID']).toEqual(url);
});
it('layer has FeatureListURL', function() {
expect(featurelist).toBeTruthy(); expect(featurelist).toBeTruthy();
});
it('FeatureListURL format parsed correctly', function() {
expect(featurelist.format).toEqual('application/vnd.ogc.se_xml'); expect(featurelist.format).toEqual('application/vnd.ogc.se_xml');
}); url = 'http://www.university.edu/data/roads_rivers.gml';
it('FeatureListURL OnlineResource parsed correctly', function() {
var url = 'http://www.university.edu/data/roads_rivers.gml';
expect(featurelist.href).toEqual(url); expect(featurelist.href).toEqual(url);
});
it('queryable property inherited correctly', function() {
expect(layers['Pressure'].queryable).toBeTruthy(); expect(layers['Pressure'].queryable).toBeTruthy();
});
it('queryable property has correct default value', function() {
expect(layers['ozone_image'].queryable).toBeFalsy(); expect(layers['ozone_image'].queryable).toBeFalsy();
});
it('cascaded property parsed correctly', function() {
expect(layers['population'].cascaded).toEqual(1); expect(layers['population'].cascaded).toEqual(1);
});
it('fixedWidth property correctly parsed', function() {
expect(layers['ozone_image'].fixedWidth).toEqual(512); expect(layers['ozone_image'].fixedWidth).toEqual(512);
});
it('fixedHeight property correctly parsed', function() {
expect(layers['ozone_image'].fixedHeight).toEqual(256); expect(layers['ozone_image'].fixedHeight).toEqual(256);
});
it('opaque property parsed correctly', function() {
expect(layers['ozone_image'].opaque).toBeTruthy(); expect(layers['ozone_image'].opaque).toBeTruthy();
});
it('noSubsets property parsed correctly', function() {
expect(layers['ozone_image'].noSubsets).toBeTruthy(); expect(layers['ozone_image'].noSubsets).toBeTruthy();
}); });
}); });
});
describe('test dimensions', function() { describe('test dimensions', function() {
var obj, capability, layers = {}, time, elevation, url; it('Test dimensions', function() {
url = 'spec/ol/parser/ogc/xml/wmscapabilities_v1_1_1/ogcsample.xml'; var obj, capability, layers = {}, time, elevation;
runs(function() {
var url = 'spec/ol/parser/ogc/xml/wmscapabilities_v1_1_1/ogcsample.xml';
goog.net.XhrIo.send(url, function(e) { goog.net.XhrIo.send(url, function(e) {
var xhr = e.target; var xhr = e.target;
obj = parser.read(xhr.getResponseXml()); obj = parser.read(xhr.getResponseXml());
@@ -222,35 +156,30 @@ describe('ol.parser.ogc.wmscapabilities_v1_1_1', function() {
time = layers['Clouds'].dimensions.time; time = layers['Clouds'].dimensions.time;
elevation = layers['Pressure'].dimensions.elevation; elevation = layers['Pressure'].dimensions.elevation;
}); });
it('Default time value parsed correctly', function() { });
waitsFor(function() {
return (obj !== undefined);
}, 'XHR timeout', 1000);
runs(function() {
expect(time['default']).toEqual('2000-08-22'); expect(time['default']).toEqual('2000-08-22');
});
it('Currect number of time extent values/periods', function() {
expect(time.values.length).toEqual(1); expect(time.values.length).toEqual(1);
});
it('Time extent values parsed correctly', function() {
expect(time.values[0]).toEqual('1999-01-01/2000-08-22/P1D'); expect(time.values[0]).toEqual('1999-01-01/2000-08-22/P1D');
});
it('Dimension units parsed correctly', function() {
expect(elevation.units).toEqual('EPSG:5030'); expect(elevation.units).toEqual('EPSG:5030');
});
it('Default elevation value parsed correctly', function() {
expect(elevation['default']).toEqual('0'); expect(elevation['default']).toEqual('0');
});
it('NearestValue parsed correctly', function() {
expect(elevation.nearestVal).toBeTruthy(); expect(elevation.nearestVal).toBeTruthy();
});
it('Absense of MultipleValues handled correctly', function() {
expect(elevation.multipleVal).toBeFalsy(); expect(elevation.multipleVal).toBeFalsy();
expect(elevation.values).toEqual(['0', '1000', '3000', '5000',
'10000']);
}); });
it('Parsing of comma-separated values done correctly', function() {
expect(elevation.values).toEqual(['0', '1000', '3000', '5000', '10000']);
}); });
}); });
describe('test contact info', function() { describe('test contact info', function() {
var obj, service, contactinfo, personPrimary, addr, url; it('Test contact info', function() {
url = 'spec/ol/parser/ogc/xml/wmscapabilities_v1_1_1/ogcsample.xml'; var obj, service, contactinfo, personPrimary, addr;
runs(function() {
var url = 'spec/ol/parser/ogc/xml/wmscapabilities_v1_1_1/' +
'ogcsample.xml';
goog.net.XhrIo.send(url, function(e) { goog.net.XhrIo.send(url, function(e) {
var xhr = e.target; var xhr = e.target;
obj = parser.read(xhr.getResponseXml()); obj = parser.read(xhr.getResponseXml());
@@ -259,73 +188,57 @@ describe('ol.parser.ogc.wmscapabilities_v1_1_1', function() {
personPrimary = contactinfo.personPrimary; personPrimary = contactinfo.personPrimary;
addr = contactinfo.contactAddress; addr = contactinfo.contactAddress;
}); });
it('object contains contactInformation property', function() { });
waitsFor(function() {
return (obj !== undefined);
}, 'XHR timeout', 1000);
runs(function() {
expect(contactinfo).toBeTruthy(); expect(contactinfo).toBeTruthy();
});
it('object contains personPrimary property', function() {
expect(personPrimary).toBeTruthy(); expect(personPrimary).toBeTruthy();
});
it('ContactPerson parsed correctly', function() {
expect(personPrimary.person).toEqual('Jeff deLaBeaujardiere'); expect(personPrimary.person).toEqual('Jeff deLaBeaujardiere');
});
it('ContactOrganization parsed correctly', function() {
expect(personPrimary.organization).toEqual('NASA'); expect(personPrimary.organization).toEqual('NASA');
});
it('ContactPosition parsed correctly', function() {
expect(contactinfo.position).toEqual('Computer Scientist'); expect(contactinfo.position).toEqual('Computer Scientist');
});
it('object contains contactAddress property', function() {
expect(addr).toBeTruthy(); expect(addr).toBeTruthy();
});
it('AddressType parsed correctly', function() {
expect(addr.type).toEqual('postal'); expect(addr.type).toEqual('postal');
});
it('Address parsed correctly', function() {
var address = 'NASA Goddard Space Flight Center, Code 933'; var address = 'NASA Goddard Space Flight Center, Code 933';
expect(addr.address).toEqual(address); expect(addr.address).toEqual(address);
});
it('City parsed correctly', function() {
expect(addr.city).toEqual('Greenbelt'); expect(addr.city).toEqual('Greenbelt');
});
it('StateOrProvince parsed correctly', function() {
expect(addr.stateOrProvince).toEqual('MD'); expect(addr.stateOrProvince).toEqual('MD');
});
it('PostCode parsed correctly', function() {
expect(addr.postcode).toEqual('20771'); expect(addr.postcode).toEqual('20771');
});
it('Country parsed correctly', function() {
expect(addr.country).toEqual('USA'); expect(addr.country).toEqual('USA');
});
it('ContactVoiceTelephone parsed correctly', function() {
expect(contactinfo.phone).toEqual('+1 301 286-1569'); expect(contactinfo.phone).toEqual('+1 301 286-1569');
});
it('ContactFacsimileTelephone parsed correctly', function() {
expect(contactinfo.fax).toEqual('+1 301 286-1777'); expect(contactinfo.fax).toEqual('+1 301 286-1777');
});
it('ContactElectronicMailAddress parsed correctly', function() {
expect(contactinfo.email).toEqual('delabeau@iniki.gsfc.nasa.gov'); expect(contactinfo.email).toEqual('delabeau@iniki.gsfc.nasa.gov');
}); });
}); });
});
describe('Test fees and constraints', function() { describe('Test fees and constraints', function() {
var obj, service, url; it('Test fees and constraints', function() {
url = 'spec/ol/parser/ogc/xml/wmscapabilities_v1_1_1/gssample.xml'; var obj, service;
runs(function() {
var url = 'spec/ol/parser/ogc/xml/wmscapabilities_v1_1_1/gssample.xml';
goog.net.XhrIo.send(url, function(e) { goog.net.XhrIo.send(url, function(e) {
var xhr = e.target; var xhr = e.target;
obj = parser.read(xhr.getResponseXml()); obj = parser.read(xhr.getResponseXml());
service = obj.service; service = obj.service;
}); });
it('Fees=none handled correctly', function() {
expect('fees' in service).toBeFalsy();
}); });
it('AccessConstraints=none handled correctly', function() { waitsFor(function() {
return (obj !== undefined);
}, 'XHR timeout', 1000);
runs(function() {
expect('fees' in service).toBeFalsy();
expect('accessConstraints' in service).toBeFalsy(); expect('accessConstraints' in service).toBeFalsy();
}); });
}); });
});
describe('Test requests', function() { describe('Test requests', function() {
var obj, request, exception, userSymbols, url; it('Test requests', function() {
url = 'spec/ol/parser/ogc/xml/wmscapabilities_v1_1_1/gssample.xml'; var obj, request, exception, userSymbols;
runs(function() {
var url = 'spec/ol/parser/ogc/xml/wmscapabilities_v1_1_1/gssample.xml';
goog.net.XhrIo.send(url, function(e) { goog.net.XhrIo.send(url, function(e) {
var xhr = e.target; var xhr = e.target;
obj = parser.read(xhr.getResponseXml()); obj = parser.read(xhr.getResponseXml());
@@ -333,51 +246,34 @@ describe('ol.parser.ogc.wmscapabilities_v1_1_1', function() {
exception = obj.capability.exception; exception = obj.capability.exception;
userSymbols = obj.capability.userSymbols; userSymbols = obj.capability.userSymbols;
}); });
it('request property exists', function() { });
waitsFor(function() {
return (obj !== undefined);
}, 'XHR timeout', 1000);
runs(function() {
expect(request).toBeTruthy(); expect(request).toBeTruthy();
});
it('got GetMap request', function() {
expect('getmap' in request).toBeTruthy(); expect('getmap' in request).toBeTruthy();
});
it('got GetFeatureInfo request', function() {
expect('getfeatureinfo' in request).toBeTruthy(); expect('getfeatureinfo' in request).toBeTruthy();
});
it('GetFeatureInfo formats correctly parsed', function() {
var formats = ['text/plain', 'text/html', 'application/vnd.ogc.gml']; var formats = ['text/plain', 'text/html', 'application/vnd.ogc.gml'];
expect(request.getfeatureinfo.formats).toEqual(formats); expect(request.getfeatureinfo.formats).toEqual(formats);
});
it('got DescribeLayer request', function() {
expect('describelayer' in request).toBeTruthy(); expect('describelayer' in request).toBeTruthy();
});
it('got GetLegendGraphic request', function() {
expect('getlegendgraphic' in request).toBeTruthy(); expect('getlegendgraphic' in request).toBeTruthy();
});
it('exception property exists', function() {
expect(exception).toBeTruthy(); expect(exception).toBeTruthy();
});
it('Exception Format parsed', function() {
expect(exception.formats).toEqual(['application/vnd.ogc.se_xml']); expect(exception.formats).toEqual(['application/vnd.ogc.se_xml']);
});
it('userSymbols property exists', function() {
expect(userSymbols).toBeTruthy(); expect(userSymbols).toBeTruthy();
});
it('supportSLD parsed', function() {
expect(userSymbols.supportSLD).toBeTruthy(); expect(userSymbols.supportSLD).toBeTruthy();
});
it('userLayer parsed', function() {
expect(userSymbols.userLayer).toBeTruthy(); expect(userSymbols.userLayer).toBeTruthy();
});
it('userStyle parsed', function() {
expect(userSymbols.userStyle).toBeTruthy(); expect(userSymbols.userStyle).toBeTruthy();
});
it('remoteWFS parsed', function() {
expect(userSymbols.remoteWFS).toBeTruthy(); expect(userSymbols.remoteWFS).toBeTruthy();
}); });
}); });
});
describe('test ogc', function() { describe('test ogc', function() {
var obj, capability, attribution, keywords, metadataURLs, url; it('Test ogc', function() {
url = 'spec/ol/parser/ogc/xml/wmscapabilities_v1_1_1/ogcsample.xml'; var obj, capability, attribution, keywords, metadataURLs;
runs(function() {
var url = 'spec/ol/parser/ogc/xml/wmscapabilities_v1_1_1/ogcsample.xml';
goog.net.XhrIo.send(url, function(e) { goog.net.XhrIo.send(url, function(e) {
var xhr = e.target; var xhr = e.target;
obj = parser.read(xhr.getResponseXml()); obj = parser.read(xhr.getResponseXml());
@@ -386,57 +282,32 @@ describe('ol.parser.ogc.wmscapabilities_v1_1_1', function() {
keywords = capability.layers[0].keywords; keywords = capability.layers[0].keywords;
metadataURLs = capability.layers[0].metadataURLs; metadataURLs = capability.layers[0].metadataURLs;
}); });
it('attribution title parsed correctly.', function() { });
waitsFor(function() {
return (obj !== undefined);
}, 'XHR timeout', 1000);
runs(function() {
expect(attribution.title).toEqual('State College University'); expect(attribution.title).toEqual('State College University');
});
it('attribution href parsed correctly.', function() {
expect(attribution.href).toEqual('http://www.university.edu/'); expect(attribution.href).toEqual('http://www.university.edu/');
});
it('attribution logo url parsed correctly.', function() {
var url = 'http://www.university.edu/icons/logo.gif'; var url = 'http://www.university.edu/icons/logo.gif';
expect(attribution.logo.href).toEqual(url); expect(attribution.logo.href).toEqual(url);
});
it('attribution logo format parsed correctly.', function() {
expect(attribution.logo.format).toEqual('image/gif'); expect(attribution.logo.format).toEqual('image/gif');
});
it('attribution logo width parsed correctly.', function() {
expect(attribution.logo.width).toEqual('100'); expect(attribution.logo.width).toEqual('100');
});
it('attribution logo height parsed correctly.', function() {
expect(attribution.logo.height).toEqual('100'); expect(attribution.logo.height).toEqual('100');
});
it('layer has 3 keywords.', function() {
expect(keywords.length).toEqual(3); expect(keywords.length).toEqual(3);
});
it('1st keyword parsed correctly.', function() {
expect(keywords[0].value).toEqual('road'); expect(keywords[0].value).toEqual('road');
});
it('layer has 2 metadata urls.', function() {
expect(metadataURLs.length).toEqual(2); expect(metadataURLs.length).toEqual(2);
});
it('type parsed correctly.', function() {
expect(metadataURLs[0].type).toEqual('FGDC'); expect(metadataURLs[0].type).toEqual('FGDC');
});
it('format parsed correctly.', function() {
expect(metadataURLs[0].format).toEqual('text/plain'); expect(metadataURLs[0].format).toEqual('text/plain');
});
it('href parsed correctly.', function() {
var href = 'http://www.university.edu/metadata/roads.txt'; var href = 'http://www.university.edu/metadata/roads.txt';
expect(metadataURLs[0].href).toEqual(href); expect(metadataURLs[0].href).toEqual(href);
});
it('layer.minScale is correct', function() {
expect(Math.round(capability.layers[0].minScale)).toEqual(250000); expect(Math.round(capability.layers[0].minScale)).toEqual(250000);
});
it('layer.maxScale is correct', function() {
expect(Math.round(capability.layers[0].maxScale)).toEqual(1000); expect(Math.round(capability.layers[0].maxScale)).toEqual(1000);
});
it('layer.minScale for max="Infinity" is correct', function() {
expect(capability.layers[1].minScale).toBeUndefined(); expect(capability.layers[1].minScale).toBeUndefined();
});
it('layer.maxScale for min="0" is correct', function() {
expect(capability.layers[1].maxScale).toBeUndefined(); expect(capability.layers[1].maxScale).toBeUndefined();
}); });
}); });
});
}); });
@@ -8,38 +8,30 @@ describe('ol.parser.ogc.wmscapabilities_v1_1_1_wmsc', function() {
}); });
describe('test read', function() { describe('test read', function() {
var obj, tilesets, tileset, url; it('Test read', function() {
url = 'spec/ol/parser/ogc/xml/wmscapabilities_v1_1_1_WMSC/wmsc.xml'; var obj, tilesets, tileset;
runs(function() {
var url = 'spec/ol/parser/ogc/xml/wmscapabilities_v1_1_1_WMSC/wmsc.xml';
goog.net.XhrIo.send(url, function(e) { goog.net.XhrIo.send(url, function(e) {
var xhr = e.target; var xhr = e.target;
obj = parser.read(xhr.getResponseXml()); obj = parser.read(xhr.getResponseXml());
tilesets = obj.capability.vendorSpecific.tileSets; tilesets = obj.capability.vendorSpecific.tileSets;
tileset = tilesets[0]; tileset = tilesets[0];
}); });
it('We expect 2 tilesets to be parsed', function() {
expect(tilesets.length).toEqual(2);
}); });
it('BBOX correctly parsed', function() { waitsFor(function() {
return (obj !== undefined);
}, 'XHR timeout', 1000);
runs(function() {
expect(tilesets.length).toEqual(2);
var bbox = [-13697515.466796875, 5165920.118906248, var bbox = [-13697515.466796875, 5165920.118906248,
-13619243.94984375, 5244191.635859374]; -13619243.94984375, 5244191.635859374];
expect(tileset.bbox['EPSG:900913'].bbox).toEqual(bbox); expect(tileset.bbox['EPSG:900913'].bbox).toEqual(bbox);
});
it('Format correctly parsed', function() {
expect(tileset.format).toEqual('image/png'); expect(tileset.format).toEqual('image/png');
});
it('Height correctly parsed', function() {
expect(tileset.height).toEqual(256); expect(tileset.height).toEqual(256);
});
it('Width correctly parsed', function() {
expect(tileset.width).toEqual(256); expect(tileset.width).toEqual(256);
});
it('Layers correctly parsed', function() {
expect(tileset.layers).toEqual('medford:hydro'); expect(tileset.layers).toEqual('medford:hydro');
});
it('SRS correctly parsed', function() {
expect(tileset.srs['EPSG:900913']).toBeTruthy(); expect(tileset.srs['EPSG:900913']).toBeTruthy();
});
it('Resolutions correctly parsed', function() {
var resolutions = [156543.03390625, 78271.516953125, 39135.7584765625, var resolutions = [156543.03390625, 78271.516953125, 39135.7584765625,
19567.87923828125, 9783.939619140625, 4891.9698095703125, 19567.87923828125, 9783.939619140625, 4891.9698095703125,
2445.9849047851562, 1222.9924523925781, 611.4962261962891, 2445.9849047851562, 1222.9924523925781, 611.4962261962891,
@@ -50,23 +42,30 @@ describe('ol.parser.ogc.wmscapabilities_v1_1_1_wmsc', function() {
0.07464553542435169, 0.037322767712175846, 0.018661383856087923, 0.07464553542435169, 0.037322767712175846, 0.018661383856087923,
0.009330691928043961, 0.004665345964021981]; 0.009330691928043961, 0.004665345964021981];
expect(tileset.resolutions).toEqual(resolutions); expect(tileset.resolutions).toEqual(resolutions);
});
it('Styles correctly parsed', function() {
expect(tileset.styles).toEqual(''); expect(tileset.styles).toEqual('');
}); });
}); });
});
describe('test fallback', function() { describe('test fallback', function() {
var obj, url; it('Test fallback', function() {
url = 'spec/ol/parser/ogc/xml/wmscapabilities_v1_1_1_WMSC/fallback.xml'; var obj;
runs(function() {
var url = 'spec/ol/parser/ogc/xml/wmscapabilities_v1_1_1_WMSC/' +
'fallback.xml';
goog.net.XhrIo.send(url, function(e) { goog.net.XhrIo.send(url, function(e) {
var xhr = e.target; var xhr = e.target;
obj = parser.read(xhr.getResponseXml()); obj = parser.read(xhr.getResponseXml());
}); });
it('layers parsed with allowFallback true', function() { });
waitsFor(function() {
return (obj !== undefined);
}, 'XHR timeout', 1000);
runs(function() {
expect(obj.capability.layers.length).toEqual(2); expect(obj.capability.layers.length).toEqual(2);
}); });
}); });
});
}); });
@@ -4,10 +4,33 @@ describe('ol.parser.ogc.wmscapabilities_v1_3_0', function() {
var parser = new ol.parser.ogc.WMSCapabilities(); var parser = new ol.parser.ogc.WMSCapabilities();
describe('test read exception', function() {
it('Error reported correctly', function() {
var result;
runs(function() {
var url = 'spec/ol/parser/ogc/xml/wmscapabilities_v1_3_0/' +
'exceptionsample.xml';
goog.net.XhrIo.send(url, function(e) {
var xhr = e.target;
result = parser.read(xhr.getResponseXml());
});
});
waitsFor(function() {
return (result !== undefined);
}, 'XHR timeout', 1000);
runs(function() {
expect(!!result.error).toBe(true);
});
});
});
describe('test read', function() {
it('Test read', function() {
var obj, capability, layers = {}, rootlayer, identifiers, authorities; var obj, capability, layers = {}, rootlayer, identifiers, authorities;
var featurelist, time, elevation, service, contactinfo, personPrimary, addr; var featurelist, time, elevation, service, contactinfo, personPrimary,
var request, exception, attribution, keywords, metadataURLs, url; addr, request, exception, attribution, keywords, metadataURLs;
url = 'spec/ol/parser/ogc/xml/wmscapabilities_v1_3_0/ogcsample.xml'; runs(function() {
var url = 'spec/ol/parser/ogc/xml/wmscapabilities_v1_3_0/ogcsample.xml';
goog.net.XhrIo.send(url, function(e) { goog.net.XhrIo.send(url, function(e) {
var xhr = e.target; var xhr = e.target;
obj = parser.read(xhr.getResponseXml()); obj = parser.read(xhr.getResponseXml());
@@ -33,264 +56,100 @@ describe('ol.parser.ogc.wmscapabilities_v1_3_0', function() {
keywords = capability.layers[0].keywords; keywords = capability.layers[0].keywords;
metadataURLs = capability.layers[0].metadataURLs; metadataURLs = capability.layers[0].metadataURLs;
}); });
describe('test read exception', function() {
var result, url;
url = 'spec/ol/parser/ogc/xml/wmscapabilities_v1_3_0/exceptionsample.xml';
goog.net.XhrIo.send(url, function(e) {
var xhr = e.target;
result = parser.read(xhr.getResponseXml());
}); });
it('Error reported correctly', function() { waitsFor(function() {
expect(!!result.error).toBe(true); return (obj !== undefined);
}); }, 'XHR timeout', 1000);
}); runs(function() {
describe('test layers', function() {
it('SRS parsed correctly for root layer', function() {
expect(rootlayer.srs).toEqual({'CRS:84': true}); expect(rootlayer.srs).toEqual({'CRS:84': true});
});
it('Inheritance of SRS handled correctly when adding SRSes', function() {
var srs = {'CRS:84': true, 'EPSG:26986': true}; var srs = {'CRS:84': true, 'EPSG:26986': true};
expect(layers['ROADS_RIVERS'].srs).toEqual(srs); expect(layers['ROADS_RIVERS'].srs).toEqual(srs);
});
it('Inheritance of SRS handled correctly when redeclaring an' +
' inherited SRS', function() {
expect(layers['Temperature'].srs).toEqual({'CRS:84': true}); expect(layers['Temperature'].srs).toEqual({'CRS:84': true});
});
it('infoFormats set correctly on layer', function() {
var infoFormats = ['text/xml', 'text/plain', 'text/html']; var infoFormats = ['text/xml', 'text/plain', 'text/html'];
expect(layers['Temperature'].infoFormats).toEqual(infoFormats); expect(layers['Temperature'].infoFormats).toEqual(infoFormats);
});
it('Correct resolution and bbox from BoundingBox', function() {
var bbox = layers['ROADS_RIVERS'].bbox['EPSG:26986']; var bbox = layers['ROADS_RIVERS'].bbox['EPSG:26986'];
expect(bbox.bbox).toEqual([189000, 834000, 285000, 962000]); expect(bbox.bbox).toEqual([189000, 834000, 285000, 962000]);
expect(bbox.res).toEqual({x: 1, y: 1}); expect(bbox.res).toEqual({x: 1, y: 1});
}); bbox = layers['ROADS_RIVERS'].bbox['CRS:84'];
it('Correct resolution and bbox from BoundingBox (override)', function() {
var bbox = layers['ROADS_RIVERS'].bbox['CRS:84'];
expect(bbox.bbox).toEqual([-71.63, 41.75, -70.78, 42.90]); expect(bbox.bbox).toEqual([-71.63, 41.75, -70.78, 42.90]);
expect(bbox.res).toEqual({x: 0.01, y: 0.01}); expect(bbox.res).toEqual({x: 0.01, y: 0.01});
}); bbox = layers['ROADS_1M'].bbox['EPSG:26986'];
it('Correctly inherited bbox and resolution', function() {
var bbox = layers['ROADS_1M'].bbox['EPSG:26986'];
expect(bbox.bbox).toEqual([189000, 834000, 285000, 962000]); expect(bbox.bbox).toEqual([189000, 834000, 285000, 962000]);
expect(bbox.res).toEqual({x: 1, y: 1}); expect(bbox.res).toEqual({x: 1, y: 1});
});
it('got identifiers from layer ROADS_RIVERS', function() {
expect(identifiers).toBeTruthy(); expect(identifiers).toBeTruthy();
});
it('authority attribute from Identifiers parsed correctly', function() {
expect('DIF_ID' in identifiers).toBeTruthy(); expect('DIF_ID' in identifiers).toBeTruthy();
});
it('Identifier value parsed correctly', function() {
expect(identifiers['DIF_ID']).toEqual('123456'); expect(identifiers['DIF_ID']).toEqual('123456');
});
it('AuthorityURLs parsed and inherited correctly', function() {
expect('DIF_ID' in authorities).toBeTruthy(); expect('DIF_ID' in authorities).toBeTruthy();
});
it('OnlineResource in AuthorityURLs parsed correctly', function() {
var url = 'http://gcmd.gsfc.nasa.gov/difguide/whatisadif.html'; var url = 'http://gcmd.gsfc.nasa.gov/difguide/whatisadif.html';
expect(authorities['DIF_ID']).toEqual(url); expect(authorities['DIF_ID']).toEqual(url);
});
it('layer has FeatureListURL', function() {
expect(featurelist).toBeTruthy(); expect(featurelist).toBeTruthy();
});
it('FeatureListURL format parsed correctly', function() {
expect(featurelist.format).toEqual('XML'); expect(featurelist.format).toEqual('XML');
}); url = 'http://www.university.edu/data/roads_rivers.gml';
it('FeatureListURL OnlineResource parsed correctly', function() {
var url = 'http://www.university.edu/data/roads_rivers.gml';
expect(featurelist.href).toEqual(url); expect(featurelist.href).toEqual(url);
});
it('queryable property inherited correctly', function() {
expect(layers['Pressure'].queryable).toBeTruthy(); expect(layers['Pressure'].queryable).toBeTruthy();
});
it('queryable property has correct default value', function() {
expect(layers['ozone_image'].queryable).toBeFalsy(); expect(layers['ozone_image'].queryable).toBeFalsy();
});
it('cascaded property parsed correctly', function() {
expect(layers['population'].cascaded).toEqual(1); expect(layers['population'].cascaded).toEqual(1);
});
it('fixedWidth property correctly parsed', function() {
expect(layers['ozone_image'].fixedWidth).toEqual(512); expect(layers['ozone_image'].fixedWidth).toEqual(512);
});
it('fixedHeight property correctly parsed', function() {
expect(layers['ozone_image'].fixedHeight).toEqual(256); expect(layers['ozone_image'].fixedHeight).toEqual(256);
});
it('opaque property parsed correctly', function() {
expect(layers['ozone_image'].opaque).toBeTruthy(); expect(layers['ozone_image'].opaque).toBeTruthy();
});
it('noSubsets property parsed correctly', function() {
expect(layers['ozone_image'].noSubsets).toBeTruthy(); expect(layers['ozone_image'].noSubsets).toBeTruthy();
});
});
describe('test dimensions', function() {
it('Default time value parsed correctly', function() {
expect(time['default']).toEqual('2000-08-22'); expect(time['default']).toEqual('2000-08-22');
});
it('Currect number of time extent values/periods', function() {
expect(time.values.length).toEqual(1); expect(time.values.length).toEqual(1);
});
it('Time extent values parsed correctly', function() {
expect(time.values[0]).toEqual('1999-01-01/2000-08-22/P1D'); expect(time.values[0]).toEqual('1999-01-01/2000-08-22/P1D');
});
it('Dimension units parsed correctly', function() {
expect(elevation.units).toEqual('CRS:88'); expect(elevation.units).toEqual('CRS:88');
});
it('Default elevation value parsed correctly', function() {
expect(elevation['default']).toEqual('0'); expect(elevation['default']).toEqual('0');
});
it('NearestValue parsed correctly', function() {
expect(elevation.nearestVal).toBeTruthy(); expect(elevation.nearestVal).toBeTruthy();
});
it('Absense of MultipleValues handled correctly', function() {
expect(elevation.multipleVal).toBeFalsy(); expect(elevation.multipleVal).toBeFalsy();
}); expect(elevation.values).toEqual(['0', '1000', '3000', '5000',
it('Parsing of comma-separated values done correctly', function() { '10000']);
expect(elevation.values).toEqual(['0', '1000', '3000', '5000', '10000']);
});
});
describe('test contact info', function() {
it('object contains contactInformation property', function() {
expect(contactinfo).toBeTruthy(); expect(contactinfo).toBeTruthy();
});
it('object contains personPrimary property', function() {
expect(personPrimary).toBeTruthy(); expect(personPrimary).toBeTruthy();
});
it('ContactPerson parsed correctly', function() {
expect(personPrimary.person).toEqual('Jeff Smith'); expect(personPrimary.person).toEqual('Jeff Smith');
});
it('ContactOrganization parsed correctly', function() {
expect(personPrimary.organization).toEqual('NASA'); expect(personPrimary.organization).toEqual('NASA');
});
it('ContactPosition parsed correctly', function() {
expect(contactinfo.position).toEqual('Computer Scientist'); expect(contactinfo.position).toEqual('Computer Scientist');
});
it('object contains contactAddress property', function() {
expect(addr).toBeTruthy(); expect(addr).toBeTruthy();
});
it('AddressType parsed correctly', function() {
expect(addr.type).toEqual('postal'); expect(addr.type).toEqual('postal');
});
it('Address parsed correctly', function() {
expect(addr.address).toEqual('NASA Goddard Space Flight Center'); expect(addr.address).toEqual('NASA Goddard Space Flight Center');
});
it('City parsed correctly', function() {
expect(addr.city).toEqual('Greenbelt'); expect(addr.city).toEqual('Greenbelt');
});
it('StateOrProvince parsed correctly', function() {
expect(addr.stateOrProvince).toEqual('MD'); expect(addr.stateOrProvince).toEqual('MD');
});
it('PostCode parsed correctly', function() {
expect(addr.postcode).toEqual('20771'); expect(addr.postcode).toEqual('20771');
});
it('Country parsed correctly', function() {
expect(addr.country).toEqual('USA'); expect(addr.country).toEqual('USA');
});
it('ContactVoiceTelephone parsed correctly', function() {
expect(contactinfo.phone).toEqual('+1 301 555-1212'); expect(contactinfo.phone).toEqual('+1 301 555-1212');
});
it('ContactElectronicMailAddress parsed correctly', function() {
expect(contactinfo.email).toEqual('user@host.com'); expect(contactinfo.email).toEqual('user@host.com');
});
});
describe('test fees and constraints', function() {
it('Fees=none handled correctly', function() {
expect('fees' in service).toBeFalsy(); expect('fees' in service).toBeFalsy();
});
it('AccessConstraints=none handled correctly', function() {
expect('accessConstraints' in service).toBeFalsy(); expect('accessConstraints' in service).toBeFalsy();
});
});
describe('test requests', function() {
it('request property exists', function() {
expect(request).toBeTruthy(); expect(request).toBeTruthy();
});
it('got GetMap request', function() {
expect('getmap' in request).toBeTruthy(); expect('getmap' in request).toBeTruthy();
});
it('got GetFeatureInfo request', function() {
expect('getfeatureinfo' in request).toBeTruthy(); expect('getfeatureinfo' in request).toBeTruthy();
});
it('GetFeatureInfo formats correctly parsed', function() {
var formats = ['text/xml', 'text/plain', 'text/html']; var formats = ['text/xml', 'text/plain', 'text/html'];
expect(request.getfeatureinfo.formats).toEqual(formats); expect(request.getfeatureinfo.formats).toEqual(formats);
});
it('exception property exists', function() {
expect(exception).toBeTruthy(); expect(exception).toBeTruthy();
}); formats = ['XML', 'INIMAGE', 'BLANK'];
it('Exception Format parsed', function() {
var formats = ['XML', 'INIMAGE', 'BLANK'];
expect(exception.formats).toEqual(formats); expect(exception.formats).toEqual(formats);
});
});
describe('test ogc', function() {
it('attribution title parsed correctly.', function() {
expect(attribution.title).toEqual('State College University'); expect(attribution.title).toEqual('State College University');
});
it('attribution href parsed correctly.', function() {
expect(attribution.href).toEqual('http://www.university.edu/'); expect(attribution.href).toEqual('http://www.university.edu/');
}); url = 'http://www.university.edu/icons/logo.gif';
it('attribution logo url parsed correctly.', function() {
var url = 'http://www.university.edu/icons/logo.gif';
expect(attribution.logo.href).toEqual(url); expect(attribution.logo.href).toEqual(url);
});
it('attribution logo format parsed correctly.', function() {
expect(attribution.logo.format).toEqual('image/gif'); expect(attribution.logo.format).toEqual('image/gif');
});
it('attribution logo width parsed correctly.', function() {
expect(attribution.logo.width).toEqual('100'); expect(attribution.logo.width).toEqual('100');
});
it('attribution logo height parsed correctly.', function() {
expect(attribution.logo.height).toEqual('100'); expect(attribution.logo.height).toEqual('100');
});
it('layer has 3 keywords.', function() {
expect(keywords.length).toEqual(3); expect(keywords.length).toEqual(3);
});
it('1st keyword parsed correctly.', function() {
expect(keywords[0].value).toEqual('road'); expect(keywords[0].value).toEqual('road');
});
it('layer has 2 metadata urls.', function() {
expect(metadataURLs.length).toEqual(2); expect(metadataURLs.length).toEqual(2);
});
it('type parsed correctly.', function() {
expect(metadataURLs[0].type).toEqual('FGDC:1998'); expect(metadataURLs[0].type).toEqual('FGDC:1998');
});
it('format parsed correctly.', function() {
expect(metadataURLs[0].format).toEqual('text/plain'); expect(metadataURLs[0].format).toEqual('text/plain');
}); url = 'http://www.university.edu/metadata/roads.txt';
it('href parsed correctly.', function() {
var url = 'http://www.university.edu/metadata/roads.txt';
expect(metadataURLs[0].href).toEqual(url); expect(metadataURLs[0].href).toEqual(url);
});
it('layer.minScale is correct', function() {
var minScale = 250000; var minScale = 250000;
expect(capability.layers[0].minScale).toEqual(minScale.toPrecision(16)); expect(capability.layers[0].minScale).toEqual(minScale.toPrecision(16));
});
it('layer.maxScale is correct', function() {
var maxScale = 1000; var maxScale = 1000;
expect(capability.layers[0].maxScale).toEqual(maxScale.toPrecision(16)); expect(capability.layers[0].maxScale).toEqual(maxScale.toPrecision(16));
});
});
describe('test WMS 1.3 specials', function() {
it('LayerLimit parsed correctly', function() {
expect(obj.service.layerLimit).toEqual(16); expect(obj.service.layerLimit).toEqual(16);
});
it('MaxHeight parsed correctly', function() {
expect(obj.service.maxHeight).toEqual(2048); expect(obj.service.maxHeight).toEqual(2048);
});
it('MaxWidth parsed correctly', function() {
expect(obj.service.maxWidth).toEqual(2048); expect(obj.service.maxWidth).toEqual(2048);
}); });
}); });
});
}); });
goog.require('goog.net.XhrIo'); goog.require('goog.net.XhrIo');
+238
View File
@@ -0,0 +1,238 @@
goog.provide('ol.test.source.TileSource');
describe('ol.source.TileSource', function() {
describe('constructor', function() {
it('returns a tile source', function() {
var source = new ol.source.TileSource({
projection: ol.Projection.getFromCode('EPSG:4326')
});
expect(source).toBeA(ol.source.Source);
expect(source).toBeA(ol.source.TileSource);
});
});
describe('#findLoadedTiles()', function() {
function isLoaded(tile) {
return !goog.isNull(tile) && tile.getState() === ol.TileState.LOADED;
}
it('adds no tiles if none are already loaded', function() {
// a source with no loaded tiles
var source = new ol.test.source.MockTileSource({});
var loadedTilesByZ = {};
var grid = source.getTileGrid();
var range = grid.getTileRangeForExtentAndZ(source.getExtent(), 3);
source.findLoadedTiles(loadedTilesByZ, isLoaded, 3, range);
var keys = goog.object.getKeys(loadedTilesByZ);
expect(keys.length).toBe(0);
});
it('adds loaded tiles to the lookup (z: 0)', function() {
// a source with no loaded tiles
var source = new ol.test.source.MockTileSource({
'0/0/0': true,
'1/0/0': true
});
var loadedTilesByZ = {};
var grid = source.getTileGrid();
var range = grid.getTileRangeForExtentAndZ(source.getExtent(), 0);
source.findLoadedTiles(loadedTilesByZ, isLoaded, 0, range);
var keys = goog.object.getKeys(loadedTilesByZ);
expect(keys.length).toBe(1);
var tile = loadedTilesByZ['0']['0/0/0'];
expect(tile).toBeA(ol.Tile);
expect(tile.state).toBe(ol.TileState.LOADED);
});
it('adds loaded tiles to the lookup (z: 1)', function() {
// a source with no loaded tiles
var source = new ol.test.source.MockTileSource({
'0/0/0': true,
'1/0/0': true
});
var loadedTilesByZ = {};
var grid = source.getTileGrid();
var range = grid.getTileRangeForExtentAndZ(source.getExtent(), 1);
source.findLoadedTiles(loadedTilesByZ, isLoaded, 1, range);
var keys = goog.object.getKeys(loadedTilesByZ);
expect(keys.length).toBe(1);
var tile = loadedTilesByZ['1']['1/0/0'];
expect(tile).toBeA(ol.Tile);
expect(tile.state).toBe(ol.TileState.LOADED);
});
it('returns true when all tiles are already loaded', function() {
// a source with no loaded tiles
var source = new ol.test.source.MockTileSource({
'1/0/0': true,
'1/0/1': true,
'1/1/0': true,
'1/1/1': true
});
var loadedTilesByZ = {};
var grid = source.getTileGrid();
var range = grid.getTileRangeForExtentAndZ(source.getExtent(), 1);
var loaded = source.findLoadedTiles(loadedTilesByZ, isLoaded, 1, range);
expect(loaded).toBe(true);
});
it('returns true when all tiles are already loaded (part 2)', function() {
// a source with no loaded tiles
var source = new ol.test.source.MockTileSource({});
var loadedTilesByZ = {
'1': {
'1/0/0': true,
'1/0/1': true,
'1/1/0': true,
'1/1/1': true,
'1/1/2': true
}
};
var grid = source.getTileGrid();
var range = grid.getTileRangeForExtentAndZ(source.getExtent(), 1);
var loaded = source.findLoadedTiles(loadedTilesByZ, isLoaded, 1, range);
expect(loaded).toBe(true);
});
it('returns false when all tiles are already loaded', function() {
// a source with no loaded tiles
var source = new ol.test.source.MockTileSource({
'1/0/0': true,
'1/0/1': true,
'1/1/0': true,
'1/1/1': false
});
var loadedTilesByZ = {};
var grid = source.getTileGrid();
var range = grid.getTileRangeForExtentAndZ(source.getExtent(), 1);
var loaded = source.findLoadedTiles(loadedTilesByZ, isLoaded, 1, range);
expect(loaded).toBe(false);
});
it('returns false when all tiles are already loaded (part 2)', function() {
// a source with no loaded tiles
var source = new ol.test.source.MockTileSource({});
var loadedTilesByZ = {
'1': {
'1/0/0': true,
'1/0/1': true,
'1/1/0': true,
'1/1/1': false
}
};
var grid = source.getTileGrid();
var range = grid.getTileRangeForExtentAndZ(source.getExtent(), 1);
var loaded = source.findLoadedTiles(loadedTilesByZ, isLoaded, 1, range);
expect(loaded).toBe(false);
});
});
});
/**
* Tile source for tests that uses a EPSG:4326 based grid with 4 resolutions and
* 256x256 tiles.
*
* @constructor
* @extends {ol.source.TileSource}
* @param {Object.<string, boolean>} loaded Lookup of already loaded tiles.
*/
ol.test.source.MockTileSource = function(loaded) {
var extent = new ol.Extent(-180, -180, 180, 180);
var tileGrid = new ol.tilegrid.TileGrid({
resolutions: [360 / 256, 180 / 256, 90 / 256, 45 / 256],
extent: extent,
origin: new ol.Coordinate(-180, -180),
tileSize: new ol.Size(256, 256)
});
goog.base(this, {
extent: extent,
projection: ol.Projection.getFromCode('EPSG:4326'),
tileGrid: tileGrid
});
/**
* @type {Object.<string, boolean>}
* @private
*/
this.loaded_ = loaded;
};
goog.inherits(ol.test.source.MockTileSource, ol.source.TileSource);
/**
* @inheritDoc
*/
ol.test.source.MockTileSource.prototype.getTile = function(tileCoord) {
var tile = new ol.Tile(tileCoord);
var key = tileCoord.toString();
if (this.loaded_[key]) {
tile.state = ol.TileState.LOADED;
}
return tile;
};
describe('ol.test.source.MockTileSource', function() {
describe('constructor', function() {
it('creates a tile source', function() {
var source = new ol.test.source.MockTileSource({});
expect(source).toBeA(ol.source.TileSource);
expect(source).toBeA(ol.test.source.MockTileSource);
});
});
describe('#getTile()', function() {
it('returns a tile with state based on constructor arg', function() {
var source = new ol.test.source.MockTileSource({
'0/0/0': true,
'1/0/0': true
});
var tile;
// check a loaded tile
tile = source.getTile(new ol.TileCoord(0, 0, 0));
expect(tile).toBeA(ol.Tile);
expect(tile.state).toBe(ol.TileState.LOADED);
// check a tile that is not loaded
tile = source.getTile(new ol.TileCoord(1, 0, -1));
expect(tile).toBeA(ol.Tile);
expect(tile.state).toBe(ol.TileState.IDLE);
// check another loaded tile
tile = source.getTile(new ol.TileCoord(1, 0, 0));
expect(tile).toBeA(ol.Tile);
expect(tile.state).toBe(ol.TileState.LOADED);
});
});
});
goog.require('goog.object');
goog.require('ol.Coordinate');
goog.require('ol.Extent');
goog.require('ol.Projection');
goog.require('ol.Tile');
goog.require('ol.TileCoord');
goog.require('ol.TileState');
goog.require('ol.source.TileSource');
goog.require('ol.tilegrid.TileGrid');