From 3f91b6fc71477bbace9bcf6acf025ff0dd3be32a Mon Sep 17 00:00:00 2001 From: Guillaume Beraudo Date: Tue, 17 Nov 2015 14:35:33 +0100 Subject: [PATCH 1/4] Mark constructors @struct Detects property misspells. --- src/abstractsynchronizer.js | 9 +++++---- src/autorenderloop.js | 3 ++- src/camera.js | 1 + src/dragbox.js | 1 + src/featureconverter.js | 1 + src/ol3cesium.js | 1 + src/rastersynchronizer.js | 1 + src/vectorsynchronizer.js | 1 + 8 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/abstractsynchronizer.js b/src/abstractsynchronizer.js index aef37bee2..8a65131c2 100644 --- a/src/abstractsynchronizer.js +++ b/src/abstractsynchronizer.js @@ -12,6 +12,7 @@ goog.require('ol.layer.Group'); * @param {!Cesium.Scene} scene * @constructor * @template T + * @struct * @api */ olcs.AbstractSynchronizer = function(map, scene) { @@ -244,12 +245,12 @@ olcs.AbstractSynchronizer.prototype.listenForGroupChanges_ = function(group) { */ olcs.AbstractSynchronizer.prototype.destroyAll = function() { this.removeAllCesiumObjects(true); // destroy - goog.object.forEach(this.olGroupListenKeys, function(keys) { + goog.object.forEach(this.olGroupListenKeys_, function(keys) { keys.forEach(ol.Observable.unByKey); }); - goog.object.forEach(this.olLayerListenKeys, ol.Observable.unByKey); - this.olGroupListenKeys = {}; - this.olLayerListenKeys = {}; + goog.object.forEach(this.olLayerListenKeys_, ol.Observable.unByKey); + this.olGroupListenKeys_ = {}; + this.olLayerListenKeys_ = {}; this.layerMap = {}; }; diff --git a/src/autorenderloop.js b/src/autorenderloop.js index 558d5bb48..44fb5c09c 100644 --- a/src/autorenderloop.js +++ b/src/autorenderloop.js @@ -10,6 +10,7 @@ goog.provide('olcs.AutoRenderLoop'); * @constructor * @param {olcs.OLCesium} ol3d * @param {boolean} debug + * @struct */ olcs.AutoRenderLoop = function(ol3d, debug) { this.ol3d = ol3d; @@ -245,7 +246,7 @@ olcs.AutoRenderLoop.prototype.notifyRepaintRequired = function() { if (this.verboseRendering && this.stoppedRendering) { console.log('starting rendering @ ' + Date.now()); } - this._lastCameraMoveTime = Date.now(); + this.lastCameraMoveTime_ = Date.now(); // TODO: do not unblock if not blocked by us this.ol3d.setBlockCesiumRendering(false); this.stoppedRendering = false; diff --git a/src/camera.js b/src/camera.js index 616cadd29..d0cc376cb 100644 --- a/src/camera.js +++ b/src/camera.js @@ -14,6 +14,7 @@ goog.require('olcs.core'); * @param {!ol.Map} map * @constructor * @api + * @struct */ olcs.Camera = function(scene, map) { /** diff --git a/src/dragbox.js b/src/dragbox.js index 1042055db..2dc72a5c9 100644 --- a/src/dragbox.js +++ b/src/dragbox.js @@ -27,6 +27,7 @@ olcs.DragBoxEventType = { * @extends {goog.events.EventTarget} * @param {Object=} opt_options Options. * @api + * @struct */ olcs.DragBox = function(opt_options) { diff --git a/src/featureconverter.js b/src/featureconverter.js index df1a92d34..46ea6e798 100644 --- a/src/featureconverter.js +++ b/src/featureconverter.js @@ -15,6 +15,7 @@ goog.require('olcs.core.VectorLayerCounterpart'); * @param {!Cesium.Scene} scene Cesium scene. * @constructor * @api + * @struct */ olcs.FeatureConverter = function(scene) { diff --git a/src/ol3cesium.js b/src/ol3cesium.js index 4e02414bb..5889f3a3b 100644 --- a/src/ol3cesium.js +++ b/src/ol3cesium.js @@ -13,6 +13,7 @@ goog.require('olcs.VectorSynchronizer'); * @param {!olcsx.OLCesiumOptions} options Options. * @constructor * @api + * @struct */ olcs.OLCesium = function(options) { diff --git a/src/rastersynchronizer.js b/src/rastersynchronizer.js index ccd6d2a2b..148c80d54 100644 --- a/src/rastersynchronizer.js +++ b/src/rastersynchronizer.js @@ -13,6 +13,7 @@ goog.require('olcs.core'); * @constructor * @extends {olcs.AbstractSynchronizer.} * @api + * @struct */ olcs.RasterSynchronizer = function(map, scene) { /** diff --git a/src/vectorsynchronizer.js b/src/vectorsynchronizer.js index 44fb779e7..3a92840d4 100644 --- a/src/vectorsynchronizer.js +++ b/src/vectorsynchronizer.js @@ -16,6 +16,7 @@ goog.require('olcs.core.VectorLayerCounterpart'); * @constructor * @extends {olcs.AbstractSynchronizer.} * @api + * @struct */ olcs.VectorSynchronizer = function(map, scene, opt_converter) { From 44ff50c326fc978eea1914dcd308fd6583e0b619 Mon Sep 17 00:00:00 2001 From: Guillaume Beraudo Date: Tue, 17 Nov 2015 14:37:31 +0100 Subject: [PATCH 2/4] Compile from and to ES5 strict --- build/ol3cesium.json | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/build/ol3cesium.json b/build/ol3cesium.json index a6c36fb46..d308a6b9f 100644 --- a/build/ol3cesium.json +++ b/build/ol3cesium.json @@ -27,8 +27,10 @@ "api", "observable" ], "compilation_level": "ADVANCED_OPTIMIZATIONS", + "language_in": "ECMASCRIPT5_STRICT", + "language_out": "ECMASCRIPT5_STRICT", "warning_level": "VERBOSE", - "output_wrapper": "(function(){%output%})();", + "output_wrapper": "(function(){%output%}).call(window);", "use_types_for_optimization": true, "create_source_map": "dist/ol3cesium.js.map", "source_map_format": "V3" From 8a5eb39cce3dcdd7882b9cd9cb2967498f638851 Mon Sep 17 00:00:00 2001 From: Guillaume Beraudo Date: Tue, 17 Nov 2015 14:38:36 +0100 Subject: [PATCH 3/4] Restart render loop on clamp to ground --- examples/vectors.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/vectors.html b/examples/vectors.html index 2010851a7..5ab421998 100644 --- a/examples/vectors.html +++ b/examples/vectors.html @@ -22,7 +22,7 @@
+ onclick="javascript:toggleClampToGround(); ol3d.getAutoRenderLoop().restartRenderLoop()" />
Vectors are synchronized from the ol3 map to the Cesium scene.
3D positioning and some styling is supported.
The render loop is automatically stopped when idle.
From be069a54c4bdc5011bbcfd43471a6a63e416cb59 Mon Sep 17 00:00:00 2001 From: Guillaume Beraudo Date: Fri, 30 Oct 2015 17:04:40 +0100 Subject: [PATCH 4/4] Fix incorrect access call to getStyleFunction --- src/featureconverter.js | 29 ++++++++++++++++++++++------- src/vectorsynchronizer.js | 4 ++-- 2 files changed, 24 insertions(+), 9 deletions(-) diff --git a/src/featureconverter.js b/src/featureconverter.js index 46ea6e798..d663ab341 100644 --- a/src/featureconverter.js +++ b/src/featureconverter.js @@ -901,11 +901,6 @@ olcs.FeatureConverter.prototype.olFeatureToCesium = */ olcs.FeatureConverter.prototype.olVectorLayerToCesium = function(olLayer, olView, featurePrimitiveMap) { - var source = olLayer.getSource(); - if (source instanceof ol.source.ImageVector) { - source = source.getSource(); - } - var features = source.getFeatures(); var proj = olView.getProjection(); var resolution = olView.getResolution(); @@ -915,6 +910,19 @@ olcs.FeatureConverter.prototype.olVectorLayerToCesium = // are defined throw new Error('View not ready'); } + + var source = olLayer.getSource(); + if (olLayer instanceof ol.layer.Image) { + if (source instanceof ol.source.ImageVector) { + source = source.getSource(); + } else { + // Not supported + return new olcs.core.VectorLayerCounterpart(proj, this.scene); + } + } + + goog.asserts.assertInstanceof(source, ol.source.Vector); + var features = source.getFeatures(); var counterpart = new olcs.core.VectorLayerCounterpart(proj, this.scene); var context = counterpart.context; for (var i = 0; i < features.length; ++i) { @@ -924,7 +932,9 @@ olcs.FeatureConverter.prototype.olVectorLayerToCesium = } var layerStyle; if (olLayer instanceof ol.layer.Image) { - layerStyle = olLayer.getSource().getStyleFunction(); + var imageSource = olLayer.getSource(); + goog.asserts.assertInstanceof(imageSource, ol.source.ImageVector); + layerStyle = imageSource.getStyleFunction(); } else { layerStyle = olLayer.getStyleFunction(); } @@ -964,7 +974,12 @@ olcs.FeatureConverter.prototype.convert = var layerStyle; if (layer instanceof ol.layer.Image) { - layerStyle = layer.getSource().getStyleFunction(); + var imageSource = layer.getSource(); + if (imageSource instanceof ol.source.ImageVector) { + layerStyle = imageSource.getStyleFunction(); + } else { + return null; + } } else { layerStyle = layer.getStyleFunction(); } diff --git a/src/vectorsynchronizer.js b/src/vectorsynchronizer.js index 3a92840d4..321df14da 100644 --- a/src/vectorsynchronizer.js +++ b/src/vectorsynchronizer.js @@ -95,8 +95,8 @@ olcs.VectorSynchronizer.prototype.createSingleLayerCounterparts = goog.asserts.assertInstanceof(olLayer, ol.layer.Layer); var source = olLayer.getSource(); - if (olLayer.getSource() instanceof ol.source.ImageVector) { - source = olLayer.getSource().getSource(); + if (source instanceof ol.source.ImageVector) { + source = source.getSource(); } goog.asserts.assertInstanceof(source, ol.source.Vector);