示例#1
0
 public static function get_sc_bbox($raw_sc)
 {
     $min_lat = $max_lat = $min_lon = $max_lon = null;
     foreach ($raw_sc->stops as $i => $stop) {
         if ($pt = Sourcemap_Proj_Point::fromGeometry($stop->geometry)) {
             $pt = Sourcemap_Proj::transform('EPSG:900913', 'WGS84', $pt);
             if ($min_lat === null || $pt->y < $min_lat) {
                 $min_lat = $pt->y;
             }
             if ($max_lat === null || $pt->y > $max_lat) {
                 $max_lat = $pt->y;
             }
             if ($min_lon === null || $pt->x < $min_lon) {
                 $min_lon = $pt->x;
             }
             if ($max_lon === null || $pt->x > $max_lon) {
                 $max_lon = $pt->x;
             }
         }
     }
     $bbox = array($min_lat, $min_lon, $max_lat, $max_lon);
     return $bbox;
 }
示例#2
0
 public static function get_image($raw_sc)
 {
     $params = array('size' => '1024x768', 'styleid' => 4993, 'format' => 'png32');
     $markers = array();
     $paths = array();
     $stop_dict = array();
     $min_lat = $max_lat = $min_lon = $max_lon = null;
     foreach ($raw_sc->stops as $i => $stop) {
         # TODO: address hard limit of 100 stops.
         if ($pt = Sourcemap_Proj_Point::fromGeometry($stop->geometry)) {
             $pt = Sourcemap_Proj::transform('EPSG:900913', 'WGS84', $pt);
             if ($min_lat === null || $pt->y < $min_lat) {
                 $min_lat = $pt->y;
             }
             if ($max_lat === null || $pt->y > $max_lat) {
                 $max_lat = $pt->y;
             }
             if ($min_lon === null || $pt->x < $min_lon) {
                 $min_lon = $pt->x;
             }
             if ($max_lon === null || $pt->x > $max_lon) {
                 $max_lon = $pt->x;
             }
             $color = '008000';
             if (isset($stop->attributes, $stop->attributes->color)) {
                 $stcolor = $stop->attributes->color;
                 if (preg_match('/^#?([A-Fa-f0-9]{3}|[A-Fa-f0-9]{6})$/', $stcolor)) {
                     $color = ltrim($stcolor, '#');
                 }
             }
             $sz = 16;
             if (isset($stop->attributes, $stop->attributes->size) && is_numeric($stop->attributes->size)) {
                 $sz = (int) $stop->attributes->size;
                 $sz += 16;
             }
             #$markerimg = "http://chart.apis.google.com/chart?cht=it&chs={$sz}x{$sz}&chco=$color&chx=ffffff,8&chf=bg,s,00000000&ext=.png";
             $markerimg = "http://chart.apis.google.com/chart?cht=it&chs={$sz}x{$sz}&chco={$color}&chx=ffffff,8&chf=bg,s,00000000&ext=.png";
             $markers[] = 'url:' . urlencode($markerimg) . '|opacity:0.85|' . $pt->y . ',' . $pt->x;
         }
         $stop_dict[$stop->local_stop_id] = $stop;
     }
     $bbox = array($min_lat, $min_lon, $max_lat, $max_lon);
     foreach ($raw_sc->hops as $i => $hop) {
         $geom = Sourcemap_Wkt::read($hop->geometry);
         $fromst = Sourcemap_Proj_Point::fromGeometry($stop_dict[$hop->from_stop_id]->geometry);
         $fromst = Sourcemap_Proj::transform('EPSG:900913', 'WGS84', $fromst);
         $tost = Sourcemap_Proj_Point::fromGeometry($stop_dict[$hop->to_stop_id]->geometry);
         $tost = Sourcemap_Proj::transform('EPSG:900913', 'WGS84', $tost);
         $bentpts = self::make_bent_line($fromst, $tost);
         $pts = array();
         foreach ($bentpts as $bpi => $bp) {
             $pts[] = sprintf("%f,%f", $bp->y, $bp->x);
         }
         $paths[] = 'color:green|weight:3|opacity:1|' . join('|', $pts);
     }
     $ps = array();
     foreach ($params as $k => $v) {
         $ps[] = "{$k}={$v}";
     }
     foreach ($markers as $i => $m) {
         $ps[] = 'marker=' . $m;
     }
     foreach ($paths as $i => $p) {
         $ps[] = 'path=' . $p;
     }
     if ($bbox[0] || $bbox[1] || $bbox[2]) {
         $ps[] = sprintf("bbox=%s", join(',', $bbox));
     } else {
         $ps[] = 'center=0,0';
         $ps[] = 'zoom=2';
     }
     $ps = join($ps, '&');
     $ch = curl_init();
     curl_setopt($ch, CURLOPT_URL, self::get_base_url());
     curl_setopt($ch, CURLOPT_POST, true);
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
     curl_setopt($ch, CURLOPT_POSTFIELDS, $ps);
     return curl_exec($ch);
 }
示例#3
0
 public function render()
 {
     $this->stitch_tiles();
     list($nwxt, $nwyt, $throwaway) = $this->tile_numbers[0][0];
     #$se = new Sourcemap_Proj_Point($this->tiles_bounds[3], $this->tiles_bounds[2]);
     #list($sext,$seyt) = Cloudmade_Tiles::get_tile_number($se->y, $se->x, $this->zoom);
     $stops = array();
     foreach ($this->raw_sc->stops as $stop) {
         $pt = Sourcemap_Proj_Point::fromGeometry($stop->geometry);
         $pt = Sourcemap_Proj::transform('EPSG:900913', 'WGS84', $pt);
         $lon = $pt->x;
         $lat = $pt->y;
         list($xt, $yt) = Cloudmade_Tiles::get_tile_number($lat, $lon, $this->zoom);
         list($xto, $yto) = Cloudmade_Tiles::get_tile_offset($lat, $lon, $this->zoom);
         $x = ($xt - $nwxt) * 256 + $xto;
         $y = ($yt - $nwyt) * 256 + $yto;
         $stops[$stop->local_stop_id] = (object) array('stop' => $stop, 'x' => $x, 'y' => $y);
     }
     foreach ($this->raw_sc->hops as $i => $hop) {
         $from = $stops[$hop->from_stop_id];
         $to = $stops[$hop->to_stop_id];
         $this->draw_hop2($hop, $from, $to);
         //$this->draw_hop($hop, $from, $to);
     }
     foreach ($stops as $sid => $st) {
         $this->draw_stop($st->stop, $st->x, $st->y);
     }
     /*ob_start();
       imagepng($this->tiles_img);
       $imgdata = ob_get_contents();
       ob_end_clean();
       return $imgdata;*/
     return $this->tiles_img;
 }