forked from species/transfor-map
-
Notifications
You must be signed in to change notification settings - Fork 4
/
filters.js
778 lines (705 loc) · 33.1 KB
/
filters.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
/* filter functions:
* take an osm-object's data:
* data: {} with data.tags,data.type,data.id,data.lat,data.lon
* return true (=displayed) or false (object will be hidden)
*
* general function of filters: if ANY filter says "yes" it is to be displayed
* e.g. one has to uncheck organic=no if he doesn't want to see explicit non-organic tagged items
*/
var filters = {
// provides: {} generate from taxonomy.json
// identity: {} generate from taxonomy.json
// interaction: {} generate from taxonomy.json
organic : { label : "Organic",
displayed : false,
function_name : function filter_organic(osm_object){ //ONLY FUNCTION WORKING RIGHT NOW, USE FOR TESTING!
if(!osm_object['tags']) {
console.log("error in filters.organic: no tags attached!");
return false;
}
var crits = filters.organic.sub_criteria;
for(key in crits) {
var current_crit = crits[key];
if(! current_crit.state)
continue;
if(osm_object.tags[current_crit.key] == current_crit.value)
return true;
// 'unknown'
if(current_crit.value === null && ! osm_object.tags.hasOwnProperty(current_crit.key))
return true;
}
return false;
},
sub_criteria : {
only : {
key : "organic",
value : "only",
label : "Only",
default_state : "enabled",
state : true
},
yes : {
key : "organic",
value : "yes",
label : "Good selection",
default_state : "enabled",
state : true
},
limited : {
key : "organic",
value : "limited",
label : "Limited selection",
default_state : "enabled",
state : true
},
no : {
key : "organic",
value : "no",
label : "None",
default_state : "enabled",
state : true
},
unknown : {
key : "organic",
value : null,
label : "Unknown",
default_state : "enabled",
state : true
}
}
},
/* fee : { label : "Gratis",
displayed : true,
function_name : function filter_opening(osm_object){
if(!osm_object['tags']) {
console.log("error in filters.fee: no tags attached!");
return false;
}
// simplified for testing
// FIXME whatif property not set?
return (osm_object.tags['fee'] == "no" ) ? true : false;
},
sub_criteria : {
no : {
key : "fee",
value : "no",
label : "Yes",
default_state : "enabled",
state : true,
},
yes : {
key : "fee",
value : "no",
label : "No",
default_state : "enabled",
state : true,
},
unknown : {
key : "fee",
value : null,
label : "Unknown",
default_state : "enabled",
state : false,
},
}
},*/
/* opening_hours : { label : "Open Now",
displayed : true,
function_name : function filter_opening(osm_object){
if(!osm_object['tags']) {
console.log("error in filters.opening_hours: no tags attached!");
return false;
}
// simplified for testing
var crits = filters.opening_hours.sub_criteria;
for(key in crits) {
if(! crits[key].state)
continue;
if(key == "open") {
// TODO add opening_hours.js here
if(osm_object.tags['opening_hours'] == "24/7" )
return true;
// else continue !
} else if (key == "closed") {
// TODO add opening_hours.js here
if(osm_object.tags['opening_hours'] == "off")
return true;
// if POI is closed, continue
} else { //unknown
return true;
}
}
return false;
},
sub_criteria : {
open : {
key : "opening_hours",
value : null,
label : "Open",
default_state : "enabled",
state : true,
},
closed : {
key : "opening_hours",
value : null,
label : "Closed",
default_state : "enabled",
state : true,
},
unknown : {
key : "opening_hours",
value : null,
label : "Unknown",
default_state : "enabled",
state : true,
},
}
},*/
wheelchair : { label : "Wheelchair accessible",
displayed : false,
function_name : function filter_wheelchair(osm_object){
if(!osm_object['tags']) {
console.log("error in filters.wheelchair: no tags attached!");
return false;
}
var crits = filters.wheelchair.sub_criteria;
for(key in crits) {
var current_crit = crits[key];
if(! current_crit.state)
continue;
if(osm_object.tags[current_crit.key] == current_crit.value)
return true;
// 'unknown'
if(current_crit.value === null && ! osm_object.tags.hasOwnProperty(current_crit.key))
return true;
}
return false;
},
sub_criteria : {
yes : {
key : "wheelchair",
value : "yes",
label : "100% accessible",
default_state : "enabled",
state : true
},
limited : {
key : "wheelchair",
value : "limited",
label : "Limited",
default_state : "enabled",
state : true
},
no : {
key : "wheelchair",
value : "no",
label : "No",
default_state : "enabled",
state : true
},
unknown : {
key : "wheelchair",
value : null,
label : "Unknown",
default_state : "enabled",
state : true
}
}
},
diet : { label : "Veggie Diet",
displayed : false,
function_name : function filter_diet(osm_object){
if(!osm_object['tags']) {
console.log("error in filters.diet: no tags attached!");
return false;
}
var crits = filters.diet.sub_criteria;
//vegan - false can mean vegan=no or vegan=unknown
var current_key = "diet:vegan";
var vegan = (osm_object.tags.hasOwnProperty(current_key) &&
osm_object.tags[current_key].match(/^only$|^yes$|^limited$/)) ||
(osm_object.tags.hasOwnProperty("cuisine") && osm_object.tags["cuisine"] == "vegan");
if(crits.vegan.state == true) {
if(vegan)
return true;
}
//vegetarian - false can mean vegetarian=no or vegetarian=unknown
current_key = "diet:vegetarian";
var vegetarian = vegan ||
(osm_object.tags.hasOwnProperty(current_key) &&
osm_object.tags[current_key].match(/^only$|^yes$|^limited$/)) ||
(osm_object.tags.hasOwnProperty("cuisine") &&
osm_object.tags["cuisine"] == "vegetarian");
if(crits.vegetarian.state == true) {
if(vegetarian)
return true;
}
// no -has diet:vegetarian=no and not cuisine=veggie
// or diet:pescetarian=only or meat shop
var nonveg_only = (osm_object.tags.hasOwnProperty("diet:pescetarian") &&
osm_object.tags["diet:pescetarian"] == "only") ||
(osm_object.tags.hasOwnProperty("shop") &&
osm_object.tags["shop"].match(/butcher|seafood|fishmonger/));
if(crits.noveg.state == true ) {
if(!vegan && !vegetarian) { //!cuisine=veggie
if(osm_object.tags.hasOwnProperty("diet:vegetarian") &&
osm_object.tags["diet:vegetarian"] == "no")
return true;
if(nonveg_only)
return true;
}
}
//unknown
if(crits.unknown.state == true) {
if(!vegan && !vegetarian) { //includes cuisine=veggie
if(! osm_object.tags.hasOwnProperty("diet:vegetarian") &&
! osm_object.tags.hasOwnProperty("diet:vegan") &&
! nonveg_only )
return true;
}
}
return false;
},
sub_criteria : {
vegan : {
key : "diet:vegan",
value : "yes|only|limited",
label : "Vegan",
default_state : "enabled",
state : true,
function_name : function filter_diet_vegan(osm_object) {
if(!osm_object['tags']) {
console.log("error in filters.diet.vegan: no tags attached!");
return false;
}
var vegan = (osm_object.tags.hasOwnProperty("diet:vegan") &&
osm_object.tags["diet:vegan"].match(/^only$|^yes$|^limited$/)) ||
(osm_object.tags.hasOwnProperty("cuisine") && osm_object.tags["cuisine"] == "vegan");
return vegan;
}
},
vegetarian : {
key : "diet:vegetarian",
value : "yes",
label : "Vegetarian",
default_state : "enabled",
state : true,
function_name : function filter_diet_vegetarian(osm_object) {
if(!osm_object['tags']) {
console.log("error in filters.diet.vegetarian: no tags attached!");
return false;
}
var vegan = (osm_object.tags.hasOwnProperty("diet:vegan") &&
osm_object.tags["diet:vegan"].match(/^only$|^yes$|^limited$/)) ||
(osm_object.tags.hasOwnProperty("cuisine") && osm_object.tags["cuisine"] == "vegan");
current_key = "diet:vegetarian";
var vegetarian = vegan ||
(osm_object.tags.hasOwnProperty(current_key) &&
osm_object.tags[current_key].match(/^only$|^yes$|^limited$/)) ||
(osm_object.tags.hasOwnProperty("cuisine") &&
osm_object.tags["cuisine"] == "vegetarian");
return vegetarian;
}
},
noveg : {
key : "diet:*",
value : "no",
label : "Non-Vegetarian",
default_state : "enabled",
state : true,
function_name : function filter_diet_noveg(osm_object) {
if(!osm_object['tags']) {
console.log("error in filters.diet.noveg: no tags attached!");
return false;
}
var crits = filters.diet.sub_criteria;
//vegan - false can mean vegan=no or vegan=unknown
var current_key = "diet:vegan";
var vegan = (osm_object.tags.hasOwnProperty(current_key) &&
osm_object.tags[current_key].match(/^only$|^yes$|^limited$/)) ||
(osm_object.tags.hasOwnProperty("cuisine") && osm_object.tags["cuisine"] == "vegan");
//vegetarian - false can mean vegetarian=no or vegetarian=unknown
current_key = "diet:vegetarian";
var vegetarian = vegan ||
(osm_object.tags.hasOwnProperty(current_key) &&
osm_object.tags[current_key].match(/^only$|^yes$|^limited$/)) ||
(osm_object.tags.hasOwnProperty("cuisine") &&
osm_object.tags["cuisine"] == "vegetarian");
// no -has diet:vegetarian=no and not cuisine=veggie
// or diet:pescetarian=only or meat shop
var nonveg_only = (osm_object.tags.hasOwnProperty("diet:pescetarian") &&
osm_object.tags["diet:pescetarian"] == "only") ||
(osm_object.tags.hasOwnProperty("shop") &&
osm_object.tags["shop"].match(/butcher|seafood/));
if(crits.noveg.state == true ) {
if(!vegan && !vegetarian) { //!cuisine=veggie
if(osm_object.tags.hasOwnProperty("diet:vegetarian") &&
osm_object.tags["diet:vegetarian"] == "no")
return true;
if(nonveg_only)
return true;
}
}
return false;
}
},
unknown : {
key : "diet:*",
value : null,
label : "Unknown",
default_state : "enabled",
state : true,
function_name : function filter_diet_unknown(osm_object) {
if(!osm_object['tags']) {
console.log("error in filters.diet.noveg: no tags attached!");
return false;
}
}
}
}
}
}
//returns if a single sub-filter matches on an osm-object (used e.g. for counting)
function filterMatches(object_tags, filter) {
if(filter.hasOwnProperty("function_name")) {
var osm_object = { tags : object_tags };
return filter.function_name(osm_object);
}
if(object_tags.hasOwnProperty(filter.key) && checkIfInMultiValue(object_tags[filter.key],filter.value))
return true;
if(filter["tags_whitelist"] && isPOIinWhiteList(filter["tags_whitelist"],object_tags))
return true;
else
return false;
}
function needsFilterMatches(object_tags, filter) {
if((object_tags.hasOwnProperty(filter.key) && checkIfInMultiValue(object_tags[filter.key],filter.value))
|| ( object_tags.hasOwnProperty('topic') && checkIfInMultiValue(object_tags['topic'],filter.value) )
|| isPOIinWhiteList(filter.tags_whitelist, object_tags) )
return true;
else
return false;
}
function filterFunctionIdentity(osm_object) {
if(!osm_object['tags']) {
console.log("error in filters.identity: no tags attached!");
return false;
}
var crits = filters.identity.sub_criteria;
for(key in crits) {
if(key == "unknown") continue;
if(! crits[key].state ) continue;
if(filterMatches(osm_object.tags,crits[key]))
return true;
}
//handle "unknown" last
if(! crits.unknown.state)
return false;
for(key in crits) { //do not display POI if in SOME subcrit's whitelist (or it's primary filter key is disabled)...
if(key == "unknown") continue;
if(filterMatches(osm_object.tags,crits[key]))
return false;
}
return true; // has no or unknown "interaction" key set, and no whitelist of any subcrit matched
}
function filterFunctionInteraction(osm_object) {
if(!osm_object['tags']) {
console.log("error in filters.Interaction: no tags attached!");
return false;
}
var crits = filters.interaction.sub_criteria;
for(key in crits) {
if(key == "unknown") continue;
if(! crits[key].state ) continue;
if(filterMatches(osm_object.tags,crits[key]))
return true;
}
//handle "unknown" last
if(! crits.unknown.state)
return false;
for(key in crits) { //do not display POI if in SOME subcrit's whitelist (or it's primary filter key is disabled)...
if(key == "unknown") continue;
if(filterMatches(osm_object.tags,crits[key]))
return false;
}
return true; // has no or unknown "interaction" key set, and no whitelist of any subcrit matched
}
/* TODO currently only the 'provides' section in taxonomy.json is used, an 'topic' section gets ignored */
function filterFunctionNeeds(osm_object) {
if(!osm_object['tags']) {
console.log("error in filters.Needs: no tags attached!");
return false;
}
var crits = filters.provides.sub_criteria;
for(key in crits) {
if(key == "unknown") continue;
if(! crits[key].state ) continue;
if(needsFilterMatches(osm_object.tags,crits[key]))
return true;
}
//handle "unknown" last
if(! crits.unknown.state)
return false;
//do not display POI if in SOME subcrit's whitelist (or it's primary filter key is disabled)...
for(key in crits) {
if(key == "unknown") continue;
if(needsFilterMatches(osm_object.tags,crits[key]))
return false;
}
// has no or unknown "provides"/"topic" key set, and no whitelist of any subcrit matched
return true;
}
// whitelists are used, if some POIs imply a value, e.g. amenity=restaurant implies provides=food
function isPOIinWhiteList(whitelist,osm_tags) {
if(! $.isArray(whitelist)) {
console.log("isPOIinWhiteList: no array given as whitelist");
return false;
}
for(var whitelist_nr = 0; whitelist_nr < whitelist.length; whitelist_nr++) { // for each object, e.g. amenity=bar
var tags_whitelist = whitelist[whitelist_nr];
for(wl_key in tags_whitelist) { // handle negation first: if this tag is set, filter exclude, regardless of others
//FIXME doesn't handle combinations of ¬ (¬a AND ¬b)
if(wl_key[0] == "¬") {
var bl_key = wl_key.substring(1);
var bl_value = tags_whitelist[wl_key];
console.log("isPOIinWhiteList: negation:" + bl_key + "=" + bl_value);
if(osm_tags.hasOwnProperty(bl_key) && checkIfInMultiValue(osm_tags[bl_key],bl_value) ) {
console.log("isPOIinWhiteList: negation found:" + bl_key + "=" + bl_value);
return false;
}
}
}
var all_wl_keys_ok = false;
for(wl_key in tags_whitelist) { // there maybe multiple keys as requirement, e.g. leisure=garden + garden:type=community
var wl_value = tags_whitelist[wl_key];
if(! osm_tags.hasOwnProperty(wl_key) ) {
all_wl_keys_ok = false;
break;
}
if(wl_value == "*") {
all_wl_keys_ok = true;
continue;
}
if(checkIfInMultiValue(osm_tags[wl_key], wl_value) ) {
all_wl_keys_ok = true;
continue;
} else {
all_wl_keys_ok = false;
break;
}
}
if(all_wl_keys_ok)
return true;
}
return false;
}
function checkIfInMultiValue(multi_value,value) {
var multivalue_array = multi_value.split(/;\s*/);
for(var i=0; i < multivalue_array.length; i++) {
if(multivalue_array[i] == value)
return true;
}
return false;
}
/* TODO it is relatively inefficient to run all filters every time a single entry is changed - later only the filters affected on change should be run */
function runFiltersOnAll() {
var marker_array = markers.GetMarkers();
for(var i = 0; i < marker_array.length; i++) {
var marker = marker_array[i];
marker.filtered = ! getFilterStatusOnPoi(marker);
}
markers.ProcessView();
}
/*
* for an POI to be displayed (return-value true),
* every filtergroup must return true for the POI!
*/
function getFilterStatusOnPoi(marker) {
for(filtername in filters) {
if( ! (typeof(filters[filtername].function_name) === 'function') )
continue;
if(! filters[filtername].function_name(marker.data))
return false;
}
return true;
}
function createValidDOMid (source) {
return source.replace(/[^a-zA-Z0-9-_]/g,"_");
}
function updateFilterCount(force) {
if(!force && open_sidebox != "sidebox-filters") //run only when menu open
return;
//at first, reset all counts
for(filtername in filters) {
for(itemname in filters[filtername].sub_criteria) {
var id = createValidDOMid('filter_'+filtername+'_'+itemname+'_counter');
document.getElementById(id).innerHTML = "-";
document.getElementById(id).style.color="#ADADAD";
}
}
//list of visible markers needed because we need to know their amount
var visible_markers = getVisibleMarkers();
for(var i = 0; i < visible_markers.length; i++) {
var marker = visible_markers[i];
var marker_id = marker.data.type + marker.data.id;
for(filtername in filters) {
var is_marker_unknown = true;
for(itemname in filters[filtername].sub_criteria) {
var el = document.getElementById(createValidDOMid('filter_'+filtername+'_'+itemname+'_counter'));
var current_count = el.innerHTML;
if(current_count == "-")
current_count = 0;
if(itemname != "unknown") {
if (filtername == "provides") {
if (needsFilterMatches(marker.data.tags, filters[filtername].sub_criteria[itemname])) {
current_count++;
is_marker_unknown = false;
}
} else {
if (filterMatches(marker.data.tags, filters[filtername].sub_criteria[itemname])) {
current_count++;
is_marker_unknown = false;
}
}
} else { // unknown is always last
if(is_marker_unknown) current_count++ ;
}
el.innerHTML = current_count;
if(current_count == "0")
el.style.color="#ADADAD";
else
el.style.color="inherit";
}
}
}
}
function toggleAllFiltersInGroup(filtername) {
var old_state = getFilterGroupState(filtername);
var new_state = (old_state == "disabled") ? true : false; // if mixed or enabled, disable all
var filter = filters[filtername];
if(filter["sub_criteria"]) {
for(itemname in filter.sub_criteria) {
var item = filter.sub_criteria[itemname];
item.state = new_state;
}
var parent_element = document.getElementById("subfilter_" + filtername);
for(var i=1; i < parent_element.children.length; i++) { //i=1 because first is "toggle all"
var div_node = parent_element.children[i].firstChild;
div_node.className = (new_state) ? "enabled" : "disabled";
}
}
else
console.log("error in toggleAllFiltersInGroup('"+filtername+"'): no subcriterias");
}
function getFilterGroupState(filtername) {
var all_enabled = false;
var all_disabled = false;
var filter = filters[filtername];
if(filter["sub_criteria"]) {
for(itemname in filter.sub_criteria) {
var item = filter.sub_criteria[itemname];
if(item.state) {
if(all_enabled)
continue;
//else
if(!all_disabled) { //begin state
all_enabled = true;
continue;
} // item enabled, until now all disabled → mixed
return "mixed";
} else { //item disabled
if(all_enabled)
return "mixed";
if(all_disabled)
continue;
all_disabled = true;
}
}
if(all_disabled)
return "disabled";
if(all_enabled)
return "enabled";
console.log("error in getFilterGroupState('"+filtername+"'): no end state reached");
}
console.log("error in getFilterGroupState('"+filtername+"'): no subcriterias");
}
/* precondition: in global var filters, an object $filtername must exist.
* returns a piece of HTML which can be added to filters sidebar
*/
function createFilterHTML(filtername) {
var filter = filters[filtername];
var sub_filters = null;
if(filter["sub_criteria"]) {
sub_filters = $('<ul>')
.attr('class', "subfilter")
.attr('id',"subfilter_" + filtername);
var all_state = getFilterGroupState(filtername); // enabled, disabled, mixed
sub_filters.append( '<li class="allswitch"><div class='+ all_state +' '
+ 'onClick="toggleAllFiltersInGroup(\''+filtername+'\'); runFiltersOnAll(); this.className = getFilterGroupState(\''+filtername+'\');" '
+ 'title="check/uncheck all entries in this group">'
+ 'Toggle all'
+ '</div>'
+'</li>');
for(itemname in filter.sub_criteria) {
var item = filter.sub_criteria[itemname];
var statevarname = 'filters.'+filtername+'.sub_criteria[\''+itemname+'\'].state'; //filters.provides.sub_criteria['food+drink'].state
var title = "“" + item.key + "” = “" + item.value + "”";
sub_filters.append('<li><div class='+item.default_state+' '
+ 'onClick="'+statevarname+' = ! '+statevarname
+'; runFiltersOnAll();'
+'this.className = ('+statevarname+') ? \'enabled\' : \'disabled\';'
+'document.getElementById(\'subfilter_' + filtername + '\').firstChild.firstChild.className = getFilterGroupState(\''+filtername+'\');"'
+ ' title="' + title + '">'
+ item.label
+ '<span id="filter_'+ createValidDOMid(filtername+'_'+itemname) +'_counter">-</span>'
+ '</div>'
+ ((item.description) ? ("<div onClick='toggleInfoBox(\"filter_info_"+createValidDOMid(filtername+'_'+itemname)+"\");'>?<div class=InfoBox id='filter_info_"+createValidDOMid(filtername+'_'+itemname)+"'>"+item.description+"</div></div>"): "")
+'</li>' );
}
}
return $('<li>')
.attr('class', filter.displayed ? 'shown' : 'hidden')
.append( '<h3 onClick="this.parentNode.className = (this.parentNode.className == \'shown\') ? \'hidden\' : \'shown\' ;">' + filter.label + '</h3>' )
.append( sub_filters );
}
// create filters out of taxonomy
function createFiltersOfTaxonomy() {
var filter_names = [ "identity","interaction","provides" ]; //must be in reverse order to be shown correct!
var filter_functions = { "provides" : filterFunctionNeeds, "identity" : filterFunctionIdentity, "interaction" : filterFunctionInteraction };
for(var i=0; i < filter_names.length; i++) {
var filter_name = filter_names[i];
var taxonomy_block = taxonomy[filter_name];
if (!taxonomy_block) {
console.log("filters: no entry in taxonomy for " + filter_name);
return;
}
filters[filter_name] = {
label: taxonomy_block.label["en"],
displayed: false,
function_name: filter_functions[filter_name],
sub_criteria: {}
};
var filter = filters[filter_name];
for(itemkey in taxonomy_block.items) {
var item = taxonomy_block.items[itemkey];
filter.sub_criteria[ item["transformap:key"] ] = {
label : item.label["en"],
key : item["osm:key"],
value : item["osm:values"][0],
description : item.description["en"],
tags_whitelist : item["osm:objects"],
default_state : "enabled",
state : true
}
}
filter.sub_criteria[ "unknown" ] = {
label : "Unknown",
key : item["osm:key"],
value : null,
tags_whitelist : [],
default_state : "enabled",
state : true
},
$('#filters').prepend(createFilterHTML(filter_name));
}
}