Permalink
Browse files

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

  • Loading branch information...
2 parents 8f578b8 + a59aa9b commit 0f2f26969d10a9a418d8e4be85cb7f08456fc2cc @tschaub tschaub committed Feb 20, 2013
@@ -13,9 +13,9 @@
height: 100%;
}
#log {
- height: 500px;
position: absolute;
top: 130px;
+ font-size: 12px;
}
#text {
position: absolute;
@@ -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');
-
-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 url = '../test/spec/ol/parser/ogc/xml/wmscapabilities_v1_3_0/ogcsample.xml';
-goog.net.XhrIo.send(url, function(e) {
- var xhr = e.target;
- result = parser.read(xhr.getResponseXml());
- if (goog.DEBUG) {
- var output = new goog.json.Serializer().serialize(result);
- goog.debug.Logger.getLogger('ol').info(output);
+
+var xhr = new XMLHttpRequest();
+xhr.open('GET', url, true);
+
+
+/**
+ * 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();
View
@@ -31,7 +31,20 @@ and explore the `examples/` directory, for example by opening
<http://localhost:8000/examples/side-by-side.html>.
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
@@ -56,14 +69,35 @@ Then:
## Add examples
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.
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
-the examples are `myexample.js` and `myexample.html` then `id` should be set to
-`myexample` in the `loader.js` URL.
+the example are `myexample.js` and `myexample.html` then the script tag's `src`
+should be set to `myexample`.
`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`
-triggers the `examples` target which creates Plovr JSON file for each example.
+`loader.js?id=<example_name>` script tag to refer to a valid URL. `build.py
+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.
@@ -93,7 +93,7 @@ goog.inherits(ol.Collection, ol.Object);
* Remove all elements from the collection.
*/
ol.Collection.prototype.clear = function() {
- while (this[ol.CollectionProperty.LENGTH]) {
+ while (this.getLength() > 0) {
this.pop();
}
};
@@ -187,7 +187,7 @@ ol.Collection.prototype.removeAt = function(index) {
* @param {*} elem Element.
*/
ol.Collection.prototype.setAt = function(index, elem) {
- var n = this[ol.CollectionProperty.LENGTH];
+ var n = this.getLength();
if (index < n) {
var prev = this.array_[index];
this.array_[index] = elem;
View
@@ -39,6 +39,13 @@ ol.ObjectProperty = {
*/
ol.Object = function(opt_values) {
goog.base(this);
+
+ /**
+ * @private
+ * @type {Object.<string, *>}
+ */
+ this.values_ = {};
+
if (goog.isDef(opt_values)) {
this.setValues(opt_values);
}
@@ -91,7 +98,8 @@ ol.Object.getAccessors = function(obj) {
* @return {string} Changed name.
*/
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');
};
@@ -101,7 +109,8 @@ ol.Object.getChangedEventType = function(key) {
* @return {string} Getter name.
*/
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));
};
@@ -121,7 +130,8 @@ ol.Object.getListeners = function(obj) {
* @return {string} Setter name.
*/
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));
};
@@ -161,20 +171,34 @@ ol.Object.prototype.changed = goog.nullFunction;
* @return {*} Value.
*/
ol.Object.prototype.get = function(key) {
+ var value;
var accessors = ol.Object.getAccessors(this);
- if (goog.object.containsKey(accessors, key)) {
+ if (accessors.hasOwnProperty(key)) {
var accessor = accessors[key];
var target = accessor.target;
var targetKey = accessor.key;
var getterName = ol.Object.getGetterName(targetKey);
if (target[getterName]) {
- return target[getterName]();
+ value = target[getterName]();
} else {
- return target.get(targetKey);
+ value = target.get(targetKey);
}
- } else {
- return this[key];
+ } else if (this.values_.hasOwnProperty(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) {
var accessors = ol.Object.getAccessors(this);
- if (goog.object.containsKey(accessors, key)) {
+ if (accessors.hasOwnProperty(key)) {
var accessor = accessors[key];
var target = accessor.target;
var targetKey = accessor.key;
@@ -211,7 +235,7 @@ ol.Object.prototype.notifyInternal_ = function(key) {
*/
ol.Object.prototype.set = function(key, value) {
var accessors = ol.Object.getAccessors(this);
- if (goog.object.containsKey(accessors, key)) {
+ if (accessors.hasOwnProperty(key)) {
var accessor = accessors[key];
var target = accessor.target;
var targetKey = accessor.key;
@@ -222,7 +246,7 @@ ol.Object.prototype.set = function(key, value) {
target.set(targetKey, value);
}
} else {
- this[key] = value;
+ this.values_[key] = value;
this.notifyInternal_(key);
}
};
@@ -232,14 +256,16 @@ ol.Object.prototype.set = function(key, value) {
* @param {Object.<string, *>} options Options.
*/
ol.Object.prototype.setOptions = function(options) {
- goog.object.forEach(options, function(value, key) {
- var setterName = ol.Object.getSetterName(key);
+ var key, value, setterName;
+ for (key in options) {
+ value = options[key];
+ setterName = ol.Object.getSetterName(key);
if (this[setterName]) {
this[setterName](value);
} else {
this.set(key, value);
}
- }, this);
+ }
};
@@ -261,7 +287,7 @@ ol.Object.prototype.unbind = function(key) {
var value = this.get(key);
var accessors = ol.Object.getAccessors(this);
delete accessors[key];
- this[key] = value;
+ this.values_[key] = value;
}
};
@@ -270,9 +296,7 @@ ol.Object.prototype.unbind = function(key) {
* Removes all bindings.
*/
ol.Object.prototype.unbindAll = function() {
- var listeners = ol.Object.getListeners(this);
- var keys = goog.object.getKeys(listeners);
- goog.array.forEach(keys, function(key) {
+ for (var key in ol.Object.getListeners(this)) {
this.unbind(key);
- }, this);
+ }
};
Oops, something went wrong. Retry.

0 comments on commit 0f2f269

Please sign in to comment.