update map service

This commit is contained in:
j 2007-08-04 09:31:05 +00:00
parent 4d4f794fd0
commit 47785eff62
7 changed files with 77 additions and 20 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

80
map.php
View file

@ -1,14 +1,19 @@
<?php <?php
set_time_limit(0); set_time_limit(0);
error_reporting(0);
include('php/library.php'); include('php/library.php');
$id = str_pad($_GET['id'], 7, '0', STR_PAD_LEFT); $id = $_GET['id'];
if ($id == '')
die('map.php returns a map for a given IMDb id<br />usage: map.php?id=ID&q=QUERY<br />ID: IMDb id<br />QUERY: search term');
$id = str_pad($id, 7, '0', STR_PAD_LEFT);
$size = $_GET['size'];
if ($size != 'small')
$size = 'large';
$q = urldecode($_GET['q']); $q = urldecode($_GET['q']);
$q = htmlentities($q); $q = htmlentities($q);
if ($id == 0)
die('map.php returns a map for a given IMDb id<br />usage: map.php?id=ID&q=QUERY<br />ID: IMDb id<br />QUERY: search term');
$point = movie2locations($id); $point = movie2locations($id);
@ -75,10 +80,20 @@ if ($point) {
function load() { function load() {
if (GBrowserIsCompatible()) { if (GBrowserIsCompatible()) {
var map = new GMap2(document.getElementById("map"));
HTML;
echo "var map = new GMap2(document.getElementById('map'));\n";
if ($size == 'large') {
echo <<<HTML
map.addControl(new GLargeMapControl()); map.addControl(new GLargeMapControl());
map.addControl(new GMapTypeControl()); map.addControl(new GMapTypeControl());
// map.addControl(new GOverviewMapControl());
HTML;
}
echo <<<HTML
var baseIcon = new GIcon(); var baseIcon = new GIcon();
baseIcon.shadow = 'http://services.0xdb.org/maps/png/markerShadow.png'; baseIcon.shadow = 'http://services.0xdb.org/maps/png/markerShadow.png';
@ -116,8 +131,14 @@ HTML;
lngSpan = 360 - lngSpan; lngSpan = 360 - lngSpan;
// alert(spanLatitude + ' ' + spanLongitude + ' ' + zoom + ' ' + latSpan + ' ' + lngSpan); // alert(spanLatitude + ' ' + spanLongitude + ' ' + zoom + ' ' + latSpan + ' ' + lngSpan);
} }
HTML;
map.setMapType(G_HYBRID_MAP); if ($size == 'small')
echo 'map.setMapType(G_SATELLITE_MAP);' . "\n";
else
echo 'map.setMapType(G_HYBRID_MAP);' . "\n";
echo <<<HTML
function createMarker(point, marker, label) { function createMarker(point, marker, label) {
var icon = new GIcon(baseIcon); var icon = new GIcon(baseIcon);
@ -125,9 +146,20 @@ HTML;
var marker = new GMarker(point, icon); var marker = new GMarker(point, icon);
// label = label.replace(/ - /g, '<br />'); // label = label.replace(/ - /g, '<br />');
// label = label.replace(/, /g, '<br />'); // label = label.replace(/, /g, '<br />');
GEvent.addListener(marker, "click", function() { HTML;
marker.openInfoWindowHtml('<span style="font-family: Helvetica, Arial; font-size: 13px">' + label + '</span>');
}); if ($size == 'large') {
echo <<<HTML
GEvent.addListener(marker, "click", function() {
marker.openInfoWindowHtml('<span style="font-family: Helvetica, Arial; font-size: 13px">' + label + '</span>');
});
HTML;
}
echo <<<HTML
return marker; return marker;
} }
createMarkers(); createMarkers();
@ -202,7 +234,14 @@ HTML;
for (var i = 0; i < location.length; i++) { for (var i = 0; i < location.length; i++) {
var point = new GLatLng(latitude[i], longitude[i]); var point = new GLatLng(latitude[i], longitude[i]);
map.addOverlay(createMarker(point, marker[i], location[i] + '<br /><span style="font-size: 10px">' + description[i] + '</span><span style="font-size: 10px">' + coordinates[i] + '</span>')); HTML;
if ($size == 'small')
echo "map.addOverlay(createMarker(point, marker[i], ''))";
else
echo "map.addOverlay(createMarker(point, marker[i], location[i] + '<br /><span style=\"font-size: 10px\">' + description[i] + '</span><span style=\"font-size: 10px\">' + coordinates[i] + '</span>'));";
echo <<<HTML
} }
} }
@ -211,10 +250,16 @@ HTML;
</script> </script>
</head> </head>
<body onload="load()" onunload="GUnload()"> <body onload="load()" onunload="GUnload()">
<div id="map" style="width: 808px; height: 505px; background: rgb(0, 0, 0)"></div> HTML;
if ($size == 'small')
echo '<div id="map" style="width: 672px; height: 192px; background: rgb(0, 0, 0)"></div>';
else
echo '<div id="map" style="width:808px; height: 505px; background: rgb(0, 0, 0)"></div>';
echo <<<HTML
</body> </body>
</html> </html>
HTML; HTML;
} }
@ -234,9 +279,18 @@ else {
</style> </style>
</head> </head>
<body> <body>
<div id="map" style="width: 808px; height: 505px; background: url(png/map.png)"></div> HTML;
if ($size == 'small')
echo "<div id=\"map\" style=\"width: 672px; height: 192px; background: url(png/mapSmall.png)\"></div>";
else
echo "<div id=\"map\" style=\"width:808px; height: 505px; background: url(png/mapLarge.png)\"></div>";
echo <<<HTML
</body> </body>
</html> </html>
HTML; HTML;
} }

View file

@ -15,7 +15,8 @@ function movie2locations($id) {
$point = array(); $point = array();
$html = file_get_contents('http://imdb.com/title/tt' . $id . '/locations'); if (strlen($id) == 7)
$html = file_get_contents('http://imdb.com/title/tt' . $id . '/locations');
$string = explode('&&locations=', $html); $string = explode('&&locations=', $html);
for ($i = 1; $i < count($string); $i++) { for ($i = 1; $i < count($string); $i++) {
@ -69,9 +70,11 @@ function movie2locations($id) {
// $locations_[$id] = $locations[$id]; // $locations_[$id] = $locations[$id];
// $locations = $locations_; // $locations = $locations_;
ksort($locations); ksort($locations);
touch('data/locations.lock'); if (!file_exists('data/locations.lock')) {
file_put_contents($file, serialize($locations)); touch('data/locations.lock');
unlink('data/locations.lock'); file_put_contents($file, serialize($locations));
unlink('data/locations.lock');
}
} }

BIN
png/mapLarge.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.2 KiB

BIN
png/mapSmall.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.8 KiB