qd30map-cesiumfr.js 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737
  1. var mapDom = document.getElementById('qd30map-cesium');
  2. var placeholderDom = document.getElementById('loading-placeholder');
  3. var navContainer = document.getElementById('nav-ui-wrap');
  4. var navParent = document.getElementById('nav-arrows');
  5. var navReset = document.getElementById('nav-reset');
  6. var mapSearchBtn = document.getElementById('map-search');
  7. var navElements = navParent.getElementsByTagName('button');
  8. var searchForm = document.getElementById('map-ui-form');
  9. var appContainer = document.getElementById('map-search');
  10. var appX = null;
  11. var appY = null;
  12. var formX= null;
  13. var formY = null;
  14. navElements[0].tabIndex = 3;
  15. navElements[1].tabIndex = 4;
  16. navElements[2].tabIndex = 5;
  17. navElements[3].tabIndex = 6;
  18. navReset.tabIndex = 7;
  19. mapSearchBtn.tabIndex = 8;
  20. for (var i=0; i < navElements.length; i++) {
  21. navElements[i].addEventListener('mousedown', function(param) {
  22. switch(param.target.id) {
  23. case 'nav-up':
  24. camera.moveUp(100);
  25. break;
  26. case 'nav-down':
  27. camera.moveDown(100);
  28. break;
  29. case 'nav-left':
  30. camera.moveLeft(100);
  31. break;
  32. case 'nav-right':
  33. camera.moveRight(100);
  34. break;
  35. }
  36. });
  37. navElements[i].addEventListener('keydown', function(param) {
  38. switch(param.target.id) {
  39. case 'nav-up':
  40. if (param.keyCode == 13) {
  41. camera.moveUp(100);
  42. }
  43. break;
  44. case 'nav-down':
  45. if (param.keyCode == 13) {
  46. camera.moveDown(100);
  47. }
  48. break;
  49. case 'nav-left':
  50. if (param.keyCode == 13) {
  51. camera.moveLeft(100);
  52. }
  53. break;
  54. case 'nav-right':
  55. if (param.keyCode == 13) {
  56. camera.moveRight(100);
  57. }
  58. break;
  59. }
  60. });
  61. navReset.onclick = function(param) {
  62. gotoQD30();
  63. };
  64. navReset.onkeyup = function(param) {
  65. if (param.keyCode == 13) {
  66. gotoQD30();
  67. }
  68. }
  69. }
  70. mapSearchBtn.onclick = function() {
  71. centerForm();
  72. };
  73. mapSearchBtn.onkeydown = function(param) {
  74. if (param.keyCode == 13) {
  75. centerForm();
  76. }
  77. };
  78. var zoomParent = document.getElementById('zoom');
  79. var zoomElements = zoomParent.getElementsByTagName('button');
  80. zoomElements[0].tabIndex = 1;
  81. zoomElements[1].tabIndex = 2;
  82. for (var a=0; a < zoomElements.length; a++) {
  83. zoomElements[a].addEventListener('mousedown', function(param) {
  84. var y = camera.position.y;
  85. switch(param.target.id) {
  86. case 'zoom-in':
  87. camera.moveForward(250);
  88. break;
  89. case 'zoom-out':
  90. camera.moveBackward(250);
  91. break;
  92. }
  93. });
  94. zoomElements[a].addEventListener('keydown', function(param) {
  95. var y = camera.position.y;
  96. switch(param.target.id) {
  97. case 'zoom-in':
  98. if (param.keyCode == 13) {
  99. camera.moveForward(100);
  100. }
  101. break;
  102. case 'zoom-out':
  103. if (param.keyCode == 13) {
  104. camera.moveBackward(100);
  105. }
  106. break;
  107. }
  108. });
  109. }
  110. //To check version
  111. // console.log(Cesium.VERSION);
  112. Cesium.BingMapsApi.defaultKey = 'mqrOOSbN2SMpDuWhHx0W~HVi_IW2A0UwRAV1xLIZuTQ~AnSezO-xLZ4_s1rf8ydB6Wf0aRdKtw_znPffJQ9qKbntyOPWFvitPVAvxT0v6dib';
  113. var viewer = new Cesium.Viewer('qd30map-cesium', {
  114. animation : false,
  115. homeButton : false,
  116. vrButton : false,
  117. infoBox : true,
  118. geocoder : false,
  119. sceneModePicker: false,
  120. selectionIndicator: true,
  121. timeline : false,
  122. navigationHelpButton : false,
  123. navigationInstructionsInitiallyVisible: false,
  124. scene3DOnly : false,
  125. shadows : true,
  126. terrainShadows : true,
  127. baseLayerPicker : false
  128. });
  129. var camera = viewer.camera;
  130. var scene = viewer.scene;
  131. var ellipsoid = scene.globe.ellipsoid;
  132. var canvas = viewer.canvas;
  133. var layers = viewer.scene.imageryLayers;
  134. var globe = viewer.scene.globe;
  135. globe.imageryLayers.removeAll();
  136. globe.baseColor = Cesium.Color.fromCssColorString('#f3f3f3');
  137. var tonerLayer = layers.addImageryProvider(Cesium.createOpenStreetMapImageryProvider({
  138. url : 'http://tile.stamen.com/toner/'
  139. }));
  140. tonerLayer.alpha = 0.2;
  141. // var terrainProvider = new Cesium.CesiumTerrainProvider({
  142. // url : '//assets.agi.com/stk-terrain/world',
  143. // requestVertexNormals: true
  144. // });
  145. canvas.setAttribute('tabindex', -1);
  146. var reset = document.getElementById('nav-reset');
  147. reset.addEventListener('click', function() {
  148. gotoQD30();
  149. });
  150. var dataSource = Cesium.GeoJsonDataSource.load('/sites/quartierdix30/files/geojson/quartier_fr.json').then(function(data) {
  151. viewer.dataSources.add(data);
  152. gotoQD30();
  153. var entities = data.entities.values;
  154. for (var i = 0; i < entities.length; i++) {
  155. var entity = entities[i];
  156. entity.polygon.outline = true;
  157. entity.polygon.outlineWidth = 1.2;
  158. entity.polygon.outlineColor = Cesium.Color.BLACK;
  159. if (entity.properties.hasOwnProperty('level')) {
  160. entity.polygon.extrudedHeight = 0.5 * (entity.properties.level * 10);
  161. }
  162. if (entity.properties.hasOwnProperty("colour")) {
  163. if (entity.properties.hasOwnProperty("event")) {
  164. entity.polygon.material = new Cesium.StripeMaterialProperty({
  165. evenColor : Cesium.Color.fromCssColorString(entity.properties.colour),
  166. oddColor : Cesium.Color.BLACK,
  167. repeat : 10
  168. });
  169. } else {
  170. entity.polygon.material = Cesium.Color.fromCssColorString(entity.properties.colour);
  171. }
  172. }
  173. if (entity.properties.hasOwnProperty("description")) {
  174. entity.description = '<div>' + entity.properties.description
  175. + '</div>';
  176. }
  177. }
  178. });
  179. function gotoQD30() {
  180. var pos = Cesium.Ellipsoid.WGS84.cartesianToCartographic(new Cesium.Cartesian3(
  181. 1278149.1996018, -4297423.8092246,
  182. 4522591.15943));
  183. pos.latitude = Cesium.Math.toDegrees(pos.latitude);
  184. pos.longitude = Cesium.Math.toDegrees(pos.longitude);
  185. viewer.camera.flyTo({
  186. destination : Cesium.Cartesian3.fromDegrees(pos.longitude, pos.latitude, pos.height),
  187. orientation : {
  188. heading : 5.51747,
  189. pitch : -1.419427,
  190. roll : 6.2675
  191. },
  192. duration: 0.5
  193. });
  194. }
  195. function clearLayers() {
  196. globe.imageryLayers.removeAll();
  197. globe.baseColor = new Cesium.Color(0, 0, 0.5, 1);
  198. }
  199. function customLayer() {
  200. globe.imageryLayers.removeAll();
  201. globe.baseColor = Cesium.Color.fromCssColorString('#f3f3f3');
  202. var tonerLayer = layers.addImageryProvider(Cesium.createOpenStreetMapImageryProvider({
  203. url : 'http://tile.stamen.com/toner/'
  204. }));
  205. tonerLayer.alpha = 0.2;
  206. }
  207. function highlight(chosenColour) {
  208. for (var j = 0; j < viewer.dataSources.get(0).entities.values.length; j++) {
  209. var entity = viewer.dataSources.get(0).entities.values[j];
  210. if (entity.properties.hasOwnProperty('colour')) {
  211. if (entity.properties.colour.toLowerCase() == chosenColour.toLowerCase()) {
  212. entity.polygon.material = Cesium.Color.BLACK;
  213. entity.polygon.outlineWidth = 2.0;
  214. }
  215. }
  216. }
  217. }
  218. function colourReset() {
  219. // for (z = viewer.entities.values.length -1; z >= 0; z--) {
  220. // if (viewer.entities.values[z].name.substring(0, 16) == 'selectionOutline') {
  221. // viewer.entities.remove(viewer.entities.values[z]);
  222. // }
  223. // }
  224. for (var j = 0; j < viewer.dataSources.get(0).entities.values.length; j++) {
  225. var entity = viewer.dataSources.get(0).entities.values[j];
  226. if (entity.properties.hasOwnProperty('colour')) {
  227. if (entity.properties.hasOwnProperty("event")) {
  228. entity.polygon.material = new Cesium.StripeMaterialProperty({
  229. evenColor : Cesium.Color.fromCssColorString(entity.properties.colour),
  230. oddColor : Cesium.Color.BLACK,
  231. repeat : 10
  232. });
  233. } else {
  234. entity.polygon.material = Cesium.Color.fromCssColorString(entity.properties.colour);
  235. entity.polygon.outlineWidth = 1.2;
  236. entity.polygon.outlineColor = Cesium.Color.BLACK;
  237. }
  238. }
  239. }
  240. }
  241. function centerApp() {
  242. window.scrollTo(appX, appY);
  243. }
  244. function centerForm() {
  245. window.scrollTo(formX, formY);
  246. }
  247. function getPosition(el) {
  248. var xPos = 0;
  249. var yPos = 0;
  250. while (el) {
  251. if (el.tagName == "BODY") {
  252. // deal with browser quirks with body/window/document and page scroll
  253. var xScroll = el.scrollLeft || document.documentElement.scrollLeft;
  254. var yScroll = el.scrollTop || document.documentElement.scrollTop;
  255. xPos += (el.offsetLeft - xScroll + el.clientLeft);
  256. yPos += (el.offsetTop - yScroll + el.clientTop);
  257. } else {
  258. // for all other non-BODY elements
  259. xPos += (el.offsetLeft - el.scrollLeft + el.clientLeft);
  260. yPos += (el.offsetTop - el.scrollTop + el.clientTop);
  261. }
  262. el = el.offsetParent;
  263. }
  264. return {
  265. x: xPos,
  266. y: yPos
  267. };
  268. }
  269. function getOffset(el) {
  270. var _x = 0;
  271. var _y = 0;
  272. while( el && !isNaN( el.offsetLeft ) && !isNaN( el.offsetTop ) ) {
  273. _x += el.offsetLeft - el.scrollLeft;
  274. _y += el.offsetTop - el.scrollTop;
  275. el = el.offsetParent;
  276. }
  277. return { top: _y, left: _x };
  278. }
  279. function domIsVisible(element) {
  280. var rect = element.getBoundingClientRect();
  281. var html = document.documentElement;
  282. return (
  283. rect.top >= 0 &&
  284. rect.left >= 0 &&
  285. rect.bottom <= (window.innerHeight || html.clientHeight) &&
  286. rect.right <= (window.innerWidth || html.clientWidth)
  287. );
  288. }
  289. viewer.scene.postRender.addEventListener(function(scene, time) {
  290. mapDom.style.display = 'inline-block';
  291. searchForm.style.display = 'inline-block';
  292. navContainer.style.display = 'block';
  293. placeholderDom.style.display = 'none';
  294. });
  295. window.onload = function() {
  296. var formPosition = getPosition(searchForm);
  297. formX = formPosition.x;
  298. formY = formPosition.y;
  299. var appPosition = getPosition(appContainer);
  300. appX = appPosition.x;
  301. appY = appPosition.y ;
  302. centerApp();
  303. var frame = viewer.infoBox.frame;
  304. var cssLink = frame.contentDocument.createElement('link');
  305. cssLink.href = Cesium.buildModuleUrl('../../../../css/qd30map.css');
  306. cssLink.rel = 'stylesheet';
  307. cssLink.type = 'text/css';
  308. frame.contentDocument.head.appendChild(cssLink);
  309. var header = document.getElementById('header');
  310. var headChilds = header.getElementsByTagName('*');
  311. for (var c = 0; c < headChilds.length; c++) {
  312. headChilds[c].tabIndex = -1;
  313. }
  314. var qdTitle = document.getElementById('block-quartierdix30-page-title');
  315. var titleChilds = qdTitle.getElementsByTagName('*');
  316. for (var d = 0; d < titleChilds.length; d++) {
  317. titleChilds[d].tabIndex = -1;
  318. }
  319. var data = viewer.dataSources.get(0);
  320. var subBtn = document.getElementById('edit-mapsubmit');
  321. subBtn.onclick = function(v) {
  322. v.preventDefault();
  323. handleSubmit();
  324. };
  325. var autoComplete = document.getElementById('ui-id-1');
  326. autoComplete.onclick = function() {
  327. handleSubmit();
  328. };
  329. autoComplete.onkeydown = function(param) {
  330. if (param.keyCode == 13) {
  331. handleSubmit();
  332. }
  333. };
  334. clickHandler = new Cesium.ScreenSpaceEventHandler(scene.canvas);
  335. clickHandler.setInputAction(function(movement) {
  336. var pickedObject = scene.pick(movement.position);
  337. if (Cesium.defined(pickedObject)) {
  338. for (var i = 0; i < data.entities.values.length; i++) {
  339. var entity = data.entities.values[i];
  340. if (entity.properties.nid != undefined) {
  341. if (entity.properties.nid == pickedObject.id.properties.nid) {
  342. if (entity.polygon.hierarchy._value.positions.length > 1) {
  343. exploreStore(entity, data);
  344. } else {
  345. gotoQD30();
  346. }
  347. }
  348. }
  349. }
  350. }
  351. }, Cesium.ScreenSpaceEventType.LEFT_CLICK);
  352. var form = document.getElementById('map-ui-form');
  353. var anchorElements = form.querySelectorAll('.form-item');
  354. for (var i = 0; i < anchorElements.length; i++) {
  355. anchorElements[i].tabIndex = 0;
  356. }
  357. for (var k=0; k < anchorElements.length; k++) {
  358. anchorElements[k].addEventListener('click', function(param) {
  359. for (var g=0; g < anchorElements.length; g++) {
  360. anchorElements[g].classList.remove('selected-store');
  361. }
  362. var choice = param.target.innerHTML.trim();
  363. for (var i = 0; i < data.entities.values.length; i++) {
  364. var entity = data.entities.values[i];
  365. if (entity.properties.nid != undefined) {
  366. var formNid = choice.substring(choice.indexOf('d">') + 3, choice.indexOf('</spa'));
  367. if (formNid == entity.properties.nid) {
  368. if (entity.polygon.hierarchy._value.positions.length > 1) {
  369. selectStore(entity, data);
  370. } else {
  371. gotoQD30();
  372. }
  373. if (!domIsVisible(appContainer)) {
  374. centerApp();
  375. }
  376. this.classList.add('selected-store');
  377. }
  378. }
  379. }
  380. });
  381. anchorElements[k].addEventListener('keyup', function(param) {
  382. for (var g=0; g < anchorElements.length; g++) {
  383. anchorElements[g].classList.remove('selected-store');
  384. }
  385. if (param.keyCode == 13) {
  386. var choice = param.target.innerHTML.trim();
  387. for (var i = 0; i < data.entities.values.length; i++) {
  388. var entity = data.entities.values[i];
  389. if (entity.properties.nid != undefined) {
  390. var formNid = choice.substring(choice.indexOf('d">') + 3, choice.indexOf('</spa'));
  391. if (formNid == entity.properties.nid) {
  392. if (entity.polygon.hierarchy._value.positions.length > 1) {
  393. selectStore(entity, data);
  394. } else {
  395. gotoQD30();
  396. }
  397. if (!domIsVisible(appContainer)) {
  398. centerApp();
  399. }
  400. this.classList.add('selected-store');
  401. }
  402. }
  403. }
  404. }
  405. });
  406. }
  407. var types = Array.from(document.querySelectorAll('summary > a.details-title'));
  408. types.forEach(function(type) {
  409. type.addEventListener('click', function(param) {
  410. var text = param.srcElement.lastChild.textContent.toLowerCase();
  411. highlightByType(text, data);
  412. });
  413. });
  414. function handleSubmit() {
  415. var search = document.getElementById('edit-search');
  416. var formNid = search.value.replace(/\D+/g, '');
  417. var length = data.entities.values.length;
  418. for (var i = 0; i < length; i++) {
  419. var entity = data.entities.values[i];
  420. if (entity.properties.nid != undefined) {
  421. if (formNid == entity.properties.nid) {
  422. if (entity.polygon.hierarchy._value.positions.length > 1) {
  423. selectStore(entity, data);
  424. } else {
  425. gotoQD30();
  426. }
  427. }
  428. }
  429. }
  430. }
  431. function selectStore(entity, data) {
  432. var pCoords = entity.polygon.hierarchy.getValue(viewer.clock.currentTime);
  433. var avgPoint = Math.round(pCoords.positions.length / 2);
  434. var topPoint = 0;
  435. for (var xy = 0; xy < pCoords.positions.length - 1; xy++) {
  436. if (pCoords.positions[xy+1].x > pCoords.positions[xy].x) {
  437. topPoint = xy;
  438. }
  439. }
  440. var pos = Cesium.Ellipsoid.WGS84.cartesianToCartographic(pCoords.positions[avgPoint]);
  441. pos.latitude = Cesium.Math.toDegrees(pos.latitude);
  442. pos.longitude = Cesium.Math.toDegrees(pos.longitude);
  443. viewer.camera.flyTo({
  444. destination : Cesium.Cartesian3.fromDegrees(pos.longitude, pos.latitude, 500),
  445. orientation : {
  446. heading : 5.51747,
  447. pitch : -1.419427,
  448. roll : 6.2675
  449. },
  450. duration: 1
  451. });
  452. colourReset();
  453. pCoords.positions.forEach(function(position) {
  454. position.x += 0.33;
  455. position.y += 0.33;
  456. });
  457. // DEBUGGING => First position is always equal to last position. Attempting removal for troubleshooting purposes
  458. // pCoords.positions.splice(pCoords.positions.length -1, 1);
  459. // viewer.entities.add({
  460. // name : 'selectionOutline',
  461. // polyline : {
  462. // positions : pCoords.positions,
  463. // width : 4,
  464. // material : new Cesium.PolylineGlowMaterialProperty({
  465. // glowPower : 0.5,
  466. // color : Cesium.Color.fromCssColorString('#008B8B'),
  467. // extrudedHeight : entity.polygon.extrudedHeight + 20
  468. // })
  469. // }
  470. // });
  471. entity.polygon.material = Cesium.Color.fromCssColorString('#000000');
  472. entity.polygon.material.outlineColor = Cesium.Color.fromCssColorString('#008B8B');
  473. entity.polygon.material.outlineWidth = 5;
  474. viewer.selectedEntity = entity;
  475. }
  476. function exploreStore(entity, data) {
  477. var pCoords = entity.polygon.hierarchy.getValue(viewer.clock.currentTime);
  478. var cartographic = new Cesium.Cartographic();
  479. var camHeight = ellipsoid.cartesianToCartographic(camera.position, cartographic).height;
  480. var avgPoint = Math.round(pCoords.positions.length / 2);
  481. var pos = Cesium.Ellipsoid.WGS84.cartesianToCartographic(pCoords.positions[avgPoint]);
  482. pos.latitude = Cesium.Math.toDegrees(pos.latitude);
  483. pos.longitude = Cesium.Math.toDegrees(pos.longitude);
  484. viewer.camera.flyTo({
  485. destination : Cesium.Cartesian3.fromDegrees(pos.longitude, pos.latitude, camHeight),
  486. orientation : {
  487. heading : camera.heading
  488. },
  489. duration: 1
  490. });
  491. colourReset();
  492. //
  493. // pCoords.positions.forEach(function(position) {
  494. // position.x += 0.33;
  495. // position.y += 0.33;
  496. // });
  497. // var selectionOutline = viewer.entities.add({
  498. // name : 'selectionOutline',
  499. // polyline : {
  500. // positions : pCoords.positions,
  501. // width : 4,
  502. // material : new Cesium.PolylineGlowMaterialProperty({
  503. // glowPower : 0.5,
  504. // color : Cesium.Color.fromCssColorString('#008B8B'),
  505. // extrudedHeight : entity.polygon.extrudedHeight + 20
  506. // })
  507. // }
  508. // });
  509. entity.polygon.material = Cesium.Color.fromCssColorString('#000000');
  510. entity.polygon.material.outlineColor = Cesium.Color.fromCssColorString('#008B8B');
  511. entity.polygon.material.outlineWidth = 5;
  512. viewer.selectedEntity = entity;
  513. }
  514. function highlightByType(type, data) {
  515. colourReset();
  516. // for (z = 0; z < viewer.entities.values.length; z++) {
  517. // if (viewer.entities.values[z].name.substring(0, 16) == 'selectionOutline') {
  518. // viewer.entities.remove(viewer.entities.values[z]);
  519. // }
  520. // }
  521. for (var j = 0; j < data.entities.values.length; j++) {
  522. var entity = data.entities.values[j];
  523. if (entity.properties.hasOwnProperty('storetypes')) {
  524. if (entity.properties.storetypes.toLowerCase().match(type)) {
  525. var pCoords = entity.polygon.hierarchy.getValue(viewer.clock.currentTime);
  526. matched = true;
  527. entity.polygon.material = Cesium.Color.fromCssColorString('#000000');
  528. entity.polygon.material.outlineColor = Cesium.Color.fromCssColorString('#008B8B');
  529. entity.polygon.material.outlineWidth = 5;
  530. // viewer.entities.add({
  531. // name : 'selectionOutline',
  532. // polyline : {
  533. // positions : pCoords.positions,
  534. // width : 4,
  535. // material : new Cesium.PolylineGlowMaterialProperty({
  536. // glowPower : 0.5,
  537. // color : Cesium.Color.fromCssColorString('#008B8B'),
  538. // extrudedHeight : entity.polygon.extrudedHeight + 20
  539. // })
  540. // }
  541. // });
  542. }
  543. }
  544. }
  545. }
  546. //Logic to close all non-target details elements
  547. var details = Array.from(document.querySelectorAll("details"));
  548. details.forEach(function(detail) {
  549. if (detail.constructor.name === 'HTMLDetailsElement') {
  550. detail.addEventListener('click', function() {
  551. for (f = 0; f < details.length; f++) {
  552. details[f].classList.remove('selected-detail');
  553. }
  554. this.classList.add('selected-detail');
  555. subDet = this.querySelectorAll('details');
  556. for (g = 0; g < subDet.length; g++) {subDet[g].classList.add('selected-detail');}
  557. closeOthers(this);
  558. });
  559. }
  560. });
  561. function closeOthers(elem) {
  562. for (var i = 0; i < details.length; i++) {
  563. if (!details[i].contains(elem)) {
  564. var selectedFound = false;
  565. var elems = details[i].querySelectorAll('*');
  566. for (z = 0; z < elems.length; z++) {
  567. if (elems[z].classList.contains('selected-detail') || elems[z].classList.contains('selected-store')) {
  568. selectedFound = true;
  569. }
  570. }
  571. if (selectedFound == false) {
  572. details[i].removeAttribute('open');
  573. }
  574. } else {
  575. details[i].setAttribute('open', 'open');
  576. }
  577. }
  578. }
  579. function getExtentView() {
  580. var cl2 = new Cesium.Cartesian2(0, 0);
  581. var leftTop = viewer.scene.camera.pickEllipsoid(cl2, ellipsoid);
  582. cr2 = new Cesium.Cartesian2(viewer.scene.canvas.width, viewer.scene.canvas.height);
  583. var rightDown = viewer.scene.camera.pickEllipsoid(cr2, ellipsoid);
  584. if (leftTop != null && rightDown != null) {
  585. leftTop = ellipsoid.cartesianToCartographic(leftTop);
  586. rightDown = ellipsoid.cartesianToCartographic(rightDown);
  587. return new Cesium.Rectangle(leftTop.longitude, rightDown.latitude, rightDown.longitude, leftTop.latitude);
  588. } else {//The sky is visible in 3D
  589. console.log("Sky is visible");
  590. return null;
  591. }
  592. }
  593. };
  594. window.onresize = function() {
  595. var formPosition = getPosition(searchForm);
  596. formX = formPosition.x;
  597. formY = formPosition.y;
  598. var appPosition = getPosition(appContainer);
  599. appX = appPosition.x;
  600. appY = appPosition.y;
  601. };
  602. (function($, Drupal) {
  603. Drupal.behaviors.qd30map = {
  604. attach: function(context, settings) {
  605. $('.closemenu').on('mouseenter', function() {
  606. $(this).find('span').show();
  607. }).on('mouseleave', function() {
  608. $(this).find('span').hide();
  609. }).on('click tap', function() {
  610. $(this).parent().parent().children('div').fadeOut(150);
  611. $(this).parent().parent().delay(50).animate({width: 'toggle'}, 300);
  612. if ($(this).parent().hasClass('closeinfo')) {
  613. infoOpen = false;
  614. $('.selected').removeClass('selected');
  615. }
  616. });
  617. $('#open-legend').on('click tap', function() {
  618. $('.map-legend-info').animate({width:'toggle'}, 300);
  619. $('.map-legend-info > div').delay(150).fadeIn(150);
  620. });
  621. }}})(jQuery, Drupal);
  622. function fade(element) {
  623. var op = 1; // initial opacity
  624. var timer = setInterval(function() {
  625. if (op <= 0.1) {
  626. clearInterval(timer);
  627. element.style.display = 'none';
  628. }
  629. element.style.opacity = op;
  630. element.style.filter = 'alpha(opacity=' + op * 100 + ")";
  631. op -= op * 0.1;
  632. }, 150);
  633. }