This repository has been archived by the owner on Jan 24, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmap.php
executable file
·210 lines (177 loc) · 5.87 KB
/
map.php
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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
<?php
/*
* AMP Data Display Interface
*
* Map display
*
* Author: Tony McGregor <[email protected]>
* Author: Jeremy Kallstrom <[email protected]>
* Version: $Id: map.php 1712 2010-03-10 22:19:05Z brendonj $
*/
//---------------------------------------------------------------------------
function findFreeSpot(&$x, &$y)
{
global $relocateX, $relocateY, $gridSize, $mapSize, $grid;
$x = (int)($x / $gridSize);
$y = (int)($y / $gridSize);
$attempt = 0;
$layer = 1;
$tryX = $x;
$tryY = $y;
while ( $tryX < 0 || $tryX > $mapSize[0] ||
$tryY < 0 || $tryY > $mapSize[0] ||
$grid[$tryX][$tryY] ) {
$tryX = $x + ($relocateX[$attempt] * $layer);
$tryY = $y + ($relocateY[$attempt] * $layer);
if ( $attempt < 7 ) {
$attempt++;
} else {
$attempt = 0;
$layer++;
}
}
$grid[$tryX][$tryY] = TRUE;
$x = $tryX * $gridSize;
$y = $tryY * $gridSize;
}
//---------------------------------------------------------------------------
// Display the selected map
if ($map != "") {
$relocateX = array(1, -1, 0, 0, 1, -1, -1, 1);
$relocateY = array(0, 0, -1, 1, -1, 1, -1, 1);
require $map . "_map_info.php";
$fileName = cacheFileName("map", $map, $src, $dst, "", "", $cached);
flush();
if (!$cached) {
$mapImage = imagecreatefromjpeg($map . ".jpg");
if (!$mapImage) {
graphError("Could not create map image");
}
$mapSize = getimagesize($map . ".jpg");
$starColour = imagecolorallocate($mapImage, $starRGB[0], $starRGB[1],
$starRGB[2]);
$selectedStarColour = imagecolorallocate($mapImage, $selectedStarRGB[0],
$selectedStarRGB[1], $selectedStarRGB[2]);
$xScale = $mapSize[0] / ($mapRight - $mapLeft);
$yScale = $mapSize[1] / ($mapBottom - $mapTop);
for ($x = 0; $x < (int)($mapSize[0] / $gridSize); $x++) {
for ($y = 0; $y < (int)($mapSize[0] / $gridSize); $y++) {
$grid[$x][$y] = FALSE;
}
}
$siteDb = dbconnect($GLOBALS[sitesDB]);
if (!$siteDb) {
page_error("Could not connect to webusers database. " .
"Please try again later.");
}
echo "<map name=\"map\">\n";
if ($src != "") {
$srcs = ampSiteList($src);
sort($srcs->srcNames);
}
if ( !$mesh || $mesh == "Any" ) {
$query = 'SELECT ampname, longname, mapx, mapy FROM sites';
} else {
$query = "select ampname, longname, mapx, mapy from srclistview where meshname = '$mesh'";
}
$result = queryAndCheckDB($siteDb, $query);
$rows = $result{'rows'};
for ($rowNum = 0; $rowNum < $rows; ++$rowNum) {
$row = $result{'results'}[$rowNum];
if ( $row['mapx'] == -200 && $row['mapy'] == -200 ) {
continue;
}
if ( $row['mapx'] == -201 && $row['mapy'] == -201 ) {
continue;
}
$xOffset = ($row['mapx'] - $mapLeft) * $xScale;
$yOffset = ($row['mapy']- $mapTop) * $yScale;
if ( $xOffset < 0 || $xOffset > $mapSize[0] ||
$yOffset < 0 || $yOffset > $mapSize[1] ) {
continue;
}
findFreeSpot($xOffset, $yOffset);
for ($point = 0; $point < ($starPoints * 2); $point += 2) {
$aStar[$point] = (int)(($star[$point ] / $starSize) +0.5) +
$xOffset;
$aStar[$point+1]=(int)(($star[$point+1] / $starSize) +0.5) +
$yOffset;
}
if ($row['ampname'] == $src) {
imagefilledpolygon($mapImage, $aStar, $starPoints,
$selectedStarColour);
} else {
imagefilledpolygon($mapImage, $aStar, $starPoints,
$starColour);
}
$gridOffset = (int)($gridSize / 2);
$link = "";
if ($src == "") {
$link = "src.php?src=" . urlencode($row['ampname']) . "&map=".urlencode($map);
} else {
if (in_array($row['ampname'], $srcs->srcNames)) {
$numWeeks = get_preference(PREF_GLOBAL, GP_LT_NUM_WEEKS, PREF_GLOBAL);
$link = "graph.php?src=$src&dst=" . urlencode($row['ampname']) .
"&rge=".urlencode($numWeeks)."-week";
}
}
if ($link != "") {
$current_site = htmlspecialchars($row["longname"]) . "(" . htmlspecialchars($row["ampname"]) . ")";
echo '<area href="'.htmlspecialchars($link).'" shape="circle"';
echo " coords=\"" . ($xOffset + $gridOffset) . ",";
echo $yOffset + $gridOffset . ",$gridSize\" alt=\"";
echo htmlspecialchars($row['ampname']) . "\" OnMouseOver=\"window.status='$current_site'; return true\" OnMouseOut=\"window.status=''; return true\" title=\"$current_site\">\n";
}
}
echo "</map>\n";
imagejpeg($mapImage, $fileName);
} //if not cached
if ($src=="") {
$type = "source";
} else {
$type = "destination";
}
echo "Click on a star to select a $type<br>";
echo "<img src=\"$fileName\" alt=\"map\" usemap=\"#map\"";
if ( $mapXSize != "" ) {
echo " width=$mapXSize";
}
if ( $mapYSize != "" ) {
echo " height=$mapYSize";
}
echo "><br>\n";
} // if $map != ""
//---------------------------------------------------------------------------
// Display a list of available maps
$maps = array();
if ( $dir = opendir(".") ) {
while ( $fileName = readdir($dir) ) {
if ( substr($fileName, -13) != "_map_info.php" ) {
continue;
}
$maps[] = substr($fileName, 0, strlen($fileName) - 13);
}
closedir($dir);
}
if ( count($maps) > 0 ) {
echo "<div>Available Maps: ";
$get = str_replace("&", "&", $get);
$get = flatten($_GET);
if ( strlen($get) > 0 ) {
$get .= "&";
}
$get = str_replace("&", "&", $get);
for ( $i = 0; $i < count($maps) ; $i++ ) {
$mapName = $maps[$i];
if ($i > 1) {
echo "| ";
}
echo "<a href=\"src.php?${get}map=".htmlspecialchars($mapName)."\">".htmlspecialchars($mapName)."</a> \n";
}
echo "</div>";
}
// Emacs control
// Local Variables:
// eval: (c++-mode)
// vim:set sw=2 ts=2 sts=2 et:
?>