* @author Oliver Georgi * @package GoogleMapAPI * @version 2.5 */ /* $Id: GoogleMapAPI.class.php,v 1.63 2007/08/03 16:29:40 mohrt Exp $ */ /* ************ Enhanced by Oliver Georgi, 2009-06-29 for use with phpwcms Content Management System ************ For best results with GoogleMaps, use XHTML compliant web pages with this header: For database caching, you will want to use this schema: CREATE TABLE `phpwcms_geocodes` ( `address` varchar(255) NOT NULL, `lon` double DEFAULT NULL, `lat` double DEFAULT NULL, PRIMARY KEY (`address`), KEY `lon` (`lon`), KEY `lat` (`lat`) ) ENGINE=MyISAM; */ class GoogleMapAPI { /** * PEAR::DB DSN for geocode caching. example: * $dsn = 'mysql://user:pass@localhost/dbname'; * * @var string */ var $dsn = null; /** * YOUR GooglMap API KEY for your site. * (http://maps.google.com/apis/maps/signup.html) * * @var string */ var $api_key = ''; /** * current map id, set when you instantiate * the GoogleMapAPI object. * * @var string */ var $map_id = null; /** * sidebar
used along with this map. * * @var string */ var $sidebar_id = null; /** * GoogleMapAPI uses the Yahoo geocode lookup API. * This is the application ID for YOUR application. * This is set upon instantiating the GoogleMapAPI object. * (http://developer.yahoo.net/faq/index.html#appid) * * @var string */ var $app_id = null; /** * use onLoad() to load the map javascript. * if enabled, be sure to include on your webpage: * * * @var string */ var $onload = true; /** * map center latitude (horizontal) * calculated automatically as markers * are added to the map. * * @var float */ var $center_lat = null; /** * map center longitude (vertical) * calculated automatically as markers * are added to the map. * * @var float */ var $center_lon = null; /** * enables map controls (zoom/move/center) * * @var boolean */ var $map_controls = true; /** * determines the map control type * small -> show move/center controls * large -> show move/center/zoom controls * * @var string */ var $control_size = 'large'; /** * enables map type controls (map/satellite/hybrid) * * @var boolean */ var $type_controls = true; /** * default map type (G_NORMAL_MAP/G_SATELLITE_MAP/G_HYBRID_MAP) * * @var boolean */ var $map_type = 'G_NORMAL_MAP'; /** * enables scale map control * * @var boolean */ var $scale_control = true; /** * enables overview map control * * @var boolean */ var $overview_control = false; /** * determines the default zoom level * * @var integer */ var $zoom = 16; /** * determines the map width * * @var integer */ var $width = '500px'; /** * determines the map height * * @var integer */ var $height = '500px'; /** * message that pops up when the browser is incompatible with Google Maps. * set to empty string to disable. * * @var integer */ var $browser_alert = 'Sorry, the Google Maps API is not compatible with this browser.'; /** * message that appears when javascript is disabled. * set to empty string to disable. * * @var string */ var $js_alert = 'Javascript must be enabled in order to use Google Maps.'; /** * determines if sidebar is enabled * * @var boolean */ var $sidebar = true; /** * determines if list of point should given * * @var boolean */ var $pointlist = false; /** * determines if to/from directions are included inside info window * * @var boolean */ var $directions = true; /** * determines if map markers bring up an info window * * @var boolean */ var $info_window = true; /** * determines if info window appears with a click or mouseover * * @var string click/mouseover */ var $window_trigger = 'click'; /** * what server geocode lookups come from * * available: YAHOO Yahoo! API. US geocode lookups only. * GOOGLE Google Maps. This can do international lookups, * but not an official API service so no guarantees. * Note: GOOGLE is the default lookup service, please read * the Yahoo! terms of service before using their API. * * @var string service name */ var $lookup_service = 'GOOGLE'; var $lookup_server = array( 'GOOGLE' => 'maps.google.de', 'YAHOO' => 'api.local.yahoo.com' ); var $driving_dir_text = array( 'dir_to' => 'Startadresse: (Straße, PLZ Stadt, Land)', 'to_button_value' => 'Los!', 'to_button_type' => 'submit', 'dir_from' => 'Zieladresse: (Straße, PLZ Stadt, Land)', 'from_button_value' => 'Los!', 'from_button_type' => 'submit', 'dir_text' => 'Route berechnen: ', 'dir_tohere' => 'Hierher', 'dir_fromhere' => 'Von hier' ); /** * version number * * @var string */ var $_version = '2.5'; /** * list of added markers * * @var array */ var $_markers = array(); /** * maximum longitude of all markers * * @var float */ var $_max_lon = -1000000; /** * minimum longitude of all markers * * @var float */ var $_min_lon = 1000000; /** * max latitude * * @var float */ var $_max_lat = -1000000; /** * min latitude * * @var float */ var $_min_lat = 1000000; /** * determines if we should zoom to minimum level (above this->zoom value) that will encompass all markers * * @var boolean */ var $zoom_encompass = true; /** * determines if we can zoom using a mouse's scroll wheel. * * @var boolean */ var $zoom_wheel = false; /** * factor by which to fudge the boundaries so that when we zoom encompass, the markers aren't too close to the edge * * @var float */ var $bounds_fudge = 0.01; /** * use the first suggestion by a google lookup if exact match not found * * @var float */ var $use_suggest = false; /** * list of added polylines * * @var array */ var $_polylines = array(); /** * icon info array * * @var array */ var $_icons = array(); /** * icon cache array * * @var array */ var $_icon_cache = array(); /** * database cache table name * * @var string */ var $_db_cache_table = 'phpwcms_geocodes'; /** * JSON class path * * @var string */ var $class_json_path = 'JSON.php'; var $use_json = false; /** * geocode placemarks returned by getGeocode * it's helpful to check this too and show * alternative addresses returned by Google Maps * * @var array */ var $Geocode_Placemark = array(); /** * debug enable * * @var bool */ var $_debug = false; /** * debug log path/file * * @var string */ var $_debug_file = ''; /** * use MooTools to access element by ID * * @var bool */ var $_mootools = FALSE; /** * class constructor * * @param string $map_id the id for this map * @param string $app_id YOUR Yahoo App ID */ function GoogleMapAPI( $map_id = 'map', $app_id = 'MyMapApp' ) { $this->map_id = $map_id; $this->sidebar_id = 'sidebar_' . $map_id; $this->app_id = $app_id; $this->document_root = $_SERVER['DOCUMENT_ROOT']; $this->_debug_file = empty($this->_debug_file) ? PHPWCMS_TEMP.'maps_url.log' : $this->_debug_file; } function initMap($map_id = 'map', $app_id = 'MyMapApp') { $this->map_id = $map_id; $this->sidebar_id = 'sidebar_' . $map_id; $this->app_id = $app_id; } /** * sets the PEAR::DB dsn * * @param string $dsn */ function setDSN( $dsn ) { $this->dsn = $dsn; } function enableMooTools() { $this->_mootools = TRUE; } function disableMooTools() { $this->_mootools = FALSE; } function useJson($path=NULL) { if($path != NULL) { $this->class_json_path = $path; } if( require_once( $this->class_json_path ) ) { $this->use_json = true; } else { $this->use_json = false; } } function useCSV() { $this->use_json = false; } /** * return the element by ID JavaScript String * * @param string $dsn */ function getElementById() { return $this->_mootools ? '$' : 'document.getElementById'; } /** * sets YOUR Google Map API key * * @param string $key */ function setAPIKey( $key ) { $this->api_key = $key; } /** * sets the width of the map * * @param string $width */ function setWidth( $width ) { if ( !preg_match( '!^(\d+)(.*)$!', $width, $_match ) ) return false; $_width = $_match[1]; $_type = $_match[2]; if ( $_type == '%' ) $this->width = $_width . '%'; else $this->width = $_width . 'px'; return true; } /** * sets the height of the map * * @param string $height */ function setHeight( $height ) { if ( !preg_match( '!^(\d+)(.*)$!', $height, $_match ) ) return false; $_height = $_match[1]; $_type = $_match[2]; if ( $_type == '%' ) $this->height = $_height . '%'; else $this->height = $_height . 'px'; return true; } /** * sets the default map zoom level * * @param string $level */ function setZoomLevel( $level ) { $this->zoom = ( int ) $level; } /** * enables the map controls (zoom/move) */ function enableMapControls() { $this->map_controls = true; } /** * disables the map controls (zoom/move) */ function disableMapControls() { $this->map_controls = false; } /** * sets the map control size (large/small) * * @param string $size */ function setControlSize( $size ) { if ( in_array( $size, array( 'large', 'small', 'medium' ) ) ) $this->control_size = $size; } /** * enables the type controls (map/satellite/hybrid) */ function enableTypeControls() { $this->type_controls = true; } /** * disables the type controls (map/satellite/hybrid) */ function disableTypeControls() { $this->type_controls = false; } /** * set default map type (map/satellite/hybrid) */ function setMapType( $type ) { switch ( $type ) { case 'hybrid': $this->map_type = 'G_HYBRID_MAP'; break; case 'satellite': $this->map_type = 'G_SATELLITE_MAP'; break; case 'physical': $this->map_type = 'G_PHYSICAL_MAP'; break; case 'moon_elevation': $this->map_type = 'G_MOON_ELEVATION_MAP'; break; case 'moon': $this->map_type = 'G_MOON_VISIBLE_MAP'; break; case 'mars_elevation': $this->map_type = 'G_MARS_ELEVATION_MAP'; break; case 'mars': $this->map_type = 'G_MARS_VISIBLE_MAP'; break; case 'mars_infrared': $this->map_type = 'G_MARS_INFRARED_MAP'; break; case 'nightsky': $this->map_type = 'G_SKY_VISIBLE_MAP'; break; case 'map': case 'normal': default: $this->map_type = 'G_NORMAL_MAP'; break; } } /** * enables onload */ function enableOnLoad() { $this->onload = true; } /** * disables onload */ function disableOnLoad() { $this->onload = false; } /** * enables sidebar */ function enableSidebar() { $this->sidebar = true; } /** * disables sidebar */ function disableSidebar() { $this->sidebar = false; } /** * enables pointlist */ function enablePointlist() { $this->pointlist = true; } /** * disables sidebar */ function disablePointlist() { $this->pointlist = false; } /** * enables map directions inside info window */ function enableDirections() { $this->directions = true; } /** * disables map directions inside info window */ function disableDirections() { $this->directions = false; } /** * set browser alert message for incompatible browsers * * @params $message string */ function setBrowserAlert( $message ) { $this->browser_alert = $message; } /** * set