// file:///Users/francoisbeaufils/Downloads/geocoder-demo-master/index.html var app = angular.module('application', ['ngMaterial', 'adaptive.detection', 'ui.bootstrap.typeahead']); app.directive('skrollr', function() { var directiveDefinitionObject = { link: function() { skrollr.init(); } }; return directiveDefinitionObject; }); app.controller('mainController', function($scope, $detection, $http, $mdSidenav, $timeout, $sce, $mdToast) { $scope.title = "Manche Numerique"; var getGeoCodeInProgress = false, nbJoursFTTH = 244, siteName = 'Eligibilité Manche Numérique', siteUrl = 'http://eligibilite.manchenumerique.fr', siteEmail = 'ftth@manchenumerique.fr', siteAddresse = '235, rue Joseph Cugnot Zone Delta, 50000 SAINT LÔ', layer = {}, currentMarker, searchExtent; var catTypeVoie = [ { "name": "Allée", "id" : "allee" }, { "name": "Avenue", "id" : "avenue" }, { "name": "Boulevard", "id" : "boulevard" }, { "name": "Carrefour", "id" : "carrefour" }, { "name": "Chemin", "id" : "chemin" }, { "name": "Cité", "id" : "cite" }, { "name": "Hammeau", "id" : "hammeau" }, { "name": "Impasse", "id" : "impasse" }, { "name": "Lieu-dit", "id" : "lieu_dit" }, { "name": "Lotissement", "id" : "lotissement" }, { "name": "Place", "id" : "place" }, { "name": "Résidence", "id" : "residence" }, { "name": "Route", "id" : "route" }, { "name": "Rue", "id" : "rue" }, { "name": "Villa", "id" : "villa" }, { "name": "Village", "id" : "village" } ]; var catVousEtes = [ { "name": "Locataire de ce logement", "id" : "locataire" }, { "name": "Occupant à titre gratuit de ce logement", "id" : "occupant_gratuit" }, { "name": "Propriétaire de ce logement", "id" : "proprietaire" } ]; var catCeLogementEst = [ { "name": "Votre résidence principale", "id" : "residence_principale" }, { "name": "Votre résidence secondaire", "id" : "residence_secondaire" } ]; $scope.formulaires = { "eligibilite": { "sections": [ { "name": "Générale", "visible": false, "lines": [ { "ctrls": [ { "name" : "Prénom", "id" : "prenom", "type" : "text", "width" : "50%", "require": true, "isValid": function(value) { return !!value && value.length > 2; }, "msg" : 'Prénom invalide' }, { "name" : "Nom", "id" : "nom", "type" : "text", "width" : "50%", "require": true, "isValid": function(value) { return !!value && value.length > 2; }, "msg" : 'Nom invalide' } ] }, { "ctrls": [ { "name" : "Email", "id" : "email", "type" : "text", "width" : null, "require": true, "isValid": function(value) { function validateEmail(email) { var re = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i; return re.test(email); } return validateEmail(value); }, "msg" : 'Email invalide.' } ] }, { "ctrls": [ { "name" : "Téléphone fixe", "id" : "telephone_fixe", "type" : "text", "width" : "50%", "require": false }, { "name" : "Téléphone portable", "id" : "telephone_portable", "type" : "text", "width" : "50%", "require": false } ] } ] }, { "name": "Adresse", "visible": true, "lines": [ { "ctrls": [ { "name" : "Numero", "id" : "numero_voie", "type" : "text", "width" : "80px", "require": false }, { "name" : "Type voie", "id" : "type_voie", "type" : "select", "width" : "106px", "require": false, "options": { "categories": catTypeVoie } }, { "name" : "Nom voie", "id" : "nom_voie", "type" : "text", "width" : "378px", "require": true, "isValid": function(value) { return !!value; }, "msg" : 'Nom de voie invalide.' } ] }, { "ctrls": [ { "name" : "Complément Adresse", "id" : "complement_addresse", "type" : "textarea", "width" : null, "require": false } ] }, { "ctrls": [ { "name" : "Bâtiment", "id" : "batiment", "type" : "text", "width" : "50%", "require": false }, { "name" : "Cage escalier", "id" : "cage_escalier", "type" : "text", "width" : "50%", "require": false } ] }, { "ctrls": [ { "name" : "Etage / Niveau", "id" : "etage", "type" : "text", "width" : "50%", "require": false }, { "name" : "Numero appartement / porte", "id" : "numero_appartement", "type" : "text", "width" : "50%", "require": false } ] }, { "ctrls": [ { "name" : "Code postal", "id" : "code_postal", "type" : "text", "width" : "50%", "require": true, "isValid": function(value) { if(!value || value.length !== 5 || isNaN(parseInt(value, 10))) { return false; } return true; }, "msg" : 'Non valide' }, { "name" : "Ville", "id" : "ville", "type" : "text", "width" : "50%", "require": true, "isValid": function(value) { return !!value && value.length > 2; }, "msg" : 'Ville invalide.' } ] } ] }, { "name": "Logement", "visible": true, "lines": [ { "ctrls": [ { "name" : "Vous êtes", "id" : "vous_etes", "type" : "radio", "width" : null, "require": true, "options": { "categories": catVousEtes, "alertes": { "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." } }, "isValid": function(value, other) { return !!value && value !== 'autre' || !!other; }, "msg" : 'Choix incomplet.' } ] }, { "ctrls": [ { "name" : "Ce logement est", "id" : "ce_logement_est", "type" : "radio", "width" : null, "require": true, "options": { "categories": catCeLogementEst }, "isValid": function(value, other) { return !!value && value !== 'autre' || !!other; }, "msg" : 'Choix incomplet.' } ] } ] }, { "name": "Conditions pour le raccordement final d’abonné dans un immeuble individuel", "visible": true, "lines": [ { "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.", "ctrls": [ { "name" : "Accord", "id" : "accord", "libelle": "Je souhaite être pré-raccordé au réseau de fibre optique et accepte les conditions de paiement de 50€. IMPORTANT : le règlement ne vous sera demandé qu’après travaux effectués", "type" : "checkbox", "width" : null, "require": true, "isValid": function(value) { return !!value; }, "msg" : 'Vous devez doner votre accord.' } ] } ] }, { "name": "Informatique et libertés", "visible": false, "lines": [ { "ctrls": [ { "name" : "Informatique et libertés", "id" : "info_et_libertes", "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.', "type" : "checkbox", "width" : null, "require": true, "isValid": function(value) { return !!value; }, "msg" : 'Vous devez accepter.' } ] } ] }, { "name": "Souscription", "visible": false, "lines": [ { "ctrls": [ { "name" : "Souscription", "id" : "souscription_engagement", "libelle": 'Vous vous engagez à souscrire un abonnement chez un operateur 50 euros, sinon 400 euros.', "type" : "checkbox", "width" : null, "require": true, "isValid": function(value) { return !!value; }, "msg" : 'Vous devez accepter.' } ] } ] } ] } }; var addCurrentMarker = function() { if(currentMarker) { map.removeLayer(currentMarker); } currentMarker = L.marker([$scope.geoCode.y, $scope.geoCode.x], {draggable: true, title: "texst"}).addTo(map); //.bindPopup(data.locations[0].name).openPopup(); 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(); reverseLocation($scope.geoCode, null, function(address) { $scope.address = address; }); currentMarker.on('dragend', function(event) { var p = currentMarker.getLatLng(); //console.log('dragend', p); $scope.geoCode = { x: p.lng, y: p.lat }; reverseLocation($scope.geoCode, null, function(address) { $scope.address = address; ariaz(address, function(result) { //console.log('ariaz', result); }); getResults(); }); }); }; var ariaz = function(address, callback) { var url = 'http://www.eligibilite-adsl.com/testXmlAriase.php?ip=80.13.25.43&insee=35238&rivoli=8993&numeroVoie=2&complementNumeroVoie='; $.get( url, function(data, status) { callback(data); }); }; var computeDateFTTH = function() { if(!$scope.results.ftth) {return;} // A date already exists if($scope.results.ftth.DATE_OUV_SERVICE_REEL || $scope.results.ftth.DATE_OUV_SERVICE_PREV) { $scope.results.ftth.date = $scope.results.ftth.DATE_OUV_SERVICE_REEL || $scope.results.ftth.DATE_OUV_SERVICE_PREV; return; } // Compute Date var momentDate = moment($scope.results.ftth.DATE_FIN_TRAV_PREV, 'DD/MM/YY'); momentDate.add(nbJoursFTTH, 'days'); $scope.results.ftth.date = momentDate.format('DD/MM/YYYY'); }; var computeFullAdress = function() { return $scope.result.eligibilite.complement_addresse; }; var formatDate = function(value) { return moment(value.toString().substr(0,4) + '-' + value.toString().substr(4,2) + '-' + value.toString().substr(6,2)).locale("fr"); }; var getRecordsFor = function(identifier, coordinates) { var records = []; _.each($scope.data[identifier], function(record) { _.some(record._polygons, function(polygon) { if(isInside(polygon, coordinates)) { records.push(record); return true; } }); }); // Debug var debug = false; if (debug) { var colors = ['red', 'green', 'blue', 'black', 'silver', 'yellow']; var marker = L.marker([coordinates.y, coordinates.x]).addTo(map); var Lpolygons = []; _.each(records, function(record, i) { var style = { color : colors[i], fillColor: colors[i], weight : 4 }; _.each(record._polygons, function(polygon) { Lpolygons.push(L.polygon(polygon, style).bindPopup($scope.getHtmlContent(identifier, record))); }); }); L.layerGroup(Lpolygons).addTo(map); } return records; }; var getResults = function() { $scope.results = {}; $.ajax({ method : "POST", url : "ajax/oracle.php", data : $scope.geoCode }) .error(function(err) { console.error('Oracle issue', err); // Debug without Oracle access 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":"02\/05\/16"}],"adsl":[{"ID_FT_ADSL":"656","LEGENDE":"TV sur ADSL","NATURE":"0 - 37"}],"mimo":null}'); }) .done(function( msg ) { onResults(msg); }); var onResults = function(results) { try { $scope.results = JSON.parse(results); $scope.results.address = $scope.address; $scope.results.ftth = parseResults($scope.results.ftth); $scope.results.adsl = parseResults($scope.results.adsl); $scope.results.mimo = parseResults($scope.results.mimo); computeDateFTTH(); } catch(e) { console.error(e); } console.log('$scope.results', results, '=>',$scope.results); $scope.$apply(); }; $scope.$evalAsync(); }; var init = function() { var stlo = [49.1154686, -1.0828136000000086]; var map = L.map('map', {zoomControl:false}).setView(stlo, 9); map.on('dblclick', function(e) { var p = e.latlng; //console.log('click', e.latlng); // e is an event object (MouseEvent in this case) $scope.geoCode = { x: p.lng, y: p.lat }; addCurrentMarker(); $scope.showResultPane(); getResults(); }); var maps = { "carte" : 'http://server.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer/tile/{z}/{y}/{x}', "satellite" : 'http://services.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}' }; var cLayer = L.tileLayer(maps.satellite, { attribution: 'Map data © OpenStreetMap contributors, CC-BY-SA, Imagery © Mapbox', maxZoom: 18 }).addTo(map); var styleOpts = { color : 'red', fillColor: 'red', weight : 8 }; $scope.data = {}; $scope.colors = { "ftth": "#8cc474", // green "mimo": "#f9b256", // orange "adsl": "#76a7fa" // blue }; $http({method: 'POST', url: 'data/dictionary.json'}).success(function(data) { $scope.dictionary = data; }); $http({method: 'POST', url: 'data/Contour_Manche.json'}).success(function(data) { var style = { color : 'blue', fillColor: 'blue', weight : 2 }; $scope.data.manche = [{ _polygons : [data.features[0].geometry.coordinates[0]], _style : style, _properties : { name : {string: 'Manche'} } }]; 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 _.each(mancheCoordinates, function(c, i) { mancheCoordinates[i] = [c[1], c[0]]; }); // Rectangle coordinates around Manche //var mancheCoordinates = [[49.732307856286, -1.97117692088061],[48.4, -1.75],[48.4, -0.5],[49.732307856286, -1.2]]; // Debug: show manche limits //L.polygon(mancheCoordinates, {color: 'blue', fillColor: 'blue',weight: 8}).addTo(map); searchExtent = { "xmin" : _.max(_.map(mancheCoordinates, function(c) {return c[1];})), "ymin" : _.max(_.map(mancheCoordinates, function(c) {return c[0];})), "xmax" : _.min(_.map(mancheCoordinates, function(c) {return c[1];})), "ymax" : _.min(_.map(mancheCoordinates, function(c) {return c[0];})), "spatialReference" : {"wkid" : 84} }; var suggestURL = 'https://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer/suggest?f=pjson&searchExtent=' + JSON.stringify(searchExtent); var i = 0, j = 0; $scope.suggestLocation = function(val) { console.log('__suggestLocation', val); $scope.suggestionsReady = false; i++; return $http.get(suggestURL, { params: { text: val } }).then(function(response) { if(val === $scope.address) { // Very important to debounce queries $scope.suggestionsReady = response.data.suggestions.length !== 0; $scope.suggestions = _.cloneDeep(response.data.suggestions); } return response.data.suggestions.map(function(item){ return item.text; }); }); }; }); //console.time('FTTH data'); $http({method: 'POST', url: 'data/FTTH_zapm_partielle.json'}).success(function(data) { var style = { color : $scope.colors.ftth, fillColor: $scope.colors.ftth, weight : 2 }; var properties = { name : {key: 'ATD'}, hidden: ['ID_PM', 'MARCHE', 'ID_FT_ADSL', 'ID_FTTH_MN_ZAPM_PARTIELLE', 'ID_ZAPM_PARTIELLE', 'ID_ZAPM'], position: ['DATE_DEB_TRAV_PREV'] }; parseData('ftth', data, style, properties); //console.timeEnd('FTTH data'); //console.debug('Data for FTTH are ready', data); if($scope.data.mimo && $scope.data.adsl && $scope.data.ftth) { $scope.loaded = true; } $scope.$evalAsync(); }); //console.time('ADSL data'); $http({method: 'POST', url: 'data/TEL_FT_ADSL.json'}).success(function(data) { var style = { color : $scope.colors.adsl, fillColor: $scope.colors.adsl, weight : 2 }; var properties = { name : {key: 'LEGENDE'}, hidden: ['NATURE', 'NRA_CETE', 'NRA_TMP', 'NRA_DPT', 'ID_FT_ADSL'] }; parseData('adsl', data, style, properties); //console.timeEnd('ADSL data'); //console.debug('Data for ADSL are ready', data); if($scope.data.mimo && $scope.data.adsl && $scope.data.ftth) { $scope.loaded = true; } $scope.$evalAsync(); }); //console.time('MiMo data'); $http({method: 'POST', url: 'data/Couverture_mimo.json'}).success(function(data) { var style = { color : $scope.colors.mimo, fillColor: $scope.colors.mimo, weight : 2 }; var properties = { name : {string: 'Couverture MiMo'}, hidden: ['ID_MIMO_COUVERTURE'] }; parseData('mimo', data, style, properties); //console.timeEnd('MiMo data'); //console.debug('Data for MIMO are ready', data); if($scope.data.mimo && $scope.data.adsl && $scope.data.ftth) { $scope.loaded = true; } $scope.$evalAsync(); }); window.map = map; $scope.mapType = 'Satellite'; $scope.view = {}; $scope.isShown = {}; }; var isDate = function(value) { return (value.toString().length === 14 && value.toString().substring(0,2) === "20"); }; var isInside = function(polygon, point) { // ray-casting algorithm based on // http://www.ecse.rpi.edu/Homepages/wrf/Research/Short_Notes/pnpoly.html var y = point.x ? point.x : point[0], x = point.y ? point.y : point[1]; var inside = false; for (var i = 0, j = polygon.length - 1; i < polygon.length; j = i++) { var xi = polygon[i][0], yi = polygon[i][1]; var xj = polygon[j][0], yj = polygon[j][1]; var intersect = ((yi > y) != (yj > y)) && (x < (xj - xi) * (y - yi) / (yj - yi) + xi); if (intersect) { inside = !inside; } } return inside; }; var parseData = function(identifier, data, style, properties) { var getPolygonsCoord = function(type, coord) { var result = []; if(type === 'Polygon') { result.push(_.map(coord[0], function(r) {return [r[1], r[0]];})); } if(type === 'MultiPolygon') { var p = []; _.each(coord, function(c) { result.push(_.map(c[0], function(r) {return [r[1], r[0]];})); }); } return result; }; var records = []; _.each(data.features, function(r) { var record = r.properties; var polygons = getPolygonsCoord(r.geometry.type, r.geometry.coordinates); record._coordinates = r.geometry.coordinates; record._type = r.geometry.type; record._polygons = polygons; record._style = style; record._properties = properties; records.push(record); }); $scope.data[identifier] = records; }; var parseResults = function(records) { if(!records || !records.length) { return null; } if(records.length === 1) { return records[0]; } var result = records[0]; return result; }; var reverseLocation = function(geoCode, address, callback) { var reverseGeo = 'http://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer/reverseGeocode?f=pjson&distance=300'; var url = reverseGeo + '&location=' + (geoCode ? $scope.geoCode.x + ',' + $scope.geoCode.y : address) ; $.get( url, function(data, status) { data = JSON.parse(data); var adresse = data && data.address && data.address.Match_addr; if(data && data.address && data.address.Address) { var i = 0; var num = ''; while(!isNaN(parseInt(data.address.Address[i], 10))) { num += data.address.Address[i]; i++; } data.address.StreetNumber = num; data.address.Address = data.address.Address.substr(num.length).trim(); var typeVoie = data.address.Address.substring(0, data.address.Address.indexOf(' ')).toLowerCase(); type = _.find(catTypeVoie, function(c){ if(c.id === typeVoie || c.name.toLowerCase() === typeVoie) { return true; } }); if(type) { data.address.StreetType = type.id; data.address.Address = data.address.Address.substr(typeVoie.length).trim(); } } //console.debug('Reverse', geoCode, address, '=>', adresse, data.address); callback(adresse, data.address); $scope.$evalAsync(); }); }; $scope.changeMap = function(value) { //console.log('Goto', value); map.removeLayer(cLayer); cLayer = L.tileLayer(maps[value], { attribution: 'Map data © OpenStreetMap contributors, CC-BY-SA, Imagery © Mapbox', maxZoom: 18 }).addTo(map); }; $scope.closeRight = function() { $mdSidenav('right').close().then(function(){}); }; $scope.computeLayer = function(identifier) { var Lpolygons = []; _.each($scope.data[identifier], function(record) { _.each(record._polygons, function(polygon) { Lpolygons.push(L.polygon(polygon, record._style).bindPopup($scope.getHtmlContent(identifier, record))); }); }); layer[identifier] = L.layerGroup(Lpolygons); }; $scope.formatDateFTTH = function(date) { if(!date) {return;} var momentDate = moment(date, 'DD/MM/YYYY'); var result = '
| ' + key + ' | '; // body += '' + value + ' | '; // body += '
|---|---|
| Numéro demande | '; body += '' + numDemande + ' | '; body += '
| Date | '; body += '' + moment().lang('fr').format('LLLL') + ' | '; body += '
| Demandeur | '; body += '' + $scope.result.eligibilite.prenom + ' ' + $scope.result.eligibilite.nom + ' | '; body += '
| ' + $scope.result.eligibilite.email + ' | '; body += '|
| Adresse | '; body += '' + computeFullAdress() + ' | '; body += '
| Vous êtes | '; body += '' + res + ' | '; body += '
| Ce logement est | '; body += '' + res2 + ' | '; body += '