From: Maxious Date: Thu, 22 Sep 2011 11:31:21 +0000 Subject: Convert to Google static maps X-Git-Url: https://maxious.lambdacomplex.org/git/?p=busui.git&a=commitdiff&h=47e1f20167d4b1cf58bc8a4ae1b283749bfeac85 --- Convert to Google static maps --- --- a/aws/busuiphp.sh +++ b/aws/busuiphp.sh @@ -1,20 +1,12 @@ cp /root/aws.php /tmp/ chmod 777 /var/cache/lighttpd/compress/ -mkdir /var/www/lib/staticmaplite/cache chcon -h system_u:object_r:httpd_sys_content_t /var/www chcon -R -h root:object_r:httpd_sys_content_t /var/www/* - -chcon -R -t httpd_sys_content_rw_t /var/www/lib/staticmaplite/cache -chmod -R 777 /var/www/lib/staticmaplite/cache chcon -R -t httpd_sys_content_rw_t /var/www/labs/tiles chmod -R 777 /var/www/labs/tiles -mkdir /var/www/lib/openid-php/oid_store -chcon -R -t httpd_sys_content_rw_t /var/www/lib/openid-php/oid_store -chmod -R 777 /var/www/lib/openid-php/oid_store - wget http://s3-ap-southeast-1.amazonaws.com/busresources/cbrfeed.zip \ -O /var/www/cbrfeed.zip --- a/css/local.css.php +++ b/css/local.css.php @@ -1,13 +1,15 @@ --- a/include/common-geo.inc.php +++ b/include/common-geo.inc.php @@ -18,58 +18,49 @@ // SELECT array_to_string(array(SELECT REPLACE(name_2006, ',', '\,') as name FROM suburbs order by name), ',') $suburbs = explode(",", "Acton,Ainslie,Amaroo,Aranda,Banks,Barton,Belconnen,Bonner,Bonython,Braddon,Bruce,Calwell,Campbell,Chapman,Charnwood,Chifley,Chisholm,City,Conder,Cook,Curtin,Deakin,Dickson,Downer,Duffy,Dunlop,Evatt,Fadden,Farrer,Fisher,Florey,Flynn,Forrest,Franklin,Fraser,Fyshwick,Garran,Gilmore,Giralang,Gordon,Gowrie,Greenway,Griffith,Gungahlin,Hackett,Hall,Harrison,Hawker,Higgins,Holder,Holt,Hughes,Hume,Isaacs,Isabella Plains,Kaleen,Kambah,Kingston,Latham,Lawson,Lyneham,Lyons,Macarthur,Macgregor,Macquarie,Mawson,McKellar,Melba,Mitchell,Monash,Narrabundah,Ngunnawal,Nicholls,Oaks Estate,O'Connor,O'Malley,Oxley,Page,Palmerston,Parkes,Pearce,Phillip,Pialligo,Red Hill,Reid,Richardson,Rivett,Russell,Scullin,Spence,Stirling,Symonston,Tharwa,Theodore,Torrens,Turner,Wanniassa,Waramanga,Watson,Weetangera,Weston,Yarralumla"); -function staticmap($mapPoints, $zoom = 0, $markerImage = "iconb", $collapsible = true, $twotone = false) { - global $basePath; - $width = 300; +function staticmap($mapPoints, $collapsible = true, $twotone = false, $path = false, $numbered = false) { + + $markers = ""; $height = 300; - $metersperpixel[9] = 305.492 * $width; - $metersperpixel[10] = 152.746 * $width; - $metersperpixel[11] = 76.373 * $width; - $metersperpixel[12] = 38.187 * $width; - $metersperpixel[13] = 19.093 * $width; - $metersperpixel[14] = 9.547 * $width; - $metersperpixel[15] = 4.773 * $width; - //$metersperpixel[16] = 2.387 * $width; - // $metersperpixel[17]=1.193*$width; - $center = ""; - $markers = ""; - $mapwidthinmeters = 50; + $width = $height; + $index = 0; if (sizeof($mapPoints) < 1) return "map error"; if (sizeof($mapPoints) === 1) { - if ($zoom == 0) - $zoom = 14; - $markers.= "{$mapPoints[0][0]},{$mapPoints[0][1]},$markerimage"; - $center = "{$mapPoints[0][0]},{$mapPoints[0][1]}"; - } - else { + $markers = "markers={$mapPoints[0][0]},{$mapPoints[0][1]}"; + } else { + if (!$numbered) { + $markers = "markers="; + } + if ($path) { + $markers.= "markers={$mapPoints[0][0]},{$mapPoints[0][1]}&path="; + } foreach ($mapPoints as $index => $mapPoint) { if ($twotone && $index == 0) { - $markers.= $mapPoint[0] . "," . $mapPoint[1] . "," . "iconr" . ($index + 1); - $center = "{$mapPoints[0][0]},{$mapPoints[0][1]}"; + $markers = "markerd=color:red|".$mapPoint[0] . "," . $mapPoint[1]."&markers="; } else { - $markers.= $mapPoint[0] . "," . $mapPoint[1] . "," . $markerImage . ($index + 1); - } - if ($index + 1 != sizeof($mapPoints)) - $markers.= "|"; - $dist = distance($mapPoints[0][0], $mapPoint[0][1], $mapPoint[0], $mapPoint[1]); - $mapwidthinmeters = ($dist > $mapwidthinmeters ? $dist : $mapwidthinmeters); - $totalLat+= $mapPoint[0]; - $totalLon+= $mapPoint[1]; - } - if ($zoom == 0) { - $mapwidthinmeters = distance($minlat, $minlon, $minlat, $maxlon); - foreach (array_reverse($metersperpixel, true) as $zoomLevel => $maxdistance) { - if ($zoom == 0 && $mapwidthinmeters * 1.5 < ($maxdistance)) - $zoom = $zoomLevel; + if ($numbered) { + $label = ($index > 9 ? 9 : $index); + $markers.= "markers=label:$label|" . $mapPoint[0] . "," . $mapPoint[1]; + if ($index + 1 != sizeof($mapPoints)) { + $markers.= "&"; + } + } else { + $markers.= $mapPoint[0] . "," . $mapPoint[1]; + if ($index + 1 != sizeof($mapPoints)) { + $markers.= "|"; + } + } + $index++; } } - $center = $totalLat / sizeof($mapPoints) . "," . $totalLon / sizeof($mapPoints); } $output = ""; if ($collapsible) $output.= '

