"...ist-git@git.uwaterloo.ca:shlomist/unionized-triangles.git" did not exist on "3d0ec474255c00a6156cab75ef95797ea99693c5"
Newer
Older
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
/* $Id$ */
/**
* GIcon manager for GMap.
*
* Required for markers to operate properly.
*/
/**
* Get the GIcon corresponding to a setname / sequence.
* There is only one GIcon for each slot in the sequence.
* The marker set wraps around when reaching the end of the sequence.
* @@@ TODO: Move this directly into the preparemarker event binding.
*/
Drupal.gmap.getIcon = function(setname, sequence) {
var othimg = ['printImage','mozPrintImage','printShadow','transparent'];
// If no setname, return google's default icon.
if (!setname) {
return G_DEFAULT_ICON;
}
if (!this.gicons) {
this.gicons = {};
}
// If no sequence, synthesise one.
if (!sequence) {
// @TODO make this per-map.
if (!this.sequences) {
this.sequences = {};
}
if (!this.sequences[setname]) {
this.sequences[setname] = -1;
}
this.sequences[setname]++;
sequence = this.sequences[setname];
}
if (!this.gicons[setname]) {
if (!Drupal.gmap.icons[setname]) {
alert('Request for invalid marker set '+setname+'!');
}
this.gicons[setname] = [];
var q = Drupal.gmap.icons[setname];
Brandon Bergren
committed
var p, t;
for (var i=0; i<q.sequence.length; i++) {
Brandon Bergren
committed
t = new GIcon();
p = Drupal.gmap.iconpath + q.path;
Brandon Bergren
committed
if (q.shadow.f !== '') {
t.shadow = p + q.shadow.f;
t.shadowSize = new GSize(q.shadow.w, q.shadow.h);
}
t.iconSize = new GSize(q.sequence[i].w,q.sequence[i].h);
t.iconAnchor = new GPoint(q.anchorX, q.anchorY);
t.infoWindowAnchor = new GPoint(q.infoX, q.infoY);
for (var j=0; j<othimg.length; j++) {
Brandon Bergren
committed
if (q[othimg[j]] !== '') {
t[othimg[j]] = p + q[othimg[j]];
}
}
// @@@ imageMap?
this.gicons[setname][i] = t;
}
delete Drupal.gmap.icons[setname];
}
// TODO: Random, other cycle methods.
return this.gicons[setname][sequence % this.gicons[setname].length];
};
/**
* JSON callback to set up the icon defs.
* When doing the JSON call, the data comes back in a packed format.
* We need to expand it and file it away in a more useful format.
*/
Drupal.gmap.iconSetup = function() {
Drupal.gmap.icons = {};
var m = Drupal.gmap.icondata;
Brandon Bergren
committed
var filef, filew, fileh, files;
for (var path in m) {if (m.hasOwnProperty(path)) {
Brandon Bergren
committed
filef = m[path].f;
filew = Drupal.gmap.expandArray(m[path].w,filef.length);
fileh = Drupal.gmap.expandArray(m[path].h,filef.length);
files = [];
for (var i = 0; i < filef.length; i++) {
files[i] = {f : filef[i], w : filew[i], h : fileh[i]};
}
Brandon Bergren
committed
for (var ini in m[path].i) {if (m[path].i.hasOwnProperty(ini)) {
$.extend(Drupal.gmap.icons,Drupal.gmap.expandIconDef(m[path].i[ini],path,files));
Brandon Bergren
committed
}}
}}
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
};
/**
* Expand a compressed array.
* This will pad arr up to len using the last value of the old array.
*/
Drupal.gmap.expandArray = function(arr,len) {
var d = arr[0];
for (var i=0; i<len; i++) {
if (!arr[i]) {
arr[i] = d;
}
else {
d = arr[i];
}
}
return arr;
};
/**
* Expand icon definition.
* This helper function is the reverse of the packer function found in
* gmap_markerinfo.inc.
*/
Drupal.gmap.expandIconDef = function(c,path,files) {
var decomp = ['key','name','sequence','anchorX','anchorY','infoX','infoY','shadow',
'printImage','mozPrintImage','printShadow','transparent'];
var fallback = ['','',[],0,0,0,0,{f: '', h: 0, w: 0},'','','',''];
var imagerep = ['shadow','printImage','mozPrintImage','printShadow','transparent'];
var defaults = {};
var sets = [];
var i, j;
// Part 1: Defaults / Markersets
// Expand arrays and fill in missing ones with fallbacks
for (i = 0; i < decomp.length; i++) {
if (!c[0][i]) {
c[0][i] = [ fallback[i] ];
}
c[0][i] = Drupal.gmap.expandArray(c[0][i],c[0][0].length);
}
for (i = 0; i < c[0][0].length; i++) {
for (j = 0; j < decomp.length; j++) {
Brandon Bergren
committed
if (i === 0) {
defaults[decomp[j]] = c[0][j][i];
}
else {
if (!sets[i-1]) {
sets[i-1] = {};
}
sets[i-1][decomp[j]] = c[0][j][i];
}
}
}
for (i = 0; i < sets.length; i++) {
for (j = 0; j < decomp.length; j++) {
Brandon Bergren
committed
if (sets[i][decomp[j]] === fallback[j]) {
sets[i][decomp[j]] = defaults[decomp[j]];
}
}
}
var icons = {};
for (i = 0; i < sets.length; i++) {
var key = sets[i].key;
icons[key] = sets[i];
icons[key].path = path;
delete icons[key].key;
delete sets[i];
for (j = 0; j < icons[key].sequence.length; j++) {
icons[key].sequence[j] = files[icons[key].sequence[j]];
}
for (j = 0; j < imagerep.length; j++) {
Brandon Bergren
committed
if (typeof(icons[key][imagerep[j]])==='number') {
icons[key][imagerep[j]] = files[icons[key][imagerep[j]]];
}
}
}
return icons;
};
/**
* We attach ourselves if we find a map somewhere needing markers.
* Note: Since we broadcast our ready event to all maps, it doesn't
* matter which one we attached to!
*/
Drupal.gmap.addHandler('gmap', function(elem) {
var obj = this;
obj.bind('init', function() {
// Only expand once.
if (!Drupal.gmap.icons) {
Drupal.gmap.iconSetup();
}
});
obj.bind('ready', function() {
// Compatibility event.
if (Drupal.gmap.icondata) {
obj.deferChange('iconsready', -1);
}