-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtesting.js
224 lines (173 loc) · 5.92 KB
/
testing.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
if(L.Browser.retina) var tp = "lr";
else var tp = "ls";
var lyrk = L.tileLayer('http://tiles.lyrk.org/'+tp+'/{z}/{x}/{y}?apikey=701dcc16672d4781b03ca506db3ef046', {
attribution: '<a href="http://geodienste.lyrk.de/copyright">Lizenzinformationen</a>, Tiles by <a href="http://geodienste.lyrk.de/">Lyrk</a>',
maxZoom: 18
});
var map = L.map('map', {
layers: [lyrk]
}).setView( new L.LatLng(20, 10), 2);
// POPUPS
function createModal(geojson) {
var modal = document.createElement("div");
var modal_url = geojson.properties.name.replace(/ /g,"-").replace(/[^a-zA-Z0-9 -]/g, '').toLowerCase();
modal.id = modal_url;
modal.className = "modal fade";
modal.innerHTML = '<div class="modal-dialog"><div class="modal-content"><div class="modal-header"><a href="#"><button>×</button></a><h2 class="modal-title">'+ geojson.properties.name +'</h2></div><div class="modal-body"><p>'+ geojson.properties.desc +'</p><p>'+geojson.properties.mail+'</p><p>'+geojson.properties.url+'</p></div></div></div>';
document.body.appendChild(modal);
}
function renderPopup(feature, url) {
partial_head = '<h2>'
if (feature.properties.url != '') {
link_start = '<a href="'+ feature.properties.url +'">';
link_end = '</a>'
}
else {
link_start = '';
link_end = '';
}
partial_foot = '</h2><br><a href="#'+ url +'">Read more</a>';
return partial_head + link_start + feature.properties.name + link_end + partial_foot;
}
function OnEachFeature(feature, layer){
if (feature.properties && feature.properties.name) {
var url = feature.properties.name.replace(/ /g,"-").replace(/[^a-zA-Z0-9 -]/g, '').toLowerCase();
createModal(feature);
/* layer.bindPopup(renderPopup(feature, url)
); */
/* layer.on('mouseover', function () {
this.openPopup();
});
layer.on('mouseout', function () {
this.closePopup();
});
*/
/* http://lea.verou.me/2011/05/change-url-hash-without-page-jump/ */
layer.on('click', function () {
/* this.openPopup(); */
/* if(history.pushState) {
history.pushState(null, null, '#' + url);
}
else { */
location.hash = '#' + url;
/*}*/
});
}
};
/*
function OnEachFeature(feature, layer){
if (feature.properties.name) {
layer.bindPopup('<b>' + feature.properties.name + '</b>' + '<br>' +
feature.properties.desc + '<br>' +
'<b>' + 'Website: ' + '</b>' + feature.properties.url + '<br>' +
'<b>' +'Contact: ' + '</b>' + feature.properties.mail
);
}
};
*/
function condense_geojson_locations ( element ) {
var callback = [];
callback[0] = unfairtobacco.locations[element].longitude;
callback[1] = unfairtobacco.locations[element].latitude;
//console.log(callback);
return callback;
}
function replace_geojson_locations ( element ) {
var copy = $.extend(true, {}, element, copy);
copy.locations = $.map(element.locations, condense_geojson_locations);
return copy;
}
function render_to_geojson ( projects ) {
var geojson_projects = {};
geojson_projects['type'] = 'FeatureCollection';
geojson_projects['features'] = [];
for (var k in projects) {
var obj = projects[k];
if (obj.locations[0] != null) {
var newFeature = {
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": replace_geojson_locations(obj).locations
},
"properties": {
"id": projects[k].ID,
"name": projects[k].name,
"desc": projects[k].description,
"url": projects[k].website_url,
"mail": projects[k].contact_email,
"orgs": projects[k].organisations,
"areas": projects[k].countries
}
};
geojson_projects['features'].push(newFeature);
};
};
return geojson_projects;
}
var unfairtobacco;
var projekte_geojson;
$.getJSON( "data.json", function( data ) {
unfairtobacco = data;
projekte_geojson = render_to_geojson(unfairtobacco.projects);
console.log(projekte_geojson);
var Layer_project = L.geoJson(projekte_geojson, {
onEachFeature: OnEachFeature
}).addTo(map);
});
///////////////// hinzufügen der Länder-GEOJSONs
var countries_ISO = [];
var countries_meta = [];
// erstellt Array mit ISO-Daten der verwiesenen Länder
function iso_render_to_array ( countries ) {
for (var k in countries) {
var obj = countries[k];
if (obj.iso_code != null) {
countries_ISO.push(countries[k]);
};
};
return countries_ISO;
}
function CreateCountryCallback(unfair) {
return function (geojson) {
merge_unfair_countries(geojson, unfair);
};
}
function merge_unfair_countries(geojson, unfair) {
var merge = $.extend(true, {}, geojson.features[0].properties, unfair)
console.log(merge);
var Layer_countries = L.geoJson(geojson, {
style: style,
//TODO onEachFeature: OnEachCountryFeature
}).addTo(map);
};
// get geoJSON anhand des ISO-Array
function get_And_Merge_Countries_to_geoJSON ( array ) {
var countriesMerged = {};
var country = {};
for (i = 0; i <= array.length; ++i) {
if ( array[i] != null) {
// http://stackoverflow.com/questions/6129145/pass-extra-parameter-to-jquery-getjson-success-callback-function
$.getJSON("countries/" + array[i].iso_code.toLowerCase() + ".geojson", CreateCountryCallback(array[i]));
}
};
}
var unfairtobaccoCountries;
var arrayCountries;
var geoJsonCountries = {};
$.getJSON( "data.json", function( data ) {
unfairtobacco = data;
arrayCountriesISO = iso_render_to_array(unfairtobacco.countries);
get_And_Merge_Countries_to_geoJSON(arrayCountriesISO);
});
/////////// Länder hervorhoben
function style(feature) {
return {
fillColor: 'red',
weight: 1,
opacity: 1,
color: 'white',
dashArray: '3',
fillOpacity: 0.8
};
}