-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathtemplate_bootstrap2.html
351 lines (316 loc) · 13.8 KB
/
template_bootstrap2.html
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
<! -- Fix for Bootstrap css with Google Maps https://github.com/twitter/bootstrap/issues/1552 -->
<style type="text/css">
.map_canvas label {
width: auto;
display: inline;
}
.map_canvas img {
max-width: none;
}
.layersDiv label {
color: white;
}
</style>
<div class="row">
<!-- Success and Error Messages for the user -->
<div class="span8 offset2" style="height:50px">
<!-- Success alert box -->
<div id="success" class="alert alert-success" style="display:none;">
<a class="close">×</a><strong>Well done!</strong> Your answer has been saved
</div>
<!-- Task completed alert box -->
<div id="taskcompleted" class="alert alert-info" style="display:none;">
<strong>The task has been completed!</strong> Thanks a lot!
</div>
<!-- Task loading alert box -->
<div id="loadingTask" class="alert alert-info">
<strong>Loading task...</strong>
</div>
<!-- Task completed alert box -->
<div id="finish" class="alert alert-success" style="display:none;">
<strong>Congratulations!</strong> You have participated in all available tasks!
<br/>
<div class="alert-actions">
<a class="btn small" href="/">Go back</a>
<a class="btn small" href="/app">or, Check other applications</a>
</div>
</div>
<!-- Error alert box -->
<div id="error" class="alert alert-error" style="display:none;">
<a class="close">×</a>
<strong>Error!</strong> Something went wrong, please contact the site administrators
</div>
<!-- Old Browser alert box -->
<div id="oldBrowser" class="alert alert-info" style="display:none;">
<a class="close">×</a>
<p><strong>Sorry!</strong> Your web browser does not support the application.<p>
<div class="alert-actions">
<a c lass="btn small" href="/app">Please, try with another application</a>
</div>
</div>
</div><!-- End of span8 offset2-->
</div><!-- End of Row-->
<div class="row">
<div class="skeleton span11 offset1">
<div id="question">
<h1>Question</h1>
<h3 id="city">City</h3>
<button id="point" class="btn btn-inverse">
<i class="icon icon-white icon-map-marker"></i> Add an Urban Park Marker
</button>
<button id="noPark" class="btn btn-submit">I do not see an urban park</button>
<button id="noCity" class="btn btn-submit" style="display:none;">City not found!</button>
<p>Task: <span id="task-id" class="label label-warning">#</span></p>
<div id="map"></div>
<i class="icon-map-marker"></i> Urban park position: <strong> Longitude:</strong> <span id="lon"></span>,
<strong>Latitude:</strong> <span id="lat"></span>
</div>
<div id="answer">
<button id="answerbtn" class="btn btn-success btn-submit"><i class="icon-check icon-white"></i> Save these coordinates for the urban park</button>
</div>
</div>
</div>
<div class="row skeleton">
<div id="disqus_thread" class="span11 offset1"></div>
</div>
<script type="text/javascript">
/* * * CONFIGURATION VARIABLES: EDIT BEFORE PASTING INTO YOUR WEBPAGE * * */
var disqus_shortname = 'pybossa'; // required: replace example with your forum shortname
var disqus_developer = 1;
/* * * DON'T EDIT BELOW THIS LINE * * */
(function() {
var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
dsq.src = 'http://' + disqus_shortname + '.disqus.com/embed.js';
(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
})();
</script>
<noscript>Please enable JavaScript to view the <a href="http://disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript>
<a href="http://disqus.com" class="dsq-brlink">comments powered by <span class="logo-disqus">Disqus</span></a>
<script src="http://www.openlayers.org/api/OpenLayers.js"></script>
<script src="http://maps.google.com/maps/api/js?v=3.6&sensor=false"></script>
<!-- PyBossa interface -->
<script>
// This function will load the marker of the city, and center the map on it
function addCity(task) {
// As this action could take some time, start the spinner
// Geocode the city using Nominatim OSM service
$.getJSON('http://nominatim.openstreetmap.org/search/' + task.info.city + '?format=json', function(output) {
if (output.length >= 1) {
// Clean previous markers
$("#navigate").addClass("active");
$("#point").removeClass("disabled");
$("#point").removeClass("active");
task.urbanParkLayer.removeAllFeatures();
task.cityLayer.removeAllFeatures();
// Create a LonLat object to load the city marker
var lonLat = new OpenLayers.LonLat(output[0].lon, output[0].lat)
.transform(
new OpenLayers.Projection("EPSG:4326"), // transform from WGS 1984
task.map.getProjectionObject() // to Spherical Mercator Projection
);
// Set the marker position
var point = new OpenLayers.Geometry.Point(lonLat.lon, lonLat.lat);
task.cityLayer.addFeatures([new OpenLayers.Feature.Vector(point)]);
// Center the map
task.map.setCenter(lonLat,13);
// Reset the lon & lat span objects
$("#lon").text("-");
$("#lat").text("-");
}
else {
// City not found, sorry
// Warn the user and try with another city
$("#warning").fadeIn();
setTimeout(function() {
$("#warning").fadeOut();
}, 2000);
$("#noCity").show();
$("#answerbtn").hide();
$("#noPark").hide();
$("#map_" + task.id).hide();
}
});
}
pybossa.taskLoaded(function(task, deferred){
if ( !$.isEmptyObject(task) ) {
var div_map = $("<div/>", {'id': "map_" + task.id, 'class': 'map_canvas'});
div_map.css("width", "620px");
div_map.css("height", "310px");
div_map.css("display", "none");
// We need to append the div element asap otherwise OpenLayers will fail
$("#map").append(div_map);
var map = new OpenLayers.Map('map_' + task.id, {
controls: [
new OpenLayers.Control.Navigation(),
new OpenLayers.Control.PanZoom(),
new OpenLayers.Control.LayerSwitcher(),
new OpenLayers.Control.MousePosition({displayProjection: new OpenLayers.Projection("EPSG:4326")}),
new OpenLayers.Control.ScaleLine(),
new OpenLayers.Control.Attribution()
]
});
// Layers
// Open Street Map (default layer)
map.addLayer(new OpenLayers.Layer.OSM("Open Street Map"));
// Google Maps Satellite layer
map.addLayer(new OpenLayers.Layer.Google(
"Google Satellite",
{type: google.maps.MapTypeId.SATELLITE}
));
// Google Maps Physical layer
map.addLayer(new OpenLayers.Layer.Google(
"Google Physical",
{type: google.maps.MapTypeId.TERRAIN}
));
// Icon for the City Marker
var styleMapCity = new OpenLayers.StyleMap({
pointRadius: 15,
externalGraphic: 'http://img225.imageshack.us/img225/5237/youarehere2.png'
});
// Icon for the Urban Park Marker
var styleMapUrbanPark = new OpenLayers.StyleMap({
pointRadius: 15,
externalGraphic: 'http://img594.imageshack.us/img594/1087/urbanpark.png'
});
// Layer for placing the city marker
var cityLayer = new OpenLayers.Layer.Vector("City marker", {
styleMap: styleMapCity,
attribution: 'Marker Icons by <a href="http://mapicons.nicolasmollet.com/">Nicolas Mollet</a>'
});
map.addLayer(cityLayer);
task.cityLayer = cityLayer;
// Layer for placing the urban park marker
var urbanParkLayer = new OpenLayers.Layer.Vector("Urban park marker", {
styleMap: styleMapUrbanPark,
attribution: 'Marker Icons by <a href="http://mapicons.nicolasmollet.com/">Nicolas Mollet</a>'
});
map.addLayer(urbanParkLayer);
task.urbanParkLayer = urbanParkLayer;
// Function to allow only the addition of one urban park per city
// The function gets the feature (point) and gets its location, transforms it to the right projection
// loads the lon and at into the HTML skeleton and disables the toolbar, so no more points can be added
disablePoint = function(feature) {
if ($("#answerbtn").hasClass("disabled")) {
$("#answerbtn").removeClass('disabled');
}
$("#lat").text(feature.geometry.y);
var tmp = feature.geometry.clone();
tmp.transform(
task.map.getProjectionObject(), // from Spherical Mercator Projection
new OpenLayers.Projection("EPSG:4326") // to transform from WGS 1984
);
$("#lon").text(tmp.x);
$("#lat").text(tmp.y);
task.lon = tmp.x;
task.lat = tmp.y;
task.drawControls['point'].deactivate();
}
// Default location to load the map
var lonLat = new OpenLayers.LonLat(-0.1279688 ,51.5077286 )
.transform(
new OpenLayers.Projection("EPSG:4326"), // transform from WGS 1984
new OpenLayers.Projection("EPSG:900913") // to Spherical Mercator Projection
);
// Enable drag & drop in the urban park Layer
var drag = new OpenLayers.Control.DragFeature(urbanParkLayer, {
onComplete: function() {
var urbanParkPoint = task.urbanParkLayer.features[0].geometry
var tmp = urbanParkPoint.clone();
tmp.transform(
task.map.getProjectionObject(), // from Spherical Mercator Projection
new OpenLayers.Projection("EPSG:4326") // to transform from WGS 1984
);
// When the marker has been dropped, update the lon & lat of the urban park
$("#lon").text(tmp.x);
$("#lat").text(tmp.y);
task.lon = tmp.x;
task.lat = tmp.y;
}
});
// Add the drag & drop control into the map
map.addControl(drag);
// Activate drag & drop
drag.activate();
var drawControls = {
point: new OpenLayers.Control.DrawFeature(urbanParkLayer, OpenLayers.Handler.Point,
{ 'featureAdded': disablePoint})
}
// Add them to the map
for (var key in drawControls) {
map.addControl(drawControls[key]);
}
task.drawControls = drawControls;
task.map = map;
task.lon = 0;
task.lat = 0;
addCity(task);
$("#loadingTask").hide();
deferred.resolve(task);
} // End if task empty
else {
deferred.resolve(task);
}
});
pybossa.presentTask(function(task, deferred){
if ( !$.isEmptyObject(task) ) {
if (task.state=='completed') {
$('#controls').hide();
$('#answer').hide();
$('#disqus_thread').hide();
$('#taskcompleted').show();
}
$("#noPark").show();
$("#answerbtn").show();
$("#noCity").hide();
$("#question h1").text(task.info.question);
$("#question h3").text(task.info.city);
$("#task-id").text(task.id);
$("#loadingTask").hide();
$("#map_" + task.id).show();
if ($("#point").hasClass("disabled")) {
$("#point").removeClass("disabled");
}
$("#point").off('click').on('click', function(){
//toggleControl('point');
task.drawControls['point'].activate();
$("#point").addClass("disabled");
});
$(".btn-submit").off('click').on('click', function(evt){
// Convert the feature location, the urban park marker position, into the GeoJSON format
var $btn = $(this);
var answer = $btn.attr("id");
var geojson = new OpenLayers.Format.GeoJSON({
'internalProjection': task.map.baseLayer.projection,
'externalProjection': new OpenLayers.Projection("EPSG:4326")
});
if ((task.urbanParkLayer.features.length == 0) && ((btnClicked == "noPark") || (btnClicked == "noCity"))) {
urbanPark = "noPark";
}
else {
if ((task.urbanParkLayer.features.length > 0) && (btnClicked == "answerbtn")) {
urbanPark = JSON.parse(geojson.write(task.urbanParkLayer.features[0]));
}
else {
alert("Please, add a marker if you think there is one!");
return
}
}
console.log(task.id);
console.log(urbanPark);
pybossa.saveTask( task.id, {'city': task.info.city, 'urbanpark': urbanPark}).done( function(data) {
// Show the feedback div
$("#success").fadeIn();
$("#map_" + task.id).remove();
// Fade out the pop-up after a 2000 miliseconds
setTimeout(function() { $("#success").fadeOut() }, 2000);
deferred.resolve();
});
});
}
else {
$(".skeleton").hide();
$("#finish").fadeIn();
}
});
pybossa.run('urbanpark');
</script>