diff --git a/bin/generate-exports.py b/bin/generate-exports.py index d098e0c7c4..8ba3d02052 100755 --- a/bin/generate-exports.py +++ b/bin/generate-exports.py @@ -120,11 +120,84 @@ class Class(Exportable): return '%sExport' % self.name +class Function(Exportable): + + def __init__(self, name, object_literal, return_type, objects): + Exportable.__init__(self, name) + self.object_literal = object_literal + self.return_type = return_type + self.objects = objects + + __repr__ = simplerepr + + def property_object_literal(self, object_literal, prop): + prop_object_literal = None + types = object_literal.prop_types[prop].split('|') + for t in types: + if t in self.objects: + o = self.objects[t] + if isinstance(o, ObjectLiteral): + if prop_object_literal: + raise RuntimeError('Multiple "literal" types found for ' + 'option %s.%s: %s, %s.' % + (object_literal.name, prop, + prop_object_literal.name, o.name)) + prop_object_literal = o + return prop_object_literal + + def recursive_export(self, lines, prop, object_literal, local_var=None, depth=1): + indent = ' ' * depth + if not local_var: + local_var = prop.split('.')[-1] + lines.append('%s/** @type {%s} */\n' % (indent, object_literal.name)) + lines.append('%svar %s =\n' % (indent, local_var)) + lines.append('%s /** @type {%s} */\n' % (indent, object_literal.name)) + lines.append('%s (%s);\n' % (indent, prop)) + lines.append('%sif (goog.isDefAndNotNull(%s)) {\n' % (indent, prop)) + for key in sorted(object_literal.prop_types.keys()): + prop_object_literal = self.property_object_literal(object_literal, key) + if prop_object_literal: + lv = self.recursive_export(lines, '%s.%s' % (prop, key), + prop_object_literal, depth=depth + 1) + lines.append('%s %s.%s =\n%s %s;\n' % + (indent, local_var, key, indent, lv)) + else: + lines.append('%s %s.%s =\n%s %s.%s;\n' % + (indent, local_var, key, indent, prop, key)) + lines.append('%s}\n' % (indent,)) + return local_var + + def export(self): + lines = [] + local_var = 'arg' + lines.append('\n\n') + lines.append('/**\n') + lines.append(' * @param {%s} options Options.\n' % (self.object_literal.extern_name(),)) + if self.return_type: + lines.append(' * @return {%s} Return value.\n' % (self.return_type,)) + lines.append(' */\n') + lines.append('%s = function(options) {\n' % (self.export_name(),)) + self.recursive_export(lines, 'options', self.object_literal, + local_var=local_var) + if self.return_type: + lines.append(' return %s(%s);\n' % (self.name, local_var)) + else: + lines.append(' %s(arg);\n' % (self.name,)) + lines.append('};\n') + lines.append('goog.exportSymbol(\n') + lines.append(' \'%s\',\n' % (self.name,)) + lines.append(' %s);\n' % (self.export_name(),)) + return ''.join(lines) + + def export_name(self): + return '%sExport' % self.name + class ObjectLiteral(Exportable): - def __init__(self, name): + def __init__(self, name, objects): Exportable.__init__(self, name) self.prop_types = {} + self.objects = objects __repr__ = simplerepr @@ -138,7 +211,12 @@ class ObjectLiteral(Exportable): for prop in sorted(self.prop_types.keys()): lines.append('\n\n') lines.append('/**\n') - lines.append(' * @type {%s}\n' % (self.prop_types[prop],)) + prop_types = self.prop_types[prop].split('|') + for i, t in enumerate(prop_types): + if t in self.objects and isinstance(self.objects[t], ObjectLiteral): + prop_types[i] = self.objects[t].extern_name() + prop_types = '|'.join(prop_types) + lines.append(' * @type {%s}\n' % (prop_types,)) lines.append(' */\n') lines.append('%s.prototype.%s;\n' % (self.extern_name(), prop)) return ''.join(lines) @@ -221,7 +299,7 @@ def main(argv): name = m.group('name') if name in objects: raise RuntimeError(line) # Name already defined - object_literal = ObjectLiteral(name) + object_literal = ObjectLiteral(name, objects) objects[name] = object_literal continue m = re.match(r'\*\s*@property\s*{(?P.*)}\s*(?P\S+)', line) @@ -262,6 +340,22 @@ def main(argv): objects[name] = symbol symbol.props.add(prop) continue + m = re.match(r'@exportFunction\s+(?P\S+)(?:\s+(?P\S+))?(?:\s+(?P\S+))?\Z', line) + if m: + name = m.group('name') + if name in objects: + raise RuntimeError(line) # Name already defined + object_literal_name = m.group('object_literal_name') + if object_literal_name not in objects: + raise RuntimeError(line) + object_literal = objects[object_literal_name] + if not isinstance(object_literal, ObjectLiteral): + raise RuntimeError(line) + return_type = m.group('return_type') + function = Function(name, object_literal, return_type, objects) + objects[name] = function + requires.add(name) + continue m = re.match(r'@exportSymbol\s+(?P\S+)(?:\s+(?P\S+))?\Z', line) if m: name = m.group('name') diff --git a/examples/animation.js b/examples/animation.js index 80c68d4a59..6182f8b243 100644 --- a/examples/animation.js +++ b/examples/animation.js @@ -1,7 +1,9 @@ goog.require('ol.Map'); goog.require('ol.RendererHints'); goog.require('ol.View2D'); -goog.require('ol.animation'); +goog.require('ol.animation.bounce'); +goog.require('ol.animation.pan'); +goog.require('ol.animation.rotate'); goog.require('ol.easing'); goog.require('ol.layer.TileLayer'); goog.require('ol.proj'); diff --git a/examples/custom-controls.js b/examples/custom-controls.js index d5d774fbc7..3dec81a30b 100644 --- a/examples/custom-controls.js +++ b/examples/custom-controls.js @@ -64,7 +64,7 @@ ol.inherits(app.RotateNorthControl, ol.control.Control); var map = new ol.Map({ - controls: ol.control.defaults({}, [ + controls: ol.control.defaults().extend([ new app.RotateNorthControl() ]), layers: [ diff --git a/examples/drag-rotate-and-zoom.js b/examples/drag-rotate-and-zoom.js index 65a7b94768..6c594af871 100644 --- a/examples/drag-rotate-and-zoom.js +++ b/examples/drag-rotate-and-zoom.js @@ -8,7 +8,7 @@ goog.require('ol.source.MapQuestOpenAerial'); var map = new ol.Map({ - interactions: ol.interaction.defaults({}, [ + interactions: ol.interaction.defaults().extend([ new ol.interaction.DragRotateAndZoom() ]), layers: [ diff --git a/examples/epsg-4326.js b/examples/epsg-4326.js index e4e49eda8d..5de5b985f9 100644 --- a/examples/epsg-4326.js +++ b/examples/epsg-4326.js @@ -22,7 +22,7 @@ var layers = [ ]; var map = new ol.Map({ - controls: ol.control.defaults({}, [ + controls: ol.control.defaults().extend([ new ol.control.ScaleLine({ units: ol.control.ScaleLineUnits.DEGREES }) diff --git a/examples/full-screen-drag-rotate-and-zoom.js b/examples/full-screen-drag-rotate-and-zoom.js index 63c78ff58a..f40cd6a116 100644 --- a/examples/full-screen-drag-rotate-and-zoom.js +++ b/examples/full-screen-drag-rotate-and-zoom.js @@ -10,10 +10,10 @@ goog.require('ol.source.BingMaps'); var map = new ol.Map({ - controls: ol.control.defaults({}, [ + controls: ol.control.defaults().extend([ new ol.control.FullScreen() ]), - interactions: ol.interaction.defaults({}, [ + interactions: ol.interaction.defaults().extend([ new ol.interaction.DragRotateAndZoom() ]), layers: [ diff --git a/examples/full-screen.js b/examples/full-screen.js index 76eabda6d9..a500d21482 100644 --- a/examples/full-screen.js +++ b/examples/full-screen.js @@ -13,7 +13,7 @@ var view = new ol.View2D({ }); var map = new ol.Map({ - controls: ol.control.defaults({}, [ + controls: ol.control.defaults().extend([ new ol.control.FullScreen() ]), layers: [ diff --git a/examples/mouse-position.js b/examples/mouse-position.js index d6c262d1f2..3819b08807 100644 --- a/examples/mouse-position.js +++ b/examples/mouse-position.js @@ -20,7 +20,7 @@ var mousePositionControl = new ol.control.MousePosition({ }); var map = new ol.Map({ - controls: ol.control.defaults({}, [mousePositionControl]), + controls: ol.control.defaults().extend([mousePositionControl]), layers: [ new ol.layer.TileLayer({ source: new ol.source.OSM() diff --git a/examples/navigation-controls.js b/examples/navigation-controls.js index 86f6d06f1e..0c09d64507 100644 --- a/examples/navigation-controls.js +++ b/examples/navigation-controls.js @@ -8,7 +8,7 @@ goog.require('ol.source.OSM'); var map = new ol.Map({ - controls: ol.control.defaults({}, [ + controls: ol.control.defaults().extend([ new ol.control.ZoomToExtent({ extent: [ 813079.7791264898, diff --git a/examples/scale-line.js b/examples/scale-line.js index dffe53948d..4013f3e59a 100644 --- a/examples/scale-line.js +++ b/examples/scale-line.js @@ -11,7 +11,7 @@ goog.require('ol.source.OSM'); var scaleLineControl = new ol.control.ScaleLine(); var map = new ol.Map({ - controls: ol.control.defaults({}, [ + controls: ol.control.defaults().extend([ scaleLineControl ]), layers: [ diff --git a/examples/ten-thousand-points.js b/examples/ten-thousand-points.js index 87552e26e0..e2f1813fcd 100644 --- a/examples/ten-thousand-points.js +++ b/examples/ten-thousand-points.js @@ -42,7 +42,7 @@ var lineStringCollection = ol.geom2.LineStringCollection.pack([ ]); var map = new ol.Map({ - controls: ol.control.defaults({}, [ + controls: ol.control.defaults().extend([ new ol.control.MousePosition({ undefinedHTML: ' ' }) diff --git a/examples/wms-custom-proj.js b/examples/wms-custom-proj.js index 45c98dff45..2d71383205 100644 --- a/examples/wms-custom-proj.js +++ b/examples/wms-custom-proj.js @@ -47,7 +47,7 @@ var layers = [ ]; var map = new ol.Map({ - controls: ol.control.defaults({}, [ + controls: ol.control.defaults().extend([ new ol.control.ScaleLine({ units: ol.control.ScaleLineUnits.METRIC }) diff --git a/src/ol/animation.exports b/src/ol/animation.exports index 5cab49819d..887adf82d7 100644 --- a/src/ol/animation.exports +++ b/src/ol/animation.exports @@ -1,4 +1,4 @@ -@exportSymbol ol.animation.bounce -@exportSymbol ol.animation.pan -@exportSymbol ol.animation.rotate -@exportSymbol ol.animation.zoom +@exportFunction ol.animation.bounce ol.animation.BounceOptions ol.PreRenderFunction +@exportFunction ol.animation.pan ol.animation.PanOptions ol.PreRenderFunction +@exportFunction ol.animation.rotate ol.animation.RotateOptions ol.PreRenderFunction +@exportFunction ol.animation.zoom ol.animation.ZoomOptions ol.PreRenderFunction diff --git a/src/ol/animation.js b/src/ol/animation.js index 3d67b58af8..1a17b97426 100644 --- a/src/ol/animation.js +++ b/src/ol/animation.js @@ -1,6 +1,9 @@ // FIXME works for View2D only -goog.provide('ol.animation'); +goog.provide('ol.animation.bounce'); +goog.provide('ol.animation.pan'); +goog.provide('ol.animation.rotate'); +goog.provide('ol.animation.zoom'); goog.require('ol.PreRenderFunction'); goog.require('ol.ViewHint'); diff --git a/src/ol/collection.exports b/src/ol/collection.exports index 11b7e20c8f..5e3dae2d8d 100644 --- a/src/ol/collection.exports +++ b/src/ol/collection.exports @@ -1,5 +1,6 @@ @exportSymbol ol.Collection @exportProperty ol.Collection.prototype.clear +@exportProperty ol.Collection.prototype.extend @exportProperty ol.Collection.prototype.forEach @exportProperty ol.Collection.prototype.getAt @exportProperty ol.Collection.prototype.getLength diff --git a/src/ol/collection.js b/src/ol/collection.js index fb3fd57962..e73eb3376e 100644 --- a/src/ol/collection.js +++ b/src/ol/collection.js @@ -86,12 +86,14 @@ ol.Collection.prototype.clear = function() { /** * @param {Array} arr Array. + * @return {ol.Collection} This collection. */ ol.Collection.prototype.extend = function(arr) { var i, ii; for (i = 0, ii = arr.length; i < ii; ++i) { this.push(arr[i]); } + return this; }; diff --git a/src/ol/control/controldefaults.exports b/src/ol/control/controldefaults.exports index 0023131772..a3ee165dd7 100644 --- a/src/ol/control/controldefaults.exports +++ b/src/ol/control/controldefaults.exports @@ -1 +1 @@ -@exportSymbol ol.control.defaults ol.control.defaults +@exportFunction ol.control.defaults ol.control.DefaultsOptions ol.Collection diff --git a/src/ol/control/controldefaults.js b/src/ol/control/controldefaults.js index 0d8c818b62..02276c7f2f 100644 --- a/src/ol/control/controldefaults.js +++ b/src/ol/control/controldefaults.js @@ -8,10 +8,9 @@ goog.require('ol.control.Zoom'); /** * @param {ol.control.DefaultsOptions=} opt_options Defaults options. - * @param {Array.=} opt_controls Additional controls. * @return {ol.Collection} Controls. */ -ol.control.defaults = function(opt_options, opt_controls) { +ol.control.defaults = function(opt_options) { var options = goog.isDef(opt_options) ? opt_options : {}; @@ -36,15 +35,11 @@ ol.control.defaults = function(opt_options, opt_controls) { var zoomControl = goog.isDef(options.zoom) ? options.zoom : true; if (zoomControl) { - var zoomControlOptions = goog.isDef(options.zoomControlOptions) ? - options.zoomControlOptions : undefined; + var zoomControlOptions = goog.isDef(options.zoomOptions) ? + options.zoomOptions : undefined; controls.push(new ol.control.Zoom(zoomControlOptions)); } - if (goog.isDef(opt_controls)) { - controls.extend(opt_controls); - } - return controls; }; diff --git a/src/ol/control/zoomcontrol.js b/src/ol/control/zoomcontrol.js index 88e80d6b98..33604f2474 100644 --- a/src/ol/control/zoomcontrol.js +++ b/src/ol/control/zoomcontrol.js @@ -6,7 +6,7 @@ goog.require('goog.dom'); goog.require('goog.dom.TagName'); goog.require('goog.events'); goog.require('goog.events.EventType'); -goog.require('ol.animation'); +goog.require('ol.animation.zoom'); goog.require('ol.control.Control'); goog.require('ol.css'); goog.require('ol.easing'); diff --git a/src/ol/control/zoomslidercontrol.js b/src/ol/control/zoomslidercontrol.js index f8d5c55bbf..d392d8286b 100644 --- a/src/ol/control/zoomslidercontrol.js +++ b/src/ol/control/zoomslidercontrol.js @@ -15,7 +15,7 @@ goog.require('goog.fx.Dragger.EventType'); goog.require('goog.math'); goog.require('goog.math.Rect'); goog.require('goog.style'); -goog.require('ol.animation'); +goog.require('ol.animation.zoom'); goog.require('ol.control.Control'); goog.require('ol.css'); goog.require('ol.easing'); diff --git a/src/ol/interaction/interaction.js b/src/ol/interaction/interaction.js index 6fb94e17a7..4fe73093b4 100644 --- a/src/ol/interaction/interaction.js +++ b/src/ol/interaction/interaction.js @@ -3,7 +3,9 @@ goog.provide('ol.interaction.Interaction'); goog.require('ol.MapBrowserEvent'); -goog.require('ol.animation'); +goog.require('ol.animation.pan'); +goog.require('ol.animation.rotate'); +goog.require('ol.animation.zoom'); goog.require('ol.easing'); diff --git a/src/ol/interaction/interactiondefaults.exports b/src/ol/interaction/interactiondefaults.exports index 2ab5e46392..6e30aa7234 100644 --- a/src/ol/interaction/interactiondefaults.exports +++ b/src/ol/interaction/interactiondefaults.exports @@ -1 +1 @@ -@exportSymbol ol.interaction.defaults ol.interaction.defaults +@exportFunction ol.interaction.defaults ol.interaction.DefaultsOptions ol.Collection diff --git a/src/ol/interaction/interactiondefaults.js b/src/ol/interaction/interactiondefaults.js index b2ba3bd2e4..0fa4c3bc7f 100644 --- a/src/ol/interaction/interactiondefaults.js +++ b/src/ol/interaction/interactiondefaults.js @@ -6,7 +6,6 @@ goog.require('ol.interaction.DoubleClickZoom'); goog.require('ol.interaction.DragPan'); goog.require('ol.interaction.DragRotate'); goog.require('ol.interaction.DragZoom'); -goog.require('ol.interaction.Interaction'); goog.require('ol.interaction.KeyboardPan'); goog.require('ol.interaction.KeyboardZoom'); goog.require('ol.interaction.MouseWheelZoom'); @@ -17,11 +16,9 @@ goog.require('ol.interaction.TouchZoom'); /** * @param {ol.interaction.DefaultsOptions=} opt_options Defaults options. - * @param {Array.=} opt_interactions Additional - * interactions. * @return {ol.Collection} Interactions. */ -ol.interaction.defaults = function(opt_options, opt_interactions) { +ol.interaction.defaults = function(opt_options) { var options = goog.isDef(opt_options) ? opt_options : {}; @@ -92,10 +89,6 @@ ol.interaction.defaults = function(opt_options, opt_interactions) { interactions.push(new ol.interaction.DragZoom()); } - if (goog.isDef(opt_interactions)) { - interactions.extend(opt_interactions); - } - return interactions; }; diff --git a/src/ol/kinetic.js b/src/ol/kinetic.js index 17e1e27d9c..1838b56db7 100644 --- a/src/ol/kinetic.js +++ b/src/ol/kinetic.js @@ -3,7 +3,7 @@ goog.provide('ol.Kinetic'); goog.require('ol.Coordinate'); goog.require('ol.PreRenderFunction'); -goog.require('ol.animation'); +goog.require('ol.animation.pan');