Skip to content

Commit ac54ca4

Browse files
committed
Allow a custom createSymbolizers function
1 parent 86e0ae2 commit ac54ca4

File tree

2 files changed

+53
-15
lines changed

2 files changed

+53
-15
lines changed

externs/olcsx.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,45 @@
55
*/
66
var olcsx;
77

8+
9+
/**
10+
* @typedef {{
11+
* map: (!ol.Map),
12+
* target: (Element|string|undefined),
13+
* createSynchronizers: ((function(!ol.Map, !Cesium.Scene): Array.<olcs.AbstractSynchronizer>)|undefined)
14+
* }}
15+
* @api
16+
*/
17+
olcsx.OLCesiumOptions;
18+
19+
20+
/**
21+
* The OpenLayers map we want to show on a Cesium scene.
22+
* @type {!ol.Map}
23+
* @api
24+
*/
25+
olcsx.OLCesiumOptions.prototype.map;
26+
27+
28+
/**
29+
* Target element for the Cesium scene.
30+
* @type {Element|string|undefined}
31+
* @api
32+
*/
33+
olcsx.OLCesiumOptions.prototype.target;
34+
35+
36+
/**
37+
* Callback function which will be called by the {@link olcs.OLCesium}
38+
* constructor to create custom synchronizers. Receives an `ol.Map` and a
39+
* `Cesium.Scene` as arguments, and needs to return an array of
40+
* {@link olcs.AbstractSynchronizer}.
41+
* @type {(function(!ol.Map, !Cesium.Scene): Array.<olcs.AbstractSynchronizer>)|undefined}
42+
* @api
43+
*/
44+
olcsx.OLCesiumOptions.prototype.createSynchronizers;
45+
46+
847
/**
948
* Core namespace.
1049
* @type {Object}

src/ol3cesium.js

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,17 @@ goog.require('olcs.VectorSynchronizer');
1111

1212

1313
/**
14-
* @param {!ol.Map} map
15-
* @param {Element|string=} opt_target Target element for the Cesium container.
14+
* @param {!olcsx.OLCesiumOptions} options Options.
1615
* @constructor
1716
* @api
1817
*/
19-
olcs.OLCesium = function(map, opt_target) {
18+
olcs.OLCesium = function(options) {
19+
2020
/**
2121
* @type {!ol.Map}
2222
* @private
2323
*/
24-
this.map_ = map;
24+
this.map_ = options.map;
2525

2626
var fillArea = 'position:absolute;top:0;left:0;width:100%;height:100%;';
2727

@@ -32,7 +32,7 @@ olcs.OLCesium = function(map, opt_target) {
3232
this.container_ = goog.dom.createDom(goog.dom.TagName.DIV,
3333
{style: fillArea + 'visibility:hidden;'});
3434

35-
var targetElement = goog.dom.getElement(opt_target || null);
35+
var targetElement = goog.dom.getElement(options.target || null);
3636
if (targetElement) {
3737
goog.dom.appendChild(targetElement, this.container_);
3838
} else {
@@ -121,17 +121,16 @@ olcs.OLCesium = function(map, opt_target) {
121121
this.scene_.globe = this.globe_;
122122
this.scene_.skyAtmosphere = new Cesium.SkyAtmosphere();
123123

124-
/**
125-
* @type {!olcs.RasterSynchronizer}
126-
* @private
127-
*/
128-
this.rasterSynchronizer_ = new olcs.RasterSynchronizer(this.map_,
129-
this.scene_);
130-
this.rasterSynchronizer_.synchronize();
124+
var synchronizers = goog.isDef(options.createSynchronizers) ?
125+
options.createSynchronizers(this.map_, this.scene_) :
126+
[
127+
new olcs.RasterSynchronizer(this.map_, this.scene_),
128+
new olcs.VectorSynchronizer(this.map_, this.scene_)
129+
];
131130

132-
this.vectorSynchronizer_ = new olcs.VectorSynchronizer(this.map_,
133-
this.scene_);
134-
this.vectorSynchronizer_.synchronize();
131+
for (var i = synchronizers.length - 1; i >= 0; --i) {
132+
synchronizers[i].synchronize();
133+
}
135134

136135
if (this.isOverMap_) {
137136
// if in "stacked mode", hide everything except canvas (including credits)

0 commit comments

Comments
 (0)