-
Notifications
You must be signed in to change notification settings - Fork 0
/
map.js
107 lines (96 loc) · 2.54 KB
/
map.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
function mapGen(array) {
var i, j, x, y;
var coords = [];
var coordsF = [];
var svg = document.getElementById('mapSVG');
while (svg.firstChild) svg.removeChild(svg.firstChild);
//load external bg-images
//loadBG(svg, -63, 108, -61, 110);
/*
//draw all stands
for (i = 0; i < data.length; i++) {
x = data[i][10];
y = data[i][11];
var notInCoords = true;
for (j = 0; j < coords.length; j++) {
if ((coords[j][0] == x) && (coords[j][1] == y))
notInCoords = false;
}
if (notInCoords)
coords.push([x, y]);
}
for (i = 0; i < coords.length; i++) {
var newMarkX = coords[i][0]*modx+offx;
var newMarkY = coords[i][1]*mody+offy;
mapAddMark(svg, "rect", newMarkX, newMarkY, 1.5, "SVGstandInactive");
}
*/
for (i = 0; i < array.length; i++) {
if( array[i][13] ) continue;
x = array[i][10];
y = array[i][11];
var notInCoords = true;
for (j = 0; j < coordsF.length; j++) {
if ((coordsF[j][0] == x) && (coordsF[j][1] == y))
notInCoords = false;
}
if (notInCoords)
coordsF.push([x, y]);
}
for (i = 0; i < coordsF.length; i++) {
var newMarkX = (coordsF[i][0]-fixx)*modx+offx;
var newMarkY = (coordsF[i][1]-fixy)*mody+offy;
mapAddMark(svg, "rect", newMarkX, newMarkY, 1.5, "SVGstand");
}
}
function loadBG(svg, sx, sy, ex, ey)
{
var x, y;
if (sx > ex) {
var a = ex;
ex = sx;
sx = a;
}
if (sy > ey) {
var a = ey;
ey = sy;
sy = a;
}
for (x = sx; x <= ex; x++){
for (y = sy; y <= ey; y++){
var bgImg = document.createElementNS(ns, 'image');
bgImg.setAttribute('href', 'http://www.odditown.com:8080/haven/tiles/live/9/'+x+'_'+y+'.png');
bgImg.setAttribute('width', '100px');
bgImg.setAttribute('height', '100px');
bgImg.setAttribute('x', (x-sx)*100);
bgImg.setAttribute('y', (y-sy)*100);
//bgImg.setAttribute('opacity','0.3');
svg.appendChild(bgImg);
}
}
}
function mapAddMark (svg, type, mx, my, r, elementClass)
{
switch (type){
case "circle" :
var mark = document.createElementNS(ns, 'circle');
mark.setAttribute('cx', mx);
mark.setAttribute('cy', my);
mark.setAttribute('r', r);
break;
case "rect" :
var mark = document.createElementNS(ns, 'rect');
mark.setAttribute('x', Math.round(mx-r));
mark.setAttribute('y', Math.round(my-r));
mark.setAttribute('width', r*2);
mark.setAttribute('height', r*2);
break;
default:
var mark = document.createElementNS(ns, 'circle');
mark.setAttribute('cx', mx);
mark.setAttribute('cy', my);
mark.setAttribute('r', 1);
}
mark.setAttribute('class', elementClass);
svg.appendChild(mark);
}