
// get the city monument list from Wikimedia monument datatbase
// and strip a few wiki tags
// https://commons.wikimedia.org/wiki/Commons:Monuments_database/API
// http://toolserver.org/~erfgoed/api/api.php
//
// Zepto.js is used to get JSONP data from toolserver 


'use strict';
 

define([], function() {
	
	var baseURL = 'http://toolserver.org/~erfgoed/api/api.php?';
	
	var params = $.param({
		format: 'json',
		action: 'search',
		srcontry: 'fr',  //TODO get this from coodinate
		srlang: 'fr',    //TODO get this from the phone
		coord: window.sessionStorage.getItem('position_latitude') + ',' + window.sessionStorage.getItem('position_longitude'),
		radius: '5000',  //TODO add a setting for this
		props: 'name|address|municipality|image'
	});
	
	var requestURL = baseURL + params + '&callback=?'
    
	$.getJSON(requestURL, function(monumentsData){
		var data = JSON.stringify(monumentsData);
		console.log(data)
		// TODO clean wiki formating like [[city]]
		// TODO sage to localstorage
	})

});

// example centered in Nice with a 5000m radius with the more usefull fields
// http://toolserver.org/~erfgoed/api/api.php?&format=json&action=search&srcountry=fr&srlang=fr&coord=43.69073,7.294788&radius=5000&props=name|address|municipality|image


// TODO clean the [[]] from the wiki syntax in the restults ...
// TODO maybe drop adresslookup ? we can work with long lat and radius
// or just use it for country lookup
// anyway this maybe usefull later for manual monument search

@@ -303,17 +303,48 @@
 ion() %7B%0A
-%09
+%0A%09// generate the lookup address
 %0A%09var ba
@@ -398,18 +398,16 @@
 .php?';%0A
-%09%0A
 %09var par
@@ -476,95 +476,86 @@
 ry: 
-'fr',  //TODO get this from coodinate%0A%09%09srlang: 'fr',    //TODO get this from the phone
+window.localStorage.getItem('position_country'),%0A%09%09srlang: navigator.language,
 %0A%09%09c
@@ -559,39 +559,37 @@
 %09%09coord: window.
-session
+local
 Storage.getItem(
@@ -628,15 +628,13 @@
 dow.
-session
+local
 Stor
@@ -679,17 +679,17 @@
 adius: '
-5
+1
 000',  /
@@ -717,16 +717,68 @@
 or this%0A
+%09%09//limit: 10, //TODO maybe add a limit in settings%0A
 %09%09props:
@@ -821,10 +821,8 @@
 %7D);%0A
-%09%0A
 %09var
@@ -872,12 +872,60 @@
 =?'%0A
+%09%0A
     
+// get the JSONP data from the external source
 %0A%09$.
@@ -953,25 +953,20 @@
 unction(
-monuments
+json
 Data)%7B%0A%09
@@ -970,20 +970,30 @@
 %7B%0A%09%09var 
-data
+monuments_list
  = JSON.
@@ -1006,43 +1006,18 @@
 ify(
-monumentsData);%0A%09%09console.log(data)
+jsonData);
 %0A%09%09/
@@ -1067,34 +1067,156 @@
 %09// 
-TODO sage to
+or use address from nominatim ?%0A%09%09%0A%09%09// save the monument list in the
  local
-s
+S
 torage%0A
+%09%09window.localStorage.setItem('monuments_list', monuments_list);%0A
 %09%7D)%0A
@@ -1280,18 +1280,18 @@
 h the mo
-re
+st
  usefull
@@ -1472,240 +1472,4 @@
 age%0A
-%0A%0A// TODO clean the %5B%5B%5D%5D from the wiki syntax in the restults ...%0A// TODO maybe drop adresslookup ? we can work with long lat and radius%0A// or just use it for country lookup%0A// anyway this maybe usefull later for manual monument search%0A

Update the monument list search