-
Notifications
You must be signed in to change notification settings - Fork 1
/
draw.js
241 lines (196 loc) · 6.99 KB
/
draw.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
function Start() {
Initmap();
DrawBezirk();
Buttons();
logoCSH();
getTotalPats();
}
function Initmap() {
// set up the map
mymap = new L.Map('mapid');
//create the tile layer with correct attribution
var osmUrl='http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png';
//var osmUrl='http://{s}.tiles.wmflabs.org/bw-mapnik/{z}/{x}/{y}.png';
//var osmUrl='http://{s}.tile.stamen.com/toner/{z}/{x}/{y}.png';
var osmAttrib='VDPS, JCS @CSH | Map data © <a href="http://openstreetmap.org">OpenStreetMap</a> contributors';
var osm = new L.TileLayer(osmUrl, {minZoom: 8, maxZoom: 13, attribution: osmAttrib});
// start the map in Austria
//mymap.setView(new L.LatLng(47.488, 12.881),7); // whole Austria
mymap.setView(new L.LatLng(47.1666, 9.9095),10); // Vorarlberg
mymap.addLayer(osm);
mymap.setMaxZoom(11);
mymap.doubleClickZoom.disable();
mymap.boxZoom.disable();
// how to disable all possible zoom mechanisms //
// mymap.dragging.disable();
// mymap.touchZoom.disable();
// mymap.scrollWheelZoom.disable();
// mymap.boxZoom.disable();
// mymap.keyboard.disable();
// if (mymap.tap) mymap.tap.disable();
}
var bzrkcolor = 1;
function DrawBezirk() {
var bc;
$.getJSON("./data/vorarlberg.geojson", function(bc) {
function style(feature) {
return {
weight: 2,
opacity: 1,
color: 'white',
dashArray: '3',
fillOpacity: 0.5,
fillColor: getBezirkColor(bzrkcolor++)
};
}
L.geoJson(bc, {
style: style
//onEachFeature: onEachFeature
}).addTo(mymap);
DrawDoctors();
});
}
function DrawDoctors() {
$("#info").append("Loading Doc info...");
var docs;
$.getJSON("./data/docnet.json", function(docs) {
var max = 0;
for(var i in docs) {
activity = parseInt(docs[i].activity);
if(max<activity) max = activity;
docs[i].links_displayed = false; // useful to know when links are on
Doc_list[docs[i].docid] = docs[i]; // build dict of docs
docs[i].initial_patients = activity; // initial nr of patients
}
activity_max = max;
for(var i in docs) {
var doctor = docs[i];
var circle = L.circle([doctor.lat, doctor.lng], {
color: 'black',
weight: 1,
fillColor: Acquired2Color(doctor.activity, doctor.initial_patients),
fillOpacity: 0.8,
radius: Activity2Radius(doctor.activity)
}).addTo(mymap);
circle_list[doctor.docid] = circle;
circle.doc_id = doctor.docid;
circle.bindPopup(
"<p class=\"circlepopup\">"+
// " Id:"+doctor.docid.toString()+
// "<br />BZ:"+doctor.district_name.toString()+
"#Pats (current): "+doctor.activity.toString()+
// "<br />#Pats (initial):"+doctor.initial_patients.toString()+
"</p>",
{
offset: new L.Point(0,-20)
}
);
circle.on('mouseover', function (e) {
this.setStyle( {
fillOpacity: 0.5,
color: 'gray'
});
this.openPopup();
});
circle.on('mouseout', function (e) {
this.setStyle( {
fillOpacity: 0.8,
color: 'black'
});
this.closePopup();
});
circle.on('mousedown', function (e) {
var doctor = Doc_list[this.doc_id]; // recalls a global var
if(e.originalEvent.altKey || e.originalEvent.shiftKey)
{
RemoveDoctor(this.doc_id);
return;
}
else
{
$('#info').html(
//"<p>"+
"Id:" + this.doc_id.toString() + "<br>" +
"BZ:" + doctor.district_name.toString() + "<br>" +
"Activity:" + doctor.activity.toString() + "<br>"
//+"</p>"
);
this.setStyle({
fillOpacity: 0.5,
color: 'white'
});
if(functioncount < 1)
{
clearLinks();
if (doctor.links_displayed) { // if links are on already, set them off
doctor.links_displayed = false;
return;
}
ShowLinks(this.doc_id);
//if the mouse remains clicked for >1sec the doc is removed
clearTimeout(Window.downTimer);
Window.downTimer = setTimeout(function () {
RemoveDoctor(doctor.docid);
}, 1000);
}
}
});
}
});
$("#info").append("<br>...done");
}
//used to clear the timer for the long-press doc removal
$(window).mouseup(function(e) {
clearTimeout(Window.downTimer);
});
// show the links from docid to others
// sets polyline pop-up
function ShowLinks(docid)
{
var doctor = Doc_list[docid]; // recalls a global var
for(var j=0; j<doctor.links.length; j+=1) {
var doc2 = Doc_list[doctor.links[j]];
var w = doctor.weights[j];
var lat_from = doctor.lat;
var lng_from = doctor.lng;
var lat_to = doc2.lat;
var lng_to = doc2.lng;
if(w<1e-2) continue; // do not show links under 1%
var line_width = w*100; // transform into line width
var polyline = L.polyline([
[lat_from, lng_from],
[lat_to, lng_to]
],
{
color: "blue",
weight: line_width,
opacity: .7,
lineJoin: 'round'
}
).addTo(mymap);
link_list.push(polyline);
doctor.links_displayed = true;
polyline.bindPopup(
"<p class=\"linkpopup\">"+
""+ Math.floor(100*w).toString()+"% of " + doctor.activity + " Patients"+
"<br />will be referred to this connection."+
"</p>"
);
polyline.on('click', function (e) {
clearLinks();
});
polyline.on('mouseover', function (e) {
this.setStyle( {
color: 'red'
})
this.openPopup();
});
polyline.on('mouseout', function (e) {
this.setStyle( {
color: 'blue'
})
this.closePopup();
});
// console.log(doctor.links[j],doctor.weights[j]);
}
}