Open Map...

'; - $output.= ''; + if (isIOSDevice()) $output.= ''; + else $output.= ''; + if ($collapsible) $output.= '
'; return $output; --- a/include/common-template.inc.php +++ b/include/common-template.inc.php @@ -103,7 +103,7 @@ }'; echo ''; echo ''; - if (strstr($_SERVER['HTTP_USER_AGENT'], 'iPhone') || strstr($_SERVER['HTTP_USER_AGENT'], 'iPod') || strstr($_SERVER['HTTP_USER_AGENT'], 'iPad')) { + if (isIOSDevice()){ echo ' --- a/include/common.inc.php +++ b/include/common.inc.php @@ -83,31 +83,15 @@ if (isDebug($debugReason)) echo "\n\n"; } - +function isIOSDevice() { + return strstr($_SERVER['HTTP_USER_AGENT'], 'iPhone') || strstr($_SERVER['HTTP_USER_AGENT'], 'iPod') || strstr($_SERVER['HTTP_USER_AGENT'], 'iPad'); +} function isJQueryMobileDevice() { // http://forum.jquery.com/topic/what-is-the-best-way-to-detect-all-useragents-which-can-handle-jquery-mobile#14737000002087897 $user_agent = $_SERVER['HTTP_USER_AGENT']; return preg_match('/iphone/i', $user_agent) || preg_match('/android/i', $user_agent) || preg_match('/webos/i', $user_agent) || preg_match('/ios/i', $user_agent) || preg_match('/bada/i', $user_agent) || preg_match('/maemo/i', $user_agent) || preg_match('/meego/i', $user_agent) || preg_match('/fennec/i', $user_agent) || (preg_match('/symbian/i', $user_agent) && preg_match('/s60/i', $user_agent) && $browser['majorver'] >= 5) || (preg_match('/symbian/i', $user_agent) && preg_match('/platform/i', $user_agent) && $browser['majorver'] >= 3) || (preg_match('/blackberry/i', $user_agent) && $browser['majorver'] >= 5) || (preg_match('/opera mobile/i', $user_agent) && $browser['majorver'] >= 10) || (preg_match('/opera mini/i', $user_agent) && $browser['majorver'] >= 5); } -function isFastDevice() { - $ua = $_SERVER['HTTP_USER_AGENT']; - $fastDevices = Array( - "Mozilla/5.0 (X11;", - "Mozilla/5.0 (Windows;", - "Mozilla/5.0 (iP", - "Mozilla/5.0 (Linux; U; Android", - "Mozilla/4.0 (compatible; MSIE" - ); - $slowDevices = Array( - "J2ME", - "MIDP", - "Opera/", - "Mozilla/2.0 (compatible;", - "Mozilla/3.0 (compatible;" - ); - return true; -} function array_flatten($a, $f = array()) { if (!$a || !is_array($a)) --- a/labs/stop.pdf.php +++ b/labs/stop.pdf.php @@ -34,7 +34,7 @@ $stop[2], $stop[3] ) - ), 0, "iconb", false) . ""; + ), 0, false) . ""; $url = $APIurl . "/json/stoptrips?stop=" . $stopid . "&time=" . midnight_seconds() . "&service_period=" . service_period(); $trips = json_decode(getPage($url)); $html.= "

"; --- a/lib/autocomplete.php +++ b/lib/autocomplete.php @@ -3,7 +3,7 @@ $result = Array(); if (isset($_REQUEST['term'])) { $term = filter_var($_REQUEST['term'], FILTER_SANITIZE_STRING); - $query = "Select stop_name,min(stop_lat) as stop_lat,min(stop_lon) as stop_lon from stops where stop_name LIKE :term group by stop_name"; + $query = "Select stop_name,min(stop_lat) as stop_lat,min(stop_lon) as stop_lon from stops where stop_name ILIKE :term group by stop_name"; $query = $conn->prepare($query); $term = "$term%"; $query->bindParam(":term", $term); --- a/lib/staticmaplite/.gitignore +++ /dev/null @@ -1,4 +1,1 @@ -cache/tiles -cache/map -cache/maps --- a/lib/staticmaplite/images/markers/GPlotter - Make Google Maps Easily.URL +++ /dev/null @@ -1,3 +1,1 @@ -[InternetShortcut] -URL=http://gplotter.offwhite.net/ --- a/lib/staticmaplite/images/markers/Google Maps Icons, Free!.URL +++ /dev/null @@ -1,3 +1,1 @@ -[InternetShortcut] -URL=http://brennan.offwhite.net/blog/2005/07/23/new-google-maps-icons-free/ --- a/lib/staticmaplite/index.html +++ /dev/null @@ -1,122 +1,1 @@ - - - - - - staticMapLite - - - -
- -
- -
-

- staticMapLite - simple map for your website -

-

-

-

- This image was created using the following simple <img> tag: -

<img src="staticmap.php?center=40.714728,-73.998672&zoom=14&size=865x512&maptype=mapnik" />
-

-
-
-
-

- Place Markers -

- -

- -

Add markers by appending them to the image URL: -

markers=40.702147,-74.015794,lightblue1|40.711614,-74.012318,lightblue2|40.718217,-73.998284,lightblue3
-

-
-
-
-

- Use Different Map Styles (Tile Sources) -

- -

-

- -
maptype=mapnik
-
-
- -
maptype=osmarenderer
-
-
- -
maptype=cycle
-
-
-

-
- -
- -
- - --- a/lib/staticmaplite/selinux-fix.sh +++ /dev/null @@ -1,3 +1,1 @@ -chcon -R -t httpd_sys_content_rw_t cache - --- a/lib/staticmaplite/staticmap.php +++ /dev/null @@ -1,273 +1,1 @@ - - * - * USAGE: - * - * staticmap.php?center=40.714728,-73.998672&zoom=14&size=512x512&maptype=mapnik&markers=40.702147,-74.015794,blues|40.711614,-74.012318,greeng|40.718217,-73.998284,redc - * - */ - -error_reporting(0); -ini_set('display_errors','off'); - -Class staticMapLite { - - protected $tileSize = 256; - protected $tileSrcUrl = array( 'mapnik' => 'http://tile.openstreetmap.org/{Z}/{X}/{Y}.png', - 'cloudmade' => 'http://b.tile.cloudmade.com/daa03470bb8740298d4b10e3f03d63e6/1/256/{Z}/{X}/{Y}.png',); - - protected $tileDefaultSrc = 'cloudmade'; - protected $markerBaseDir = 'images/markers'; - protected $osmLogo = 'images/osm_logo.png'; - - protected $useTileCache = true; - protected $tileCacheBaseDir = './cache/tiles'; - - protected $useMapCache = true; - protected $mapCacheBaseDir = './cache/maps'; - protected $mapCacheID = ''; - protected $mapCacheFile = ''; - protected $mapCacheExtension = 'png'; - - protected $zoom, $lat, $lon, $width, $height, $markers, $image, $maptype; - protected $centerX, $centerY, $offsetX, $offsetY; - - public function __construct(){ - $this->zoom = 0; - $this->lat = 0; - $this->lon = 0; - $this->width = 500; - $this->height = 350; - $this->markers = array(); - $this->maptype = $this->tileDefaultSrc; - } - - public function parseParams(){ - global $_GET; - - // get zoom from GET paramter - $this->zoom = $_GET['zoom']?intval($_GET['zoom']):0; - if($this->zoom>18)$this->zoom = 18; - - // get lat and lon from GET paramter - list($this->lat,$this->lon) = split(',',$_GET['center']); - $this->lat = floatval($this->lat); - $this->lon = floatval($this->lon); - - // get zoom from GET paramter - if($_GET['size']){ - list($this->width, $this->height) = split('x',$_GET['size']); - $this->width = intval($this->width); - $this->height = intval($this->height); - } - if($_GET['markers']){ - $markers = split('%7C|\|',$_GET['markers']); - foreach($markers as $marker){ - list($markerLat, $markerLon, $markerImage) = split(',',$marker); - $markerLat = floatval($markerLat); - $markerLon = floatval($markerLon); - $markerImage = basename($markerImage); - $this->markers[] = array('lat'=>$markerLat, 'lon'=>$markerLon, 'image'=>$markerImage); - } - - } - if($_GET['maptype']){ - if(array_key_exists($_GET['maptype'],$this->tileSrcUrl)) $this->maptype = $_GET['maptype']; - } - } - - public function lonToTile($long, $zoom){ - return (($long + 180) / 360) * pow(2, $zoom); - } - - public function latToTile($lat, $zoom){ - return (1 - log(tan($lat * pi()/180) + 1 / cos($lat* pi()/180)) / pi()) /2 * pow(2, $zoom); - } - - public function initCoords(){ - $this->centerX = $this->lonToTile($this->lon, $this->zoom); - $this->centerY = $this->latToTile($this->lat, $this->zoom); - $this->offsetX = floor((floor($this->centerX)-$this->centerX)*$this->tileSize); - $this->offsetY = floor((floor($this->centerY)-$this->centerY)*$this->tileSize); - } - - public function createBaseMap(){ - $this->image = imagecreatetruecolor($this->width, $this->height); - $startX = floor($this->centerX-($this->width/$this->tileSize)/2); - $startY = floor($this->centerY-($this->height/$this->tileSize)/2); - $endX = ceil($this->centerX+($this->width/$this->tileSize)/2); - $endY = ceil($this->centerY+($this->height/$this->tileSize)/2); - $this->offsetX = -floor(($this->centerX-floor($this->centerX))*$this->tileSize); - $this->offsetY = -floor(($this->centerY-floor($this->centerY))*$this->tileSize); - $this->offsetX += floor($this->width/2); - $this->offsetY += floor($this->height/2); - $this->offsetX += floor($startX-floor($this->centerX))*$this->tileSize; - $this->offsetY += floor($startY-floor($this->centerY))*$this->tileSize; - - for($x=$startX; $x<=$endX; $x++){ - for($y=$startY; $y<=$endY; $y++){ - $url = str_replace(array('{Z}','{X}','{Y}'),array($this->zoom, $x, $y), $this->tileSrcUrl[$this->maptype]); - $tileImage = imagecreatefromstring($this->fetchTile($url)); - $destX = ($x-$startX)*$this->tileSize+$this->offsetX; - $destY = ($y-$startY)*$this->tileSize+$this->offsetY; - imagecopy($this->image, $tileImage, $destX, $destY, 0, 0, $this->tileSize, $this->tileSize); - } - } - } - - - public function placeMarkers(){ - foreach($this->markers as $marker){ - $markerLat = $marker['lat']; - $markerLon = $marker['lon']; - $markerImage = $marker['image']; - $markerIndex++; - $markerFilename = $markerImage?(file_exists($this->markerBaseDir.'/'.$markerImage.".png")?$markerImage:'lightblue'.$markerIndex):'lightblue'.$markerIndex; - if(file_exists($this->markerBaseDir.'/'.$markerFilename.".png")){ - $markerImg = imagecreatefrompng($this->markerBaseDir.'/'.$markerFilename.".png"); - } else { - $markerImg = imagecreatefrompng($this->markerBaseDir.'/lightblue1.png'); - } - $destX = floor(($this->width/2)-$this->tileSize*($this->centerX-$this->lonToTile($markerLon, $this->zoom))); - $destY = floor(($this->height/2)-$this->tileSize*($this->centerY-$this->latToTile($markerLat, $this->zoom))); - $destY = $destY - imagesy($markerImg); - - imagecopy($this->image, $markerImg, $destX, $destY, 0, 0, imagesx($markerImg), imagesy($markerImg)); - - }; -} - - - - public function tileUrlToFilename($url){ - return $this->tileCacheBaseDir."/".str_replace(array('http://'),'',$url); - } - - public function checkTileCache($url){ - $filename = $this->tileUrlToFilename($url); - if(file_exists($filename)){ - return file_get_contents($filename); - } - } - - public function checkMapCache(){ - $this->mapCacheID = md5($this->serializeParams()); - $filename = $this->mapCacheIDToFilename(); - if(file_exists($filename)) return true; - } - - public function serializeParams(){ - return join("&",array($this->zoom,$this->lat,$this->lon,$this->width,$this->height, serialize($this->markers),$this->maptype)); - } - - public function mapCacheIDToFilename(){ - if(!$this->mapCacheFile){ - $this->mapCacheFile = $this->mapCacheBaseDir."/".substr($this->mapCacheID,0,2)."/".substr($this->mapCacheID,2,2)."/".substr($this->mapCacheID,4); - } - return $this->mapCacheFile.".".$this->mapCacheExtension; - } - - - - public function mkdir_recursive($pathname, $mode){ - return mkdir($pathname, $mode, true); - } - public function writeTileToCache($url, $data){ - $filename = $this->tileUrlToFilename($url); - $this->mkdir_recursive(dirname($filename),0777); - file_put_contents($filename, $data); - } - - public function fetchTile($url){ - if($this->useTileCache && ($cached = $this->checkTileCache($url))) return $cached; - $ch = curl_init(); - curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); - curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0"); - curl_setopt($ch, CURLOPT_URL, $url); - $tile = curl_exec($ch); - curl_close($ch); - if($this->useTileCache){ - $this->writeTileToCache($url,$tile); - } - return $tile; - - } - - public function copyrightNotice(){ - $logoImg = imagecreatefrompng($this->osmLogo); - imagecopy($this->image, $logoImg, imagesx($this->image)-imagesx($logoImg), imagesy($this->image)-imagesy($logoImg), 0, 0, imagesx($logoImg), imagesy($logoImg)); - - } - - public function sendHeader(){ - header('Content-Type: image/png'); - $expires = 60*60*24*14; - header("Pragma: public"); - header("Cache-Control: maxage=".$expires); - header('Expires: ' . gmdate('D, d M Y H:i:s', time()+$expires) . ' GMT'); - } - - public function makeMap(){ - $this->initCoords(); - $this->createBaseMap(); - if(count($this->markers))$this->placeMarkers(); - if($this->osmLogo) $this->copyrightNotice(); - } - - public function showMap(){ - $this->parseParams(); - if($this->useMapCache){ - // use map cache, so check cache for map - if(!$this->checkMapCache()){ - // map is not in cache, needs to be build - $this->makeMap(); - $this->mkdir_recursive(dirname($this->mapCacheIDToFilename()),0777); - imagepng($this->image,$this->mapCacheIDToFilename(),9); - $this->sendHeader(); - if(file_exists($this->mapCacheIDToFilename())){ - return file_get_contents($this->mapCacheIDToFilename()); - } else { - return imagepng($this->image); - } - } else { - // map is in cache - $this->sendHeader(); - return file_get_contents($this->mapCacheIDToFilename()); - } - - } else { - // no cache, make map, send headers and deliver png - $this->makeMap(); - // $this->sendHeader(); - // do some extra compression - imagetruecolortopalette($this->image, false, 256); - return imagepng($this->image, 9, PNG_ALL_FILTERS); - - } - } - -} - -$map = new staticMapLite(); -print $map->showMap(); - -?> - --- a/myway/myway_timeliness_reconcile.php +++ b/myway/myway_timeliness_reconcile.php @@ -80,7 +80,7 @@ echo "

{$myway_stop[0]}

"; $stopNameParts = explode(" ", $myway_stop[0]); $markers = array(); - $stopKey = 1; + $stopKey = 0; $foundStops = getStops(false, "", $stopNameParts[0] . " " . $stopNameParts[1]); if (sizeof($foundStops) > 0) { echo "
"; @@ -92,7 +92,7 @@ echo ""; } echo '
" . $stopKey++ . "" . $stopResult['stop_name'] . "" . $stopResult['stop_code'] . "
'; - echo "" . staticmap($markers, 0, "icong", false) . "
\n"; + echo "" . staticmap($markers,false,false,false,true) . "
\n"; } echo '
--- a/stopList.php +++ b/stopList.php @@ -77,7 +77,7 @@ $sub_stop["stop_lon"] ); } - echo staticmap($stopPositions, 0, "iconb", true, true); + echo staticmap($stopPositions, true, true); placeSettings(); echo ''; } else if (isset($suburb)) { --- a/tripPlanner.php +++ b/tripPlanner.php @@ -65,7 +65,7 @@ $leg->from->lon ); } - echo '' . staticmap($legMarkers, 0, "iconb", false) . "
\n"; + echo '' . staticmap($legMarkers, false, false, true) . "
\n"; echo '
    '; foreach ($itinerary->legs->leg as $legNumber => $leg) { echo '
  • '; @@ -81,7 +81,7 @@ $itinerary->legs->leg->from->lat, $itinerary->legs->leg->from->lon ) - ), 0, "iconb", false) . "
    \n"; + ), false, false, true) . "
    \n"; processLeg(0, $itinerary->legs->leg); } echo "

    "; @@ -100,7 +100,7 @@ $step->lon ); } - echo "" . staticmap($walkStepMarkers, 0, "icong", false) . "
    \n"; + echo "" . staticmap($walkStepMarkers, false, false, true) . "
    \n"; foreach ($leg->steps->walkSteps as $stepNumber => $step) { echo "Walking step " . ($stepNumber + 1) . ": "; if ($step->relativeDirection == "CONTINUE") {