cesium.js 117 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775
  1. "use strict";
  2. // Copyright 2012 United States Government, as represented by the Secretary of Defense, Under
  3. // Secretary of Defense (Personnel & Readiness).
  4. //
  5. // Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
  6. // in compliance with the License. You may obtain a copy of the License at
  7. //
  8. // http://www.apache.org/licenses/LICENSE-2.0
  9. //
  10. // Unless required by applicable law or agreed to in writing, software distributed under the License
  11. // is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
  12. // or implied. See the License for the specific language governing permissions and limitations under
  13. // the License.
  14. define( [ "module",
  15. "vwf/model",
  16. "vwf/utility",
  17. "vwf/utility/color",
  18. "vwf/model/cesium/Cesium"
  19. ],
  20. function( module, model, utility, Color, Cesium ) {
  21. return model.load( module, {
  22. // == Module Definition ====================================================================
  23. // -- initialize ---------------------------------------------------------------------------
  24. initialize: function( options ) {
  25. checkCompatibility.call( this );
  26. if ( options === undefined ) { options = {}; }
  27. this.state.scenes = {}; // id => { scene: Cesium.Scene }
  28. this.state.nodes = {}; // id => { name: string, cesiumObj: }
  29. this.state.prototypes = {};
  30. this.state.createImageryProvider = function( options ) {
  31. var imageProvider = undefined;
  32. if ( options && options.imageryProvider ) {
  33. var url, ext, credit, type, mapStyle, params, layers;
  34. if ( !utility.isString( options ) ) {
  35. url = options.imageryProvider.url;
  36. ext = options.imageryProvider.fileExtension;
  37. mapStyle = options.imageryProvider.mapStyle;
  38. credit = options.imageryProvider.credit;
  39. type = options.imageryProvider.type;
  40. params = options.imageryProvider.params;
  41. layers = options.imageryProvider.layers;
  42. } else {
  43. type = options.imageryProvider;
  44. }
  45. switch ( type ) {
  46. case "bingAerial":
  47. imageProvider = new Cesium.BingMapsImageryProvider({
  48. "url" : url || '//dev.virtualearth.net',
  49. "mapStyle" : mapStyle || Cesium.BingMapsStyle.AERIAL
  50. });
  51. break;
  52. case "bingAerialLabel":
  53. imageProvider = new Cesium.BingMapsImageryProvider({
  54. "url" : url || '//dev.virtualearth.net',
  55. "mapStyle" : mapStyle || Cesium.BingMapsStyle.AERIAL_WITH_LABELS
  56. });
  57. break;
  58. case "bingRoad":
  59. imageProvider = new Cesium.BingMapsImageryProvider( {
  60. "url": url || '//dev.virtualearth.net',
  61. "mapStyle": mapStyle || Cesium.BingMapsStyle.ROAD
  62. } );
  63. break;
  64. case "esriWorld":
  65. imageProvider = new Cesium.ArcGisMapServerImageryProvider({
  66. "url" : url || '//services.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer',
  67. });
  68. break;
  69. case "esriStreet":
  70. imageProvider = new Cesium.ArcGisMapServerImageryProvider({
  71. "url" : url || '//server.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer'
  72. } );
  73. break;
  74. case "esriGeo":
  75. imageProvider = new Cesium.ArcGisMapServerImageryProvider({
  76. "url" : url || '//services.arcgisonline.com/ArcGIS/rest/services/NatGeo_World_Map/MapServer/',
  77. "proxy" : new Cesium.DefaultProxy('/proxy/')
  78. });
  79. break;
  80. case "openStreet":
  81. imageProvider = new Cesium.OpenStreetMapImageryProvider({});
  82. break;
  83. case "mapQuestStreet":
  84. imageProvider = new Cesium.OpenStreetMapImageryProvider({
  85. "url": url || '//otile1.mqcdn.com/tiles/1.0.0/osm/'
  86. });
  87. break;
  88. case "stamen":
  89. imageProvider = new Cesium.OpenStreetMapImageryProvider({
  90. "url": url || '//stamen-tiles.a.ssl.fastly.net/watercolor/',
  91. "fileExtension": fileExtension || 'jpg',
  92. "credit": credit || 'Map tiles by Stamen Design, under CC BY 3.0. Data by OpenStreetMap, under CC BY SA.'
  93. });
  94. break;
  95. case "naturalEarth":
  96. imageProvider = new Cesium.TileMapServiceImageryProvider({
  97. "url" : url || require.toUrl('Assets/Textures/NaturalEarthII')
  98. });
  99. break;
  100. case "single":
  101. imageProvider = new Cesium.SingleTileImageryProvider({
  102. "url" : url || require.toUrl('Assets/Textures/NE2_LR_LC_SR_W_DR_2048.jpg')
  103. } );
  104. break;
  105. case "usInfrared":
  106. imageProvider = new Cesium.WebMapServiceImageryProvider({
  107. "url" : url || '//mesonet.agron.iastate.edu/cgi-bin/wms/goes/conus_ir.cgi?',
  108. "layers" : layers || 'goes_conus_ir',
  109. "credit" : credit || 'Infrared data courtesy Iowa Environmental Mesonet',
  110. "parameters" : params || {
  111. "transparent" : 'true',
  112. "format" : 'image/png'
  113. },
  114. "proxy": new Cesium.DefaultProxy('/proxy/')
  115. });
  116. break;
  117. case "usWeather":
  118. imageProvider = new Cesium.WebMapServiceImageryProvider({
  119. "url" : url || '//mesonet.agron.iastate.edu/cgi-bin/wms/nexrad/n0r.cgi?',
  120. "layers" : layers || 'nexrad-n0r',
  121. "credit" : credit || 'Radar data courtesy Iowa Environmental Mesonet',
  122. "parameters" : params || {
  123. "transparent" : 'true',
  124. "format" : 'image/png'
  125. },
  126. "proxy" : new Cesium.DefaultProxy('/proxy/')
  127. });
  128. break;
  129. case "tms":
  130. imageProvider = new Cesium.TileMapServiceImageryProvider({
  131. "url" : url || '../images/cesium_maptiler/Cesium_Logo_Color'
  132. });
  133. break;
  134. case "image":
  135. imageProvider = new Cesium.SingleTileImageryProvider({
  136. "url" : url || '../images/Cesium_Logo_overlay.png',
  137. "rectangle" : Cesium.Rectangle.fromDegrees(-115.0, 38.0, -107, 39.75)
  138. });
  139. break;
  140. case "grid":
  141. imageProvider = new Cesium.GridImageryProvider();
  142. break;
  143. case "tile":
  144. imageProvider = new Cesium.TileCoordinatesImageryProvider();
  145. break;
  146. }
  147. options.imageryProvider = imageProvider;
  148. }
  149. return imageProvider;
  150. };
  151. this.state.createTerrainProvider = function( options ) {
  152. var terrainProvider = undefined;
  153. if ( options ) {
  154. var type, url, credit, ext;
  155. type = utility.isString( options ) ? options : options.type;
  156. url = options.url || undefined;
  157. credit = options.credit || undefined;
  158. ext = options.ext || undefined;
  159. switch ( type ) {
  160. case "cesium": // remove if all refences can be found
  161. case "CesiumTerrainProvider":
  162. terrainProvider = new Cesium.CesiumTerrainProvider({
  163. url : url || '//cesiumjs.org/smallterrain',
  164. credit : credit || 'Terrain data courtesy Analytical Graphics, Inc.'
  165. });
  166. break;
  167. case "NaturalEarthII":
  168. case "TileMapServiceImageryProvider":
  169. terrainProvider = new Cesium.TileMapServiceImageryProvider({
  170. url: url || '../vwf/model/Assets/Textures/NaturalEarthII',
  171. fileExtension: ext || 'jpg'
  172. });
  173. break;
  174. case "cesiumMesh":
  175. terrainProvider = new Cesium.CesiumTerrainProvider({
  176. url : url || '//cesiumjs.org/stk-terrain/tilesets/world/tiles'
  177. });
  178. break;
  179. case "ArcGisImageServerTerrainProvider":
  180. terrainProvider = new Cesium.ArcGisImageServerTerrainProvider({
  181. url : url || '//elevation.arcgisonline.com/ArcGIS/rest/services/WorldElevation/DTMEllipsoidal/ImageServer',
  182. // sample token : 'KED1aF_I4UzXOHy3BnhwyBHU4l5oY6rO6walkmHoYqGp4XyIWUd5YZUC1ZrLAzvV40pR6gBXQayh0eFA8m6vPg..',
  183. proxy : new Cesium.DefaultProxy('/terrain/')
  184. });
  185. break;
  186. default:
  187. // tilingScheme - parm 1
  188. // ellipsoid - parm 2
  189. terrainProvider = new Cesium.EllipsoidTerrainProvider();
  190. break;
  191. }
  192. }
  193. return terrainProvider;
  194. };
  195. this.state.createClock = function( options ) {
  196. };
  197. this.state.createSkyBox = function( options ) {
  198. };
  199. this.state.setSceneMode = function( options ) {
  200. };
  201. this.state.createMapProjection = function( options ) {
  202. };
  203. // turns on logger debugger console messages
  204. this.debug = {
  205. "creation": false,
  206. "initializing": false,
  207. "parenting": false,
  208. "deleting": false,
  209. "properties": false,
  210. "initProperties": false,
  211. "createProperties": false,
  212. "setting": false,
  213. "getting": false,
  214. "prototypes": false
  215. };
  216. },
  217. // == Model API ============================================================================
  218. // -- creatingNode ------------------------------------------------------------------------
  219. creatingNode: function( nodeID, childID, childExtendsID, childImplementsIDs,
  220. childSource, childType, childIndex, childName, callback ) {
  221. var childURI = nodeID === 0 ? childIndex : undefined;
  222. var appID = this.kernel.application();
  223. if ( this.debug.creation ) {
  224. this.logger.infox( "creatingNode", nodeID, childID, childExtendsID, childImplementsIDs, childSource, childType, childName );
  225. }
  226. var self = this;
  227. var kernel = this.kernel;
  228. var prototypeID = utility.ifPrototypeGetId( appID, this.state.prototypes, nodeID, childID );
  229. if ( prototypeID !== undefined ) {
  230. if ( this.debug.prototypes ) {
  231. this.logger.infox( "prototype: ", prototypeID );
  232. }
  233. this.state.prototypes[ prototypeID ] = {
  234. parentID: nodeID,
  235. ID: childID,
  236. extendsID: childExtendsID,
  237. implementsID: childImplementsIDs,
  238. source: childSource,
  239. type: childType,
  240. uri: childURI,
  241. name: childName
  242. };
  243. return;
  244. }
  245. var node = undefined, parentNode, sceneNode;
  246. var protos = getPrototypes.call( this, childExtendsID );
  247. var createNode = function() {
  248. return {
  249. parentID: nodeID,
  250. ID: childID,
  251. extendsID: childExtendsID,
  252. implementsIDs: childImplementsIDs,
  253. source: childSource,
  254. type: childType,
  255. name: childName,
  256. loadComplete: callback,
  257. prototypes: protos
  258. };
  259. };
  260. var createSceneNode = function( id ) {
  261. var sNode = createNode();
  262. sNode.sceneNode = findSceneNode.call( self, sNode )
  263. return sNode;
  264. };
  265. if ( isCesium.call( this, protos ) ) {
  266. if ( this.state.scenes[ childID ] === undefined ) {
  267. this.state.scenes[ childID ] = node = createNode();
  268. }
  269. } else if ( isGlobe.call( this, protos ) ) {
  270. this.state.nodes[ childID ] = node = createNode();
  271. parentNode = findParent.call( this, nodeID );
  272. if ( parentNode && parentNode.globe ) {
  273. node.cesiumObj = parentNode.globe;
  274. node.cesiumObj.vwfID = childID;
  275. node.terrainProviderValue = "";
  276. node.imageryProviderValue = "";
  277. }
  278. } else if ( isAtmosphere.call( this, protos ) ) {
  279. this.state.nodes[ childID ] = node = createNode();
  280. parentNode = findParent.call( this, nodeID );
  281. if ( parentNode && parentNode.scene ) {
  282. if ( !parentNode.scene.skyAtmosphere ) {
  283. parentNode.scene.skyAtmosphere = new Cesium.SkyAtmosphere();
  284. }
  285. node.cesiumObj = parentNode.scene.skyAtmosphere;
  286. node.cesiumObj.vwfID = childID;
  287. }
  288. } else if ( isSkyBox.call( this, protos ) ) {
  289. this.state.nodes[ childID ] = node = createNode();
  290. parentNode = findParent.call( this, nodeID );
  291. if ( parentNode && parentNode.scene ) {
  292. if ( !parentNode.scene.skyBox ) {
  293. var skyBoxBaseUrl = '../vwf/model/Assets/Textures/SkyBox/tycho2t3_80';
  294. parentNode.scene.skyBox = new Cesium.SkyBox({
  295. positiveX : skyBoxBaseUrl + '_px.jpg',
  296. negativeX : skyBoxBaseUrl + '_mx.jpg',
  297. positiveY : skyBoxBaseUrl + '_py.jpg',
  298. negativeY : skyBoxBaseUrl + '_my.jpg',
  299. positiveZ : skyBoxBaseUrl + '_pz.jpg',
  300. negativeZ : skyBoxBaseUrl + '_mz.jpg'
  301. });
  302. }
  303. node.cesiumObj = parentNode.scene.skyBox;
  304. node.cesiumObj.vwfID = childID;
  305. }
  306. } else if ( isSun.call( this, protos ) ) {
  307. this.state.nodes[ childID ] = node = createNode();
  308. parentNode = findParent.call( this, nodeID );
  309. if ( parentNode && parentNode.scene ) {
  310. if ( !parentNode.scene.sun ) {
  311. parentNode.scene.sun = new Cesium.Sun();
  312. }
  313. node.cesiumObj = parentNode.scene.sun;
  314. node.cesiumObj.vwfID = childID;
  315. }
  316. } else if ( isBillboard.call( this, protos ) ) {
  317. this.state.nodes[ childID ] = node = createSceneNode( childID );
  318. parentNode = findParent.call( this, nodeID );
  319. if ( parentNode && parentNode.cesiumObj instanceof Cesium.Entity ) {
  320. node.cesiumObj = parentNode.cesiumObj.billboard;
  321. } else {
  322. var canvas = document.createElement( 'canvas' );
  323. canvas.width = 16;
  324. canvas.height = 16;
  325. var context2D = canvas.getContext( '2d' );
  326. context2D.beginPath();
  327. context2D.arc( 8, 8, 8, 0, Cesium.Math.TWO_PI, true );
  328. context2D.closePath();
  329. context2D.fillStyle = 'rgb(255,255,255)';
  330. context2D.fill();
  331. // this is making a collection per billboard, which
  332. // probably isn't exactly what we want, but without an
  333. // idea of exactly how we'll be using billboards,
  334. // I'm just going to leave this implementation as is
  335. var bbCollection = node.sceneNode.scene.primitives.add( new Cesium.BillboardCollection() );
  336. var bb = bbCollection.add( {
  337. "image": canvas,
  338. "imageId": childID,
  339. "color" : Cesium.Color.RED,
  340. "scale" : 1,
  341. "imageIndex": 0
  342. } );
  343. node.bbCollection = bbCollection;
  344. node.cesiumObj = bb;
  345. node.cesiumObj.vwfID = childID;
  346. }
  347. } else if ( isLabel.call( this, protos ) ) {
  348. this.state.nodes[ childID ] = node = createSceneNode( childID );
  349. parentNode = findParent.call( this, nodeID );
  350. if ( parentNode && parentNode.cesiumObj instanceof Cesium.Entity ) {
  351. node.cesiumObj = parentNode.cesiumObj.label;
  352. } else {
  353. var labels = node.sceneNode.scene.primitives.add( new Cesium.LabelCollection() );
  354. var lbl = labels.add( {
  355. "font" : '10px Helvetica',
  356. "fillColor" : { red : 0.0, blue : 1.0, green : 1.0, alpha : 1.0 },
  357. "outlineColor" : { red : 0.0, blue : 0.0, green : 0.0, alpha : 1.0 },
  358. "outlineWidth" : 2,
  359. "style" : Cesium.LabelStyle.FILL_AND_OUTLINE
  360. } );
  361. node.labelCollection = labels;
  362. node.cesiumObj = lbl;
  363. node.cesiumObj.vwfID = childID;
  364. }
  365. } else if ( isPolylineCollection.call( this, protos ) ) {
  366. this.state.nodes[ childID ] = node = createSceneNode( childID );
  367. node.cesiumObj = new Cesium.PolylineCollection();
  368. node.cesiumObj.vwfID = childID;
  369. } else if ( isPolyline.call( this, protos ) ) {
  370. this.state.nodes[ childID ] = node = createSceneNode( childID );
  371. parentNode = findParent.call( this, nodeID );
  372. if ( parentNode && parentNode.cesiumObj instanceof Cesium.Entity ) {
  373. node.cesiumObj = parentNode.cesiumObj.polyline;
  374. } else {
  375. var primitives = node.sceneNode.scene.primitives;
  376. if ( parentNode.cesiumObj && parentNode.cesiumObj instanceof Cesium.PolylineCollection ) {
  377. node.polylineCollection = parentNode.cesiumObj;
  378. }
  379. if ( node.polylineCollection === undefined ) {
  380. node.polylineCollection = new Cesium.PolylineCollection();
  381. }
  382. node.cesiumObj = node.polylineCollection.add( childSource );
  383. if ( !primitives.contains( node.polylineCollection ) ) {
  384. primitives.add( node.polylineCollection );
  385. }
  386. node.cesiumObj.vwfID = childID;
  387. }
  388. } else if ( isGeometry.call( this, protos ) ) {
  389. this.state.nodes[ childID ] = node = createSceneNode( childID );
  390. node.geometry = undefined;
  391. node.cesiumObj = undefined;
  392. node.primitive = undefined;
  393. } else if ( isModel.call( this, protos ) ) {
  394. this.state.nodes[ childID ] = node = createSceneNode( childID );
  395. node.cesiumObj = undefined;
  396. loadAsset( node );
  397. } else if ( isMaterial.call( this, protos ) ) {
  398. this.state.nodes[ childID ] = node = createSceneNode( childID );
  399. var parentNode = this.state.nodes[ nodeID ];
  400. if ( parentNode && parentNode.cesiumObj ) {
  401. if ( parentNode.cesiumObj.getMaterial ) {
  402. node.cesiumObj = parentNode.cesiumObj.getMaterial();
  403. } else {
  404. node.cesiumObj = parentNode.cesiumObj.material;
  405. }
  406. node.cesiumObj.vwfID = childID;
  407. }
  408. node.context = undefined;
  409. // if undefined or the wrong type, create a new material and
  410. // set on the parent node
  411. if ( node.cesiumObj === undefined || ( childType && node.cesiumObj.type != childType.type ) ) {
  412. if ( childType && childType.context ) {
  413. node.context = node.scene._context;
  414. }
  415. node.cesiumObj = Cesium.Material.fromType( node.context, childType.type );
  416. if ( parentNode.cesiumObj.setMaterial ) {
  417. parentNode.cesiumObj.setMaterial( node.cesiumObj );
  418. } else {
  419. parentNode.cesiumObj.material = node.cesiumObj;
  420. }
  421. }
  422. } else if ( isCamera.call( this, protos ) ) {
  423. this.state.nodes[ childID ] = node = createSceneNode( childID );
  424. if ( nodeID === this.kernel.application() && childName === 'camera' ) {
  425. node.cesiumObj = node.sceneNode.scene.camera;
  426. } else {
  427. var camera = new Cesium.Camera( canvas );
  428. camera.position = toCartesian3();
  429. camera.direction = Cartesian3.UNIT_Z.negate();
  430. camera.up = Cartesian3.UNIT_Y;
  431. camera.frustum.fovy = CesiumMath.PI_OVER_THREE;
  432. camera.frustum.near = 1.0;
  433. camera.frustum.far = 2.0;
  434. node.cesiumObj = camera;
  435. }
  436. node.cesiumObj.vwfID = childID;
  437. } else if ( isDynamicObject.call( this, protos ) ) {
  438. this.state.nodes[ childID ] = node = createNode();
  439. var sceneNode = findSceneNode.call( this, node );
  440. parentNode = findParent.call( this, nodeID );
  441. if ( parentNode ) {
  442. if ( parentNode.dynObjs ) {
  443. node.cesiumObj = parentNode.dynObjs.getObject( childName );
  444. node.cesiumObj.vwfID = childID;
  445. }
  446. }
  447. } else if ( isNode3.call( this, protos ) ) {
  448. this.state.nodes[ childID ] = node = createNode();
  449. var sceneNode = findSceneNode.call( this, node );
  450. parentNode = findParent.call( this, nodeID );
  451. switch ( childType ) {
  452. case "model/vnd.google-earth.kmz":
  453. break;
  454. case "model/vnd.google-earth.kml+xml":
  455. break;
  456. case "model/vnd.cesium.czml+xml":
  457. if ( sceneNode && sceneNode.cesiumViewer ) {
  458. var viewer = sceneNode.cesiumViewer;
  459. var cds = new Cesium.CzmlDataSource();
  460. cds.loadUrl( childSource ).then( function() {
  461. viewer.homeButton.viewModel.command();
  462. var dataClock = cds.getClock();
  463. if( typeof dataClock !== 'undefined' ) {
  464. dataClock.clone( viewer.clock );
  465. viewer.timeline.zoomTo( dataClock.startTime, dataClock.stopTime );
  466. }
  467. } );
  468. viewer.dataSources.add( cds );
  469. } else {
  470. node.dynObjs = new Cesium.DynamicObjectCollection();
  471. // Create the standard CZML visualizer collection
  472. node.visualizers = Cesium.VisualizerCollection.createCzmlStandardCollection( sceneNode.scene, node.dynObjs );
  473. // Process the CZML, which populates the collection with DynamicObjects
  474. Cesium.processCzml( childSource, node.dynObjs );
  475. //// Figure out the time span of the data
  476. //var availability = dynObjs.computeAvailability();
  477. //// Set the clock range
  478. //clock.startTime = availability.start.clone();
  479. //clock.currentTime = availability.start.clone();
  480. //clock.stopTime = availability.stop.clone();
  481. //clock.clockRange = Cesium.ClockRange.LOOP_STOP;
  482. }
  483. break;
  484. default:
  485. break;
  486. }
  487. }
  488. // If we do not have a load a model for this node, then we are almost done, so we can update all
  489. // the driver properties w/ the stop-gap function below.
  490. // Else, it will be called at the end of the assetLoaded callback
  491. //if ( ! ( childType == "model/vnd.collada+xml" ||
  492. // childType == "model/vnd.osgjs+json+compressed") )
  493. // notifyDriverOfPrototypeAndBehaviorProps();
  494. // Since prototypes are created before the object, it does not get "setProperty" updates for
  495. // its prototype (and behavior) properties. Therefore, we cycle through those properties to
  496. // notify the drivers of the property values so they can react accordingly
  497. // TODO: Have the kernel send the "setProperty" updates itself so the driver need not
  498. // NOTE: Identical code exists in GLGE, and Threejs drivers, so if an change is necessary, it should be made
  499. // there, too
  500. function notifyDriverOfPrototypeAndBehaviorProps() {
  501. var ptPropValue;
  502. var protos = getPrototypes.call( self, childExtendsID );
  503. protos.forEach( function( prototypeID ) {
  504. for ( var propertyName in kernel.getProperties( prototypeID ) ) {
  505. //console.info( " 1 getting "+propertyName+" of: " + childExtendsID );
  506. ptPropValue = kernel.getProperty( childExtendsID, propertyName );
  507. if ( ptPropValue !== undefined && ptPropValue !== null && childID !== undefined && childID !== null) {
  508. //console.info( " 1 setting "+propertyName+" of: " + childID + " to " + ptPropValue );
  509. self.settingProperty( childID, propertyName, ptPropValue );
  510. }
  511. }
  512. } );
  513. childImplementsIDs.forEach( function( behaviorID ) {
  514. for ( var propertyName in kernel.getProperties( behaviorID ) ) {
  515. //console.info( " 2 getting "+propertyName+" of: " + behaviorID );
  516. ptPropValue = kernel.getProperty( behaviorID, propertyName );
  517. if ( ptPropValue !== undefined && ptPropValue !== null && childID !== undefined && childID !== null) {
  518. //console.info( " 2 setting "+propertyName+" of: " + childID + " to " + ptPropValue );
  519. self.settingProperty( childID, propertyName, ptPropValue );
  520. }
  521. }
  522. } );
  523. };
  524. },
  525. initializingNode: function( nodeID, childID, childExtendsID, childImplementsIDs,
  526. childSource, childType, childIndex, childName ) {
  527. if ( this.debug.initializing ) {
  528. this.logger.infox( "initializingNode", nodeID, childID, childExtendsID, childImplementsIDs, childSource, childType, childName );
  529. }
  530. // if ( this.state.nodes[ childID ] ) {
  531. // var node = this.state.nodes[ childID ];
  532. // if ( node.geometryType !== undefined ) {
  533. // createGeometryPrimitive( childID, undefined );
  534. // }
  535. // }
  536. },
  537. // -- deletingNode -------------------------------------------------------------------------
  538. deletingNode: function( nodeID ) {
  539. if ( this.debug.deleting ) {
  540. this.logger.infox( "deletingNode", nodeID );
  541. }
  542. if ( this.state.nodes[ nodeID ] ) {
  543. var node = this.state.nodes[ nodeID ];
  544. var scene = this.state.scenes[ node.sceneID ];
  545. var sceneNode = findSceneNode.call( this, node );
  546. if ( node.cesiumObj ) {
  547. if ( node.cesiumObj instanceof Cesium.Billboard ) {
  548. if ( node.bbCollection ) {
  549. node.bbCollection.remove( node.cesiumObj );
  550. if ( node.bbCollection.getLength() == 0 ) {
  551. sceneNode.scene.primitives.remove( node.bbCollection );
  552. }
  553. node.bbCollection = undefined;
  554. node.cesiumObj = undefined;
  555. }
  556. node.cesiumObj = undefined;
  557. } else if ( node.cesiumObj instanceof Cesium.Label ) {
  558. if ( node.labelCollection ) {
  559. node.labelCollection.remove( node.cesiumObj );
  560. if ( node.labelCollection.getLength() == 0 ) {
  561. sceneNode.scene.primitives.remove( node.labelCollection );
  562. }
  563. node.labelCollection = undefined;
  564. node.cesiumObj = undefined;
  565. }
  566. node.cesiumObj = undefined;
  567. } else if ( node.cesiumObj instanceof Cesium.Polyline ) {
  568. var parentNode = this.state.nodes[ node.parentID ];
  569. if ( parentNode ) {
  570. if ( parentNode.cesiumObj instanceof Cesium.PolylineCollection ) {
  571. // this should work, but there's an error in Cesium
  572. // when an object is removed the member isn't deleted
  573. // then later when the collection is removed, the _polylines
  574. // var has a series of null references
  575. //parentNode.cesiumObj.remove( node.cesiumObj );
  576. node.cesiumObj = undefined;
  577. }
  578. }
  579. } else if ( node.cesiumObj instanceof Cesium.PolylineCollection ) {
  580. sceneNode.scene.primitives.remove( node.cesiumObj );
  581. node.cesiumObj = undefined;
  582. }
  583. }
  584. delete this.state.nodes[ nodeID ];
  585. }
  586. },
  587. // -- addingChild ------------------------------------------------------------------------
  588. //addingChild: function( nodeID, childID, childName ) {
  589. //},
  590. // -- movingChild ------------------------------------------------------------------------
  591. //movingChild: function( nodeID, childID, childName ) {
  592. //},
  593. // -- removingChild ------------------------------------------------------------------------
  594. //removingChild: function( nodeID, childID, childName ) {
  595. //},
  596. // -- creatingProperty ---------------------------------------------------------------------
  597. creatingProperty: function( nodeID, propertyName, propertyValue ) {
  598. var value = undefined;
  599. if ( this.debug.properties || this.debug.createProperties) {
  600. this.logger.infox( "C === creatingProperty ", nodeID, propertyName, propertyValue );
  601. }
  602. if ( utility.validObject( propertyValue ) ) {
  603. var node = this.state.nodes[ nodeID ];
  604. if ( node === undefined ) node = this.state.scenes[ nodeID ];
  605. if ( node !== undefined ) {
  606. switch ( propertyName ) {
  607. default:
  608. value = this.settingProperty( nodeID, propertyName, propertyValue );
  609. break;
  610. }
  611. }
  612. }
  613. return value;
  614. },
  615. // -- initializingProperty -----------------------------------------------------------------
  616. initializingProperty: function( nodeID, propertyName, propertyValue ) {
  617. var value = undefined;
  618. if ( this.debug.properties || this.debug.initProperties ) {
  619. this.logger.infox( " I === initializingProperty ", nodeID, propertyName, propertyValue );
  620. }
  621. if ( utility.validObject( propertyValue ) ) {
  622. var node = this.state.nodes[ nodeID ];
  623. if ( node === undefined ) node = this.state.scenes[ nodeID ];
  624. if ( node !== undefined ) {
  625. switch ( propertyName ) {
  626. case "geometryDefinition":
  627. var geoDef = JSON.parse( JSON.stringify( propertyValue ) );
  628. var geoObjects = createGeometryPrimitive( nodeID, geoDef );
  629. if ( geoObjects !== undefined ) {
  630. node.geometry = geoObjects.geometry;
  631. node.cesiumObj = geoObjects.geometryInstance;
  632. node.primitive = geoObjects.primitive;
  633. if ( node.cesiumObj !== undefined ) {
  634. node.sceneNode.scene.primitives.add( node.primitive );
  635. }
  636. }
  637. break;
  638. default:
  639. value = this.settingProperty( nodeID, propertyName, propertyValue );
  640. break;
  641. }
  642. }
  643. }
  644. return value;
  645. },
  646. // -- settingProperty ----------------------------------------------------------------------
  647. settingProperty: function( nodeID, propertyName, propertyValue ) {
  648. var value = propertyValue;
  649. var node = this.state.nodes[ nodeID ];
  650. if ( this.debug.properties || this.debug.setting ) {
  651. this.logger.infox( " S === settingProperty ", nodeID, propertyName, propertyValue );
  652. }
  653. if ( node ) {
  654. if ( utility.validObject( propertyValue ) ) {
  655. switch ( propertyName ) {
  656. case "visible":
  657. if ( node.cesiumObj.show !== undefined ) {
  658. node.cesiumObj.show = Boolean( propertyValue );
  659. } else if ( node.cesiumObj.setShow ) {
  660. node.cesiumObj.setShow( Boolean( propertyValue ) );
  661. }
  662. break;
  663. case "position":
  664. if ( node.cesiumObj === undefined ) {
  665. if ( node.geometryType !== undefined ) {
  666. if ( node.properties !== undefined ) {
  667. node.properties[ propertyName ] = propertyValue;
  668. } else {
  669. // already created need to modify the existing object
  670. }
  671. }
  672. } else {
  673. if ( node.cesiumObj.position !== undefined ) {
  674. node.cesiumObj.position = toCartesian3( propertyValue );
  675. if ( node.cesiumObj instanceof Cesium.Camera ) {
  676. this.state.cameraInfo.position = node.cesiumObj.position;
  677. }
  678. } else if ( node.cesiumObj.setPosition ) {
  679. var pos = toCartesian3( propertyValue );
  680. node.cesiumObj.setPosition( pos );
  681. this.state.cameraInfo.isInitialized();
  682. }
  683. }
  684. break;
  685. case "positions":
  686. case "radius":
  687. case "length":
  688. case "topRadius":
  689. case "bottomRadius":
  690. case "dimensions":
  691. if ( node.cesiumObj === undefined ) {
  692. if ( node.properties !== undefined ) {
  693. node.properties[ propertyName ] = propertyValue;
  694. } else {
  695. // already created need to modify the existing object
  696. }
  697. }
  698. break;
  699. case "pixelOffset":
  700. node.cesiumObj.pixelOffset = toCartesian2( propertyValue );
  701. break;
  702. case "eyeOffset":
  703. node.cesiumObj.eyeOffset = toCartesian3( propertyValue );
  704. break;
  705. case "horizontalOrigin":
  706. switch ( propertyValue ) {
  707. case "left":
  708. node.cesiumObj.horizontalOrigin = Cesium.HorizontalOrigin.LEFT;
  709. break;
  710. case "right":
  711. node.cesiumObj.horizontalOrigin = Cesium.HorizontalOrigin.RIGHT;
  712. break;
  713. case "center":
  714. node.cesiumObj.horizontalOrigin = Cesium.HorizontalOrigin.CENTER;
  715. break;
  716. }
  717. break;
  718. case "verticalOrigin":
  719. switch ( propertyValue ) {
  720. case "top":
  721. node.cesiumObj.verticalOrigin = Cesium.VerticalOrigin.TOP;
  722. break;
  723. case "bottom":
  724. node.cesiumObj.verticalOrigin = Cesium.VerticalOrigin.BOTTOM;
  725. break;
  726. case "center":
  727. node.cesiumObj.verticalOrigin = Cesium.VerticalOrigin.CENTER;
  728. break;
  729. }
  730. break;
  731. case "scale":
  732. node.cesiumObj.scale = parseFloat( propertyValue );;
  733. break;
  734. case "imageIndex":
  735. var val = Number( propertyValue );
  736. node.cesiumObj.setImageIndex( val );
  737. break;
  738. case "color":
  739. var vwfColor = new utility.color( propertyValue );
  740. if ( vwfColor ) {
  741. if ( node.cesiumObj !== undefined ) {
  742. node.cesiumObj._color.red = vwfColor.red() / 255;
  743. node.cesiumObj._color.green = vwfColor.green() / 255;
  744. node.cesiumObj._color.blue = vwfColor.blue() / 255;
  745. node.cesiumObj._color.alpha = vwfColor.alpha();
  746. } else if ( node.geometryType !== undefined ) {
  747. if ( node.properties !== undefined ) {
  748. node.properties[ propertyName ] = propertyValue;
  749. } else {
  750. // already created need to modify the existing object
  751. }
  752. }
  753. }
  754. break;
  755. case "font":
  756. if ( node.cesiumObj instanceof Cesium.Label ) {
  757. node.cesiumObj.font = propertyValue;
  758. }
  759. break;
  760. case "fillColor":
  761. if ( node.cesiumObj instanceof Cesium.Label ) {
  762. var vwfColor = new utility.color( propertyValue );
  763. if ( vwfColor ) {
  764. node.cesiumObj.fillColor.red = vwfColor.red() / 255;
  765. node.cesiumObj.fillColor.green = vwfColor.green() / 255;
  766. node.cesiumObj.fillColor.blue = vwfColor.blue() / 255;
  767. node.cesiumObj.fillColor.alpha = vwfColor.alpha();
  768. }
  769. }
  770. break;
  771. case "style":
  772. if ( node.cesiumObj instanceof Cesium.Label ) {
  773. switch ( propertyValue ) {
  774. case "fill":
  775. node.cesiumObj.style = Cesium.LabelStyle.FILL;
  776. break;
  777. case "filloutline":
  778. node.cesiumObj.style = Cesium.LabelStyle.FILL_AND_OUTLINE;
  779. break;
  780. case "outline":
  781. node.cesiumObj.style = Cesium.LabelStyle.OUTLINE;
  782. break;
  783. }
  784. }
  785. break;
  786. case "outlineColor":
  787. if ( node.cesiumObj instanceof Cesium.Label ) {
  788. var vwfColor = new utility.color( propertyValue );
  789. if ( vwfColor ) {
  790. node.cesiumObj.outlineColor.red = vwfColor.red() / 255;
  791. node.cesiumObj.outlineColor.green = vwfColor.green() / 255;
  792. node.cesiumObj.outlineColor.blue = vwfColor.blue() / 255;
  793. node.cesiumObj.outlineColor.alpha = vwfColor.alpha();
  794. }
  795. }
  796. break;
  797. case "outlineWidth":
  798. if ( node.cesiumObj instanceof Cesium.Label ) {
  799. node.cesiumObj.outlineWidth = Number( propertyValue );
  800. }
  801. break;
  802. case "text":
  803. if ( node.cesiumObj instanceof Cesium.Label ) {
  804. node.cesiumObj.text = propertyValue;
  805. }
  806. break;
  807. case "image":
  808. if ( node.cesiumObj instanceof Cesium.Billboard ) {
  809. // set and image on the billboard
  810. // TODO
  811. }
  812. break;
  813. case "direction":
  814. if ( node.cesiumObj instanceof Cesium.Camera ) {
  815. node.cesiumObj.direction = toCartesian3( propertyValue );
  816. this.state.cameraInfo.direction = node.cesiumObj.direction;
  817. this.state.cameraInfo.isInitialized();
  818. }
  819. break;
  820. case "fovy":
  821. if ( node.cesiumObj instanceof Cesium.Camera && node.cesiumObj.frustum ) {
  822. node.cesiumObj.frustum.fovy = parseFloat( propertyValue );
  823. }
  824. break;
  825. case "near":
  826. if ( node.cesiumObj instanceof Cesium.Camera && node.cesiumObj.frustum ) {
  827. node.cesiumObj.frustum.near = parseFloat( propertyValue );
  828. }
  829. break;
  830. case "far":
  831. if ( node.cesiumObj instanceof Cesium.Camera && node.cesiumObj.frustum ) {
  832. node.cesiumObj.frustum.far = parseFloat( propertyValue );
  833. }
  834. break;
  835. case "right":
  836. if ( node.cesiumObj instanceof Cesium.Camera ) {
  837. node.cesiumObj.right = toCartesian3( propertyValue );
  838. this.state.cameraInfo.right = node.cesiumObj.right;
  839. this.state.cameraInfo.isInitialized();
  840. }
  841. break;
  842. case "transform":
  843. if ( node.cesiumObj instanceof Cesium.Camera ) {
  844. node.cesiumObj.transform = arrayToMatrix4( propertyValue );
  845. }
  846. break;
  847. case "modelMatrix":
  848. if ( node.cesiumObj !== undefined ) {
  849. if ( node.cesiumObj.hasOwnProperty( propertyName ) ) {
  850. node.cesiumObj.modelMatrix = arrayToMatrix4( propertyValue );
  851. }
  852. }
  853. break;
  854. case "up":
  855. if ( node.cesiumObj instanceof Cesium.Camera ) {
  856. node.cesiumObj.up = toCartesian3( propertyValue );
  857. this.state.cameraInfo.up = node.cesiumObj.up;
  858. this.state.cameraInfo.isInitialized();
  859. }
  860. break;
  861. case "fabric":
  862. if ( node.cesiumObj instanceof Cesium.Material ) {
  863. // this parameter is the context, which I'm not exactly
  864. // sure what to do about that right now
  865. node.cesiumObj.material = new Cesium.Material( undefined, propertyValue );
  866. }
  867. value = undefined;
  868. break;
  869. case "type":
  870. if ( node.cesiumObj instanceof Cesium.Material ) {
  871. // best to set the type in the fabric
  872. // switch ( propertyValue ) {
  873. // case "Color":
  874. // case "Image":
  875. // case "DiffuseMap":
  876. // case "AlphaMap":
  877. // case "SpecularMap":
  878. // case "EmissionMap":
  879. // case "BumpMap":
  880. // case "NormalMap":
  881. // case "Reflection":
  882. // case "Refraction":
  883. // case "Fresnel":
  884. // case "Brick":
  885. // case "Wood":
  886. // case "Asphalt":
  887. // case "Cement":
  888. // case "Grass":
  889. // case "Grid":
  890. // case "Stripe":
  891. // case "Checkerboard":
  892. // case "Dot":
  893. // case "Tiedye":
  894. // case "Facet":
  895. // case "Blob":
  896. // case "Water":
  897. // case "RimLighting":
  898. // case "erosion":
  899. // case "Fade":
  900. // case "PolylineArrow":
  901. // case "PolylineGlow":
  902. // case "PolylineOutline":
  903. // default:
  904. // node.cesiumObj = Cesium.Material.fromType( undefined, propertyValue );
  905. // break;
  906. // }
  907. if ( node.cesiumObj.type != propertyValue ) {
  908. node.cesiumObj.type = propertyValue;
  909. }
  910. }
  911. break;
  912. case "uniforms":
  913. if ( node.cesiumObj instanceof Cesium.Material ) {
  914. // the uniforms properties are based upon the material type
  915. // check the Material spec at //cesium.agi.com/refdoc.html
  916. // for more information
  917. var uni = node.cesiumObj.uniforms;
  918. if ( uni ) {
  919. if ( propertyValue instanceof Object ) {
  920. for( var prop in propertyValue ) {
  921. switch( prop ) {
  922. case "color":
  923. uni.color = cesiumColor( propertyValue[ prop ] )
  924. break;
  925. default:
  926. uni[ prop ] = propertyValue[ prop ];
  927. break;
  928. }
  929. }
  930. }
  931. }
  932. }
  933. break;
  934. case "shaderSource":
  935. if ( node.cesiumObj instanceof Cesium.Material ) {
  936. node.cesiumObj.shaderSource = propertyValue;
  937. }
  938. break;
  939. case "positions":
  940. if ( node.cesiumObj instanceof Cesium.Polyline || node.cesiumObj instanceof Cesium.Geometry ) {
  941. var points = [];
  942. if ( propertyValue instanceof Array ) {
  943. var len = propertyValue.length;
  944. for ( var i = 0; i < len; i++ ) {
  945. points.push( toCartesian3( propertyValue ) );
  946. }
  947. }
  948. node.cesiumObj.positions = points;
  949. }
  950. break;
  951. case "width":
  952. if ( node.cesiumObj instanceof Cesium.Polyline ) {
  953. node.cesiumObj.width = Number( propertyValue );
  954. }
  955. break;
  956. // case "extent":
  957. // if ( node.cesiumObj instanceof Cesium.Polygon ) {
  958. // var pv = propertyValue;
  959. // if ( pv instanceof Array ) {
  960. // switch ( pv.length ) {
  961. // case 4:
  962. // node.cesiumObj.configureExtent( new Cesium.Extent( pv[0], pv[1], pv[2], pv[3] ) );
  963. // break;
  964. // case 6:
  965. // node.cesiumObj.configureExtent( new Cesium.Extent( pv[0], pv[1], pv[2], pv[3], pv[4], pv[5] ) );
  966. // break;
  967. // }
  968. // }
  969. // }
  970. // value = undefined;
  971. // break;
  972. case "height":
  973. if ( node.cesiumObj === undefined ) {
  974. if ( node.properties !== undefined ) {
  975. node.properties[ propertyName ] = propertyValue;
  976. }
  977. } else if ( node.cesiumObj instanceof Cesium.Polygon ) {
  978. node.cesiumObj.height = Number( propertyValue );
  979. }
  980. break;
  981. case "hierarchy":
  982. if ( node.cesiumObj instanceof Cesium.Polygon ) {
  983. node.cesiumObj.configureFromPolygonHierarchy( propertyValue );
  984. }
  985. break;
  986. case "granularity":
  987. if ( node.cesiumObj instanceof Cesium.Polygon ) {
  988. node.cesiumObj.granularity = Number( propertyValue );
  989. }
  990. break;
  991. case "availability":
  992. if ( node.cesiumObj instanceof Cesium.Entity ) {
  993. var start = propertyValue.start;
  994. var stop = propertyValue.stop;
  995. var startIncluded = propertyValue.isStartIncluded ? propertyValue.isStartIncluded : true;
  996. var stopIncluded = propertyValue.isStopIncluded ? propertyValue.isStopIncluded : true;
  997. if ( start && stop ) {
  998. node.cesiumObj.availability = new TimeInterval( start, stop, startIncluded, stopIncluded );
  999. }
  1000. }
  1001. break;
  1002. //case "orientation":
  1003. // if ( node.cesiumObj instanceof Cesium.Entity ) {
  1004. //
  1005. // }
  1006. // break;
  1007. //case "point":
  1008. // if ( node.cesiumObj instanceof Cesium.Entity ) {
  1009. //
  1010. // }
  1011. // break;
  1012. //case "vector":
  1013. // if ( node.cesiumObj instanceof Cesium.Entity ) {
  1014. //
  1015. // }
  1016. // break;
  1017. //case "vertexPositions":
  1018. // if ( node.cesiumObj instanceof Cesium.Entity ) {
  1019. //
  1020. // }
  1021. // break;
  1022. case "viewFrom":
  1023. if ( node.cesiumObj instanceof Cesium.Entity ) {
  1024. node.cesiumObj.viewFrom = toCartesian3( propertyValue );
  1025. }
  1026. break;
  1027. case "northPoleColor":
  1028. if ( node.cesiumObj instanceof Cesium.Globe ) {
  1029. var vwfColor = new utility.color( propertyValue );
  1030. if ( vwfColor ) {
  1031. node.cesiumObj.northPoleColor = vwfColorToCartesian3( vwfColor );
  1032. }
  1033. }
  1034. break;
  1035. case "southPoleColor":
  1036. if ( node.cesiumObj instanceof Cesium.Globe ) {
  1037. var vwfColor = new utility.color( propertyValue );
  1038. if ( vwfColor ) {
  1039. node.cesiumObj.southPoleColor = vwfColorToCartesian3( vwfColor );
  1040. }
  1041. }
  1042. break;
  1043. case "logoOffset":
  1044. if ( node.cesiumObj instanceof Cesium.Globe ) {
  1045. node.cesiumObj.logoOffset = toCartesian2( propertyValue );
  1046. }
  1047. break;
  1048. case "tileCacheSize":
  1049. if ( node.cesiumObj instanceof Cesium.Globe ) {
  1050. node.cesiumObj.tileCacheSize = Number( propertyValue );
  1051. }
  1052. break;
  1053. case "oceanNormalMapUrl":
  1054. if ( node.cesiumObj instanceof Cesium.Globe ) {
  1055. node.cesiumObj.oceanNormalMapUrl = propertyValue;
  1056. }
  1057. break;
  1058. case "depthTestAgainstTerrain":
  1059. if ( node.cesiumObj instanceof Cesium.Globe ) {
  1060. node.cesiumObj.depthTestAgainstTerrain = Boolean( propertyValue );
  1061. }
  1062. break;
  1063. case "terrainProvider":
  1064. if ( node.cesiumObj instanceof Cesium.Globe ) {
  1065. var requestedType = propertyValue.type || propertyValue.terrainProvider || propertyValue;
  1066. if ( requestedType === node.terrainProviderValue ) {
  1067. break;
  1068. }
  1069. node.terrainProvider = this.state.createTerrainProvider( propertyValue );
  1070. node.cesiumObj.depthTestAgainstTerrain = ( node.terrainProvider !== undefined );
  1071. if ( node.terrainProvider !== undefined ) {
  1072. node.terrainProviderValue = requestedType;
  1073. node.cesiumObj.terrainProvider = node.terrainProvider;
  1074. }
  1075. }
  1076. value = undefined;
  1077. break;
  1078. default:
  1079. value = undefined;
  1080. break;
  1081. }
  1082. } else {
  1083. value = undefined;
  1084. }
  1085. } else if ( this.state.scenes[ nodeID ] ) {
  1086. node = this.state.scenes[ nodeID ];
  1087. var scene = node.scene;
  1088. if ( ( node.cesiumWidget !== undefined || scene.globe !== undefined ) && utility.validObject( propertyValue ) ) {
  1089. switch ( propertyName ) {
  1090. case "clientControl":
  1091. this.state.clientControl = propertyValue;
  1092. break;
  1093. case "cameraViewData":
  1094. if ( this.kernel.client() != this.kernel.moniker() ) {
  1095. var camera = scene._camera;
  1096. if ( propertyValue.direction ) {
  1097. camera.direction = toCartesian3( propertyValue.direction );
  1098. }
  1099. if ( propertyValue.position ) {
  1100. camera.position = toCartesian3( propertyValue.position );
  1101. }
  1102. if ( propertyValue.up ) {
  1103. camera.up = toCartesian3( propertyValue.up );
  1104. }
  1105. if ( propertyValue.right ) {
  1106. camera.right = toCartesian3( propertyValue.right );
  1107. }
  1108. this.state.cameraInfo.getCurrent( camera );
  1109. }
  1110. break;
  1111. case "imageryProvider":
  1112. var requestedType = propertyValue.type || propertyValue.terrainProvider;
  1113. if ( node.imageryProviderValue === requestedType ) {
  1114. return;
  1115. }
  1116. node.imageProvider = this.state.createImageryProvider ( {
  1117. "imageryProvider": propertyValue
  1118. } );
  1119. if ( node.imageProvider !== undefined ) {
  1120. scene.globe.imageryLayers().addImageryProvider( node.imageProvider );
  1121. node.imageryProviderValue = requestedType;
  1122. }
  1123. value = undefined;
  1124. break;
  1125. case "renderStyle":
  1126. // using the Cesium.Widget
  1127. if ( node.cesiumWidget ) {
  1128. var currentRS = this.gettingProperty( nodeID, propertyName );
  1129. if ( currentRS != propertyValue ) {
  1130. switch ( propertyValue ) {
  1131. case "3D":
  1132. node.cesiumWidget._transitioner.to3D();
  1133. break;
  1134. case "2D":
  1135. node.cesiumWidget._transitioner.to2D();
  1136. break;
  1137. case "2.5D":
  1138. node.cesiumWidget._transitioner.toColumbusView();
  1139. break;
  1140. }
  1141. }
  1142. } else if ( node.transitioner ) {
  1143. switch ( propertyValue ) {
  1144. case "3D":
  1145. node.transitioner.morphTo3D();
  1146. break;
  1147. case "2D":
  1148. node.transitioner.morphTo2D();
  1149. break;
  1150. case "2.5D":
  1151. node.transitioner.morphToColumbusView();
  1152. break;
  1153. }
  1154. }
  1155. value = undefined;
  1156. break;
  1157. case "backgroundColor":
  1158. if( node.scene ) {
  1159. node.scene.backgroundColor = cesiumColor( propertyValue );
  1160. }
  1161. break;
  1162. case "enableLook":
  1163. if( node.scene ) {
  1164. var controller = node.scene.screenSpaceCameraController;
  1165. if ( controller ) {
  1166. controller.enableLook = Boolean( propertyValue );
  1167. }
  1168. }
  1169. break;
  1170. case "enableRotate":
  1171. if( node.scene ) {
  1172. var controller = node.scene.screenSpaceCameraController;
  1173. if ( controller ) {
  1174. controller.enableRotate = Boolean( propertyValue );
  1175. }
  1176. }
  1177. break;
  1178. case "enableTilt":
  1179. if( node.scene ) {
  1180. var controller = node.scene.screenSpaceCameraController;
  1181. if ( controller ) {
  1182. controller.enableTilt = Boolean( propertyValue );
  1183. }
  1184. }
  1185. break;
  1186. case "enableTranslate":
  1187. if( node.scene ) {
  1188. var controller = node.scene.screenSpaceCameraController;
  1189. if ( controller ) {
  1190. controller.enableTranslate = Boolean( propertyValue );
  1191. }
  1192. }
  1193. break;
  1194. case "enableZoom":
  1195. if( node.scene ) {
  1196. var controller = node.scene.screenSpaceCameraController;
  1197. if ( controller ) {
  1198. controller.enableZoom = Boolean( propertyValue );
  1199. }
  1200. }
  1201. break;
  1202. case "clientControl": //
  1203. // propertyValue.event is being ignored
  1204. if ( this.state.clientControl.locked == false ) {
  1205. if ( this.state.clientControl.controller != propertyValue.controller ) {
  1206. // switching controllers, disable all non-controllers
  1207. if ( propertyValue.controller != this.kernel.moniker() ) {
  1208. this.state.mouse.enable( false );
  1209. }
  1210. }
  1211. // new client in control
  1212. this.state.clientControl = propertyValue;
  1213. } else if ( !propertyValue.locked ) {
  1214. // leave the controller set, but update locked
  1215. // this will allow the camera to keep moving by the
  1216. // current controller
  1217. if ( this.state.clientControl.controller == propertyValue.controller ) {
  1218. this.state.clientControl.locked = false;
  1219. this.state.mouse.enable( true );
  1220. }
  1221. } else {
  1222. console.info( "state.clientControl ignoring:{ event: " + propertyValue.event + ", controller: " + propertyValue.controller + ", locked: " + propertyValue.locked + " }" );
  1223. }
  1224. break;
  1225. default:
  1226. value = undefined;
  1227. break;
  1228. }
  1229. } else {
  1230. value = undefined;
  1231. }
  1232. } else {
  1233. value = undefined;
  1234. }
  1235. return value;
  1236. },
  1237. // -- gettingProperty ----------------------------------------------------------------------
  1238. gettingProperty: function( nodeID, propertyName, propertyValue ) {
  1239. var node = this.state.nodes[ nodeID ];
  1240. if( !node ) node = this.state.scenes[ nodeID ];
  1241. var value = undefined;
  1242. if ( this.debug.properties || this.debug.getting ) {
  1243. this.logger.infox( " G === gettingProperty ", nodeID, propertyName, propertyValue );
  1244. }
  1245. if( !node ) return undefined;
  1246. switch ( propertyName ) {
  1247. case "visible":
  1248. if ( node.cesiumObj ) {
  1249. if ( node.cesiumObj.getShow ) {
  1250. value = node.cesiumObj.getShow();
  1251. } else {
  1252. value = node.cesiumObj.show;
  1253. }
  1254. }
  1255. break;
  1256. case "position":
  1257. if ( node.cesiumObj ) {
  1258. var pos = node.cesiumObj.position;
  1259. if ( pos ) {
  1260. value = [ pos.x, pos.y, pos.z ];
  1261. }
  1262. }
  1263. break;
  1264. case "pixelOffset":
  1265. if ( node.cesiumObj ) {
  1266. var pos = node.cesiumObj.pixelOffset;
  1267. value = [ pos.x, pos.y ];
  1268. }
  1269. break;
  1270. case "eyeOffset":
  1271. if ( node.cesiumObj ) {
  1272. var pos = node.cesiumObj.eyeOffset;
  1273. value = [ pos.x, pos.y, pos.z ];
  1274. }
  1275. case "horizontalOrigin":
  1276. if ( node.cesiumObj ) {
  1277. switch ( node.cesiumObj.horizontalOrigin ) {
  1278. case Cesium.HorizontalOrigin.LEFT:
  1279. value = "left";
  1280. break;
  1281. case Cesium.HorizontalOrigin.RIGHT:
  1282. value = "right";
  1283. break;
  1284. case Cesium.HorizontalOrigin.CENTER:
  1285. value = "center";
  1286. break;
  1287. }
  1288. }
  1289. break;
  1290. case "verticalOrigin":
  1291. if ( node.cesiumObj ) {
  1292. switch ( node.cesiumObj.verticalOrigin ) {
  1293. case Cesium.VerticalOrigin.TOP:
  1294. value = "top";
  1295. break;
  1296. case Cesium.VerticalOrigin.BOTTOM:
  1297. value = "bottom";
  1298. break;
  1299. case Cesium.VerticalOrigin.CENTER:
  1300. value = "center";
  1301. break;
  1302. }
  1303. }
  1304. break;
  1305. case "scale":
  1306. if ( node.cesiumObj ) {
  1307. value = node.cesiumObj.scale;
  1308. }
  1309. break;
  1310. case "imageIndex":
  1311. if ( node.cesiumObj ) {
  1312. value = node.cesiumObj.imageIndex;
  1313. }
  1314. break;
  1315. case "color":
  1316. if( node.cesiumObj && node.cesiumObj._color ) {
  1317. var clr = node.cesiumObj._color;
  1318. if ( clr.alpha == 1 ) {
  1319. value = "rgb("+(clr.red*255)+","+(clr.green*255)+","+(clr.blue*255)+")";
  1320. } else {
  1321. value = "rgba("+(clr.red*255)+","+(clr.green*255)+","+(clr.blue*255)+","+clr.alpha+")";
  1322. }
  1323. }
  1324. break;
  1325. case "font":
  1326. if ( node.cesiumObj instanceof Cesium.Label ) {
  1327. value = node.cesiumObj.font;
  1328. }
  1329. break;
  1330. case "fillColor":
  1331. if( node.cesiumObj ) {
  1332. var clr = node.cesiumObj.fillColor;
  1333. if ( clr.alpha == 1 ) {
  1334. value = "rgb("+(clr.red*255)+","+(clr.green*255)+","+(clr.blue*255)+")";
  1335. } else {
  1336. value = "rgba("+(clr.red*255)+","+(clr.green*255)+","+(clr.blue*255)+","+clr.alpha+")";
  1337. }
  1338. }
  1339. break;
  1340. case "style":
  1341. if ( node.cesiumObj instanceof Cesium.Label ) {
  1342. switch ( node.cesiumObj.style ) {
  1343. case Cesium.LabelStyle.FILL:
  1344. value = "fill";
  1345. break;
  1346. case Cesium.LabelStyle.FILL_AND_OUTLINE:
  1347. value = "filloutline";
  1348. break;
  1349. case Cesium.LabelStyle.OUTLINE:
  1350. value = "outline";
  1351. break;
  1352. }
  1353. }
  1354. break;
  1355. case "outlineColor":
  1356. if( node.cesiumObj ) {
  1357. var clr = node.cesiumObj.outlineColor;
  1358. if ( clr.alpha == 1 ) {
  1359. value = "rgb("+(clr.red*255)+","+(clr.green*255)+","+(clr.blue*255)+")";
  1360. } else {
  1361. value = "rgba("+(clr.red*255)+","+(clr.green*255)+","+(clr.blue*255)+","+clr.alpha+")";
  1362. }
  1363. }
  1364. break;
  1365. case "outlineWidth":
  1366. if ( node.cesiumObj instanceof Cesium.Label ) {
  1367. value = node.cesiumObj.outlineWidth;
  1368. }
  1369. break;
  1370. case "text":
  1371. if ( node.cesiumObj instanceof Cesium.Label ) {
  1372. value = node.cesiumObj.text;
  1373. }
  1374. break;
  1375. case "imageryProvider":
  1376. break;
  1377. case "terrainProvider":
  1378. break;
  1379. case "northPoleColor":
  1380. if ( node.cesiumObj instanceof Cesium.Globe ) {
  1381. var clr = node.cesiumObj.northPoleColor;
  1382. value = "rgb(" + ( clr.x*255 ) + "," + (clr.y*255) + "," + (clr.z*255) + ")";
  1383. }
  1384. break;
  1385. case "southPoleColor":
  1386. if ( node.cesiumObj instanceof Cesium.Globe ) {
  1387. var clr = node.cesiumObj.southPoleColor;
  1388. value = "rgb(" + ( clr.x*255 ) + "," + (clr.y*255) + "," + (clr.z*255) + ")";
  1389. }
  1390. break;
  1391. break;
  1392. case "logoOffset":
  1393. if ( node.cesiumObj instanceof Cesium.Globe ) {
  1394. var pos = node.cesiumObj.logoOffset;
  1395. value = pos !== undefined ? [ pos.x, pos.y ] : undefined;
  1396. }
  1397. break;
  1398. case "tileCacheSize":
  1399. if ( node.cesiumObj instanceof Cesium.Globe ) {
  1400. value = node.cesiumObj.tileCacheSize;
  1401. }
  1402. break;
  1403. case "oceanNormalMapUrl":
  1404. if ( node.cesiumObj instanceof Cesium.Globe ) {
  1405. value = node.cesiumObj.oceanNormalMapUrl;
  1406. }
  1407. break;
  1408. case "depthTestAgainstTerrain":
  1409. if ( node.cesiumObj instanceof Cesium.Globe ) {
  1410. value = node.cesiumObj.depthTestAgainstTerrain;
  1411. }
  1412. break;
  1413. case "cameraViewData":
  1414. if ( node.scene ) {
  1415. var camera = node.scene._camera;
  1416. var value = {}
  1417. var vec;
  1418. if ( camera.direction ) {
  1419. vec = camera.direction;
  1420. value.direction = [ vec.x, vec.y, vec.z ];
  1421. }
  1422. if ( camera.position ) {
  1423. vec = camera.position;
  1424. value.position = [ vec.x, vec.y, vec.z ];
  1425. }
  1426. if ( camera.up ) {
  1427. vec = camera.up;
  1428. value.up = [ vec.x, vec.y, vec.z ];
  1429. }
  1430. if ( camera.right ) {
  1431. vec = camera.right;
  1432. value.right = [ vec.x, vec.y, vec.z ];
  1433. }
  1434. }
  1435. break;
  1436. case "renderStyle":
  1437. if ( node.scene && node.scene.mode ) {
  1438. switch ( node.scene.mode ) {
  1439. case Cesium.SceneMode.COLUMBUS_VIEW:
  1440. value = "2.5D";
  1441. break;
  1442. case Cesium.SceneMode.SCENE2D:
  1443. value = "2D";
  1444. break;
  1445. case Cesium.SceneMode.SCENE3D:
  1446. value = "3D";
  1447. break;
  1448. }
  1449. }
  1450. break;
  1451. case "backgroundColor":
  1452. if( node.scene ) {
  1453. var clr = node.scene.backgroundColor
  1454. if ( clr.alpha == 1 ) {
  1455. value = "rgb("+(clr.red*255)+","+(clr.green*255)+","+(clr.blue*255)+")";
  1456. } else {
  1457. value = "rgba("+(clr.red*255)+","+(clr.green*255)+","+(clr.blue*255)+","+clr.alpha+")";
  1458. }
  1459. }
  1460. break;
  1461. case "clientControl":
  1462. value = this.state.clientControl;
  1463. break;
  1464. case "direction":
  1465. if ( node.cesiumObj instanceof Cesium.Camera ) {
  1466. var vec3 = node.cesiumObj.direction;
  1467. value = [ vec3.x, vec3.y, vec3.z ];
  1468. }
  1469. break;
  1470. case "fovy":
  1471. if ( node.cesiumObj instanceof Cesium.Camera ) {
  1472. value = node.cesiumObj.frustum.fovy;
  1473. }
  1474. break;
  1475. case "near":
  1476. if ( node.cesiumObj instanceof Cesium.Camera ) {
  1477. value = node.cesiumObj.frustum.near;
  1478. }
  1479. break;
  1480. case "far":
  1481. if ( node.cesiumObj instanceof Cesium.Camera ) {
  1482. value = node.cesiumObj.frustum.far;
  1483. }
  1484. break;
  1485. case "right":
  1486. if ( node.cesiumObj instanceof Cesium.Camera ) {
  1487. var vec3 = node.cesiumObj.right;
  1488. value = [ vec3.x, vec3.y, vec3.z ]; }
  1489. break;
  1490. case "transform":
  1491. if ( node.cesiumObj instanceof Cesium.Camera ) {
  1492. value = matrix4ToArray( node.cesiumObj.transform );
  1493. }
  1494. break;
  1495. case "modelMatrix":
  1496. if ( node.cesiumObj !== undefined ) {
  1497. if ( node.cesiumObj.hasOwnProperty( propertyName ) ) {
  1498. value = matrix4ToArray( node.cesiumObj.modelMatrix );
  1499. }
  1500. }
  1501. break;
  1502. case "up":
  1503. if ( node.cesiumObj instanceof Cesium.Camera ) {
  1504. var vec3 = node.cesiumObj.up;
  1505. value = [ vec3.x, vec3.y, vec3.z ];
  1506. }
  1507. break;
  1508. case "fabric":
  1509. // current state stored by the object model
  1510. break;
  1511. case "type":
  1512. if ( node.cesiumObj instanceof Cesium.Material ) {
  1513. value = node.cesiumObj.type;
  1514. }
  1515. break;
  1516. case "shaderSource":
  1517. if ( node.cesiumObj instanceof Cesium.Material ) {
  1518. value = node.cesiumObj.shaderSource;
  1519. }
  1520. break;
  1521. case "uniforms":
  1522. if ( node.cesiumObj instanceof Cesium.Material ) {
  1523. // this can be used
  1524. var uni = node.cesiumObj.uniforms;
  1525. if ( uni ) {
  1526. value = {};
  1527. for ( var prop in uni ) {
  1528. if ( uni.hasOwnProperty( prop ) ) {
  1529. switch( prop ) {
  1530. case "color":
  1531. var clr = uni[ prop ];
  1532. if ( clr.alpha == 1 ) {
  1533. value[ prop ] = "rgb("+(clr.red*255)+","+(clr.green*255)+","+(clr.blue*255)+")";
  1534. } else {
  1535. value[ prop ] = "rgba("+(clr.red*255)+","+(clr.green*255)+","+(clr.blue*255)+","+clr.alpha+")";
  1536. }
  1537. break;
  1538. default:
  1539. value[ prop ] = uni[ prop ];
  1540. break;
  1541. }
  1542. }
  1543. }
  1544. }
  1545. }
  1546. break;
  1547. case "positions":
  1548. //if ( node.cesiumObj instanceof Cesium.Polyline || node.cesiumObj instanceof Cesium.Polygon ) {
  1549. if ( node.cesiumObj.getPositions ) {
  1550. var cesiumPoints = node.cesiumObj.positions;
  1551. var len = cesiumPoints.length;
  1552. value = [];
  1553. for ( var i = 0; i < len; i++ ) {
  1554. value.push( [ cesiumPoints[i].x, cesiumPoints[i].y, cesiumPoints[i].z ] );
  1555. }
  1556. }
  1557. break;
  1558. case "width":
  1559. if ( node.cesiumObj instanceof Cesium.Polyline ) {
  1560. value = node.cesiumObj.width;
  1561. }
  1562. break;
  1563. case "height":
  1564. if ( node.cesiumObj instanceof Cesium.Polygon ) {
  1565. value = node.cesiumObj.height;
  1566. }
  1567. break;
  1568. case "granularity":
  1569. if ( node.cesiumObj instanceof Cesium.Polygon ) {
  1570. value = node.cesiumObj.granularity;
  1571. }
  1572. break;
  1573. case "orientation":
  1574. if ( node.cesiumObj instanceof Cesium.Entity ) {
  1575. value = node.cesiumObj.orientation.getValue();
  1576. }
  1577. break;
  1578. case "point":
  1579. if ( node.cesiumObj instanceof Cesium.Entity ) {
  1580. value = node.cesiumObj.point.getValue();
  1581. }
  1582. break;
  1583. case "vector":
  1584. if ( node.cesiumObj instanceof Cesium.Entity ) {
  1585. value = node.cesiumObj.vector.getValue();
  1586. }
  1587. break;
  1588. case "vertexPositions":
  1589. if ( node.cesiumObj instanceof Cesium.Entity ) {
  1590. value = node.cesiumObj.vertexPositions.getValue();
  1591. }
  1592. break;
  1593. case "viewFrom":
  1594. if ( node.cesiumObj instanceof Cesium.Entity ) {
  1595. value = node.cesiumObj.viewFrom;
  1596. }
  1597. break;
  1598. case "enableLook":
  1599. if( node.scene ) {
  1600. var controller = node.scene.screenSpaceCameraController;
  1601. if ( controller ) {
  1602. value = controller.enableLook;
  1603. }
  1604. }
  1605. break;
  1606. case "enableRotate":
  1607. if( node.scene ) {
  1608. var controller = node.scene.screenSpaceCameraController;
  1609. if ( controller ) {
  1610. value = controller.enableRotate;
  1611. }
  1612. }
  1613. break;
  1614. case "enableTilt":
  1615. if( node.scene ) {
  1616. var controller = node.scene.screenSpaceCameraController;
  1617. if ( controller ) {
  1618. value = controller.enableTilt;
  1619. }
  1620. }
  1621. break;
  1622. case "enableTranslate":
  1623. if( node.scene ) {
  1624. var controller = node.scene.screenSpaceCameraController;
  1625. if ( controller ) {
  1626. value = controller.enableTranslate;
  1627. }
  1628. }
  1629. break;
  1630. case "enableZoom":
  1631. if( node.scene ) {
  1632. var controller = node.scene.screenSpaceCameraController;
  1633. if ( controller ) {
  1634. value = controller.enableZoom;
  1635. }
  1636. }
  1637. break;
  1638. }
  1639. return value;
  1640. },
  1641. // TODO: deletingMethod
  1642. // -- callingMethod --------------------------------------------------------------------------
  1643. //callingMethod: function( nodeID, methodName /* [, parameter1, parameter2, ... ] */ ) { // TODO: parameters
  1644. // return undefined;
  1645. //},
  1646. // TODO: creatingEvent, deltetingEvent, firingEvent
  1647. // -- executing ------------------------------------------------------------------------------
  1648. //executing: function( nodeID, scriptText, scriptType ) {
  1649. // return undefined;
  1650. //},
  1651. // == ticking =============================================================================
  1652. } );
  1653. // == PRIVATE ========================================================================================
  1654. function checkCompatibility() {
  1655. this.compatibilityStatus = { compatible:true, errors:{} }
  1656. var contextNames = ["webgl","experimental-webgl","moz-webgl","webkit-3d"];
  1657. for(var i = 0; i < contextNames.length; i++){
  1658. try{
  1659. var canvas = document.createElement('canvas');
  1660. var gl = canvas.getContext(contextNames[i]);
  1661. if(gl){
  1662. return true;
  1663. }
  1664. }
  1665. catch(e){}
  1666. }
  1667. this.compatibilityStatus.compatible = false;
  1668. this.compatibilityStatus.errors["WGL"] = "This browser is not compatible. The vwf/view/threejs driver requires WebGL.";
  1669. return false;
  1670. }
  1671. function getPrototypes( extendsID ) {
  1672. var prototypes = [];
  1673. var id = extendsID;
  1674. while ( id !== undefined ) {
  1675. prototypes.push( id );
  1676. id = this.kernel.prototype( id );
  1677. }
  1678. return prototypes;
  1679. }
  1680. function findParent( ID ) {
  1681. var retNode = this.state.nodes[ ID ];
  1682. if ( retNode === undefined ) {
  1683. retNode = this.state.scenes[ ID ];
  1684. }
  1685. return retNode;
  1686. }
  1687. function findSceneNode( node ) {
  1688. var parentID = node.parentID;
  1689. var sceneNode = undefined;
  1690. var protos = undefined;
  1691. var parent = findParent.call( this, parentID );
  1692. while ( parent && sceneNode === undefined ) {
  1693. protos = getPrototypes.call( this, parent.extendsID );
  1694. if ( protos && isCesium.call( this, protos ) ) {
  1695. sceneNode = parent;
  1696. } else {
  1697. parent = findParent.call( this, parent.parentID );
  1698. }
  1699. }
  1700. if ( sceneNode === undefined ) {
  1701. sceneNode = this.state.scenes[ this.kernel.application() ]
  1702. }
  1703. return sceneNode;
  1704. }
  1705. function isCesium( prototypes ) {
  1706. var foundCesium = false;
  1707. if ( prototypes ) {
  1708. var len = prototypes.length;
  1709. for ( var i = 0; i < len && !foundCesium; i++ ) {
  1710. foundCesium = ( prototypes[i] == "http://vwf.example.com/cesium.vwf" );
  1711. }
  1712. }
  1713. return foundCesium;
  1714. }
  1715. function isGlobe( prototypes ) {
  1716. var foundCesium = false;
  1717. if ( prototypes ) {
  1718. var len = prototypes.length;
  1719. for ( var i = 0; i < len && !foundCesium; i++ ) {
  1720. foundCesium = ( prototypes[i] == "http://vwf.example.com/cesium/globe.vwf" );
  1721. }
  1722. }
  1723. return foundCesium;
  1724. }
  1725. function isSun( prototypes ) {
  1726. var foundCesium = false;
  1727. if ( prototypes ) {
  1728. var len = prototypes.length;
  1729. for ( var i = 0; i < len && !foundCesium; i++ ) {
  1730. foundCesium = ( prototypes[i] == "http://vwf.example.com/cesium/sun.vwf" );
  1731. }
  1732. }
  1733. return foundCesium;
  1734. }
  1735. function isAtmosphere( prototypes ) {
  1736. var foundCesium = false;
  1737. if ( prototypes ) {
  1738. var len = prototypes.length;
  1739. for ( var i = 0; i < len && !foundCesium; i++ ) {
  1740. foundCesium = ( prototypes[i] == "http://vwf.example.com/cesium/atmosphere.vwf" );
  1741. }
  1742. }
  1743. return foundCesium;
  1744. }
  1745. function isSkyBox( prototypes ) {
  1746. var foundCesium = false;
  1747. if ( prototypes ) {
  1748. var len = prototypes.length;
  1749. for ( var i = 0; i < len && !foundCesium; i++ ) {
  1750. foundCesium = ( prototypes[i] == "http://vwf.example.com/cesium/skybox.vwf" );
  1751. }
  1752. }
  1753. return foundCesium;
  1754. }
  1755. function isBillboard( prototypes ) {
  1756. var foundCesium = false;
  1757. if ( prototypes ) {
  1758. var len = prototypes.length;
  1759. for ( var i = 0; i < len && !foundCesium; i++ ) {
  1760. foundCesium = ( prototypes[i] == "http://vwf.example.com/cesium/billboard.vwf" );
  1761. }
  1762. }
  1763. return foundCesium;
  1764. }
  1765. function isDynamicObject( prototypes ) {
  1766. var foundCesium = false;
  1767. if ( prototypes ) {
  1768. var len = prototypes.length;
  1769. for ( var i = 0; i < len && !foundCesium; i++ ) {
  1770. foundCesium = ( prototypes[i] == "http://vwf.example.com/cesium/dynamicObject.vwf" );
  1771. }
  1772. }
  1773. return foundCesium;
  1774. }
  1775. function isLabel( prototypes ) {
  1776. var foundCesium = false;
  1777. if ( prototypes ) {
  1778. var len = prototypes.length;
  1779. for ( var i = 0; i < len && !foundCesium; i++ ) {
  1780. foundCesium = ( prototypes[i] == "http://vwf.example.com/cesium/label.vwf" );
  1781. }
  1782. }
  1783. return foundCesium;
  1784. }
  1785. function isPolylineCollection( prototypes ) {
  1786. var foundCesium = false;
  1787. if ( prototypes ) {
  1788. var len = prototypes.length;
  1789. for ( var i = 0; i < len && !foundCesium; i++ ) {
  1790. foundCesium = ( prototypes[i] == "http://vwf.example.com/cesium/polylineCollection.vwf" );
  1791. }
  1792. }
  1793. return foundCesium;
  1794. }
  1795. function isPolyline( prototypes ) {
  1796. var foundCesium = false;
  1797. if ( prototypes ) {
  1798. var len = prototypes.length;
  1799. for ( var i = 0; i < len && !foundCesium; i++ ) {
  1800. foundCesium = ( prototypes[i] == "http://vwf.example.com/cesium/polyline.vwf" );
  1801. }
  1802. }
  1803. return foundCesium;
  1804. }
  1805. function isModel( prototypes ) {
  1806. var foundCesium = false;
  1807. if ( prototypes ) {
  1808. var len = prototypes.length;
  1809. for ( var i = 0; i < len && !foundCesium; i++ ) {
  1810. foundCesium = ( prototypes[i] == "http://vwf.example.com/cesium/model.vwf" );
  1811. }
  1812. }
  1813. return foundCesium;
  1814. }
  1815. function isGeometry( prototypes ) {
  1816. var foundCesium = false;
  1817. if ( prototypes ) {
  1818. var len = prototypes.length;
  1819. for ( var i = 0; i < len && !foundCesium; i++ ) {
  1820. foundCesium = ( prototypes[i] == "http://vwf.example.com/cesium/geometry.vwf" );
  1821. }
  1822. }
  1823. return foundCesium;
  1824. }
  1825. function isMaterial( prototypes ) {
  1826. var foundCesium = false;
  1827. if ( prototypes ) {
  1828. var len = prototypes.length;
  1829. for ( var i = 0; i < len && !foundCesium; i++ ) {
  1830. foundCesium = ( prototypes[i] == "http://vwf.example.com/cesium/material.vwf" );
  1831. }
  1832. }
  1833. return foundCesium;
  1834. }
  1835. function isCamera( prototypes ) {
  1836. var foundCesium = false;
  1837. if ( prototypes ) {
  1838. var len = prototypes.length;
  1839. for ( var i = 0; i < len && !foundCesium; i++ ) {
  1840. foundCesium = ( prototypes[i] == "http://vwf.example.com/cesium/camera.vwf" );
  1841. }
  1842. }
  1843. return foundCesium;
  1844. }
  1845. function isNode3( prototypes ) {
  1846. var foundCesium = false;
  1847. if ( prototypes ) {
  1848. var len = prototypes.length;
  1849. for ( var i = 0; i < len && !foundCesium; i++ ) {
  1850. foundCesium = ( prototypes[i] == "http://vwf.example.com/cesium/node3.vwf" );
  1851. }
  1852. }
  1853. return foundCesium;
  1854. }
  1855. function vwfColor( color ) {
  1856. var vwfColor = {};
  1857. vwfColor['r'] = color['r']*255;
  1858. vwfColor['g'] = color['g']*255;
  1859. vwfColor['b'] = color['b']*255;
  1860. if ( color['a'] !== undefined && color['a'] != 1 ) {
  1861. vwfColor['a'] = color['a'];
  1862. vwfColor = new utility.color( "rgba("+vwfColor['r']+","+vwfColor['g']+","+vwfColor['b']+","+vwfColor['a']+")" );
  1863. } else {
  1864. vwfColor = new utility.color( "rgb("+vwfColor['r']+","+vwfColor['g']+","+vwfColor['b']+")" );
  1865. }
  1866. return vwfColor;
  1867. }
  1868. function cesiumColor( color ) {
  1869. var vwfColor = new utility.color( color );
  1870. if ( vwfColor ) {
  1871. return new Cesium.Color(
  1872. vwfColor.red()/255,
  1873. vwfColor.green()/255,
  1874. vwfColor.blue()/255,
  1875. vwfColor.alpha()
  1876. );
  1877. }
  1878. return new Cesium.Color( 1.0, 1.0, 1.0, 1.0 );
  1879. }
  1880. function matrix4ToArray( mat ) {
  1881. return [
  1882. mat['0'], mat['1'], mat['2'], mat['3'],
  1883. mat['4'], mat['5'], mat['6'], mat['7'],
  1884. mat['8'], mat['9'], mat['10'], mat['11'],
  1885. mat['12'], mat['13'], mat['14'], mat['15']
  1886. ];
  1887. }
  1888. function arrayToMatrix4( arry ) {
  1889. return Cesium.Matrix4.fromArray( arry );
  1890. }
  1891. function toCartesian2( value ) {
  1892. if ( value instanceof Array ) {
  1893. if ( value.length > 1 ) {
  1894. return new Cesium.Cartesian2( value[ 0 ], value[ 1 ] );
  1895. }
  1896. } else if ( value.x !== undefined && value.y !== undefined ) {
  1897. return new Cesium.Cartesian2( value.x, value.y );
  1898. }
  1899. return new Cesium.Cartesian2( 0, 0 );
  1900. }
  1901. function toCartesian3( value ) {
  1902. if ( value instanceof Array ) {
  1903. if ( value.length > 2 ) {
  1904. return new Cesium.Cartesian3( value[ 0 ], value[ 1 ], value[ 2 ] );
  1905. }
  1906. } else if ( value.x !== undefined && value.y !== undefined && value.z !== undefined ) {
  1907. return new Cesium.Cartesian3( value.x, value.y, value.z );
  1908. }
  1909. return new Cesium.Cartesian3( 0, 0, 0 );
  1910. }
  1911. function toCartesian4( value ) {
  1912. if ( value instanceof Array ) {
  1913. if ( value.length > 3 ) {
  1914. return new Cesium.Cartesian4( value[ 0 ], value[ 1 ], value[ 2 ], value[ 3 ] );
  1915. }
  1916. } else if ( value.x !== undefined && value.y !== undefined && value.z !== undefined && value.w !== undefined) {
  1917. return new Cesium.Cartesian4( value.x, value.y, value.z, value.w );
  1918. }
  1919. return new Cesium.Cartesian4( 0, 0, 0, 0 );
  1920. }
  1921. function toRectangle( value ) {
  1922. if ( value instanceof Array ) {
  1923. if ( value.length > 3 ) {
  1924. return new Cesium.Rectangle( value[ 0 ], value[ 1 ], value[ 2 ], value[ 3 ] );
  1925. }
  1926. } else if ( value.west !== undefined && value.south !== undefined && value.east !== undefined && value.north !== undefined) {
  1927. return new Cesium.Rectangle( value.west, value.south, value.east, value.north );
  1928. }
  1929. return new Cesium.Rectangle( 0, 0, 0, 0 );
  1930. }
  1931. function vwfColorToCartesian3( vwfColor ) {
  1932. return new Cesium.Cartesian3(
  1933. vwfColor.red() / 255,
  1934. vwfColor.green() / 255,
  1935. vwfColor.blue() / 255
  1936. );
  1937. }
  1938. function createGeometry( options ) {
  1939. var geo = undefined;
  1940. var geometryType = options.type ? options.type : options;
  1941. //console.log( "createGeometry", JSON.stringify( options ) );
  1942. cesiumifyOptions( options );
  1943. switch ( geometryType.toLowerCase() ) {
  1944. case "box":
  1945. case "boxgeometry":
  1946. if ( options.dimensions !== undefined ) {
  1947. geo = new Cesium.BoxGeometry.fromDimensions( options );
  1948. } else {
  1949. geo = new Cesium.BoxGeometry( options );
  1950. }
  1951. break;
  1952. case "boxoutline":
  1953. case "boxoutlinegeometry":
  1954. if ( options.dimensions !== undefined ) {
  1955. geo = new Cesium.BoxOutlineGeometry.fromDimensions( options );
  1956. } else {
  1957. geo = new Cesium.BoxOutlineGeometry( options );
  1958. }
  1959. break;
  1960. case "circle":
  1961. case "circlegeometry":
  1962. geo = new Cesium.CircleGeometry( options );
  1963. break;
  1964. case "circleoutline":
  1965. case "circleoutlinegeometry":
  1966. geo = new Cesium.CircleOutlineGeometry( options );
  1967. break;
  1968. case "corridor":
  1969. case "corridorgeometry":
  1970. geo = new Cesium.CorridorGeometry( options );
  1971. break;
  1972. case "corridoroutline":
  1973. case "corridoroutlinegeometry":
  1974. geo = new Cesium.CorridorOutlineGeometry( options );
  1975. break;
  1976. case "cylinder":
  1977. case "cylindergeometry":
  1978. geo = new Cesium.CylinderGeometry( options );
  1979. break;
  1980. case "cylinderoutline":
  1981. case "cylinderoutlinegeometry":
  1982. geo = new Cesium.CylinderOutlineGeometry( options );
  1983. break;
  1984. case "ellipse":
  1985. case "ellipsegeometry":
  1986. geo = new Cesium.EllipseGeometry( options );
  1987. break;
  1988. case "ellipseoutline":
  1989. case "ellipseoutlinegeometry":
  1990. geo = new Cesium.EllipseOutlineGeometry( options );
  1991. break;
  1992. case "ellipsoid":
  1993. case "ellipsoidgeometry":
  1994. geo = new Cesium.EllipsoidGeometry( options );
  1995. break;
  1996. case "ellipsoidoutline":
  1997. case "ellipsoidoutlinegeometry":
  1998. geo = new Cesium.EllipsoidOutlineGeometry( options );
  1999. break;
  2000. case "polygon":
  2001. case "polygongeometry":
  2002. if ( options.positions !== undefined ) {
  2003. geo = new Cesium.PolygonGeometry.fromPositions( options );
  2004. } else {
  2005. geo = new Cesium.PolygonGeometry( options );
  2006. }
  2007. break;
  2008. case "polygonoutline":
  2009. case "polygonoutlinegeometry":
  2010. if ( options.positions !== undefined ) {
  2011. geo = new Cesium.PolygonOutlineGeometry.fromPositions( options );
  2012. } else {
  2013. geo = new Cesium.PolygonOutlineGeometry( options );
  2014. }
  2015. break;
  2016. // polyline is special and is included in the polylineCollection
  2017. // case "polyline":
  2018. // geo = new Cesium.PolylineGeometry( options );
  2019. // break;
  2020. case "polylinevolume":
  2021. case "polylinevolumegeometry":
  2022. geo = new Cesium.PolylineVolumeGeometry( options );
  2023. break;
  2024. case "rectangle":
  2025. case "rectanglegeometry":
  2026. geo = new Cesium.RectangleGeometry( options )
  2027. break;
  2028. case "rectangleoutline":
  2029. case "rectangleoutlinegeometry":
  2030. geo = new Cesium.RectangleOutlineGeometry( options );
  2031. break;
  2032. case "simplepolyline":
  2033. case "simplepolylinegeometry":
  2034. geo = new Cesium.SimplePolylineGeometry( options );
  2035. break;
  2036. case "sphere":
  2037. case "spheregeometry":
  2038. geo = new Cesium.SphereGeometry( options );
  2039. break;
  2040. case "sphereoutline":
  2041. case "sphereoutlinegeometry":
  2042. geo = new Cesium.SphereOutlineGeometry( options );
  2043. break;
  2044. case "wall":
  2045. case "wallgeometry":
  2046. geo = new Cesium.WallGeometry( options );
  2047. break;
  2048. case "walloutline":
  2049. case "walloutlinegeometry":
  2050. geo = new Cesium.WallOutlineGeometry( options );
  2051. break;
  2052. }
  2053. return geo;
  2054. }
  2055. function createGeometryPrimitive( id, options ) {
  2056. var primitive = undefined;
  2057. var geometry = undefined;
  2058. var geometryInstance = undefined;
  2059. //console.log( "createGeometryPrimitive", id, JSON.stringify( options ) );
  2060. geometry = createGeometry( options.geometry );
  2061. if ( geometry !== undefined ) {
  2062. if ( options.instance === undefined ) {
  2063. options.instance = {};
  2064. } else {
  2065. cesiumifyOptions( options.instance );
  2066. }
  2067. options.instance.id = id;
  2068. options.instance.geometry = geometry;
  2069. geometryInstance = new Cesium.GeometryInstance( options.instance );
  2070. if ( options.primitive === undefined ) {
  2071. options.primitive = {}
  2072. } else {
  2073. cesiumifyOptions( options.primitive );
  2074. }
  2075. options.primitive.geometryInstances = geometryInstance;
  2076. options.primitive.appearance = createAppearance( options.primitive.appearance );
  2077. primitive = new Cesium.Primitive( options.primitive );
  2078. }
  2079. return {
  2080. "primitive": primitive,
  2081. "geometry": geometry,
  2082. "geometryInstance": geometryInstance
  2083. };
  2084. }
  2085. function createAppearance( options ) {
  2086. var appearance = undefined;
  2087. //console.log( "createAppearance", JSON.stringify( options ) );
  2088. if ( options ) {
  2089. var appearanceType = options.type ? options.type : "material";
  2090. var materialOptions = options.material ? options.material : undefined;
  2091. options.material = createMaterial( materialOptions );
  2092. switch ( appearanceType.toLowerCase() ) {
  2093. case "ellipsoidsurface":
  2094. case "ellipsoidsurfaceappearance":
  2095. appearance = new Cesium.EllipsoidSurfaceAppearance( options );
  2096. break;
  2097. case "perinstancecolor":
  2098. case "perinstancecolorappearance":
  2099. appearance = new Cesium.PerInstanceColorAppearance( options );
  2100. break;
  2101. case "debug":
  2102. case "debugappearance":
  2103. appearance = new Cesium.DebugAppearance( options );
  2104. break;
  2105. case "polylinecolor":
  2106. case "polylinecolorappearance":
  2107. appearance = new Cesium.PolylineColorAppearance( options );
  2108. break;
  2109. case "polylinematerial":
  2110. case "polylinematerialappearance":
  2111. appearance = new Cesium.PolylineMaterialAppearance( options );
  2112. break;
  2113. case "material":
  2114. case "materialappearance":
  2115. default:
  2116. appearance = new Cesium.MaterialAppearance( options );
  2117. break;
  2118. }
  2119. } else {
  2120. appearance = new Cesium.MaterialAppearance();
  2121. }
  2122. return appearance;
  2123. }
  2124. function loadAsset( node ) {
  2125. var scene = node.sceneNode.scene;
  2126. var primitives = scene.primitives;
  2127. var src = node.source;
  2128. if ( !utility.isString( node.source ) ) {
  2129. src = node.source.url;
  2130. }
  2131. switch ( node.type ) {
  2132. case "model/vnd.gltf+json":
  2133. node.loadComplete( false );
  2134. node.cesiumObj = Cesium.Model.fromGltf( {
  2135. "url": src,
  2136. "id": node.ID,
  2137. "minimumPixelSize": 128
  2138. } );
  2139. if ( node.cesiumObj !== undefined ) {
  2140. primitives.add( node.cesiumObj );
  2141. }
  2142. node.cesiumObj.readyToRender.addEventListener( function( model ) {
  2143. node.loadComplete( true );
  2144. } );
  2145. break;
  2146. }
  2147. }
  2148. function cesiumifyOptions( options, geometry ) {
  2149. if ( options !== undefined ) {
  2150. if ( options.color !== undefined ) {
  2151. options.color = cesiumColor( options.color );
  2152. if ( options.convertColorToInstance ) {
  2153. options.color = Cesium.ColorGeometryInstanceAttribute.fromColor( options.color );
  2154. delete options.convertColorToInstance;
  2155. }
  2156. }
  2157. if ( options.colorInstance !== undefined ) {
  2158. options.color = Cesium.ColorGeometryInstanceAttribute.fromColor( cesiumColor( options.colorInstance ) );
  2159. delete options.colorInstance;
  2160. }
  2161. if ( options.translucent !== undefined ) {
  2162. if ( utility.isString( options.translucent ) && (
  2163. options.translucent !== "true" ||
  2164. options.translucent !== "false" ||
  2165. options.translucent !== "0" ||
  2166. options.translucent !== "1" ) ) {
  2167. options.translucent = new Function( options.translucent );
  2168. }
  2169. }
  2170. if ( options.materialSupport !== undefined ) {
  2171. switch ( options.materialSupport.toLowerCase() ) {
  2172. case "basic":
  2173. options.materialSupport = Cesium.MaterialAppearance.MaterialSupport.BASIC;
  2174. break;
  2175. case "all":
  2176. options.materialSupport = Cesium.MaterialAppearance.MaterialSupport.ALL;
  2177. break;
  2178. default:
  2179. options.materialSupport = Cesium.MaterialAppearance.MaterialSupport.TEXTURED;
  2180. break;
  2181. }
  2182. }
  2183. if ( options.positions !== undefined ) {
  2184. if ( options.positions.degrees !== undefined ) {
  2185. options.positions = Cesium.Cartesian3.fromDegreesArray( options.positions.degrees );
  2186. delete options.positions.degrees;
  2187. } else {
  2188. if ( options.positions instanceof Array && options.positions.length > 1 ) {
  2189. var i, positions = [];
  2190. if ( options.positions[ 0 ] instanceof Array ) {
  2191. switch ( options.positions[ 0 ].length ) {
  2192. case 2:
  2193. for ( i = 0; i < options.positions.length; i++ ) {
  2194. positions.push( toCartesian2( options.positions[ i ] ) );
  2195. }
  2196. break;
  2197. case 3:
  2198. for ( i = 0; i < options.positions.length; i++ ) {
  2199. positions.push( toCartesian3( options.positions[ i ] ) );
  2200. }
  2201. break;
  2202. case 4:
  2203. for ( i = 0; i < options.positions.length; i++ ) {
  2204. positions.push( toCartesian4( options.positions[ i ] ) );
  2205. }
  2206. break;
  2207. }
  2208. }
  2209. options.positions = positions;
  2210. }
  2211. }
  2212. }
  2213. if ( options.radii !== undefined ) {
  2214. options.radii = toCartesian3( options.radii );
  2215. }
  2216. if ( options.center !== undefined ) {
  2217. if ( options.center.degrees !== undefined ) {
  2218. options.center = Cesium.Cartesian3.fromDegrees(
  2219. options.center.degrees[ 0 ],
  2220. options.center.degrees[ 1 ]
  2221. );
  2222. delete options.center.degrees;
  2223. } else {
  2224. options.center = toCartesian3( options.center );
  2225. }
  2226. }
  2227. if ( options.rectangle !== undefined ) {
  2228. if ( options.rectangle.degrees !== undefined ) {
  2229. options.rectangle = Cesium.Rectangle.fromDegrees(
  2230. options.rectangle.degrees[ 0 ],
  2231. options.rectangle.degrees[ 1 ],
  2232. options.rectangle.degrees[ 2 ],
  2233. options.rectangle.degrees[ 3 ]
  2234. );
  2235. delete options.rectangle.degrees;
  2236. } else {
  2237. options.rectangle = toRectangle( options.rectangle );
  2238. }
  2239. }
  2240. if ( options.vertexFormat !== undefined ) {
  2241. if ( utility.isString( options.vertexFormat ) ) {
  2242. switch ( options.vertexFormat.toLowerCase() ) {
  2243. case "ellipsoidsurface":
  2244. options.vertexFormat = Cesium.EllipsoidSurfaceAppearance.VERTEX_FORMAT;
  2245. break;
  2246. case "perinstancecolor":
  2247. options.vertexFormat = Cesium.PerInstanceColorAppearance.VERTEX_FORMAT;
  2248. break;
  2249. }
  2250. } else if ( options.vertexFormat.vertexFormatType !== undefined ) {
  2251. if ( options.vertexFormat.material !== undefined ) {
  2252. options.vertexFormat.material = createMaterial( options.vertexFormat.material );
  2253. }
  2254. switch ( options.vertexFormat.vertexFormatType.toLowerCase() ) {
  2255. case "ellipsoidsurface":
  2256. options.vertexFormat = Cesium.EllipsoidSurfaceAppearance.VERTEX_FORMAT;
  2257. break;
  2258. case "perinstancecolor":
  2259. options.vertexFormat = Cesium.PerInstanceColorAppearance.VERTEX_FORMAT;
  2260. break;
  2261. }
  2262. }
  2263. }
  2264. if ( options.modelMatrix !== undefined ) {
  2265. if ( options.modelMatrix.degrees !== undefined ) {
  2266. options.modelMatrix = Cesium.Matrix4.multiplyByTranslation(
  2267. Cesium.Transforms.eastNorthUpToFixedFrame(
  2268. Cesium.Cartesian3.fromDegrees(
  2269. options.modelMatrix.degrees[ 0 ],
  2270. options.modelMatrix.degrees[ 1 ]
  2271. ) ), new Cesium.Cartesian3( 0.0, 0.0, options.modelMatrix.z || 0 ),
  2272. new Cesium.Matrix4() );
  2273. } else {
  2274. if ( options.modelMatrix instanceof Array && options.modelMatrix.length > 15 ) {
  2275. options.modelMatrix = arrayToMatrix4( options.modelMatrix );
  2276. }
  2277. }
  2278. }
  2279. if ( options.dimensions !== undefined ) {
  2280. options.dimensions = toCartesian3( options.dimensions );
  2281. }
  2282. if ( options.attributes ) {
  2283. cesiumifyOptions( options.attributes );
  2284. }
  2285. if ( options.polygonHierarchy ) {
  2286. cesiumifyOptions( options.polygonHierarchy );
  2287. }
  2288. }
  2289. }
  2290. function createMaterial( options ) {
  2291. var material = undefined;
  2292. //console.log( "createMaterial", JSON.stringify( options ) );
  2293. if ( options !== undefined ) {
  2294. if ( utility.isString( options ) ) {
  2295. material = new Cesium.Material.fromType( options );
  2296. } else if ( options.type !== undefined ) {
  2297. material = new Cesium.Material.fromType( options.type, cesiumifyOptions( options.uniforms ) );
  2298. } else {
  2299. if ( options.fabric !== undefined && options.fabric.uniforms !== undefined ) {
  2300. cesiumifyOptions( options.fabric.uniforms );
  2301. }
  2302. if ( options.translucent !== undefined ) {
  2303. cesiumifyOptions( options );
  2304. }
  2305. material = new Cesium.Material( options );
  2306. }
  2307. } else {
  2308. material = new Cesium.Material();
  2309. }
  2310. return material;
  2311. }
  2312. });