first commit
This commit is contained in:
30
modules/gmaps/config/gmaps.php
Normal file
30
modules/gmaps/config/gmaps.php
Normal file
@@ -0,0 +1,30 @@
|
||||
<?php defined('SYSPATH') OR die('No direct access allowed.');
|
||||
|
||||
/**
|
||||
* You should set your own API key in application/config/gmaps.php
|
||||
* This API key is usable for http://localhost/*
|
||||
*/
|
||||
|
||||
$config['api_key'] = 'ABQIAAAAnfs7bKE82qgb3Zc2YyS-oBT2yXp_ZAY8_ufC3CFXhHIE1NvwkxSySz_REpPq-4WZA27OwgbtyR3VcA';
|
||||
|
||||
/**
|
||||
* Using a localised google domain gives more accurated results on geolocation
|
||||
* For example, searches for "Toledo" will return different results within the domain of Spain (http://maps.google.es)
|
||||
* specified by a country code of "es" than within the default domain within the United States (http://maps.google.com).
|
||||
*/
|
||||
|
||||
$config['api_domain'] = 'maps.google.com';
|
||||
|
||||
/**
|
||||
* This is used to determine how many times we should retry the geocode when Google sends back a 620 status code.
|
||||
* The 620 status code is used as a way to let you know Google is rate limiting your requests.
|
||||
*/
|
||||
|
||||
$config['retries'] = 10;
|
||||
|
||||
/**
|
||||
* This is used to determine how long we should wait before retrying (in microseconds).
|
||||
* Default: 100000 (0.1 seconds)
|
||||
*/
|
||||
|
||||
$config['retry_delay'] = 100000;
|
||||
179
modules/gmaps/controllers/gmaps_demo.php
Normal file
179
modules/gmaps/controllers/gmaps_demo.php
Normal file
@@ -0,0 +1,179 @@
|
||||
<?php defined('SYSPATH') OR die('No direct access allowed.');
|
||||
/**
|
||||
* Gmaps module demo controller. This controller should NOT be used in production.
|
||||
* It is for demonstration purposes only!
|
||||
*
|
||||
* $Id: gmaps_demo.php 3769 2008-12-15 00:48:56Z zombor $
|
||||
*
|
||||
* @package Gmaps
|
||||
* @author Woody Gilk
|
||||
* @copyright (c) 2007-2008 Kohana Team
|
||||
* @license http://kohanaphp.com/license.html
|
||||
*/
|
||||
class Gmaps_Demo_Controller extends Controller {
|
||||
|
||||
// Do not allow to run in production
|
||||
const ALLOW_PRODUCTION = FALSE;
|
||||
|
||||
public function index()
|
||||
{
|
||||
// Create a new Gmap
|
||||
$map = new Gmap('map', array
|
||||
(
|
||||
'ScrollWheelZoom' => TRUE,
|
||||
));
|
||||
|
||||
// Set the map center point
|
||||
$map->center(0, 0, 1)->controls('large')->types('G_PHYSICAL_MAP', 'add');
|
||||
|
||||
// Add a custom marker icon
|
||||
$map->add_icon('tinyIcon', array
|
||||
(
|
||||
'image' => 'http://labs.google.com/ridefinder/images/mm_20_red.png',
|
||||
'shadow' => 'http://labs.google.com/ridefinder/images/mm_20_shadow.png',
|
||||
'iconSize' => array('12', '20'),
|
||||
'shadowSize' => array('22', '20'),
|
||||
'iconAnchor' => array('6', '20'),
|
||||
'infoWindowAnchor' => array('5', '1')
|
||||
));
|
||||
|
||||
// Add a new marker
|
||||
$map->add_marker(44.9801, -93.2519, '<strong>Minneapolis, MN</strong><p>Hello world!</p>', array('icon' => 'tinyIcon', 'draggable' => true, 'bouncy' => true));
|
||||
|
||||
View::factory('gmaps/api_demo')->set(array('api_url' => Gmap::api_url(), 'map' => $map->render()))->render(TRUE);
|
||||
}
|
||||
|
||||
public function image_map()
|
||||
{
|
||||
$points = array('-37.814251' => '144.963169', '-33.867139' => '151.207114', '-27.467580' => '153.027892');
|
||||
|
||||
View::factory('gmaps/static_demo')->set(array('simple' => Gmap::static_map(44.9801, -93.2519),'multi' => Gmap::static_map($points)))->render(TRUE);
|
||||
}
|
||||
|
||||
public function azmap()
|
||||
{
|
||||
// Create a new Gmap
|
||||
$map = new Gmap('map', array
|
||||
(
|
||||
'ScrollWheelZoom' => TRUE,
|
||||
));
|
||||
|
||||
// Set the map center point
|
||||
$map->center(0, 35, 2)->controls('large');
|
||||
|
||||
// Set marker locations
|
||||
foreach (ORM::factory('location')->find_all() as $location)
|
||||
{
|
||||
// Add a new marker
|
||||
$map->add_marker($location->lat, $location->lon,
|
||||
|
||||
// Get the info window HTML
|
||||
View::factory('gmaps/info_window')->bind('location', $location)->render());
|
||||
}
|
||||
|
||||
header('Content-Type: text/javascript');
|
||||
echo $map->render();
|
||||
}
|
||||
|
||||
public function admin()
|
||||
{
|
||||
$valid = ! empty($_POST);
|
||||
|
||||
$_POST = Validation::factory($_POST)
|
||||
->pre_filter('trim')
|
||||
->add_rules('title', 'required', 'length[4,32]')
|
||||
->add_rules('description', 'required', 'length[4,127]')
|
||||
->add_rules('link', 'length[6,127]', 'valid::url')
|
||||
->add_rules('address', 'required', 'length[4,127]')
|
||||
->add_callbacks('address', array($this, '_admin_check_address'));
|
||||
|
||||
if ($_POST->validate())
|
||||
{
|
||||
// Create a new location
|
||||
$location = ORM::factory('location');
|
||||
|
||||
//
|
||||
foreach ($_POST->as_array() as $key => $val)
|
||||
{
|
||||
$location->$key = $val;
|
||||
}
|
||||
|
||||
echo Kohana::debug($_POST->as_array());
|
||||
}
|
||||
|
||||
if ($errors = $_POST->errors())
|
||||
{
|
||||
foreach ($errors as $input => $rule)
|
||||
{
|
||||
// Add the errors
|
||||
$_POST->message($input, Kohana::lang("gmaps.form.$input"));
|
||||
}
|
||||
}
|
||||
|
||||
View::factory('gmaps/admin')->render(TRUE);
|
||||
}
|
||||
|
||||
public function _admin_check_address(Validation $array, $input)
|
||||
{
|
||||
if ($array[$input] == '')
|
||||
return;
|
||||
|
||||
// Fetch the lat and lon via Gmap
|
||||
list ($lat, $lon) = Gmap::address_to_ll($array[$input]);
|
||||
|
||||
if ($lat === NULL OR $lon === NULL)
|
||||
{
|
||||
// Add an error
|
||||
$array->add_error($input, 'address');
|
||||
}
|
||||
else
|
||||
{
|
||||
// Set the latitude and longitude
|
||||
$_POST['lat'] = $lat;
|
||||
$_POST['lon'] = $lon;
|
||||
}
|
||||
}
|
||||
|
||||
public function jquery()
|
||||
{
|
||||
$map = new Gmap('map');
|
||||
|
||||
$map->center(0, 35, 16)->controls('large');
|
||||
|
||||
View::factory('gmaps/jquery')->set(array('api_url' => Gmap::api_url(), 'map' => $map->render('gmaps/jquery_javascript')))->render(TRUE);
|
||||
}
|
||||
|
||||
public function xml()
|
||||
{
|
||||
// Get all locations
|
||||
$locations = ORM::factory('location')->find_all();
|
||||
|
||||
// Create the XML container
|
||||
$xml = new SimpleXMLElement('<gmap></gmap>');
|
||||
|
||||
foreach ($locations as $location)
|
||||
{
|
||||
// Create a new mark
|
||||
$node = $xml->addChild('marker');
|
||||
|
||||
// Set the latitude and longitude
|
||||
$node->addAttribute('lon', sprintf('%F', $location->lon));
|
||||
$node->addAttribute('lat', sprintf('%F', $location->lat));
|
||||
|
||||
$node->html = View::factory('gmaps/xml')->bind('location', $location)->render();
|
||||
|
||||
foreach ($location->as_array() as $key => $val)
|
||||
{
|
||||
// Skip the ID
|
||||
if ($key === 'id') continue;
|
||||
|
||||
// Add the data to the XML
|
||||
$node->$key = $val;
|
||||
}
|
||||
}
|
||||
|
||||
header('Content-Type: text/xml');
|
||||
echo $xml->asXML();
|
||||
}
|
||||
|
||||
} // End Google Map Controller
|
||||
7
modules/gmaps/i18n/en_US/gmaps.php
Normal file
7
modules/gmaps/i18n/en_US/gmaps.php
Normal file
@@ -0,0 +1,7 @@
|
||||
<?php defined('SYSPATH') OR die('No direct access allowed.');
|
||||
|
||||
$lang = array
|
||||
(
|
||||
'invalid_marker' => 'Invalid marker params (latitude: %s, longitude: %s)',
|
||||
'invalid_dimensions' => 'Invalid map dimensions (width: %s, height: %s)',
|
||||
);
|
||||
7
modules/gmaps/i18n/pl_PL/gmaps.php
Normal file
7
modules/gmaps/i18n/pl_PL/gmaps.php
Normal file
@@ -0,0 +1,7 @@
|
||||
<?php defined('SYSPATH') OR die('No direct access allowed.');
|
||||
|
||||
$lang = array
|
||||
(
|
||||
'invalid_marker' => 'Nieprawidłowe parametry markera (szerokość geograficzna: %s, długość geograficzna: %s)',
|
||||
'invalid_dimensions' => 'Nieprawidłowe wymiary mapy (szerokość: %s, wysokość: %s)',
|
||||
);
|
||||
387
modules/gmaps/libraries/Gmap.php
Normal file
387
modules/gmaps/libraries/Gmap.php
Normal file
@@ -0,0 +1,387 @@
|
||||
<?php defined('SYSPATH') OR die('No direct access allowed.');
|
||||
/**
|
||||
* Google Maps API integration.
|
||||
*
|
||||
* $Id: Gmap.php 4302 2009-05-01 02:49:41Z kiall $
|
||||
*
|
||||
* @package Gmaps
|
||||
* @author Kohana Team
|
||||
* @copyright (c) 2007-2008 Kohana Team
|
||||
* @license http://kohanaphp.com/license.html
|
||||
*/
|
||||
class Gmap_Core {
|
||||
|
||||
// Map settings
|
||||
protected $id;
|
||||
protected $options;
|
||||
protected $center;
|
||||
protected $control;
|
||||
protected $overview_control;
|
||||
protected $type_control = FALSE;
|
||||
|
||||
// Map types
|
||||
protected $types = array();
|
||||
protected $default_types = array
|
||||
(
|
||||
'G_NORMAL_MAP','G_SATELLITE_MAP','G_HYBRID_MAP','G_PHYSICAL_MAP'
|
||||
);
|
||||
|
||||
// Markers icons
|
||||
protected $icons = array();
|
||||
|
||||
// Map markers
|
||||
protected $markers = array();
|
||||
|
||||
/**
|
||||
* Set the GMap center point.
|
||||
*
|
||||
* @param string $id HTML map id attribute
|
||||
* @param array $options array of GMap constructor options
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($id = 'map', $options = NULL)
|
||||
{
|
||||
// Set map ID and options
|
||||
$this->id = $id;
|
||||
$this->options = new Gmap_Options((array) $options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return GMap javascript url
|
||||
*
|
||||
* @param string API component
|
||||
* @param array API parameters
|
||||
* @return string
|
||||
*/
|
||||
public static function api_url($component = 'jsapi', $parameters = NULL, $separator = '&')
|
||||
{
|
||||
if (empty($parameters['ie']))
|
||||
{
|
||||
// Set input encoding to UTF-8
|
||||
$parameters['ie'] = 'utf-8';
|
||||
}
|
||||
|
||||
if (empty($parameters['oe']))
|
||||
{
|
||||
// Set ouput encoding to input encoding
|
||||
$parameters['oe'] = $parameters['ie'];
|
||||
}
|
||||
|
||||
if (empty($parameters['key']))
|
||||
{
|
||||
// Set the API key last
|
||||
$parameters['key'] = Kohana::config('gmaps.api_key');
|
||||
}
|
||||
|
||||
return 'http://'.Kohana::config('gmaps.api_domain').'/'.$component.'?'.http_build_query($parameters, '', $separator);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the latitude and longitude of an address.
|
||||
*
|
||||
* @param string $address address
|
||||
* @return array longitude, latitude
|
||||
*/
|
||||
public static function address_to_ll($address)
|
||||
{
|
||||
$lat = NULL;
|
||||
$lon = NULL;
|
||||
|
||||
if ($xml = Gmap::address_to_xml($address))
|
||||
{
|
||||
// Get the latitude and longitude from the Google Maps XML
|
||||
// NOTE: the order (lon, lat) is the correct order
|
||||
list ($lon, $lat) = explode(',', $xml->Response->Placemark->Point->coordinates);
|
||||
}
|
||||
|
||||
return array($lat, $lon);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the XML geocode address lookup.
|
||||
* ! Results of this method are cached for 1 day.
|
||||
*
|
||||
* @param string $address adress
|
||||
* @return object SimpleXML
|
||||
*/
|
||||
public static function address_to_xml($address)
|
||||
{
|
||||
static $cache;
|
||||
|
||||
// Load Cache
|
||||
if ($cache === NULL)
|
||||
{
|
||||
$cache = Cache::instance();
|
||||
}
|
||||
|
||||
// Address cache key
|
||||
$key = 'gmap-address-'.sha1($address);
|
||||
|
||||
if ($xml = $cache->get($key))
|
||||
{
|
||||
// Return the cached XML
|
||||
return simplexml_load_string($xml);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Setup the retry counter and retry delay
|
||||
$remaining_retries = Kohana::config('gmaps.retries');
|
||||
$retry_delay = Kohana::config('gmaps.retry_delay');
|
||||
|
||||
// Set the XML URL
|
||||
$xml_url = Gmap::api_url('maps/geo', array('output' => 'xml', 'q' => $address), '&');
|
||||
|
||||
// Disable error reporting while fetching the feed
|
||||
$ER = error_reporting(~E_NOTICE);
|
||||
|
||||
// Enter the request/retry loop.
|
||||
while ($remaining_retries)
|
||||
{
|
||||
// Load the XML
|
||||
$xml = simplexml_load_file($xml_url);
|
||||
|
||||
if (is_object($xml) AND ($xml instanceof SimpleXMLElement) AND (int) $xml->Response->Status->code === 200)
|
||||
{
|
||||
// Cache the XML
|
||||
$cache->set($key, $xml->asXML(), array('gmaps'), 86400);
|
||||
|
||||
// Since the geocode was successful, theres no need to try again
|
||||
$remaining_retries = 0;
|
||||
}
|
||||
elseif ((int) $xml->Response->Status->code === 620)
|
||||
{
|
||||
/* Goole is rate limiting us - either we're making too many requests too fast, or
|
||||
* we've exceeded the 15k per 24hour limit. */
|
||||
|
||||
// Reduce the number of remaining retries
|
||||
$remaining_retries--;
|
||||
if ( ! $remaining_retries)
|
||||
return FALSE;
|
||||
|
||||
// Sleep for $retry_delay microseconds before trying again.
|
||||
usleep($retry_delay);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Invalid XML response
|
||||
$xml = FALSE;
|
||||
|
||||
// Dont retry.
|
||||
$remaining_retries = 0;
|
||||
}
|
||||
}
|
||||
|
||||
// Turn error reporting back on
|
||||
error_reporting($ER);
|
||||
}
|
||||
|
||||
return $xml;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an image map
|
||||
*
|
||||
* @param mixed $lat latitude or an array of marker points
|
||||
* @param float $lon longitude
|
||||
* @param integer $zoom zoom level (1-19)
|
||||
* @param string $type map type (roadmap or mobile)
|
||||
* @param integer $width map width
|
||||
* @param integer $height map height
|
||||
* @return string
|
||||
*/
|
||||
public static function static_map($lat = 0, $lon = 0, $zoom = 6, $type = NULL, $width = 300, $height = 300)
|
||||
{
|
||||
// Valid map types
|
||||
$types = array('roadmap', 'mobile');
|
||||
|
||||
// Maximum width and height are 640px
|
||||
$width = min(640, abs($width));
|
||||
$height = min(640, abs($height));
|
||||
|
||||
$parameters['size'] = $width.'x'.$height;
|
||||
|
||||
// Minimum zoom = 0, maximum zoom = 19
|
||||
$parameters['zoom'] = max(0, min(19, abs($zoom)));
|
||||
|
||||
if (in_array($type, $types))
|
||||
{
|
||||
// Set map type
|
||||
$parameters['maptype'] = $type;
|
||||
}
|
||||
|
||||
if (is_array($lat))
|
||||
{
|
||||
foreach ($lat as $_lat => $_lon)
|
||||
{
|
||||
$parameters['markers'][] = $_lat.','.$_lon;
|
||||
}
|
||||
|
||||
$parameters['markers'] = implode('|', $parameters['markers']);
|
||||
}
|
||||
else
|
||||
{
|
||||
$parameters['center'] = $lat.','.$lon;
|
||||
}
|
||||
|
||||
return Gmap::api_url('staticmap', $parameters);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the GMap center point.
|
||||
*
|
||||
* @chainable
|
||||
* @param float $lat latitude
|
||||
* @param float $lon longitude
|
||||
* @param integer $zoom zoom level (1-19)
|
||||
* @param string $type default map type
|
||||
* @return object
|
||||
*/
|
||||
public function center($lat, $lon, $zoom = 6, $type = 'G_NORMAL_MAP')
|
||||
{
|
||||
$zoom = max(0, min(19, abs($zoom)));
|
||||
$type = ($type != 'G_NORMAL_MAP' AND in_array($type, $this->default_types, true)) ? $type : 'G_NORMAL_MAP';
|
||||
|
||||
// Set center location, zoom and default map type
|
||||
$this->center = array($lat, $lon, $zoom, $type);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the GMap controls size.
|
||||
*
|
||||
* @chainable
|
||||
* @param string $size small or large
|
||||
* @return object
|
||||
*/
|
||||
public function controls($size = NULL)
|
||||
{
|
||||
// Set the control type
|
||||
$this->control = (strtolower($size) == 'small') ? 'Small' : 'Large';
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the GMap overview map.
|
||||
*
|
||||
* @chainable
|
||||
* @param integer $width width
|
||||
* @param integer $height height
|
||||
* @return object
|
||||
*/
|
||||
public function overview($width = '', $height = '')
|
||||
{
|
||||
$size = (is_int($width) AND is_int($height)) ? 'new GSize('.$width.','.$height.')' : '';
|
||||
$this->overview_control = 'map.addControl(new google.maps.OverviewMapControl('.$size.'));';
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the GMap type controls.
|
||||
* by default renders G_NORMAL_MAP, G_SATELLITE_MAP, and G_HYBRID_MAP
|
||||
*
|
||||
* @chainable
|
||||
* @param string $type map type
|
||||
* @param string $action add or remove map type
|
||||
* @return object
|
||||
*/
|
||||
public function types($type = NULL, $action = 'remove')
|
||||
{
|
||||
$this->type_control = TRUE;
|
||||
|
||||
if ($type !== NULL AND in_array($type, $this->default_types, true))
|
||||
{
|
||||
// Set the map type and action
|
||||
$this->types[$type] = (strtolower($action) == 'remove') ? 'remove' : 'add';
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a custom marker icon
|
||||
*
|
||||
* @chainable
|
||||
* @param string $name icon name
|
||||
* @param array $options icon options
|
||||
* @return object
|
||||
*/
|
||||
public function add_icon($name, array $options)
|
||||
{
|
||||
// Add a new cusotm icon
|
||||
$this->icons[] = new Gmap_Icon($name, $options);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the GMap marker point.
|
||||
*
|
||||
* @chainable
|
||||
* @param float $lat latitude
|
||||
* @param float $lon longitude
|
||||
* @param string $html HTML for info window
|
||||
* @param array $options marker options
|
||||
* @return object
|
||||
*/
|
||||
public function add_marker($lat, $lon, $html = '', $options = array())
|
||||
{
|
||||
// Add a new marker
|
||||
$this->markers[] = new Gmap_Marker($lat, $lon, $html, $options);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Render the map into GMap Javascript.
|
||||
*
|
||||
* @param string $template template name
|
||||
* @param array $extra extra fields passed to the template
|
||||
* @return string
|
||||
*/
|
||||
public function render($template = 'gmaps/javascript', $extra = array())
|
||||
{
|
||||
// Latitude, longitude, zoom and default map type
|
||||
list ($lat, $lon, $zoom, $default_type) = $this->center;
|
||||
|
||||
// Map
|
||||
$map = 'var map = new google.maps.Map2(document.getElementById("'.$this->id.'"));';
|
||||
|
||||
// Map controls
|
||||
$controls[] = empty($this->control) ? '' : 'map.addControl(new google.maps.'.$this->control.'MapControl());';
|
||||
|
||||
// Map Types
|
||||
if ($this->type_control === TRUE)
|
||||
{
|
||||
if (count($this->types) > 0)
|
||||
{
|
||||
foreach($this->types as $type => $action)
|
||||
$controls[] = 'map.'.$action.'MapType('.$type.');';
|
||||
}
|
||||
|
||||
$controls[] = 'map.addControl(new google.maps.MapTypeControl());';
|
||||
}
|
||||
|
||||
if ( ! empty($this->overview_control))
|
||||
$controls[] = $this->overview_control;
|
||||
|
||||
// Map centering
|
||||
$center = 'map.setCenter(new google.maps.LatLng('.$lat.', '.$lon.'), '.$zoom.', '.$default_type.');';
|
||||
|
||||
$data = array_merge($extra, array
|
||||
(
|
||||
'map' => $map,
|
||||
'options' => $this->options,
|
||||
'controls' => implode("\n", $controls),
|
||||
'center' => $center,
|
||||
'icons' => $this->icons,
|
||||
'markers' => $this->markers,
|
||||
));
|
||||
|
||||
// Render the Javascript
|
||||
return View::factory($template, $data)->render();
|
||||
}
|
||||
|
||||
} // End Gmap
|
||||
120
modules/gmaps/libraries/Gmap_Icon.php
Normal file
120
modules/gmaps/libraries/Gmap_Icon.php
Normal file
@@ -0,0 +1,120 @@
|
||||
<?php defined('SYSPATH') OR die('No direct access allowed.');
|
||||
/**
|
||||
* GMaps Icon library.
|
||||
*
|
||||
* $Id$
|
||||
*
|
||||
* @package Gmaps
|
||||
* @author Kohana Team
|
||||
* @copyright (c) 2007-2008 Kohana Team
|
||||
* @license http://kohanaphp.com/license.html
|
||||
*/
|
||||
class Gmap_Icon_Core {
|
||||
|
||||
// Valid options
|
||||
protected $valid_options = array
|
||||
(
|
||||
'image',
|
||||
'shadow',
|
||||
'iconSize',
|
||||
'shadowSize',
|
||||
'iconAnchor',
|
||||
'infoWindowAnchor',
|
||||
'printImage',
|
||||
'mozPrintImage',
|
||||
'printShadow',
|
||||
'transparent',
|
||||
'imageMap',
|
||||
'maxHeight',
|
||||
'dragCrossImage',
|
||||
'dragCrossSize',
|
||||
'dragCrossAnchor'
|
||||
);
|
||||
|
||||
// Settable options
|
||||
protected $options = array();
|
||||
|
||||
// Icon name
|
||||
protected $name;
|
||||
|
||||
/**
|
||||
* Create a new GMap icon
|
||||
*
|
||||
* @param string $name icon name
|
||||
* @param array $options GMap2 icon options
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($name, array $options)
|
||||
{
|
||||
// set icon name
|
||||
$this->name = $name;
|
||||
|
||||
foreach ($options as $key => $value)
|
||||
{
|
||||
if (in_array($key, $this->valid_options, true))
|
||||
{
|
||||
// Set all valid methods
|
||||
switch($key)
|
||||
{
|
||||
case 'image':
|
||||
case 'shadow':
|
||||
case 'printImage':
|
||||
case 'mozPrintImage':
|
||||
case 'printShadow':
|
||||
case 'transparent':
|
||||
case 'dragCrossImage':
|
||||
$this->set_url($key, $value);
|
||||
break;
|
||||
case 'iconAnchor':
|
||||
case 'infoWindowAnchor':
|
||||
case 'infoShadowAnchor':
|
||||
case 'dragCrossAnchor':
|
||||
$this->set_point($key, $value);
|
||||
break;
|
||||
case 'iconSize':
|
||||
case 'shadowSize':
|
||||
case 'dragCrossSize':
|
||||
$this->set_size($key, $value);
|
||||
break;
|
||||
default:
|
||||
$this->options[$key] = json_encode($value);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function set_url($key, $url)
|
||||
{
|
||||
$this->options[$key] = (valid::url($url)) ? '"'.$url.'";' : '"'.url::site($url).'";';
|
||||
}
|
||||
|
||||
public function set_size($key, $val)
|
||||
{
|
||||
$this->options[$key] = 'new google.maps.Size('.implode(',', $val).');';
|
||||
}
|
||||
|
||||
public function set_point($key, $val)
|
||||
{
|
||||
$this->options[$key] = 'new google.maps.Point('.implode(',', $val).');';
|
||||
}
|
||||
|
||||
public function render($tabs = 0)
|
||||
{
|
||||
// Create the tabs
|
||||
$tabs = empty($tabs) ? '' : str_repeat("\t", $tabs);
|
||||
|
||||
$output = array();
|
||||
|
||||
// Render each option
|
||||
$output[] = "var $this->name = ".((count($this->options) > 1) ? 'new google.maps.Icon();' : 'new google.maps.Icon(G_DEFAULT_ICON);');
|
||||
|
||||
foreach($this->options as $option => $value)
|
||||
{
|
||||
$output[] = "$this->name.$option = $value";
|
||||
}
|
||||
|
||||
return implode("\n".$tabs, $output);
|
||||
}
|
||||
|
||||
} // End Gmap Icon
|
||||
84
modules/gmaps/libraries/Gmap_Marker.php
Normal file
84
modules/gmaps/libraries/Gmap_Marker.php
Normal file
@@ -0,0 +1,84 @@
|
||||
<?php defined('SYSPATH') OR die('No direct access allowed.');
|
||||
|
||||
class Gmap_Marker_Core {
|
||||
|
||||
// Marker HTML
|
||||
public $html;
|
||||
|
||||
// Latitude and longitude
|
||||
public $latitude;
|
||||
public $longitude;
|
||||
|
||||
// Marker ID
|
||||
protected static $id = 0;
|
||||
|
||||
// Marker Options
|
||||
protected $options = array();
|
||||
protected $valid_options = array
|
||||
(
|
||||
'icon',
|
||||
'dragCrossMove',
|
||||
'title',
|
||||
'clickable',
|
||||
'draggable',
|
||||
'bouncy',
|
||||
'bounceGravity',
|
||||
'autoPan'
|
||||
);
|
||||
|
||||
/**
|
||||
* Create a new GMap marker.
|
||||
*
|
||||
* @param float $lat latitude
|
||||
* @param float $lon longitude
|
||||
* @param string $html HTML of info window
|
||||
* @param array $options marker options
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($lat, $lon, $html, $options = array())
|
||||
{
|
||||
if ( ! is_numeric($lat) OR ! is_numeric($lon))
|
||||
throw new Kohana_Exception('gmaps.invalid_marker', $lat, $lon);
|
||||
|
||||
// Set the latitude and longitude
|
||||
$this->latitude = $lat;
|
||||
$this->longitude = $lon;
|
||||
|
||||
// Set the info window HTML
|
||||
$this->html = $html;
|
||||
|
||||
if (count($options) > 0)
|
||||
{
|
||||
foreach ($options as $option => $value)
|
||||
{
|
||||
// Set marker options
|
||||
if (in_array($option, $this->valid_options, true))
|
||||
$this->options[] = "$option:$value";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function render($tabs = 0)
|
||||
{
|
||||
// Create the tabs
|
||||
$tabs = empty($tabs) ? '' : str_repeat("\t", $tabs);
|
||||
|
||||
// Marker ID
|
||||
$marker = 'm'.++self::$id;
|
||||
|
||||
$output[] = 'var '.$marker.' = new google.maps.Marker(new google.maps.LatLng('.$this->latitude.', '.$this->longitude.'), {'.implode(",", $this->options).'});';
|
||||
if ($html = $this->html)
|
||||
{
|
||||
$output[] = 'google.maps.Event.addListener('.$marker.', "click", function()';
|
||||
$output[] = '{';
|
||||
$output[] = "\t".$marker.'.openInfoWindowHtml(';
|
||||
$output[] = "\t\t'".implode("'+\n\t\t$tabs'", explode("\n", $html))."'";
|
||||
$output[] = "\t);";
|
||||
$output[] = '});';
|
||||
}
|
||||
$output[] = 'map.addOverlay('.$marker.');';
|
||||
|
||||
return implode("\n".$tabs, $output);
|
||||
}
|
||||
|
||||
} // End Gmap Marker
|
||||
70
modules/gmaps/libraries/Gmap_Options.php
Normal file
70
modules/gmaps/libraries/Gmap_Options.php
Normal file
@@ -0,0 +1,70 @@
|
||||
<?php defined('SYSPATH') OR die('No direct access allowed.');
|
||||
/**
|
||||
* GMaps options container.
|
||||
*
|
||||
* $Id: Gmap_Options.php 4179 2009-04-07 23:39:20Z zombor $
|
||||
*
|
||||
* @package Gmaps
|
||||
* @author Kohana Team
|
||||
* @copyright (c) 2007-2008 Kohana Team
|
||||
* @license http://kohanaphp.com/license.html
|
||||
*/
|
||||
class Gmap_Options_Core {
|
||||
|
||||
// Valid options
|
||||
protected $valid_options = array
|
||||
(
|
||||
'Dragging',
|
||||
'InfoWindow',
|
||||
'DoubleClickZoom',
|
||||
'ContinuousZoom',
|
||||
'GoogleBar',
|
||||
'ScrollWheelZoom'
|
||||
);
|
||||
|
||||
// Settable options
|
||||
protected $options = array();
|
||||
|
||||
/**
|
||||
* Create a new GMap options
|
||||
*
|
||||
* @param array GMap2 object options
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(array $options)
|
||||
{
|
||||
foreach ($options as $key => $value)
|
||||
{
|
||||
if (in_array($key, $this->valid_options))
|
||||
{
|
||||
// Set all valid options
|
||||
$this->options[$key] = (bool) $value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function render($tabs = 0)
|
||||
{
|
||||
// Create the tabs
|
||||
$tabs = empty($tabs) ? '' : str_repeat("\t", $tabs);
|
||||
|
||||
// Render each option
|
||||
$output = array();
|
||||
foreach ($this->options as $option => $value)
|
||||
{
|
||||
if ($value === TRUE)
|
||||
{
|
||||
// Add an enable
|
||||
$output[] = 'map.enable'.$option.'();';
|
||||
}
|
||||
else
|
||||
{
|
||||
// Add a disable
|
||||
$output[] = 'map.disable'.$option.'();';
|
||||
}
|
||||
}
|
||||
|
||||
return implode("\n".$tabs, $output);
|
||||
}
|
||||
|
||||
} // End Gmap Options
|
||||
23
modules/gmaps/models/location.php
Normal file
23
modules/gmaps/models/location.php
Normal file
@@ -0,0 +1,23 @@
|
||||
<?php defined('SYSPATH') OR die('No direct access allowed.');
|
||||
|
||||
/*
|
||||
|
||||
CREATE TABLE `locations` (
|
||||
`id` mediumint(8) unsigned NOT NULL auto_increment,
|
||||
`created` int(10) unsigned NOT NULL,
|
||||
`title` varchar(32) NOT NULL,
|
||||
`description` varchar(127) NOT NULL,
|
||||
`link` varchar(127) NOT NULL,
|
||||
`lon` float(10,6) NOT NULL,
|
||||
`lat` float(10,6) NOT NULL,
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE KEY `uniq_ll` (`lon`,`lat`)
|
||||
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
|
||||
|
||||
*/
|
||||
|
||||
class Location_Model extends ORM {
|
||||
|
||||
// Exciting!
|
||||
|
||||
} // End Location Model
|
||||
16
modules/gmaps/views/gmaps/api_demo.php
Normal file
16
modules/gmaps/views/gmaps/api_demo.php
Normal file
@@ -0,0 +1,16 @@
|
||||
<?php defined('SYSPATH') OR die('No direct access allowed.'); ?>
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||
<head>
|
||||
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
|
||||
<title>Google Maps JavaScript API Example</title>
|
||||
<script src="<?php echo $api_url ?>" type="text/javascript"></script>
|
||||
<script type="text/javascript">
|
||||
<?php echo $map ?>
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
<p>You can use your scroll wheel to zoom in and out of the map.</p>
|
||||
<div id="map" style="width: 600px; height: 400px"></div>
|
||||
</body>
|
||||
</html>
|
||||
11
modules/gmaps/views/gmaps/info_window.php
Normal file
11
modules/gmaps/views/gmaps/info_window.php
Normal file
@@ -0,0 +1,11 @@
|
||||
<?php defined('SYSPATH') OR die('No direct access allowed.'); ?>
|
||||
<div class="gmap-html">
|
||||
<span class="image"><?php echo html::image(array('src' => $location->link, 'alt' => $location->title, 'width' => 100, 'height' => 100)) ?></span>
|
||||
<h6 class="title"><?php echo $location->title ?></h6>
|
||||
<?php
|
||||
|
||||
echo '<p>', implode("</p>\n<p>", explode("\n\n", $location->description)), "</p>\n";
|
||||
|
||||
?>
|
||||
<p class="link"><?php echo html::anchor($location->link, $location->title) ?></p>
|
||||
</div>
|
||||
24
modules/gmaps/views/gmaps/javascript.php
Normal file
24
modules/gmaps/views/gmaps/javascript.php
Normal file
@@ -0,0 +1,24 @@
|
||||
<?php defined('SYSPATH') OR die('No direct access allowed.'); ?>
|
||||
google.load("maps", "2.x", {"language" : "<?php echo substr(Kohana::config('locale.language.0'), 0, 2);?>"});
|
||||
function initialize() {
|
||||
if (GBrowserIsCompatible()) {
|
||||
// Initialize the GMap
|
||||
<?php echo $map, "\n" ?>
|
||||
<?php echo $controls, "\n" ?>
|
||||
<?php echo $center, "\n" ?>
|
||||
<?php echo $options->render(1), "\n" ?>
|
||||
<?php if ( ! empty($icons)): ?>
|
||||
|
||||
// Build custom marker icons
|
||||
<?php foreach($icons as $icon): ?>
|
||||
<?php echo $icon->render(1), "\n" ?>
|
||||
<?php endforeach ?>
|
||||
<?php endif ?>
|
||||
|
||||
// Show map points
|
||||
<?php foreach($markers as $marker): ?>
|
||||
<?php echo $marker->render(1), "\n" ?>
|
||||
<?php endforeach ?>
|
||||
}
|
||||
}
|
||||
google.setOnLoadCallback(initialize);
|
||||
17
modules/gmaps/views/gmaps/jquery.php
Normal file
17
modules/gmaps/views/gmaps/jquery.php
Normal file
@@ -0,0 +1,17 @@
|
||||
<?php defined('SYSPATH') OR die('No direct access allowed.'); ?>
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||
<head>
|
||||
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
|
||||
<title>Gmaps jQuery + XML Example</title>
|
||||
<script src="<?php echo $api_url ?>" type="text/javascript"></script>
|
||||
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js" type="text/javascript"></script>
|
||||
<script type="text/javascript">
|
||||
<?php echo $map?>
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
<p>You can use your scroll wheel to zoom in and out of the map.</p>
|
||||
<div id="map" style="width:600px;height:400px;"></div>
|
||||
</body>
|
||||
</html>
|
||||
49
modules/gmaps/views/gmaps/jquery_javascript.php
Normal file
49
modules/gmaps/views/gmaps/jquery_javascript.php
Normal file
@@ -0,0 +1,49 @@
|
||||
<?php defined('SYSPATH') OR die('No direct access allowed.'); ?>
|
||||
google.load("maps", "2.x", {"language" : "<?php echo substr(Kohana::config('locale.language.0'), 0, 2);?>"});
|
||||
|
||||
$(function()
|
||||
{
|
||||
if (GBrowserIsCompatible())
|
||||
{
|
||||
// Initialize the Gmap
|
||||
<?php echo $map, "\n" ?>
|
||||
<?php echo $controls, "\n" ?>
|
||||
<?php echo $center, "\n" ?>
|
||||
<?php echo $options->render(1), "\n" ?>
|
||||
|
||||
// Load map markers
|
||||
$.ajax
|
||||
({
|
||||
type: 'GET',
|
||||
url: '<?php echo url::site('google_map/xml') ?>',
|
||||
dataType: 'xml',
|
||||
success: function(data, status)
|
||||
{
|
||||
$(data).find('marker').each(function()
|
||||
{
|
||||
// Current marker
|
||||
var node = $(this);
|
||||
|
||||
// Extract HTML
|
||||
var html = node.find('html').text();
|
||||
|
||||
// Create a new map marker
|
||||
var marker = new google.maps.Marker(new google.maps.LatLng(node.attr("lat"), node.attr("lon")));
|
||||
google.maps.Event.addListener(marker, "click", function()
|
||||
{
|
||||
marker.openInfoWindowHtml(html);
|
||||
});
|
||||
|
||||
// Add the marker to the map
|
||||
map.addOverlay(marker);
|
||||
});
|
||||
},
|
||||
error: function(request, status, error)
|
||||
{
|
||||
alert('There was an error retrieving the marker information, please refresh the page to try again.');
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
// Unload the map when the window is closed
|
||||
$(document.body).unload(function(){ GBrowserIsCompatible() && GUnload(); });
|
||||
13
modules/gmaps/views/gmaps/static_demo.php
Normal file
13
modules/gmaps/views/gmaps/static_demo.php
Normal file
@@ -0,0 +1,13 @@
|
||||
<?php defined('SYSPATH') OR die('No direct access allowed.'); ?>
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||
<head>
|
||||
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
|
||||
<title>Google Maps Static Map Example</title>
|
||||
</head>
|
||||
<body>
|
||||
<img src="<?php echo $simple;?>" />
|
||||
<img src="<?php echo $multi;?>" />
|
||||
|
||||
</body>
|
||||
</html>
|
||||
2
modules/gmaps/views/gmaps/xml.php
Normal file
2
modules/gmaps/views/gmaps/xml.php
Normal file
@@ -0,0 +1,2 @@
|
||||
<?php defined('SYSPATH') OR die('No direct access allowed.'); ?>
|
||||
<p><?=$location->title;?>, <br /><?=$location->description;?></p>
|
||||
Reference in New Issue
Block a user