-
Notifications
You must be signed in to change notification settings - Fork 0
/
registration.js
134 lines (113 loc) · 4 KB
/
registration.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
$(function () {
var m = mapbox.map('map', mapbox.layer().id('forosocialcriptana.map-ns0xydjk')),
point,
_d, // Down Event
tol = 4, // Touch Tolerance
_downLock = false,
_clickTimeout = false,
init = true;
m.ui.attribution.add().content('<a href="http://www.forosocialcriptana.com">Foro Social de Campo de Criptana</a>');
m.ui.zoomer.add();
m.centerzoom({
lat: 39.396805714385486,
lon: -3.0959129333496094
}, 12);
var markerEvents = {
touchstart: onDown,
mousedown: onDown
};
var touchEnds = {
touchend: onUp,
touchmove: onUp,
touchcancel: touchCancel
};
// Set up events
$(m.parent).on(markerEvents);
$(m.parent).on('touchstart', onDown);
// Clear the double-click timeout to prevent double-clicks from triggering popups.
function killTimeout() {
if (_clickTimeout) {
window.clearTimeout(_clickTimeout);
_clickTimeout = null;
return true;
} else {
return false;
}
}
// A handler for 'down' events - which means `mousedown` and `touchstart`
function onDown(e) {
// Ignore double-clicks by ignoring clicks within 300ms of each other.
if (killTimeout()) {
return;
}
// Prevent interaction offset calculations happening while the user is dragging the map.
// Store this event so that we can compare it to the up event
_downLock = true;
_d = new MM.Point(e.clientX, e.clientY);
if (e.type === 'mousedown') {
$(document.body).on('click', onUp);
// Only track single-touches. Double-touches will not affect this control
} else if (e.type === 'touchstart' && e.touches.length === 1) {
// Touch moves invalidate touches
$(m.parent).on(touchEnds);
}
}
function touchCancel() {
$(m.parent).off(touchEnds);
_downLock = false;
}
function onUp(e) {
var evt = {},
pos = new MM.Point(e.clientX, e.clientY);
_downLock = false;
for (var key in e) {
evt[key] = e[key];
}
$(document.body).off('click', onUp);
$(m.parent).off(touchEnds);
if (e.type === 'touchend') {
// If this was a touch and it survived, there's no need to avoid a double-tap
markerInteraction(e);
} else if (Math.round(pos.y / tol) === Math.round(_d.y / tol) && Math.round(pos.x / tol) === Math.round(_d.x / tol)) {
// Contain the event data in a closure.
_clickTimeout = window.setTimeout(
function () {
_clickTimeout = null;
m.removeLayer(point);
addMarker(e);
}, 300);
}
return onUp;
}
function addMarker(e) {
var pos = MM.getMousePoint(e, m);
var l = m.pointLocation(pos);
// Create and add marker layer
point = mapbox.markers.layer().features([{
'geometry': {
'type': 'Point',
'coordinates': [l.lon, l.lat]
},
'properties': {
'image': './img/feedback-point.png'
}
}]).factory(function (f) {
var mark = document.createElement('div');
mark.className = 'marker';
var img = document.createElement('img');
img.className = 'marker-point';
img.setAttribute('src', f.properties.image);
mark.appendChild(img)
// center the map on where it was selected.
m.ease.location({
lat: l.lat,
lon: l.lon
}).zoom(m.zoom()).optimal();
return mark;
});
m.addLayer(point);
// Here put the coordinates in field Latitud and Longitud
$('#entry_1350527290').attr('value', l.lat.toFixed(5));
$('#entry_1394268219').attr('value', l.lon.toFixed(5));
}
});