qd30mini-cesium.js 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. (function($, Drupal) {
  2. Drupal.behaviors.qd30mini = {
  3. attach: function(context, settings) {
  4. Cesium.BingMapsApi.defaultKey = 'mqrOOSbN2SMpDuWhHx0W~HVi_IW2A0UwRAV1xLIZuTQ~AnSezO-xLZ4_s1rf8ydB6Wf0aRdKtw_znPffJQ9qKbntyOPWFvitPVAvxT0v6dib';
  5. var viewer = new Cesium.Viewer('boutique-map-cesium', {
  6. animation: false,
  7. homeButton: false,
  8. vrButton: false,
  9. infoBox: false,
  10. geocoder: false,
  11. sceneModePicker: false,
  12. selectionIndicator: true,
  13. timeline: false,
  14. navigationHelpButton: false,
  15. navigationInstructionsInitiallyVisible: false,
  16. scene3DOnly: false,
  17. shadows: true,
  18. terrainShadows: true,
  19. // imageryProvider : new Cesium.createOpenStreetMapImageryProvider({
  20. // url : 'https://stamen-tiles.a.ssl.fastly.net/toner-background/'
  21. // url : 'http://tile.stamen.com/toner/',
  22. // alpha : 0.5
  23. // brightness : 1.0,
  24. // contrast : 1.0,
  25. // hue : 3.0,
  26. // saturation : 3.0,
  27. // url : 'http://tile.stamen.com/watercolor/',
  28. // 'https://b.tile.openstreetmap.org'
  29. // }),
  30. baseLayerPicker: false
  31. });
  32. var camera = viewer.camera;
  33. var scene = viewer.scene;
  34. var ellipsoid = scene.globe.ellipsoid;
  35. var canvas = viewer.canvas;
  36. var layers = viewer.scene.imageryLayers;
  37. var globe = viewer.scene.globe;
  38. globe.imageryLayers.removeAll();
  39. globe.baseColor = Cesium.Color.fromCssColorString('#f3f3f3');
  40. var tonerLayer = layers.addImageryProvider(Cesium.createOpenStreetMapImageryProvider({
  41. url : 'http://tile.stamen.com/toner/'
  42. }));
  43. tonerLayer.alpha = 0.2;
  44. var terrainProvider = new Cesium.CesiumTerrainProvider({
  45. url : '//assets.agi.com/stk-terrain/world',
  46. requestVertexNormals: true
  47. });
  48. var dataSource = Cesium.GeoJsonDataSource.load('/sites/quartierdix30/files/geojson/quartier_en.json').then(function(data) {
  49. viewer.dataSources.add(data);
  50. var entities = data.entities.values;
  51. var billboards = new Cesium.BillboardCollection();
  52. for (var i = 0; i < entities.length; i++) {
  53. var entity = entities[i];
  54. entity.polygon.outline = true;
  55. entity.polygon.outlineWidth = 1.2;
  56. entity.polygon.outlineColor = Cesium.Color.BLACK;
  57. if (entity.properties.hasOwnProperty('level')) {
  58. entity.polygon.extrudedHeight = 0.5 * (entity.properties.level * 10);
  59. }
  60. if (entity.properties.hasOwnProperty("colour")) {
  61. if (entity.properties.hasOwnProperty("event")) {
  62. entity.polygon.material = new Cesium.StripeMaterialProperty({
  63. evenColor : Cesium.Color.fromCssColorString(entity.properties.colour),
  64. oddColor : Cesium.Color.BLACK,
  65. repeat : 10
  66. });
  67. } else {
  68. entity.polygon.material = Cesium.Color.fromCssColorString(entity.properties.colour);
  69. }
  70. }
  71. if (entity.properties.hasOwnProperty("description")) {
  72. entity.description = '<div>' + entity.properties.description
  73. + '</div>';
  74. }
  75. }
  76. });
  77. function gotoQD30() {
  78. var pos = Cesium.Ellipsoid.WGS84.cartesianToCartographic(new Cesium.Cartesian3(
  79. 1278149.1996018, -4297423.8092246,
  80. 4522591.15943));
  81. pos.latitude = Cesium.Math.toDegrees(pos.latitude);
  82. pos.longitude = Cesium.Math.toDegrees(pos.longitude);
  83. viewer.camera.flyTo({
  84. destination : Cesium.Cartesian3.fromDegrees(pos.longitude, pos.latitude, pos.height),
  85. orientation : {
  86. heading : 5.51747,
  87. pitch : -1.419427,
  88. roll : 6.2675
  89. },
  90. duration: 0.5
  91. });
  92. }
  93. function colourReset() {
  94. for (var j = 0; j < viewer.dataSources.get(0).entities.values.length; j++) {
  95. var entity = viewer.dataSources.get(0).entities.values[j];
  96. if (entity.properties.hasOwnProperty('colour')) {
  97. entity.polygon.material = new Cesium.Color.fromCssColorString(entity.properties.colour);
  98. }
  99. }
  100. }
  101. function selectStore(entity, data) {
  102. var pCoords = entity.polygon.hierarchy.getValue(viewer.clock.currentTime);
  103. var avgPoint = pCoords.positions.length > 1 ? Math.round(pCoords.positions.length / 2) : 0;
  104. var topPoint = 0;
  105. for (var xy = 0; xy < pCoords.positions.length - 1; xy++) {
  106. if (pCoords.positions[xy+1].x > pCoords.positions[xy].x) {
  107. topPoint = xy;
  108. }
  109. }
  110. var pos = Cesium.Ellipsoid.WGS84.cartesianToCartographic(pCoords.positions[avgPoint]);
  111. pos.latitude = Cesium.Math.toDegrees(pos.latitude);
  112. pos.longitude = Cesium.Math.toDegrees(pos.longitude);
  113. viewer.camera.flyTo({
  114. destination : Cesium.Cartesian3.fromDegrees(pos.longitude +0.0008, pos.latitude -0.0012, 300),
  115. // destination : Cesium.Cartesian3.fromDegrees(pos.longitude, pos.latitude, 300),
  116. orientation : {
  117. heading : 5.982409,
  118. pitch : -1.075697,
  119. roll : 6.281078
  120. },
  121. duration: 1
  122. });
  123. for (var j = 0; j < data.entities.values.length; j++) {
  124. if (entity.id == data.entities.values[j].id) {
  125. for (z = 0; z < viewer.entities.values.length; z++) {
  126. if (viewer.entities.values[z].name == 'selectionOutline') {
  127. viewer.entities.remove(viewer.entities.values[z]);
  128. }
  129. }
  130. viewer.entities.add({
  131. name : 'selectionOutline',
  132. polyline : {
  133. positions : pCoords.positions,
  134. width : 20,
  135. material : new Cesium.PolylineGlowMaterialProperty({
  136. glowPower : 0.9,
  137. color : Cesium.Color.fromCssColorString('#008B8B'),
  138. extrudedHeight : entity.polygon.extrudedHeight + 20
  139. })
  140. }
  141. });
  142. }
  143. }
  144. colourReset();
  145. entity.polygon.material = Cesium.Color.fromCssColorString('#000000');
  146. viewer.selectedEntity = entity;
  147. }
  148. function gotoBoutique(title, data) {
  149. var choice = title.trim();
  150. var found = false;
  151. if (choice == 'Quartier Dix 30') {
  152. gotoQD30();
  153. } else {
  154. var length = data.entities.values.length;
  155. for (var i = 0; i < length; i++) {
  156. var entity = data.entities.values[i];
  157. if (entity.properties.name != undefined) {
  158. if (entity.properties.name.toLowerCase() == choice.toLowerCase()) {
  159. found = true;
  160. if (entity.polygon.hierarchy._value.positions.length > 1) {
  161. selectStore(entity, data);
  162. } else {
  163. gotoQD30();
  164. }
  165. }
  166. }
  167. }
  168. }
  169. if (!found) gotoQD30();
  170. }
  171. window.onload = function() {
  172. var data = viewer.dataSources.get(0);
  173. gotoBoutique(settings.boutique_title, data);
  174. // var frame = viewer.infoBox.frame;
  175. // var cssLink = frame.contentDocument.createElement('link');
  176. // cssLink.href = Cesium.buildModuleUrl('../../../../css/qd30minimap.css');
  177. // cssLink.rel = 'stylesheet';
  178. // cssLink.type = 'text/css';
  179. // frame.contentDocument.head.appendChild(cssLink);
  180. clickHandler = new Cesium.ScreenSpaceEventHandler(scene.canvas);
  181. clickHandler.setInputAction(function(movement) {
  182. var pickedObject = scene.pick(movement.position);
  183. if (Cesium.defined(pickedObject)) {
  184. for (var i = 0; i < data.entities.values.length; i++) {
  185. var entity = data.entities.values[i];
  186. if (entity.properties.name != undefined) {
  187. if (entity.properties.name.toLowerCase().trim() == pickedObject.id.properties.name.toLowerCase().trim()) {
  188. gotoBoutique(pickedObject.id.properties.name, data);
  189. }
  190. }
  191. }
  192. }
  193. }, Cesium.ScreenSpaceEventType.LEFT_CLICK);
  194. }
  195. }}})(jQuery, Drupal);