Permalink
Browse files

Add BAN

  • Loading branch information...
DoFabien committed Aug 9, 2015
1 parent eff5a05 commit aad9251caea4128c6916847e885405f9278e8f9a
@@ -27,55 +27,23 @@ var ModalInstanceCtrl = function ($scope, $modalInstance,data) {
};
}

$scope.onFileSelectXLS = function($files) {
var file = $files[0];
var fr = new FileReader();
var fr_res = fr.readAsText(file);
fr.onload = function(event) {
var res = event.currentTarget.result;
//workbook.SheetNames.forEach(function(sheetName) {
//$scope.import_csv(event.currentTarget.result)

workbook.SheetNames.forEach(function(sheetName) {
var csv = XLS.utils.make_csv(workbook.Sheets[sheetName]);
if(csv.length > 0){
result.push("SHEET: " + sheetName);
result.push("");
result.push(csv);
}
});
return result.join("\n");


};
}


$scope.import_csv = function (str_full){
str_full = str_full.replace(/\n/g,'');// on enleve le retour \n pour les systèmes windows
// $scope.csv_full = csv_full;
var rows = str_full.split('\r');
var separateur = $scope.searchSeparateur(rows[0]);
// console.log(rows[0]);
$scope.importer_text(rows,separateur,true);
}

$scope.import_text = function (str_full){

// console.log(str_full)
var rows = str_full.split('\n');
//console.log(rows[0])
var rows = str_full.split('\n');
var separateur = $scope.searchSeparateur(rows[0]);
//console.log(separateur);
$scope.importer_text(rows,separateur,false);
}


$scope.searchSeparateur= function(row){
var separateur =';';
if(row.split(',').length >row.split(';').length ){separateur = ',';}
if(row.split(/\t/).length >row.split(',').length ){separateur = '\t';}

return (separateur);
}

