Show
Ignore:
Timestamp:
02/23/2008 01:41:41 PM (9 months ago)
Author:
Shadowhand
Message:

Hooray! Gmaps module in a working (but early) form!

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/modules/gmaps/controllers/google_map.php

    r2154 r2158  
    11<?php defined('SYSPATH') or die('No direct script access.'); 
    2  
     2/** 
     3 * Gmaps module demo controller. 
     4 * 
     5 * $Id$ 
     6 * 
     7 * @package    Gmaps 
     8 * @author     Woody Gilk 
     9 * @copyright  (c) 2007-2008 Kohana Team 
     10 * @license    http://kohanaphp.com/license.html 
     11 */ 
    312class Google_Map_Controller extends Controller { 
    413 
    514        public function index() 
    615        { 
    7                 View::factory('gmaps/api_demo')->render(TRUE); 
     16                $this->db = Database::instance('mysql://root:r00tdb@localhost/azmap'); 
     17 
     18                // Create a new Gmap 
     19                $map = new Gmap('map'); 
     20 
     21                // Set the map center point 
     22                $map->center(0, 0, 1)->controls('large'); 
     23 
     24                // Add a new marker 
     25                $map->add_marker(44.9801, -93.2519, '<strong>Minneapolis, MN</strong><p>Hello world!</p>'); 
     26 
     27                View::factory('gmaps/api_demo')->set('map', $map->render())->render(TRUE); 
    828        } 
    929 
    10         public function markers() 
     30        public function azmap() 
    1131        { 
    12                 $map = new Gmap; 
    13                  
    14                 $markers[] = Gmap::marker('South Africa'); 
    15                 $markers[] = Gmap::marker('8601 Edinbrook Crossing, 55443'); 
     32                $this->db = Database::instance('mysql://root:r00tdb@localhost/azmap'); 
    1633 
    17                 foreach ($markers as $marker) 
     34                // Create a new Gmap 
     35                $map = new Gmap('map', array 
     36                ( 
     37                        'ScrollWheelZoom' => TRUE, 
     38                )); 
     39 
     40                // Set the map center point 
     41                $map->center(0, 35, 2)->controls('large'); 
     42 
     43                // Set marker locations 
     44                foreach (ORM::factory('location')->find_all() as $location) 
    1845                { 
    19                         echo html::anchor 
    20                         ( 
    21                                 'http://maps.google.com/?&q=' 
    22                                 .rawurlencode($marker->address).'&ll=' 
    23                                 .rawurlencode($marker->lon.','.$marker->lat) 
    24                                 .'&z=10&iwloc=addr' 
    25                         ).'<br/>'; 
     46                        // Add a new marker 
     47                        $map->add_marker($location->lat, $location->lon, 
     48                                // Get the info window HTML 
     49                                View::factory('gmaps/info_window')->bind('location', $location)->render()); 
    2650                } 
    2751 
     52                header('Content-type: text/javascript'); 
     53                echo $map->render(); 
    2854        } 
    2955 
    30         public function georss() 
     56        public function jquery() 
    3157        { 
    32                 View::factory('gmaps/rss_demo')->render(TRUE); 
     58                View::factory('gmaps/jquery')->render(TRUE); 
    3359        } 
    3460 
    35         public function feed() 
     61        public function xml() 
    3662        { 
    37                 header('Content-Type: text/xml; charset=utf-8'); 
    38                 require Kohana::find_file('views', 'gmaps/rss', FALSE, 'xml'); 
     63                $this->db = Database::instance('mysql://root:r00tdb@localhost/azmap'); 
     64 
     65                // Get all locations 
     66                $locations = ORM::factory('location')->find_all(); 
     67 
     68                // Create the XML container 
     69                $xml = new SimpleXMLElement('<gmap></gmap>'); 
     70 
     71                foreach ($locations as $location) 
     72                { 
     73                        // Create a new mark 
     74                        $node = $xml->addChild('marker'); 
     75 
     76                        // Set the latitutde and longitude 
     77                        $node->addAttribute('lon', $location->lon); 
     78                        $node->addAttribute('lat', $location->lat); 
     79 
     80                        $node->html = View::factory('gmaps/xml')->bind('location', $location)->render(); 
     81 
     82                        foreach ($location->as_array() as $key => $val) 
     83                        { 
     84                                // Skip the ID 
     85                                if ($key === 'id') continue; 
     86 
     87                                // Add the data to the XML 
     88                                $node->$key = $val; 
     89                        } 
     90                } 
     91 
     92                header('Content-Type: text/xml'); 
     93                echo $xml->asXML(); 
    3994        } 
    4095