@@ -9,7 +9,7 @@ const ListComponent = {
99 template : template
1010} ;
1111
12- function controller ( $state , $stateParams , $timeout , leafletData , wikidata ) {
12+ function controller ( $state , $stateParams , $timeout , leafletData , localStorageService , wikidata ) {
1313 let vm = this ;
1414 const id = $stateParams . id [ 0 ] === 'Q' ? $stateParams . id : 'Q' + $stateParams . id ;
1515
@@ -35,21 +35,55 @@ function controller($state, $stateParams, $timeout, leafletData, wikidata) {
3535 lng : 19.545 ,
3636 zoom : 7
3737 } ,
38- markers : { }
38+ markers : { } ,
39+ layers : {
40+ baselayers : {
41+ osm : {
42+ name : 'OpenStreetMap' ,
43+ type : 'xyz' ,
44+ url : '//{s}.tile.openstreetmap.org/{z}/{x}/{y}.png' ,
45+ layerOptions : {
46+ subdomains : [ 'a' , 'b' , 'c' ] ,
47+ attribution : '© <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors' ,
48+ continuousWorld : true
49+ }
50+ }
51+ } ,
52+ overlays : {
53+ monuments : {
54+ name : 'Monuments' ,
55+ type : 'markercluster' ,
56+ visible : true
57+ }
58+ }
59+ }
3960 } ;
4061
62+ if ( ! id || id === 'Q' ) {
63+ vm . showMap = true ;
64+ return ;
65+ }
66+
67+ let langs = $stateParams . lang ? [ $stateParams . lang ] : [ ] ;
68+ langs = langs . concat ( localStorageService . get ( 'languages' ) || [ 'en' , 'de' ] ) ;
69+ wikidata . setLanguages ( langs ) ;
70+
4171 wikidata . getSearch ( id ) . then ( results => {
4272 vm . search . selectedItem = results . length ? results [ 0 ] : undefined ;
4373 } ) ;
4474
45- wikidata . getSPARQL ( `SELECT DISTINCT ?item ?itemLabel ?admin ?adminLabel ?coord ?image WHERE {
46- ?item p:P1435 ?monument .
47- ?item wdt:P131* wd:` + id + ` .
48- ?item wdt:P131 ?admin .
49- ?item wdt:P625 ?coord .
50- OPTIONAL { ?item wdt:P18 ?image }
51- SERVICE wikibase:label { bd:serviceParam wikibase:language "pl,en" }
52- }` ) . then ( data => {
75+ wikidata . getSPARQL ( `SELECT DISTINCT ?item ?itemLabel (SAMPLE(?admin) AS ?admin) (SAMPLE(?adminLabel) AS ?adminLabel) (SAMPLE(?coord) AS ?coord) (SAMPLE(?image) AS ?image)
76+ WHERE {
77+ ?item p:P1435 ?monument .
78+ ?item wdt:P131* wd:` + id + ` .
79+ ?item wdt:P131 ?admin .
80+ ?item wdt:P625 ?coord .
81+ OPTIONAL { ?item wdt:P18 ?image }
82+ OPTIONAL { ?admin rdfs:label ?adminLabel. FILTER(LANG(?adminLabel) = "` + langs [ 0 ] + `"). }
83+ SERVICE wikibase:label { bd:serviceParam wikibase:language "` + langs . join ( ',' ) + `" }
84+ }
85+ GROUP BY ?item ?itemLabel
86+ ORDER BY ?itemLabel` ) . then ( data => {
5387 // console.log(data)
5488 vm . list = data . map ( element => ( {
5589 name : {
@@ -58,10 +92,10 @@ function controller($state, $stateParams, $timeout, leafletData, wikidata) {
5892 } ,
5993 admin : {
6094 value_id : element . admin . value . substring ( element . admin . value . indexOf ( '/Q' ) + 1 ) ,
61- value : element . adminLabel . value
95+ value : element . adminLabel ? element . adminLabel . value : element . admin . value . substring ( element . admin . value . indexOf ( '/Q' ) + 1 )
6296 } ,
6397 coord : element . coord . value ? element . coord . value . replace ( 'Point(' , '' ) . replace ( ')' , '' ) . split ( ' ' ) : false ,
64- image : element . image ? element . image . value . replace ( 'wiki/Special:FilePath' , 'w/index.php?title=Special:Redirect/file' ) + '&width=75 ' : false
98+ image : element . image ? element . image . value . replace ( 'wiki/Special:FilePath' , 'w/index.php?title=Special:Redirect/file' ) + '&width=120 ' : false
6599 } ) ) ;
66100 return vm . list ;
67101 } ) . then ( list => {
@@ -72,6 +106,7 @@ function controller($state, $stateParams, $timeout, leafletData, wikidata) {
72106 lat : + element . coord [ 1 ] ,
73107 lng : + element . coord [ 0 ] ,
74108 message : element . name . value ,
109+ layer : 'monuments' ,
75110 icon : icon
76111 } ;
77112 bounds . push ( [ + element . coord [ 1 ] , + element . coord [ 0 ] ] ) ;
0 commit comments