app.js 44 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349
  1. // file:///Users/francoisbeaufils/Downloads/geocoder-demo-master/index.html
  2. var app = angular.module('application', ['ngMaterial', 'adaptive.detection', 'ui.bootstrap.typeahead']);
  3. app.directive('skrollr', function() {
  4. var directiveDefinitionObject = {
  5. link: function() {
  6. skrollr.init();
  7. }
  8. };
  9. return directiveDefinitionObject;
  10. });
  11. app.controller('mainController', function($scope, $detection, $http, $mdSidenav, $timeout, $sce, $mdToast) {
  12. $scope.title = "Manche Numerique";
  13. var getGeoCodeInProgress = false,
  14. nbJoursFTTH = 244,
  15. siteName = 'Eligibilité Manche Numérique',
  16. siteUrl = 'http://eligibilite.manchenumerique.fr',
  17. siteEmail = 'ftth@manchenumerique.fr',
  18. siteAddresse = '235, rue Joseph Cugnot Zone Delta, 50000 SAINT LÔ',
  19. siteTel = '02.33.77.83.60',
  20. layer = {},
  21. currentMarker, searchExtent;
  22. var catTypeVoie = [
  23. {
  24. "name": "Allée",
  25. "id" : "allee"
  26. },
  27. {
  28. "name": "Avenue",
  29. "id" : "avenue"
  30. },
  31. {
  32. "name": "Boulevard",
  33. "id" : "boulevard"
  34. },
  35. {
  36. "name": "Carrefour",
  37. "id" : "carrefour"
  38. },
  39. {
  40. "name": "Chemin",
  41. "id" : "chemin"
  42. },
  43. {
  44. "name": "Cité",
  45. "id" : "cite"
  46. },
  47. {
  48. "name": "Hammeau",
  49. "id" : "hammeau"
  50. },
  51. {
  52. "name": "Impasse",
  53. "id" : "impasse"
  54. },
  55. {
  56. "name": "Lieu-dit",
  57. "id" : "lieu_dit"
  58. },
  59. {
  60. "name": "Lotissement",
  61. "id" : "lotissement"
  62. },
  63. {
  64. "name": "Place",
  65. "id" : "place"
  66. },
  67. {
  68. "name": "Résidence",
  69. "id" : "residence"
  70. },
  71. {
  72. "name": "Route",
  73. "id" : "route"
  74. },
  75. {
  76. "name": "Rue",
  77. "id" : "rue"
  78. },
  79. {
  80. "name": "Villa",
  81. "id" : "villa"
  82. },
  83. {
  84. "name": "Village",
  85. "id" : "village"
  86. }
  87. ];
  88. var catVousEtes = [
  89. {
  90. "name": "Locataire de ce logement",
  91. "id" : "locataire"
  92. },
  93. {
  94. "name": "Occupant à titre gratuit de ce logement",
  95. "id" : "occupant_gratuit"
  96. },
  97. {
  98. "name": "Propriétaire de ce logement",
  99. "id" : "proprietaire"
  100. }
  101. ];
  102. var catCeLogementEst = [
  103. {
  104. "name": "Votre résidence principale",
  105. "id" : "residence_principale"
  106. },
  107. {
  108. "name": "Votre résidence secondaire",
  109. "id" : "residence_secondaire"
  110. }
  111. ];
  112. var catAccord = [
  113. {
  114. "name": "J’ai l’intention de souscrire à une offre Très Haut Débit après le pré-raccordement",
  115. "id" : "avec_souscription"
  116. },
  117. {
  118. "name": "Je n’ai pas l’intention de souscrire à une offre Très Haut Débit après le pré-raccordement",
  119. "id" : "sans_souscription"
  120. }
  121. ];
  122. $scope.formulaires = {
  123. "eligibilite": {
  124. "sections": [
  125. {
  126. "name": "Générale",
  127. "visible": false,
  128. "lines": [
  129. {
  130. "ctrls": [
  131. {
  132. "name" : "Prénom",
  133. "id" : "prenom",
  134. "type" : "text",
  135. "width" : "50%",
  136. "require": true,
  137. "isValid": function(value) {
  138. return !!value && value.length > 2;
  139. },
  140. "msg" : 'Prénom invalide'
  141. },
  142. {
  143. "name" : "Nom",
  144. "id" : "nom",
  145. "type" : "text",
  146. "width" : "50%",
  147. "require": true,
  148. "isValid": function(value) {
  149. return !!value && value.length > 2;
  150. },
  151. "msg" : 'Nom invalide'
  152. }
  153. ]
  154. },
  155. {
  156. "ctrls": [
  157. {
  158. "name" : "Email",
  159. "id" : "email",
  160. "type" : "text",
  161. "width" : null,
  162. "require": true,
  163. "isValid": function(value) {
  164. function validateEmail(email) {
  165. var re = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
  166. return re.test(email);
  167. }
  168. return validateEmail(value);
  169. },
  170. "msg" : 'Email invalide.'
  171. }
  172. ]
  173. },
  174. {
  175. "ctrls": [
  176. {
  177. "name" : "Téléphone fixe",
  178. "id" : "telephone_fixe",
  179. "type" : "text",
  180. "width" : "50%",
  181. "require": false
  182. },
  183. {
  184. "name" : "Téléphone portable",
  185. "id" : "telephone_portable",
  186. "type" : "text",
  187. "width" : "50%",
  188. "require": false
  189. }
  190. ]
  191. }
  192. ]
  193. },
  194. {
  195. "name": "Adresse",
  196. "visible": true,
  197. "lines": [
  198. {
  199. "ctrls": [
  200. {
  201. "name" : "Numero",
  202. "id" : "numero_voie",
  203. "type" : "text",
  204. "width" : "80px",
  205. "require": false
  206. },
  207. {
  208. "name" : "Type voie",
  209. "id" : "type_voie",
  210. "type" : "select",
  211. "width" : "106px",
  212. "require": false,
  213. "options": {
  214. "categories": catTypeVoie
  215. }
  216. },
  217. {
  218. "name" : "Nom voie",
  219. "id" : "nom_voie",
  220. "type" : "text",
  221. "width" : "378px",
  222. "require": true,
  223. "isValid": function(value) {
  224. return !!value;
  225. },
  226. "msg" : 'Nom de voie invalide.'
  227. }
  228. ]
  229. },
  230. {
  231. "ctrls": [
  232. {
  233. "name" : "Complément Adresse",
  234. "id" : "complement_addresse",
  235. "type" : "textarea",
  236. "width" : null,
  237. "require": false
  238. }
  239. ]
  240. },
  241. {
  242. "ctrls": [
  243. {
  244. "name" : "Bâtiment",
  245. "id" : "batiment",
  246. "type" : "text",
  247. "width" : "50%",
  248. "require": false
  249. },
  250. {
  251. "name" : "Cage escalier",
  252. "id" : "cage_escalier",
  253. "type" : "text",
  254. "width" : "50%",
  255. "require": false
  256. }
  257. ]
  258. },
  259. {
  260. "ctrls": [
  261. {
  262. "name" : "Etage / Niveau",
  263. "id" : "etage",
  264. "type" : "text",
  265. "width" : "50%",
  266. "require": false
  267. },
  268. {
  269. "name" : "Numero appartement / porte",
  270. "id" : "numero_appartement",
  271. "type" : "text",
  272. "width" : "50%",
  273. "require": false
  274. }
  275. ]
  276. },
  277. {
  278. "ctrls": [
  279. {
  280. "name" : "Code postal",
  281. "id" : "code_postal",
  282. "type" : "text",
  283. "width" : "50%",
  284. "require": true,
  285. "isValid": function(value) {
  286. if(!value || value.length !== 5 || isNaN(parseInt(value, 10))) {
  287. return false;
  288. }
  289. return true;
  290. },
  291. "msg" : 'Non valide'
  292. },
  293. {
  294. "name" : "Ville",
  295. "id" : "ville",
  296. "type" : "text",
  297. "width" : "50%",
  298. "require": true,
  299. "isValid": function(value) {
  300. return !!value && value.length > 2;
  301. },
  302. "msg" : 'Ville invalide.'
  303. }
  304. ]
  305. }
  306. ]
  307. },
  308. {
  309. "name": "Logement",
  310. "visible": true,
  311. "lines": [
  312. {
  313. "ctrls": [
  314. {
  315. "name" : "Vous êtes",
  316. "id" : "vous_etes",
  317. "type" : "radio",
  318. "width" : null,
  319. "require": true,
  320. "other" : true,
  321. "options": {
  322. "categories": catVousEtes,
  323. "alertes": {
  324. "locataire": "Si vous êtes locataire, vous devez impérativement avertir votre propriétaire que vous souhaitez bénéficier du pré-raccordement à la fibre optique."
  325. }
  326. },
  327. "isValid": function(value, other) {
  328. return !!value && value !== 'autre' || !!other;
  329. },
  330. "msg" : 'Choix incomplet.'
  331. }
  332. ]
  333. },
  334. {
  335. "ctrls": [
  336. {
  337. "name" : "Ce logement est",
  338. "id" : "ce_logement_est",
  339. "type" : "radio",
  340. "width" : null,
  341. "require": true,
  342. "other" : true,
  343. "options": {
  344. "categories": catCeLogementEst
  345. },
  346. "isValid": function(value, other) {
  347. return !!value && value !== 'autre' || !!other;
  348. },
  349. "msg" : 'Choix incomplet.'
  350. }
  351. ]
  352. }
  353. ]
  354. },
  355. {
  356. "name": "Conditions pour le raccordement final d’abonné dans un immeuble individuel",
  357. "visible": true,
  358. "lines": [
  359. {
  360. "text": "Manche Numérique propose aux personnes qui le souhaitent, de faire d’ores et déjà raccorder leur logement ou local à usage professionnel, au futur réseau de communications électroniques à Très Haut Débit FTTH. Le montant de ce raccordement s’élevera à 50 € pour les personnes qui souscriront à une offre Très Haut Débit auprès d’un opérateur et de 400 € pour ceux qui demanderont uniquement la pose de la prise, sans souscription d’un abonnement.",
  361. "ctrls": [
  362. {
  363. "name" : "Accord",
  364. "id" : "accord",
  365. "options": {
  366. "categories": catAccord,
  367. },
  368. "type" : "radio",
  369. "width" : null,
  370. "require": true,
  371. "other" : false,
  372. "isValid": function(value) {
  373. return !!value;
  374. },
  375. "msg" : 'Choix incorrect.',
  376. "note" : 'IMPORTANT : le règlement ne vous sera demandé qu’après travaux effectués'
  377. }
  378. ]
  379. }
  380. ]
  381. },
  382. {
  383. "name": "Informatique et libertés",
  384. "visible": false,
  385. "lines": [
  386. {
  387. "ctrls": [
  388. {
  389. "name" : "Informatique et libertés",
  390. "id" : "info_et_libertes",
  391. "libelle": 'La personne responsable du traitement de la présente demande de pré-raccordement est le représentant du Syndicat Mixte Manche Numérique, le Président, Monsieur Serge DESLANDES. Les informations portées sur ce formulaire sont obligatoires. Elles font l’objet d’un traitement informatisé destiné au raccordement final de l’usager à la fibre optique (FTTH) ainsi qu’à l’exploitation du réseau optique. Les destinataires des données sont : le Syndicat Mixte Manche Numérique, les entreprises en charge de réaliser les travaux de raccordement, ainsi que l’exploitant du réseau optique. Conformément à la loi "informatique et libertés" du 6 janvier 1978 modifiée, vous bénéficiez d’un droit d’accès, de rectification aux informations qui vous concernent, d’opposition au traitement de vos données personnelles. Si vous souhaitez exercer ce droit et obtenir communication des informations vous concernant, veuillez-vous adresser au Syndicat Mixte Manche Numérique ftth@manchenumerique.fr. Dans l’hypothèse où le présent formulaire est incomplet et/ou illisible, la présente demande de raccordement ne sera pas traitée.',
  392. "type" : "checkbox",
  393. "width" : null,
  394. "require": true,
  395. "isValid": function(value) {
  396. return !!value;
  397. },
  398. "msg" : 'Vous devez accepter.'
  399. }
  400. ]
  401. }
  402. ]
  403. }
  404. ]
  405. }
  406. };
  407. var addCurrentMarker = function(withReverse) {
  408. if(currentMarker) {
  409. map.removeLayer(currentMarker);
  410. }
  411. currentMarker = L.marker([$scope.geoCode.y, $scope.geoCode.x], {draggable: true, title: "texst"}).addTo(map); //.bindPopup(data.locations[0].name).openPopup();
  412. currentMarker.bindPopup("L'adresse que vous nous avez fournie est localisée sur la carte. Il se peut que la position réelle de votre logement soit un peu différente. Dans ce cas, merci de déplacer le pointeur sur la carte pour le positionner à l'emplacement de votre logement.").openPopup();
  413. if(withReverse) {
  414. $scope.magicKey = null;
  415. reverseLocation($scope.geoCode, null, function(address) {
  416. $scope.address = address;
  417. });
  418. }
  419. currentMarker.on('dragend', function(event) {
  420. var p = currentMarker.getLatLng();
  421. //console.log('dragend', p);
  422. $scope.magicKey = null;
  423. $scope.geoCode = {
  424. x: p.lng,
  425. y: p.lat
  426. };
  427. reverseLocation($scope.geoCode, null, function(address) {
  428. $scope.address = address;
  429. getResults();
  430. });
  431. });
  432. };
  433. var computeDateFTTH = function() {
  434. if(!$scope.results.ftth) {return;}
  435. // A date already exists
  436. if($scope.results.ftth.DATE_OUV_SERVICE_REEL || $scope.results.ftth.DATE_OUV_SERVICE_PREV) {
  437. $scope.results.ftth.date = $scope.results.ftth.DATE_OUV_SERVICE_REEL || $scope.results.ftth.DATE_OUV_SERVICE_PREV;
  438. return;
  439. }
  440. else if($scope.results.ftth.DATE_FIN_TRAV_PREV) {
  441. // Compute Date
  442. var momentDate = moment($scope.results.ftth.DATE_FIN_TRAV_PREV, 'DD/MM/YY');
  443. momentDate.add(nbJoursFTTH, 'days');
  444. $scope.results.ftth.date = momentDate.format('DD/MM/YYYY');
  445. }
  446. };
  447. var computeFullAddress = function() {
  448. return $scope.result.eligibilite.complement_addresse;
  449. };
  450. var formatDate = function(value) {
  451. return moment(value.toString().substr(0,4) + '-' + value.toString().substr(4,2) + '-' + value.toString().substr(6,2)).locale("fr");
  452. };
  453. var getFullAddress = function(callback) {
  454. if($scope.magicKey) {
  455. var findURL = 'http://api-adresse.data.gouv.fr/search/?';
  456. var url = findURL + "q=" + $scope.address;
  457. $.get(
  458. url,
  459. function(data, status) {
  460. var next = function(record) {
  461. reverseLocation($scope.geoCode, null, function(string, address) {
  462. if(record) {
  463. address.StreetNumber = record.housenumber;
  464. address.Match_addr = $scope.address;
  465. }
  466. callback(null, address);
  467. });
  468. };
  469. if(data && data.features && data.features[0] && data.features[0].properties) {
  470. next(data.features[0].properties);
  471. }
  472. else {
  473. next();
  474. }
  475. });
  476. }
  477. else {
  478. reverseLocation($scope.geoCode, null, function(string, address) {
  479. callback(null, address);
  480. });
  481. }
  482. };
  483. var getRecordsFor = function(identifier, coordinates) {
  484. var records = [];
  485. _.each($scope.data[identifier], function(record) {
  486. _.some(record._polygons, function(polygon) {
  487. if(isInside(polygon, coordinates)) {
  488. records.push(record);
  489. return true;
  490. }
  491. });
  492. });
  493. // Debug
  494. var debug = false;
  495. if (debug) {
  496. var colors = ['red', 'green', 'blue', 'black', 'silver', 'yellow'];
  497. var marker = L.marker([coordinates.y, coordinates.x]).addTo(map);
  498. var Lpolygons = [];
  499. _.each(records, function(record, i) {
  500. var style = {
  501. color : colors[i],
  502. fillColor: colors[i],
  503. weight : 4
  504. };
  505. _.each(record._polygons, function(polygon) {
  506. Lpolygons.push(L.polygon(polygon, style).bindPopup($scope.getHtmlContent(identifier, record)));
  507. });
  508. });
  509. L.layerGroup(Lpolygons).addTo(map);
  510. }
  511. return records;
  512. };
  513. var getResults = function() {
  514. $scope.results = {};
  515. $.ajax({
  516. method : "POST",
  517. url : "ajax/oracle.php",
  518. data : $scope.geoCode
  519. })
  520. .error(function(err) {
  521. console.error('Oracle issue', err);
  522. //[{"ID_ZAPM_PARTIELLE":"119CP0","DATE_OUV_SERVICE_REEL":null,"DATE_OUV_SERVICE_PREV":null,"DATE_FIN_TRAV_PREV":null}]
  523. // Debug without Oracle access
  524. onResults('{"x":-1.1060984089996,"y":49.119046582,"ftth":[{"ID_ZAPM_PARTIELLE":"203AP0","DATE_OUV_SERVICE_REEL":null,"DATE_OUV_SERVICE_PREV":null,"DATE_FIN_TRAV_PREV":"04\/05\/16"}],"adsl":[{"ID_FT_ADSL":"656","LEGENDE":"TV sur ADSL","NATURE":"0 - 37"}],"mimo":null}');
  525. })
  526. .done(function( msg ) {
  527. onResults(msg);
  528. });
  529. var onResults = function(results) {
  530. try {
  531. $scope.results = JSON.parse(results);
  532. $scope.results.address = $scope.address;
  533. $scope.results.ftth = parseResults($scope.results.ftth);
  534. $scope.results.adsl = parseResults($scope.results.adsl);
  535. $scope.results.mimo = parseResults($scope.results.mimo);
  536. computeDateFTTH();
  537. }
  538. catch(e) {
  539. console.error(e);
  540. alert('Probleme de connexion à la base de donnée Oracle.');
  541. $scope.hideResultPane();
  542. }
  543. //console.log('$scope.results', results, '=>', $scope.results);
  544. $scope.$apply();
  545. };
  546. $scope.$evalAsync();
  547. };
  548. var init = function() {
  549. var stlo = [49.1154686, -1.0828136000000086];
  550. var map = L.map('map', {zoomControl:false}).setView(stlo, 9);
  551. map.on('dblclick', function(e) {
  552. var p = e.latlng;
  553. //console.log('click', e.latlng); // e is an event object (MouseEvent in this case)
  554. $scope.geoCode = {
  555. x: p.lng,
  556. y: p.lat
  557. };
  558. addCurrentMarker(true);
  559. $scope.showResultPane();
  560. getResults();
  561. });
  562. var maps = {
  563. "carte" : 'http://server.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer/tile/{z}/{y}/{x}',
  564. "satellite" : 'http://services.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}'
  565. };
  566. var cLayer = L.tileLayer(maps.satellite, {
  567. attribution: 'Map data &copy; <a href="http://openstreetmap.org">OpenStreetMap</a> contributors, <a href="http://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>, Imagery © <a href="http://mapbox.com">Mapbox</a>',
  568. maxZoom: 18
  569. }).addTo(map);
  570. var styleOpts = {
  571. color : 'red',
  572. fillColor: 'red',
  573. weight : 8
  574. };
  575. $scope.data = {};
  576. $scope.colors = {
  577. "ftth": "#8cc474", // green
  578. "mimo": "#f9b256", // orange
  579. "adsl": "#76a7fa" // blue
  580. };
  581. $http({method: 'POST', url: 'data/dictionary.json'}).success(function(data) {
  582. $scope.dictionary = data;
  583. });
  584. $http({method: 'POST', url: 'data/Contour_Manche.json'}).success(function(data) {
  585. var style = {
  586. color : 'blue',
  587. fillColor: 'blue',
  588. weight : 2
  589. };
  590. $scope.data.manche = [{
  591. _polygons : [data.features[0].geometry.coordinates[0]],
  592. _style : style,
  593. _properties : {
  594. name : {string: 'Manche'}
  595. }
  596. }];
  597. var mancheCoordinates = data && data.features && data.features[0] && data.features[0].geometry && data.features[0].geometry.coordinates && data.features[0].geometry.coordinates[0]; // response data
  598. _.each(mancheCoordinates, function(c, i) {
  599. mancheCoordinates[i] = [c[1], c[0]];
  600. });
  601. // Rectangle coordinates around Manche
  602. //var mancheCoordinates = [[49.732307856286, -1.97117692088061],[48.4, -1.75],[48.4, -0.5],[49.732307856286, -1.2]];
  603. // Debug: show manche limits
  604. //L.polygon(mancheCoordinates, {color: 'blue', fillColor: 'blue',weight: 8}).addTo(map);
  605. searchExtent = {
  606. "xmin" : _.max(_.map(mancheCoordinates, function(c) {return c[1];})),
  607. "ymin" : _.max(_.map(mancheCoordinates, function(c) {return c[0];})),
  608. "xmax" : _.min(_.map(mancheCoordinates, function(c) {return c[1];})),
  609. "ymax" : _.min(_.map(mancheCoordinates, function(c) {return c[0];})),
  610. "spatialReference" : {"wkid" : 84}
  611. };
  612. var suggestURL = 'https://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer/suggest?f=pjson&searchExtent=' + JSON.stringify(searchExtent);
  613. var i = 0, j = 0;
  614. $scope.suggestLocation = function(val) {
  615. //console.log('__suggestLocation', val);
  616. $scope.suggestionsReady = false;
  617. i++;
  618. return $http.get(suggestURL, {
  619. params: {
  620. text: val
  621. }
  622. }).then(function(response) {
  623. if(val === $scope.address) { // Very important to debounce queries
  624. $scope.suggestionsReady = response.data.suggestions.length !== 0;
  625. $scope.suggestions = _.cloneDeep(response.data.suggestions);
  626. }
  627. return response.data.suggestions.map(function(item){
  628. return item.text;
  629. });
  630. });
  631. };
  632. });
  633. //console.time('FTTH data');
  634. $http({method: 'POST', url: 'data/FTTH_zapm_partielle.json'}).success(function(data) {
  635. var style = {
  636. color : $scope.colors.ftth,
  637. fillColor: $scope.colors.ftth,
  638. weight : 2
  639. };
  640. var properties = {
  641. name : {key: 'ATD'},
  642. hidden: ['ID_PM', 'MARCHE', 'ID_FT_ADSL', 'ID_FTTH_MN_ZAPM_PARTIELLE', 'ID_ZAPM_PARTIELLE', 'ID_ZAPM'],
  643. position: ['DATE_DEB_TRAV_PREV']
  644. };
  645. parseData('ftth', data, style, properties);
  646. //console.timeEnd('FTTH data');
  647. //console.debug('Data for FTTH are ready', data);
  648. if($scope.data.mimo && $scope.data.adsl && $scope.data.ftth) {
  649. $scope.loaded = true;
  650. }
  651. $scope.$evalAsync();
  652. });
  653. //console.time('ADSL data');
  654. $http({method: 'POST', url: 'data/TEL_FT_ADSL.json'}).success(function(data) {
  655. var style = {
  656. color : $scope.colors.adsl,
  657. fillColor: $scope.colors.adsl,
  658. weight : 2
  659. };
  660. var properties = {
  661. name : {key: 'LEGENDE'},
  662. hidden: ['NATURE', 'NRA_CETE', 'NRA_TMP', 'NRA_DPT', 'ID_FT_ADSL']
  663. };
  664. parseData('adsl', data, style, properties);
  665. //console.timeEnd('ADSL data');
  666. //console.debug('Data for ADSL are ready', data);
  667. if($scope.data.mimo && $scope.data.adsl && $scope.data.ftth) {
  668. $scope.loaded = true;
  669. }
  670. $scope.$evalAsync();
  671. });
  672. //console.time('MiMo data');
  673. $http({method: 'POST', url: 'data/Couverture_mimo.json'}).success(function(data) {
  674. var style = {
  675. color : $scope.colors.mimo,
  676. fillColor: $scope.colors.mimo,
  677. weight : 2
  678. };
  679. var properties = {
  680. name : {string: 'Couverture MiMo'},
  681. hidden: ['ID_MIMO_COUVERTURE']
  682. };
  683. parseData('mimo', data, style, properties);
  684. //console.timeEnd('MiMo data');
  685. //console.debug('Data for MIMO are ready', data);
  686. if($scope.data.mimo && $scope.data.adsl && $scope.data.ftth) {
  687. $scope.loaded = true;
  688. }
  689. $scope.$evalAsync();
  690. });
  691. window.map = map;
  692. $scope.mapType = 'Satellite';
  693. $scope.view = {};
  694. $scope.isShown = {};
  695. };
  696. var isDate = function(value) {
  697. return (value.toString().length === 14 && value.toString().substring(0,2) === "20");
  698. };
  699. var isInside = function(polygon, point) {
  700. // ray-casting algorithm based on
  701. // http://www.ecse.rpi.edu/Homepages/wrf/Research/Short_Notes/pnpoly.html
  702. var y = point.x ? point.x : point[0],
  703. x = point.y ? point.y : point[1];
  704. var inside = false;
  705. for (var i = 0, j = polygon.length - 1; i < polygon.length; j = i++) {
  706. var xi = polygon[i][0], yi = polygon[i][1];
  707. var xj = polygon[j][0], yj = polygon[j][1];
  708. var intersect = ((yi > y) != (yj > y)) && (x < (xj - xi) * (y - yi) / (yj - yi) + xi);
  709. if (intersect) {
  710. inside = !inside;
  711. }
  712. }
  713. return inside;
  714. };
  715. var parseData = function(identifier, data, style, properties) {
  716. var getPolygonsCoord = function(type, coord) {
  717. var result = [];
  718. if(type === 'Polygon') {
  719. result.push(_.map(coord[0], function(r) {return [r[1], r[0]];}));
  720. }
  721. if(type === 'MultiPolygon') {
  722. var p = [];
  723. _.each(coord, function(c) {
  724. result.push(_.map(c[0], function(r) {return [r[1], r[0]];}));
  725. });
  726. }
  727. return result;
  728. };
  729. var records = [];
  730. _.each(data.features, function(r) {
  731. var record = r.properties;
  732. var polygons = getPolygonsCoord(r.geometry.type, r.geometry.coordinates);
  733. record._coordinates = r.geometry.coordinates;
  734. record._type = r.geometry.type;
  735. record._polygons = polygons;
  736. record._style = style;
  737. record._properties = properties;
  738. records.push(record);
  739. });
  740. $scope.data[identifier] = records;
  741. };
  742. var parseResults = function(records) {
  743. if(!records || !records.length) {
  744. return null;
  745. }
  746. if(records.length === 1) {
  747. return records[0];
  748. }
  749. var result = records[0];
  750. return result;
  751. };
  752. var reverseLocation = function(geoCode, address, callback) {
  753. var reverseGeo = 'http://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer/reverseGeocode?f=pjson&distance=300';
  754. var url = reverseGeo + '&location=' + (geoCode ? $scope.geoCode.x + ',' + $scope.geoCode.y : address) ;
  755. $.get(
  756. url,
  757. function(data, status) {
  758. data = JSON.parse(data);
  759. var adresse = data && data.address && data.address.Match_addr;
  760. if(data && data.address && data.address.Address) {
  761. var i = 0;
  762. var num = '';
  763. while(!isNaN(parseInt(data.address.Address[i], 10))) {
  764. num += data.address.Address[i];
  765. i++;
  766. }
  767. data.address.StreetNumber = num;
  768. data.address.Address = data.address.Address.substr(num.length).trim();
  769. var typeVoie = data.address.Address.substring(0, data.address.Address.indexOf(' ')).toLowerCase();
  770. type = _.find(catTypeVoie, function(c){
  771. if(c.id === typeVoie || c.name.toLowerCase() === typeVoie) {
  772. return true;
  773. }
  774. });
  775. if(type) {
  776. data.address.StreetType = type.id;
  777. data.address.Address = data.address.Address.substr(typeVoie.length).trim();
  778. }
  779. }
  780. //console.debug('Reverse', geoCode, address, '=>', adresse, data.address);
  781. callback(adresse, data.address);
  782. $scope.$evalAsync();
  783. });
  784. };
  785. $scope.changeMap = function(value) {
  786. //console.log('Goto', value);
  787. map.removeLayer(cLayer);
  788. cLayer = L.tileLayer(maps[value], {
  789. attribution: 'Map data &copy; <a href="http://openstreetmap.org">OpenStreetMap</a> contributors, <a href="http://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>, Imagery © <a href="http://mapbox.com">Mapbox</a>',
  790. maxZoom: 18
  791. }).addTo(map);
  792. };
  793. $scope.closeRight = function() {
  794. $mdSidenav('right').close().then(function(){});
  795. };
  796. $scope.computeLayer = function(identifier) {
  797. var Lpolygons = [];
  798. _.each($scope.data[identifier], function(record) {
  799. _.each(record._polygons, function(polygon) {
  800. Lpolygons.push(L.polygon(polygon, record._style).bindPopup($scope.getHtmlContent(identifier, record)));
  801. });
  802. });
  803. layer[identifier] = L.layerGroup(Lpolygons);
  804. };
  805. $scope.formatDateFTTH = function(date) {
  806. if(!date || date === "Invalid date") {return;}
  807. var momentDate = moment(date, 'DD/MM/YYYY');
  808. var result = '<div class="popup-line"><div class="box-eligibilite-title">Date prévisionnelle abonnement FTTH</div><div style="font-weight: bold;" class="popup-value">' + momentDate.locale("fr").format('ddd, LL') + '</div><div class="popup-small-date">' + momentDate.locale("fr").fromNow() + '</div></div>';
  809. return $sce.trustAsHtml(result);
  810. };
  811. $scope.formatResults = function(identifier, results) {
  812. return $sce.trustAsHtml($scope.getHtmlContent(identifier, results));
  813. };
  814. $scope.getGeoCode = function(address, magicKey, callback) {
  815. var findURL = 'https://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer/find?f=pjson&searchExtent=' + JSON.stringify(searchExtent);
  816. getGeoCodeInProgress = true;
  817. var url = findURL + "&text=" + address + ((magicKey) ? ("&magicKey=" + magicKey) : ', Basse-Normandie, France');
  818. //console.log('url', url);
  819. $.get(
  820. url,
  821. function(data, status) {
  822. data = JSON.parse(data);
  823. console.debug('address, magicKey', address, magicKey, data);
  824. if (status === 'success' && data.locations[0]) {
  825. if(data.locations[0].extent.xmax < searchExtent.xmin &&
  826. data.locations[0].extent.xmax > searchExtent.xmax &&
  827. data.locations[0].extent.xmin > searchExtent.xmax &&
  828. data.locations[0].extent.xmin > searchExtent.xmax) {
  829. getGeoCodeInProgress = false;
  830. //console.debug('getGeoCode', address, magicKey, '=>', data);
  831. return callback(null, data);
  832. }
  833. getGeoCodeInProgress = false;
  834. //console.debug('getGeoCode', address, magicKey, '=>', 'No result');
  835. callback('No result for ' + address);
  836. } else {
  837. getGeoCodeInProgress = false;
  838. //console.debug('getGeoCode', address, magicKey, '=>', 'No result');
  839. callback(status !== 'success' ? status : 'No result for ' + address);
  840. }
  841. });
  842. };
  843. $scope.getHtmlContent = function(identifier, record) {
  844. //var title = record._properties.name.string ? record._properties.name.string : record[record._properties.name.key];
  845. // Tooltip content
  846. var tooltip = '';
  847. _.each(record, function(value, property) {
  848. if(property.charAt(0) === '_' ||
  849. (property === 'date' && identifier === 'ftth') ||
  850. value === null ||
  851. typeof value === 'undefined') {
  852. return;
  853. }
  854. var label = $scope.dictionary[property] || property;
  855. value = $scope.dictionary[value] || value;
  856. var date;
  857. if(property.substring(0, 5) === 'DATE_' && !$scope.dictionary[value] && isDate(value)) {
  858. date = formatDate(value);
  859. }
  860. tooltip += '<div class="popup-line"><div class="popup-label">' + label + '</div><div class="popup-value">' + (date ? date.locale("fr").format('ddd, LL') : value) + '</div><div class="popup-small-date">' + (date ? date.locale("fr").fromNow() : '') + '</div></div>';
  861. });
  862. if(identifier === 'adsl') {
  863. tooltip = '<a style="float: right;" href="http://www.ariase.com/fr/eligibilite/test.html" target="_blank">Tester mon éligibilité ADSL avec Ariase.com</a>';
  864. }
  865. return tooltip;
  866. };
  867. $scope.hideLayer = function(identifier) {
  868. map.removeLayer(layer[identifier]);
  869. };
  870. $scope.hideResultPane = function() {
  871. if(!$('#result').height()) {return;}
  872. $('#result').animate({height: 0}, 1000);
  873. $('#map').animate({
  874. height: $('body').height(),
  875. }, 1000, function() {
  876. // Animation complete.
  877. map.invalidateSize();
  878. var centerPoint = $scope.geoCode ? new L.LatLng($scope.geoCode.y, $scope.geoCode.x) : stlo;
  879. map.setView(centerPoint, 14);
  880. });
  881. };
  882. $scope.initPopup = function() {
  883. //console.log('initPopup', $scope.geoCode);
  884. $scope.postForm = null;
  885. getFullAddress(function(err, address) {
  886. if(err) {console.error(err);}
  887. //console.log('add', address);
  888. $scope.result = {eligibilite: {}, autres: {}};
  889. // Debug
  890. // $scope.result.eligibilite.prenom = 'Francois';
  891. // $scope.result.eligibilite.nom = 'Beaufils';
  892. // $scope.result.eligibilite.email = 'francoisbeaufils@zeno-labs.com';
  893. // $scope.result.eligibilite.vous_etes = 'locataire';
  894. // $scope.result.eligibilite.ce_logement_est = 'residence_principale';
  895. // $scope.result.eligibilite.info_et_libertes = true;
  896. // $scope.result.eligibilite.accord = 'avec_souscription';
  897. $scope.result.eligibilite.geo_code = JSON.stringify($scope.geoCode);
  898. $scope.result.eligibilite.code_postal = address.Postal;
  899. $scope.result.eligibilite.complement_addresse = address.Match_addr;
  900. $scope.result.eligibilite.nom_voie = address.Address;
  901. $scope.result.eligibilite.numero_voie = address.StreetNumber;
  902. $scope.result.eligibilite.type_voie = address.StreetType;
  903. $scope.result.eligibilite.ville = address.City;
  904. });
  905. };
  906. $scope.isFormValid = function() {
  907. if(!$scope.result || !$scope.result.eligibilite) {return;}
  908. var isValid = true;
  909. _.each($scope.formulaires.eligibilite.sections, function(section) {
  910. _.each(section.lines, function(line) {
  911. _.each(line.ctrls, function(ctrl) {
  912. ctrl.invalid = false;
  913. if(ctrl.require && !ctrl.isValid($scope.result.eligibilite[ctrl.id], $scope.result.autres[ctrl.id])) {
  914. isValid = false;
  915. ctrl.invalid = true;
  916. }
  917. });
  918. });
  919. });
  920. return isValid;
  921. };
  922. $scope.onSubmitAddress = function($item, $model, $label) {
  923. // console.log('onSubmitAddress address', $scope.address);
  924. // console.log('onSubmitAddress $item', $item);
  925. // console.log('onSubmitAddress $model', $model);
  926. // console.log('onSubmitAddress $label', $label);
  927. // Get magic key
  928. var item = _.find($scope.suggestions, {text: $item});
  929. if(!item) {
  930. item = $scope.suggestions[0];
  931. $scope.address = item.text;
  932. }
  933. $scope.magicKey = item.magicKey;
  934. //console.log('onSubmitAddress -_-item', item, '=>', $scope.magicKey);
  935. $scope.getGeoCode($scope.address, $scope.magicKey, function(err, data) {
  936. $scope.geoCode = data && data.locations && data.locations[0] && data.locations[0].feature.geometry;
  937. if(err) {console.error('Geocode error', err);}
  938. var toast = toast || {
  939. template: '<md-toast><i class = " md-error"></i> Oups! Aucun résultat trouvé dans la Manche pour: ' + $scope.address + '</md-toast>',
  940. hideDelay: 3000,
  941. position: 'bottom right'
  942. };
  943. // $mdToast.simple()
  944. // .template(')
  945. // .position('bottom right')
  946. // .hideDelay(3000);
  947. if(err || !$scope.geoCode) {
  948. $scope.hideResultPane();
  949. $mdToast.show(toast);
  950. }
  951. //console.log('Addresses found for', $scope.address, '=>', data, '=> Geocode:', $scope.geoCode);
  952. if($scope.geoCode) {
  953. addCurrentMarker();
  954. $scope.showResultPane();
  955. getResults();
  956. }
  957. });
  958. };
  959. $scope.postFormEl = function() {
  960. $scope.postForm = {inProgress: true};
  961. _.each($scope.result.autres, function(value, key) {
  962. $scope.result.eligibilite[key] = value;
  963. });
  964. //console.log('postForm', $scope.result.eligibilite);
  965. $scope.$evalAsync();
  966. function mysql_real_escape_string (str) {
  967. if(typeof str !== 'string') {return str;}
  968. return str.replace(/[\0\x08\x09\x1a\n\r"'\\\%]/g, function (char) {
  969. switch (char) {
  970. case "\0":
  971. return "\\0";
  972. case "\x08":
  973. return "\\b";
  974. case "\x09":
  975. return "\\t";
  976. case "\x1a":
  977. return "\\z";
  978. case "\n":
  979. return "\\n";
  980. case "\r":
  981. return "\\r";
  982. case "\"":
  983. case "'":
  984. case "\\":
  985. case "%":
  986. return "\\"+char; // prepends a backslash to backslash, percent,
  987. // and double/single quotes
  988. }
  989. });
  990. }
  991. var keys = '';
  992. var values = '';
  993. _.each($scope.result.eligibilite, function(value, key) {
  994. keys += '`' + key + '`, ';
  995. values += "'" + mysql_real_escape_string(value) + "', ";
  996. });
  997. var dateTime = (new Date ((new Date((new Date(new Date())).toISOString() )).getTime() - ((new Date()).getTimezoneOffset()*60000))).toISOString().slice(0, 19).replace('T', ' ');
  998. var query = "INSERT INTO `eligibilite`.`demandes` (`date`," + keys.substring(0, keys.length -2) + ") VALUES ('" + dateTime + "', " + values.substring(0, values.length -2) + ");";
  999. console.log('query', query);
  1000. $.ajax({
  1001. method : "POST",
  1002. url : "ajax/datastores.php",
  1003. data : {query: query}
  1004. })
  1005. .done(function( msg ) {
  1006. if(!isNaN(msg)) {
  1007. $scope.postForm = {ok: true};
  1008. var numDemande = moment().format('YYYYMMDD') + msg;
  1009. var body = 'Bonjour ' + $scope.result.eligibilite.prenom + ' ' + $scope.result.eligibilite.nom + ', <br>' +
  1010. 'Nous vous confirmons votre demande de pré-raccordement FTTH. <br><br>' +
  1011. 'Cette demande porte le numéro: ' +
  1012. '<span style="color: #31708f;font-size:17px; font-weight:bold;">' + numDemande + '</span><br><br>' +
  1013. 'Voici le détail de votre demande:' +
  1014. '<div style="color: #31708f;background-color: #d9edf7;border-color: #bce8f1;padding: 10px;margin: 1em;font-size:14px;">' +
  1015. '<table style="line-height: 40px;">';
  1016. // _.each($scope.result.eligibilite, function(value, key) {
  1017. // body += '<tr>';
  1018. // body += '<th style="text-align:left;">' + key + '</th>';
  1019. // body += '<td>' + value + '</td>';
  1020. // body += '</tr>';
  1021. // });
  1022. // Numero demande
  1023. body += '<tr>';
  1024. body += '<th style="text-align: left;white-space: nowrap;height: 40px;color: #666;">Numéro demande</th>';
  1025. body += '<td>' + numDemande + '</td>';
  1026. body += '</tr>';
  1027. // Date demande
  1028. body += '<tr>';
  1029. body += '<th style="text-align: left;white-space: nowrap;height: 40px;color: #666;">Date</th>';
  1030. body += '<td>' + moment().lang('fr').format('LLLL') + '</td>';
  1031. body += '</tr>';
  1032. // Demandeur
  1033. body += '<tr>';
  1034. body += '<th style="text-align: left;white-space: nowrap;height: 40px;color: #666;">Demandeur</th>';
  1035. body += '<td>' + $scope.result.eligibilite.prenom + ' ' + $scope.result.eligibilite.nom + '</td>';
  1036. body += '</tr>';
  1037. // Email
  1038. body += '<tr>';
  1039. body += '<th style="text-align: left;white-space: nowrap;height: 40px;color: #666;">Email</th>';
  1040. body += '<td>' + $scope.result.eligibilite.email + '</td>';
  1041. body += '</tr>';
  1042. // Adresse
  1043. body += '<tr>';
  1044. body += '<th style="text-align: left;white-space: nowrap;height: 40px;color: #666;">Adresse</th>';
  1045. body += '<td>' + computeFullAddress() + '</td>';
  1046. body += '</tr>';
  1047. // Vous etes
  1048. var cat = _.find(catVousEtes, {id: $scope.result.eligibilite.vous_etes});
  1049. var res = cat && cat.name ? cat.name : $scope.result.eligibilite.vous_etes;
  1050. body += '<tr>';
  1051. body += '<th style="text-align: left;white-space: nowrap;height: 40px;color: #666;">Vous êtes</th>';
  1052. body += '<td>' + res + '</td>';
  1053. body += '</tr>';
  1054. // Ce logement est
  1055. var cat2 = _.find(catCeLogementEst, {id: $scope.result.eligibilite.ce_logement_est});
  1056. var res2 = cat2 && cat2.name ? cat2.name : $scope.result.eligibilite.ce_logement_est;
  1057. body += '<tr>';
  1058. body += '<th style="text-align: left;white-space: nowrap;height: 40px;color: #666;">Ce logement est</th>';
  1059. body += '<td>' + res2 + '</td>';
  1060. body += '</tr>';
  1061. //console.log('$scope.result', $scope.result);
  1062. body += '</table></div><br><br>';
  1063. body += 'Conformément à la loi "informatique et libertés" du 6 janvier 1978 modifiée, vous bénéficiez d’un droit d’accès, de rectification aux informations qui vous concernent, d’opposition au traitement de vos données personnelles. Si vous souhaitez exercer ce droit et obtenir la communication des informations vous concernant, merci de nous contacter :' + '<br>' +
  1064. '<table style="">' +
  1065. ' <tr>' +
  1066. ' <th style="text-align: left;white-space: nowrap;height: 30px;color: #666;">Email</th><td>' + siteEmail + '</td>' +
  1067. ' </tr><tr>' +
  1068. ' <th style="text-align: left;white-space: nowrap;height: 30px;color: #666;">Adresse</th><td>' + siteAddresse + '</td>' +
  1069. ' </tr><tr>' +
  1070. ' <th style="text-align: left;white-space: nowrap;height: 30px;color: #666;">Tel</th><td>' + siteTel + '</td>' +
  1071. ' </tr>' +
  1072. '</table><br><br>';
  1073. body += 'A bientôt sur: <a href="' + siteUrl + '">' + siteName + '</a>';
  1074. console.log('body', body);
  1075. var mail = {
  1076. to : $scope.result.eligibilite.email,
  1077. sujet : 'Votre demande de pré-raccordement FTTH n° ' + numDemande,
  1078. message: body
  1079. };
  1080. $.ajax({
  1081. method : "POST",
  1082. url : "ajax/datastores.php",
  1083. data : {
  1084. siteEmail: siteEmail,
  1085. mail : mail}
  1086. })
  1087. .done(function( msg ) {
  1088. console.log('Mail result', msg);
  1089. });
  1090. $scope.result.eligibilite = {};
  1091. $scope.autres = {};
  1092. $scope.address = null;
  1093. $scope.magicKey = null;
  1094. }
  1095. else {
  1096. $scope.postForm = {error: msg};
  1097. }
  1098. $scope.hideResultPane();
  1099. $scope.$apply();
  1100. });
  1101. };
  1102. $scope.showLayer = function(identifier) {
  1103. map.addLayer(layer[identifier]);
  1104. };
  1105. $scope.showResultPane = function() {
  1106. var bodyHeight = $('body').height();
  1107. var height = Math.max(300, bodyHeight / 3);
  1108. var heightMap = bodyHeight - height;
  1109. $('#result').animate({height: height + 'px'}, 1000);
  1110. $('#map').animate({
  1111. height: heightMap + 'px',
  1112. }, 1000, function() {
  1113. // Animation complete.
  1114. map.invalidateSize();
  1115. map.setView(new L.LatLng($scope.geoCode.y, $scope.geoCode.x), 14);
  1116. });
  1117. };
  1118. $scope.toggleResultPane = function() {
  1119. if($('#result').height()) {
  1120. return $scope.hideResultPane();
  1121. }
  1122. if($scope.results && $scope.results.ftth) {
  1123. return $scope.showResultPane();
  1124. }
  1125. };
  1126. $scope.toggleRight = function() {
  1127. $mdSidenav('right').toggle()
  1128. .then(function(){});
  1129. };
  1130. $scope.$watch('view', function(view) {
  1131. if(_.isEmpty(view)) {return;}
  1132. $('#layer-loading').removeClass('force-hidden').find('.md-inner').show();
  1133. setTimeout(function() {
  1134. _.each(view, function(value, key) {
  1135. if($scope.isShown[key] !== value) {
  1136. if(value) {
  1137. if(typeof $scope.isShown[key] !== 'undefined') {
  1138. $scope.showLayer(key);
  1139. $('#layer-loading').find('.md-inner').hide();
  1140. }
  1141. else {
  1142. $timeout(function() {
  1143. $scope.computeLayer(key);
  1144. $scope.showLayer(key);
  1145. $('#layer-loading').find('.md-inner').hide();
  1146. }, 500);
  1147. }
  1148. }
  1149. else {
  1150. $scope.hideLayer(key);
  1151. setTimeout(function() {
  1152. $('#layer-loading').find('.md-inner').hide();
  1153. }, 1000);
  1154. }
  1155. $scope.isShown[key] = value;
  1156. }
  1157. });
  1158. });
  1159. }, true);
  1160. $(window).resize(function() {
  1161. if(!$('#result').height()) {return;}
  1162. $scope.showResultPane();
  1163. });
  1164. init();
  1165. });