@@ -84,7 +52,6 @@ var ModalInstanceCtrl = function ($scope, $modalInstance,data) {
$scope.field_for_select = [];
$scope.importer_text = function(rows,separateur,scope_apply){
$scope.data_geocode = [];
// rows[0] = rows[0].replace(' ','_');
var fields = rows[0].split(separateur); // champ
$scope.obj_field_ind = []
for (k=0;k<fields.length;k++){
@@ -101,27 +68,18 @@ var ModalInstanceCtrl = function ($scope, $modalInstance,data) {
$scope.champs_geocod.lng = 'f'+(fields.length +2);
$scope.champs_geocod.lat = 'f'+(fields.length +3);

//$scope.obj_field_ind[k] = {ind:k, lbl:'_Score'};
//onsole.log($scope.obj_field_ind);

for (i=1;i<rows.length;i++){
if (rows[i].split(separateur).length >1){
var array_rows = rows[i].split(separateur);

var obj = new Object();
for (j=0;j<$scope.obj_field_ind.length;j++){
obj[$scope.obj_field_ind[j].ind] = array_rows[j];
}

//console.log (obj);
$scope.data_geocode.push(obj);
}
}
if (scope_apply == true){
$scope.$apply();
}
//console.log($scope.data_geocode);
}


} //FIN DU CONTROLEUR ModalInstanceCtrl
} //EOF CONTROLEUR ModalInstanceCtrl
86 app.js
@@ -16,10 +16,7 @@ app.controller('Ctrl1', function($scope,$upload,$timeout,$modal, cfpLoadingBar)
if(navigator.geolocation){navigator.geolocation.getCurrentPosition(get_position);}

function get_position(location){
// console.log(location.coords.longitude);
// console.log(location.coords.latitude);
map.setView([ location.coords.latitude, location.coords.longitude], 8);

}

$scope.btn_disabled = true;
@@ -28,7 +25,6 @@ app.controller('Ctrl1', function($scope,$upload,$timeout,$modal, cfpLoadingBar)
$scope.marker_data = [];
$scope.adresse = '';
$scope.scrore_min = 93;

$scope.columnDefs = [{displayName: "En attente de données" ,enableCellEdit: false, width: "*"}];


@@ -97,7 +93,6 @@ app.controller('Ctrl1', function($scope,$upload,$timeout,$modal, cfpLoadingBar)
function on_drag_end_Marker(e) {
var leaflet_id = e.target._leaflet_id;
var index= $scope.findWithAttr($scope.data_geocode,'leaflet_id',leaflet_id);
console.log(e);
FGroup.removeLayer(leaflet_id);
$scope.add_marker(e.target._latlng.lat,e.target._latlng.lng,index,100);
}
@@ -121,7 +116,6 @@ app.controller('Ctrl1', function($scope,$upload,$timeout,$modal, cfpLoadingBar)
headers.push($scope.field_lbl_ind[i].lbl);
}
csv+=headers.join(';')+"\r\n";
//console.log(headers);
for (j=0;j<$scope.data_geocode.length;j++){
var row =[];
for (k=0;k<$scope.field_lbl_ind.length;k++){
@@ -200,22 +194,18 @@ app.controller('Ctrl1', function($scope,$upload,$timeout,$modal, cfpLoadingBar)

/*FORCE LE GEOCODAGE DE LA LIGNE MEME SI LE SCORE EST PLUS HAUT*/
$scope.row_geocode_forcing = function (row,fct){
console.log(row);
var elem = row.entity;
var ind = $scope.get_ind_obj(elem)
console.log(ind);
var num = elem[$scope.champs_geocode.numero];
var rue = elem[$scope.champs_geocode.rue];
var cp = elem[$scope.champs_geocode.cp];
var commune = elem[$scope.champs_geocode.commune];
fct(num,rue,cp,commune,ind,true);
}



/*AJOUTER UN MARKER*/
$scope.add_marker = function(lat,lng,ind,score){
console.log($scope.data_geocode[ind]['leaflet_id']);

FGroup.removeLayer($scope.data_geocode[ind]['leaflet_id']);
var url_marker ='';
if (score > 99){url_marker='images/black.png';}
@@ -232,15 +222,14 @@ app.controller('Ctrl1', function($scope,$upload,$timeout,$modal, cfpLoadingBar)
marker.on('drag', on_drag_Marker);// lors du drag d'un marker
marker.on('dragend', on_drag_end_Marker);
}

/*GEOCODE UN TABLEAU D'OBJETS */
$scope.process_geogoding_async = function(array_data,timmer,fct){
var current_elem =0;
cfpLoadingBar.start();
cfpLoadingBar.set(0.01);
$scope.btn_disabled = true;
$scope.show_btn_cancel = true;

loop_asynch();

function loop_asynch(){ // boucle asynchron avec un timer pour ne pas bloquer l'application et afficher la barre de progression
@@ -263,11 +252,9 @@ app.controller('Ctrl1', function($scope,$upload,$timeout,$modal, cfpLoadingBar)
}
else{
$scope.btn_disabled = false;
console.log ("ok");
$scope.show_btn_cancel = false;
map.fitBounds(FGroup.getBounds());
cfpLoadingBar.complete()

}
}
}
@@ -278,7 +265,7 @@ app.controller('Ctrl1', function($scope,$upload,$timeout,$modal, cfpLoadingBar)
var adresse = num+' ' + rue + ',' +cp +',' + commune +', France';
var adresse_encoded = encodeURIComponent(adresse);
var url = "http://maps.googleapis.com/maps/api/geocode/json?address="+adresse_encoded+"&sensor=true"
console.log(url);

$.ajax({
type: "get",
url:url ,
@@ -320,9 +307,7 @@ app.controller('Ctrl1', function($scope,$upload,$timeout,$modal, cfpLoadingBar)
$scope.data_geocode[i][$scope.champs_geocode.lng] = data.results[0].geometry.location.lng;
$scope.data_geocode[i][$scope.champs_geocode.score] = score;
$scope.add_marker(data.results[0].geometry.location.lat, data.results[0].geometry.location.lng, i,score);

}

}
}
}
@@ -511,6 +496,64 @@ app.controller('Ctrl1', function($scope,$upload,$timeout,$modal, cfpLoadingBar)

};

/*GEOCODER BAN*/
$scope.geocodeBan = function (num,rue,cp,commune,i,forcing){
var adresse = num+' ' + rue + ',' +cp +',' + commune +', France';
var adresse_encoded = encodeURIComponent(adresse);
http://api-adresse.data.gouv.fr/search/?q=8 bd du port
var url = "http://api-adresse.data.gouv.fr/search/?q="+adresse_encoded+"&limit=1"
console.log(url);
$.ajax({
type: "get",
url:url ,
async: false,
success: result,
dataType: "json"
});
function result(data){
console.log(data.features[0]);
var res = data.features[0];
console.log(res.properties.type);
console.log(res.properties.score);
var lat = res.geometry.coordinates[1];
var lng = res.geometry.coordinates[0];
console.log(lat);
console.log(lng);

var score = 0;
var score_type =0;
var score_precision = 0;

switch (res.properties.type) {
case 'housenumber': score_type = 90 ;break;
case 'street':score_type = 60;break;
default: score_type = 0;break;
}

var _score = res.properties.score;
if (_score > 0.90) { score_precision = 9 }
else if (_score > 0.80) { score_precision = 8 }
else if (_score > 0.70) { score_precision = 7 }
else if (_score > 0.60) { score_precision = 6 }
else if (_score > 0.50) { score_precision = 5 }
else if (_score > 0.40) { score_precision = 4 }
else if (_score > 0.20) { score_precision = 2 }
else if (_score > 0.10) { score_precision = 0 }
else { score_precision = -5 };


score = score_type+score_precision;
//console.log (score_type + ' + ' + score_precision + ' = ' + score);
if($scope.data_geocode[i][$scope.champs_geocode.score] < score || $scope.data_geocode[i][$scope.champs_geocode.score] == undefined || forcing==true){
$scope.data_geocode[i][$scope.champs_geocode.geocoder] = 'BAN';
$scope.data_geocode[i][$scope.champs_geocode.lat] = lat;
$scope.data_geocode[i][$scope.champs_geocode.lng] = lng;
$scope.data_geocode[i][$scope.champs_geocode.score] = score;
$scope.add_marker(lat,lng, i,score);

}
}
}


/*OUVERTURE DE LA POPUP D'IMPORT*/
@@ -546,10 +589,11 @@ app.controller('Ctrl1', function($scope,$upload,$timeout,$modal, cfpLoadingBar)

}
var w_col_button = 16;
column.push({ field: '', width:w_col_button, cellTemplate: '<img src="images/google.png" title="Google Geocoder!" ng-click="row_geocode_forcing(row,geocode_google)">' });
column.push({ field: '', width:w_col_button, cellTemplate: '<img src="images/BAN.png" title="Geocoder cette ligne avec la BAN!" ng-click="row_geocode_forcing(row,geocodeBan)">' });
column.push({ field: '', width:w_col_button, cellTemplate: '<img src="images/google.png" title="Geocoder cette ligne avec le service de Google!" ng-click="row_geocode_forcing(row,geocode_google)">' });
column.push({ field: '', width:w_col_button, cellTemplate: '<img src="images/ign.png" title="Geocoder cette ligne avec le service de l\'IGN!" ng-click="row_geocode_forcing(row,geocode_ign)">' });
column.push({ field: '', width:w_col_button, cellTemplate: '<img src="images/bing.jpg" title="Geocoder cette ligne avec le service de Bing" ng-click="row_geocode_forcing(row,geocode_bing)">' });
column.push({ field: '', width:w_col_button, cellTemplate: '<img src="images/osm.png" title="Geocoder cette ligne avec le service de MapQuest" ng-click="row_geocode_forcing(row,geocode_osm)">' });
column.push({ field: '', width:w_col_button, cellTemplate: '<img src="images/bing.jpg" title="Geocoder cette ligne avec le service de Bing!" ng-click="row_geocode_forcing(row,geocode_bing)">' });
column.push({ field: '', width:w_col_button, cellTemplate: '<img src="images/osm.png" title="Geocoder cette ligne avec le service de MapQuest!" ng-click="row_geocode_forcing(row,geocode_osm)">' });
$scope.columnDefs = column;


BIN +372 Bytes images/BAN.png
Binary file not shown.
@@ -7,18 +7,14 @@
<link rel="stylesheet" href="lib/leaflet/leaflet.css" />
<link rel="stylesheet" href="lib/loading-bar.css"/>



<script src="lib/angular.js"></script>
<script src="lib/jquery-2.0.3.min.js"></script>

<script src="lib/ui-bootstrap-tpls-0.10.0.min.js"></script>
<script type="text/javascript" src="lib/ng-grid.debug.js"></script>
<script src="config.js" type="application/javascript"></script>
<script src="app.js"></script>




<meta charset="UTF-8">
<title>DoGeocodeur</title>
</head>
@@ -29,56 +25,55 @@
<script src="lib/angular-file-upload-shim.min.js"></script>
<script src="lib/angular-file-upload.min.js"></script>
<script src="ModalInstanceCtrl.js" type="text/javascript"></script>
<script src="http://maps.google.com/maps/api/js?v=3.2&sensor=false"></script>

<script src="http://maps.google.com/maps/api/js?v=3.2&sensor=false"></script>
<script src="lib/leaflet/leaflet-google.js"></script>



<div id="header"></div>

<div id="main">

<div id="header"></div>
<div id="main">

<div id="map"></div>

<div id="rigth">
<button id="btn_import" ng-click ="open_popup()" class="btn btn-primary btn-sm" > Importer des données</button>
<button id="btn_import" ng-click ="open_popup()" class="btn btn-primary btn-sm" > Importer des données</button>


<div id="btn_process" >
<span id="span_score_min">
<label class="lbl_center" for="score_min">Geocoder uniquement les adresses <br> dont le "score" est inférieur à :</label>

<input id="score_min" type="number" ng-model="scrore_min" min="35" max="99">
</span><br>
<span id="span_score_min">
<label class="lbl_center" for="score_min">Geocoder uniquement les adresses <br> dont le "score" est inférieur à :</label>
<input id="score_min" type="number" ng-model="scrore_min" min="35" max="99">
</span><br>

<button ng-show='show_btn_cancel' ng-click ="show_btn_cancel = false" class="btn btn-danger btn" > Interrompre le géocodage</button><br>
<label class="lbl_center">Procéder au géocodage avec :</label><br>

<button ng-disabled="btn_disabled" ng-click ="process_geogoding_async(data_geocode,50,geocodeBan)" class="btn btn-warning btn" > BAN</button><br>
<button ng-disabled="btn_disabled" ng-click ="process_geogoding_async(data_geocode,50,geocode_google)" class="btn btn-warning btn" > Google</button><br>
<button ng-disabled="btn_disabled" ng-click ="process_geogoding_async(data_geocode,200,geocode_bing) " class="btn btn-warning btn" > Bing</button><br>
<button ng-disabled="btn_disabled" ng-click ="process_geogoding_async(data_geocode,50,geocode_ign) " class="btn btn-warning btn" > IGN</button><br>
<button ng-disabled="btn_disabled" ng-click ="process_geogoding_async(data_geocode,50,geocode_osm) " class="btn btn-warning btn" > OSM MapQuest</button><br>


</div>
</div>
<div class="gridStyle" ng-grid="gridOptions"></div>

<div class="gridStyle" ng-grid="gridOptions"></div>
</div>





<div id="footer">

<button ng-click="export(generate_CSV(),Date.now(),'Export_CSV.csv','text/csv')" class="btn btn-success btn-sm" > Exporter en CSV</button>
<button ng-click="export(generate_KML(),Date.now(),'Export_kml.kml','application/vnd.google-earth.kml+xml')" class="btn btn-success btn-sm" > Exporter en KML</button>
<button ng-click="export(generate_GEOJSON(),Date.now(),'Export_geojson.geojson','application/json')" class="btn btn-success btn-sm" > Exporter en GeoJson</button>

</div>







<div id="footer">

<button ng-click="export(generate_CSV(),Date.now(),'Export_CSV.csv','text/csv')" class="btn btn-success btn-sm" > Exporter en CSV</button>
<button ng-click="export(generate_KML(),Date.now(),'Export_kml.kml','application/vnd.google-earth.kml+xml')" class="btn btn-success btn-sm" > Exporter en KML</button>
<button ng-click="export(generate_GEOJSON(),Date.now(),'Export_geojson.geojson','application/json')" class="btn btn-success btn-sm" > Exporter en GeoJson</button>

</div>




</body>
</html>
Oops, something went wrong.

0 comments on commit aad9251

Please sign in to comment.