This repository was archived by the owner on Jul 17, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSwarmOnline.MyMap.js
143 lines (120 loc) · 4.7 KB
/
SwarmOnline.MyMap.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
Ext.ns('SwarmOnline');
Ext.regModel('Location', {
fields: [{
name: 'lat',
type: 'float'
}, {
name: 'lng',
type: 'float'
}, {
name: 'distance',
type: 'float'
}]
});
SwarmOnline.MyMap = Ext.extend(Ext.Map, {
markerCache: new Ext.util.MixedCollection(),
loadCount: 1,
initComponent: function(){
this.store = new Ext.data.Store({
model: 'Location',
proxy: {
type: 'ajax',
url: 'server/search.php',
reader: {
type: 'json',
root: 'result'
}
}
});
this.store.on({
load: function(store, records, successful){
if (successful) {
this.loadCount = this.loadCount + 1;
for (var i = 0; i < records.length; i++) {
var record = records[i];
// only add markers that haven't already been added
if (!this.markerExists(record.data.lat, record.data.lng)) {
// cache the latest position so it isn't re-added later
this.markerCache.add({
lat: record.data.lat,
lng: record.data.lng
});
var markerPos = new google.maps.LatLng(record.data.lat, record.data.lng);
// add the marker
var marker = new google.maps.Marker({
map: this.map,
position: markerPos,
icon: 'http://www.swarmonline.com/wp-content/uploads/TutorialFiles/Demos/Ext.ux.touch.MapLoader/icons/black' + ((this.loadCount < 10) ? '0' + this.loadCount : this.loadCount) + '.png'
});
}
}
}
},
scope: this
});
Ext.apply(this, {
plugins: [new Ext.ux.touch.MapLoader({
store: this.store
})],
centered: true,
mapOptions: {
center: new google.maps.LatLng(55.857809, -4.242511),
zoom: 17
},
listeners: {
//mapload: this.doLoadPoints,
scope: this
}
});
SwarmOnline.MyMap.superclass.initComponent.call(this);
},
doLoadPoints: function(centre, bounds, boundingRadius, bufferRadius, zoom){
this.loadCount = this.loadCount + 1;
Ext.Ajax.request({
url: 'server/search.php',
method: 'get',
params: {
centre: Ext.encode(centre),
bounds: Ext.encode(bounds),
boundingRadius: boundingRadius,
bufferRadius: bufferRadius,
zoom: zoom
},
success: function(response){
var jsonResponse = Ext.decode(response.responseText);
if (jsonResponse.result) {
for (var i = 0; i < jsonResponse.result.length; i++) {
var resultPos = jsonResponse.result[i];
if (!this.markerExists(resultPos.lat, resultPos.lng)) {
this.markerCache.add({
lat: resultPos.lat,
lng: resultPos.lng
});
var pos = new google.maps.LatLng(resultPos.lat, resultPos.lng);
var marker = new google.maps.Marker({
map: this.map,
position: pos,
icon: 'http://www.stuartashworth.com/SenchaTouch/Plugins%20&%20Extensions/Ext.ux.touch.MapLoader/icons/black' + ((this.loadCount < 10) ? '0' + this.loadCount : this.loadCount) + '.png'
});
}
}
}
},
scope: this
});
},
/**
* Check if the passed in position has already been added
* @param {Object} lat
* @param {Object} lng
*/
markerExists: function(lat, lng){
var exists = false;
this.markerCache.each(function(item){
if (item.lat === lat && item.lng === lng) {
exists = true;
}
}, this);
return exists;
}
});