-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
138 lines (122 loc) · 4.94 KB
/
main.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
function l(l){
console.log(l);
}
var mapObj = {
readyState : false,
map : {},
markerLayer_self : {},
m_interaction : {},
usr_changing_coords : false,
usr_track_position : true,
map_div : 'mapDiv',
map_div_dimensions : {width:$(document).width(),height:$(document).height()},
curCoords : {},
viewCoords : {},
curZoom : 17,
features_self : [{
"geometry": { "type": "Point", "coordinates": [0, 0]},
"properties": {
'marker-color': '#f63a39',
'marker-symbol': 'pitch',
'marker-size': 'medium', }
}],
initmap : function(){
console.log($(document).width())
this.curCoords.lat=0;
this.curCoords.lon=0;
this.map = mapbox.map(this.map_div,false,{x:this.map_div_dimensions.width,y:this.map_div_dimensions.height}).zoom(this.curZoom).center({ lat: 0, lon: 0 });
this.markerLayer_self = mapbox.markers.layer().features(this.features_self) .key(function(f) { return f.properties.id;});;
this.m_interaction = mapbox.markers.interaction(this.markerLayer_self);
/*this.m_interaction.formatter(function(feature) {
var o = '<a target="_blank" href="' + feature.properties.url + '">' +
'<img src="' + feature.properties.image + '">' +
'<h2>' + feature.properties.city + '</h2>' +
'</a>';
return o;
});*/
this.map.addLayer(mapbox.layer().id('shmatul.map-tuk5ly8t'));
this.map.addLayer(this.markerLayer_self);
this.map.setZoomRange(16, 18);
this.map.smooth(false);
this.map.addCallback("panned", function(map, panOffset) {mapObj.usr_panning();});
this.map.addCallback("zoomed", function(map, panOffset) {mapObj.usr_panning();});
},
SetCurrentGPSLocation : function(lat,lon){
console.log("Setting current GPS location. "+lat+","+lon);
//simulate movement form latest point? later on
this.features_self[0].geometry.coordinates[0] = lon;
this.features_self[0].geometry.coordinates[1] = lat;
this.markerLayer_self.features(this.features_self);
this.curCoords.lat = lat;
this.curCoords.lon = lon;
if (this.usr_track_position==true){
this.map.center({ 'lat': lat, 'lon': lon },false);
this.viewCoords.lon = this.curCoords.lon;
this.viewCoords.lat = this.curCoords.lat;
}
},
simulateMovement: function(newLon,newLat)
{
//console.log(newLon);
//console.log(this function sucked);
},
usr_panning : function(){
this.usr_track_position = false;
if (this.usr_changing_coords == false)
{
this.usr_changing_coords = true;
setTimeout(function(){mapObj.usr_changing_coords_f()},500);
}
},
usr_changing_coords_f : function()
{
//function to determine when user finished panning/zooming/w.e to retrieve new parking slots according to panned area
newCoords = this.map.getCenter();
newZoom = this.map.getZoom();
if ((newCoords.lan == this.viewCoords.lan) && (newCoords.lon == this.viewCoords.lon) )
{
// usr_changing_coords = false;
l("done panning, fetching new parkings right now...");
this.usr_changing_coords = false;
console.log("current coords",this.curCoords,"viewcoors",this.viewCoords);
}
else
{
this.viewCoords.lat = newCoords.lat;
this.viewCoords.lon = newCoords.lon;
this.curZoom = newZoom;
$("#mapDiv_usr_tracking").show();
setTimeout(function(){mapObj.usr_changing_coords_f()},0);
}
},
reset_location :function()
{
this.usr_track_position = true;
$("#mapDiv_usr_tracking").hide();
this.SetCurrentGPSLocation(this.curCoords.lat,this.curCoords.lon);
}
}
function onDeviceReady(manual)
{
console.log("aaa");
$.mobile.loading( 'show' );
mapObj.initmap();
//curCoords = {lat:"32.066158",lon:'34.777819'}; s
//this is a timer for tracking position movement, needs to be validated(!!)
if (!manual)
{
var watchID = navigator.geolocation.watchPosition(function(position){
l("Got new position from gps");
console.log(position);
mapObj.SetCurrentGPSLocation(position.coords.latitude,position.coords.longitude);
}, function(error){
l(error);
alert("cannot find location!");
}, { frequency: 3000 });
}
else
mapObj.SetCurrentGPSLocation(32.573905,34.951977);
//var int=self.setInterval(function(){.html((mapObj.usr_track_position) ? "" : '<a href="" onclick="javascript:mapObj.usr_track_position=true;">Reset Location</a>');},100);
}
$(document).ready(function(){onDeviceReady(false);});
//document.addEventListener("deviceready",onDeviceReady,false);