Skip to content
Snippets Groups Projects
Commit 4a594a95 authored by Brandon Bergren's avatar Brandon Bergren
Browse files

HEAD is now empty. What was here is now DRUPAL-4-7--2.

parent 36b23162
No related branches found
No related tags found
No related merge requests found
GMAP API DOCUMENTATION
The gmap API allows other modules to integrate Google Maps into their
Drupal Site. It can also be used by theme developers to integrate Google
maps into portions of their theme.
It can also be used to insert a map into any block of php.
INSTALLATION
To install the gmap API you must install the GMap.module.
1) copy the gmap directory into the modules directory
2) edit the theme files to ensure that the html file has the following at
the top of each page (the first one is recommended by Google, the
second is required for the lines overlays to work in IE:
<!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" xmlns:v="urn:schemas-microsoft-com:vml">
3) Get a GMap API Key at http://www.google.com/apis/maps/signup.html
4) enable the 'gmap module' in drupal
5) edit admin/settings/gmap to include the key you received from google and
change any other default setting.
If you are not using the filter built into the gmap.module and you do not
intend to insert google maps into nodes, then you can use the "Dynamic"
setting which will only load the google javascript on pages with Google
maps.
PROGRAMMING API
There are two different methods of inserting a Google Map using the gmap
API. The first is using a macro as can be built from the macro creator
included as part of this module. The second uses the gmap associative
array to define the Google Map function.
Macro
The macro is straight with each variable separated by a "|" and then uses
an "=" to define that variable. Possible parameters are:
id - the id for the map. Each map on a page must have a unique id.
center - The comma separated latitude and longitude of the centre of
the map.
width - width of the map
height - height of the map
zoom - the zoom factor of the google map
align - the alignment of the map 'right', 'left' or 'center'
control - the control shown on the map 'Large', 'Small', or 'None'
type - 'Map', 'Hybrid' or 'Satellite'
points/markers - a string of points to mark on the map with + between
each point
line - the line is defined by a set of points separated by a +
track - Draws a line based on the points in the .plt file
feed - the RSS feed with geo:lat information to be parsed by js
The following shape types require XMaps: (xmaps is not currently functioning)
circle - a circle based on a center point and a radius in km separated
by a + and optionally can include the number of sizes.
rpolygon - a regular polygon is defined by the center point and a point
on the permiter separated by a +
polygon - a polygon is defined by a set of points
For a more detailed explanation on how to make complicated macros see:
http://webgeer.com/gmapdemo
You can convert a macro into a gmap array with the function
gmap_parse_macro($instring,$ver=2) $ver is only required if you need to
use a macro generated with an old version of gmap where the format was
longitude, latitude (set to 1 in that case).
Gmap Array
The GMap Array is an associative array with the following definitions:
id - the id of the map every map on a page must have a unique id
width - width of the map should be either 'px' or '%'
height - height of the map
latitude - a string of the latitude of the centre of the map
longitude - a string of the longitude of the centre of the map
zoom - the zoom factor of the google map
align - the alignment of the map 'right', 'left' or 'center'
control - the control shown on the map 'Large', 'Small', or 'None'
tcontrol - whether the type control is on the map or not: 'off' or 'on'
scontrol - whether the scale control is on the map or not: 'off' or 'on'
ocontrol - the 'width,height' of the overview map control
type - 'Map', 'Hybrid' or 'Satellite'
drag - 'yes' or 'no' map is draggable. Default is 'yes'
markers - an array of marker arrays. Each marker array is an associative
array with the following elements:
'latitude' - the latitude of the marker
'longitude' - the longitude of the marker
'markername' - the marker icon to use. For example if it is set
to 'number', then the icons in the marker directory named
'number1.png', 'number2.png' etc. will be used. If these don't
exist 'number.png' would be used. If that doesn't exist then
the default marker will be used. (optional)
'label' - html text to be located in a pop-up window when you click
on the marker.
shapes - an array of shape arrays. Each shape array can have the
following elements:
'type' - 'line', 'circle', 'rpolygon', or 'polygon'
'color' - the hex for the color to create the line (eg. '#00dd00')
'width' - the width of the line in px
'opacity' - between 0 and 1 for the opacity of the line
'pattern' - a broken line definition '20 5 10 5' would mean 20 px
long line, 5x break, 10px line 5px break 20px line ...
(xmaps objects only)
'text' - the text used in the line (xmaps only)
'fillcolor' - the fill color for filled objects (xmaps objects only)
'fillopacity' - the opacity of the filled objects (xmaps object only)
tracks - an array of track arrays. Each track array can have the
following elements:
'filename' - a filename for the track (.plt) file. Should be
relative to the drupal base url.
'type', 'color', etc... same as the shape line.
feeds - an array of feed arrays. Each feed array can have the
following elements:
'url' - the url of the feed.
'markername' - the marker icon to use. same as for markers
except that numbered markers are not supported.
wmss - an array of WMS services arrays. Each WMS service array can have the
following elements:
'name' - the name of the custom map (no spaces or special chars).
'url' - the url of the WMS service.
'format' - image format to retrieve. Depends of WMS service:
'image/gif','image/png','image/jpeg'
'layers' - a comma separated list of layers advertized by WMS service
to show in this custom map.
'minresolution' - lowest zoom level of this custom map.
'maxresolution' - highest zoom level of this custom map.
'copyrights' - an array of copyrights to display. Each copyright array
can have the following elements:
'minzoom' - lowest zoom level at which this information applies.
'bounds' - a comma separated list of coordinates defining a
region to which this copyright information applies: 'S,W,N,E'
'text' - text of the copyright message.
'overlaywith' - (optional) overlay WMS layers with this Google layers:
'Map', 'Hybrid', 'Satellite' or 'None'(default)
'merczoomlevel' - (optional) zoom factor of the google map where WMS service
should advertize layers in Transverse Mercator projection instead
of WGS84 projection. See discussion of this topic here:
http://johndeck.blogspot.com/#112679047816546118
'opacity' - (optional) Opacity level for this tile from 0.0 (transparent)
to 1.0 (opaque)
The gmap marker is converted to the javascript to display the map using the
function gmap_draw_map($gmap, $javascript=''), where $gmap is a map
variable and javascript is some javascript to be run when the map is
loaded. Note that the string '{mapid}' in the javascript will be
replaced with the mapid of the map being drawn.
It should be noted that the default map settings provided on the
admin/settings/gmap page will be used for any value that is not provided.
An example of the gmap_draw_map function being used.
$myshapes=array(array('color' => '#00dd00',
'type'=>'line',
'opacity' => '0.5',
'points' => array( array('latitude'=>'49.19011831503412','longitude'=>'-123.20737838745117'),
array('latitude'=>'49.18506953036687','longitude'=>'-123.16274642944336'))),
array('color' => '#00dd00',
'opacity' => '0.5',
'type'=>'line',
'points' => array(array('latitude'=>'49.20526157803394','longitude'=>'-123.19965362548828'),
array('latitude'=>'49.20077516864678','longitude'=>'-123.16102981567383'))));
$mymarkers=array(array('markername'=>'blue',
'label' => 'Terminal bus stop',
'latitude' =>'49.19236205396474',
'longitude'=>'-123.1790542602539'),
array('markername'=>'green',
'label' => 'Service buildings bus stop',
'latitude' =>'49.19224986943509',
'longitude'=>'-123.1538200378418'),
array('markername'=>'green',
'label' => 'Transer to Vancouver bus',
'latitude' =>'49.191801128772326',
'longitude'=>'-123.14231872558594'));
$mymap=array('id' => 'mymap',
'latitude' => '49.19258642226091',
'longitude'=>' -123.17647933959961',
'zoom' => 13,
'width' => '100%',
'height' => '400px',
'type' => 'Satellite',
'shapes' => $shapes,
'markers' => $mymarkers);
gmap_draw_map($mymap);
$Id$
Description
-----------
The main GMap module is primarily an API module. The API that allows
other modules or administrators to convert either an array of
specifications or a macro text into a html/javascript text that
will include the google map on their page.
The module includes a macro generator which will allow you to interactively
create a gmap macro suitable for using for a variety of purposes with this
module.
Included with this module is a filter, which allows you to take the text
created from the macro and insert it into a node and the filter will
convert this into a google map shown on the node.
Also packaged with this module is the module gmap_location.module. This
lets one display location information from nodes or users on google maps.
Installation
------------
1) copy the gmap directory into the modules directory
2) edit the theme files to ensure that the html file has the following at
the top of each page (the first one is recommended by Google, the
second is required for the lines overlays to work in IE:
<!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" xmlns:v="urn:schemas-microsoft-com:vml">
3) Get a GMap API Key at http://www.google.com/apis/maps/signup.html
4) enable the 'gmap module' in drupal
5) edit admin/settings/gmap to include the key you received from google and
change any other default setting.
6) configure an 'input format' so that the gmap filter is activated. If
this will be on a 'html filtered' format, ensure that the weighting is
such that the HTML filter comes before the gmap filter.
7) (optional) To use clusterer.js (useful if you have more than about 100 markers on a page)
get the javascript file from http://www.acme.com/javascript/#Clusterer and copy into
your gmap directory
8) (optional) To use wms features get the script http://dist.codehaus.org/geoserver/gmaps-geoserver_scripts/wms-gs-1_0_0.js
and install it in your gmap directory.
Instructions
------------
Macro
-----
A gmap macro can be created on the map/macro page and the text can then be
copied and pasted into any node where the gmap filter is enabled.
Default settings will be the initial settings and will be used for any
parameter not inserted into the macro.
A gmap can also be inserted into any page or template by using either the
macro text and the function gmap_from_text($macro); or using the
function gmap_from_var($gmapvar); where $gmapvar is an associative array.
After you insert the macro into a node, you can edit it using raw values
that you get from elsewhere to create a set of points or lines on the map.
It should be noted that when editing the macro you are not limited to 3
points on the map. An unlimited number of points may be added separated
by the '+' symbol. This could be used, for example, to plot a series of
points that you get from a GPS.
It should be noted that currently the macro parsing (filter) has much more
functionality than can be created using the macro creator.
User
----
If the user functions are enables (on the settings page) then users are
able to edit their location using an interactive google map on the edit
user page. Alternatively they can enter in their Latitude and Longitude
and the map will set their location.
Any user that has permission for "show user map" will then be able to see
a map of all of the user locations at: q=gmapusers if a user has permission
to "user location" when they click on the marker they will see what user it
is.
Nodes
-----
In order to set the location of a node using an interactive gmap, the user
must have access permission to enter lat/longitude in location.module.
The location of the current node can be shown by activating the block
"location". This block can be displayed below the content or anywhere
else that blocks can be displayed.
A map showing all of the nodes with location information can be viewed at
map/node
Markers
-------
You can set a custom marker. A number of custom markers are located in the
markers directory. Markers that don't use the standard shape are located in
subdirectories. small is for a small markers, large is for an oversized marker
and flat is for markers without shadows.
If you would like to create your own marker, the best way to do it is to take
an existing marker and make the changes you want, you should keep the same
size and shape. it must be saved with a '.png' extension.
I would like to increase the library of markers, so if you create an interesting
marker, please e-mail it to me.
Demo
----
For a few pages that show some of the items mentioned above see:
http://www.webgeer.com/map/macro
http://www.webgeer.com/gmapdemo
http://www.webgeer.com/map/users
For a website that uses the location.module and gmap.module integration
with gmap_location.module see:
http://photo-tips.ca/
Bugs & quirks
-------------
- The gmap.module user location setting functionality is not compatible with
the location.module module user setting functionality. Furthermore, the
location.module does not let you insert the lat/long manually. If you
would like to display ther users on a map, I recommend disabling the
user functionality within location.module.
- If a gmap is in a collapsed area when it is uncollapsed it will not display
the whole map, if you drag the map, it will be redrawn and the whole map
will be visible.
- xmaps does not work with google map v2 yet, so that functionality has been
disabled.
- There is a conflict between the xmaps script and the javascript that does
the collapsing menus. If want to use the xmaps functionality, it is
recommended that you comment out all of the statements in the function
"collapseEnsureErrorsVisible()" in misc/collapse.js.
(xmaps not currently available so this is irreleveant now)
- The "dynamic" gmap method of inserting the initialization script does not
work with the filter functionality. (It does work with user functionality).
- When you preview a node, if the map is shown in the short version, it
will not be shown on the long version of the node, this is because only
one copy of a mapid can be shown on the same page.
To do
-----
- rationalize all of the different default map variables, so that most of them
use the 'default map' settings of the gmap.
- Significantly upgrade the macro creator.
- The documentation (both in the code and this file) needs to be significantly
improved.
- create interface to geocoding for address or postal code to Long, Lat
conversion. Preferably on the client side of the javascript gmapmacro
page. (Probably wont do this, leave this functionality to location.module)
- Create an API that will allow the use of the macro creation tool in any
module.
- Create setting to suppress the option of changing some of the settings in
the macro creation page. This could be used so that all maps generated
are the same size, or the same magnification.
Credit
------
Written by:
James Blake
http://www.webgeer.com/James
Thanks to the following for their contributions:
Robert Douglass - for revamping some parts that really needed to be
revamped and cleaning up a lot of little things.
Paul Rollo - for his contribution on showing how to include a location map
in a block.
Nick Jehlen - who commissioned much of the initial work of gmap_location.module
for the website http://enoughfear.com.
History
-------
(I haven't been keeping up with this sorry)
2005-12-xx:
- forked the 4.6/4.7 version, both versions will continue to be developed
for a while longer.
- added gmap user functionality
- width and height can be either px or %
- gmapmacro no longer needs to reload page (now works without clean url's)
- generalized gmap_from_var so that uses an array of points, or an array
of lines, ...
- 37518-Info windows associated with points (markers) can be shown
- can optionally include xgmap options such as circle/polygon/style types
2005-10-15 Quite a few fixes. (some reported in the project and some just
noted myself)
-Map controls are properly initialized in the gmapmacro page (can be
removed or changed)
-33949-Prevent errors from occurring if the Google Map key still blank
(not yet set)
-34036-Hybrid and Satellite maps now show in nodes
-33951-Long,Lat order and terminology corrected (note old Macros will
still work)
-33730-Alignment problem fixed. Now uses css.
-A few other little bugs
2005-10-10 Fix a number of little things and improve the macro interface
2005-10-09 Initial Release (probably too early)
v\:* {
behavior:url(#default#VML);
}
.gmap-popup{
}
.gmap-tooltip{
padding: 2px;
margin: 0;
border: solid black 1px;
}
/* $Id$ */
var baseIcon=new Array();
var geocoder = null;
function gmap_init() {
baseIcon['standard'] = new GIcon();
baseIcon['standard'].image = "http://www.google.com/mapfiles/marker.png";
baseIcon['standard'].shadow = "http://www.google.com/mapfiles/shadow50.png"
baseIcon['standard'].iconSize = new GSize(20, 34);
baseIcon['standard'].shadowSize = new GSize(37, 34);
baseIcon['standard'].iconAnchor = new GPoint(9, 34);
baseIcon['standard'].infoWindowAnchor = new GPoint(9, 2);
baseIcon['standard'].infoShadowAnchor = new GPoint(18, 25);
baseIcon['big']=new GIcon();
baseIcon['big'].image= gmapMarkerLocation + "/big/blue.png";
baseIcon['big'].shadow=gmapMarkerLocation + "/big/shadow.png";
baseIcon['big'].iconsize=new GSize(30,51);
baseIcon['big'].shadowSize=new GSize(56,51);
baseIcon['big'].iconAnchor=new GPoint(13,34);
baseIcon['big'].infoWindowAnchor=new GPoint(13,3);
baseIcon['big'].infoShadowAnchor=new GPoint(27,37);
baseIcon['small'] = new GIcon();
baseIcon['small'].image = gmapMarkerLocation + "/small/red.png";
baseIcon['small'].shadow = gmapMarkerLocation + "/small/shadow.png";
baseIcon['small'].iconSize = new GSize(12, 20);
baseIcon['small'].shadowSize = new GSize(22, 20);
baseIcon['small'].iconAnchor = new GPoint(6, 20);
baseIcon['small'].infoWindowAnchor = new GPoint(5, 1);
baseIcon['flat'] = new GIcon();
baseIcon['flat'].image = gmapMarkerLocation + "/flat/x.png";
baseIcon['flat'].shadow = "";
baseIcon['flat'].iconSize = new GSize(16, 16);
baseIcon['flat'].shadowSize = new GSize(0, 0);
baseIcon['flat'].iconAnchor = new GPoint(8, 8);
baseIcon['flat'].infoWindowAnchor = new GPoint(8, 8);
}
function createIcon(marker) {
var re = /markers\/([a-zA-Z0-9]+)\//;
var m = re.exec(marker);
var bicon='standard' ;
if (m) {
if (baseIcon[m[1]]) {
var bicon=m[1];
}
}
var markerIcon = new GIcon(baseIcon[bicon]);
markerIcon.image = marker;
return markerIcon;
}
function createGMarker(point, htmltext, marker, tooltip, towebsite) {
if (marker.length >0) {
var markerIcon=createIcon(marker);
var returnMarker = new GMarker(point, {icon: markerIcon, title: tooltip});
}
else {
var returnMarker = new GMarker(point, {title: tooltip});
}
if (!towebsite) towebsite='';
// Show this htmltext info window when it is clicked.
if (towebsite.length>0 && markerlink){
GEvent.addListener(returnMarker, 'click', function() {
open(towebsite,'_self');
});
}
else if (htmltext.length>0) {
GEvent.addListener(returnMarker, 'click', function() {
returnMarker.openInfoWindowHtml(htmltext);
});
}
return returnMarker;
}
//moves thispoint based on the form with the id gmap-longitude and gmap-latitude
thispoint=false;
function gmap_textchange(thismap) {
if (thispoint) {
thismap.removeOverlay(thispoint);
}
thismap.panTo(newpoint=new GLatLng($("gmap-latitude").value, $("gmap-longitude").value));
thismap.addOverlay(thispoint=new GMarker(newpoint));
}
function gmap_geocodeaddress(thismap, address) {
geocoder.getLatLng(
address,
function(point) {
if (!point) {
alert(address + " not found");
} else {
if (thispoint) {
thismap.removeOverlay(thispoint);
}
thismap.setCenter(point, 13);
var thispoint = new GMarker(point);
thismap.addOverlay(thispoint);
$("gmap-latitude").value=point.lat();
$("gmap-longitude").value=point.lng();
}
}
);
if (thispoint) {
thismap.removeOverlay(thispoint);
}
thismap.panTo(newpoint=new GLatLng($("gmap-latitude").value, $("gmap-longitude").value));
thismap.addOverlay(thispoint=new GMarker(newpoint));
}
function createMarkerFromRSS(item,icon) {
var title = item.getElementsByTagName("title")[0].childNodes[0].nodeValue;
var description = item.getElementsByTagName("description")[0].childNodes[0].nodeValue;
var link = item.getElementsByTagName("link")[0].childNodes[0].nodeValue;
//SC Good practice is not to have to check for which browser - so just use specified NS in all cases
if (navigator.userAgent.toLowerCase().indexOf("msie") < 0) {
//SC Non IE specific code (uses spec in MZ)
if (item.getElementsByTagName("lat").length>0) {
item.getElementsByTagName("lat")[0].normalize();
if (item.getElementsByTagName("lat")[0].hasChildNodes()) {
var lat = item.getElementsByTagName("lat")[0].childNodes[0].nodeValue;
var lng = item.getElementsByTagName("long")[0].childNodes[0].nodeValue;
}
} else {
if (item.getElementsByTagName("latitude").length>0) {
item.getElementsByTagName("latitude")[0].normalize();
if (item.getElementsByTagName("latitude")[0].hasChildNodes()) {
var lat = item.getElementsByTagName("latitude")[0].childNodes[0].nodeValue;
var lng = item.getElementsByTagName("longitude")[0].childNodes[0].nodeValue;
}
}
}
} else {
//SC IE specific code - has to have specified NS in tagname wont work in MZ code
//SC When checking for presence or NULL - IE considers .length attribute false
//SC used active check like hasChildNodes
if (null != item.getElementsByTagName("geourl:latitude")) {
//SC The normalise function is not available (I think?) to IE so needs to be extracted
var lat = item.getElementsByTagName("geourl:latitude")[0].childNodes[0].nodeValue;
var lng = item.getElementsByTagName("geourl:longitude")[0].childNodes[0].nodeValue;
} else {
if (null != item.getElementsByTagName("icbm:latitude")) {
var lat = item.getElementsByTagName("icbm:latitude")[0].childNodes[0].nodeValue;
var lng = item.getElementsByTagName("icbm:longitude")[0].childNodes[0].nodeValue;
} else {
if (null != item.getElementsByTagName("geo:lat")) {
//SC Be aware that with responseText it is likely that corrupted tags will
// get through and you end up with badly formed numbers. As I suspect can happen here.
// thats why I left the geo tag til last - as that is still up in the air.
var lat = item.getElementsByTagName("geo:lat")[0].childNodes[0].nodeValue;
var lng = item.getElementsByTagName("geo:long")[0].childNodes[0].nodeValue;
}
}
}
}
//SC Finally we have it all to go ahead - we could concatenate HTML from description later.
var point = new GLatLng(parseFloat(lat), parseFloat(lng));
var html = "<a href=\"" + link + "\">" + title + "</a>";
var marker=createGMarker(point, html, icon, title, link);
return marker;
}
function parseGeoRSS(map, rssurl,icon) {
var request = GXmlHttp.create();
request.open("GET", rssurl, true);
request.onreadystatechange = function() {
if (request.readyState == 4) {
//SC var xmlDoc = request.responseXML; IE does not respond to responseXML if not good
//SC Google suggest their own interface for this
var xmlDoc = GXml.parse(request.responseText);
//SC var items = xmlDoc.documentElement.getElementsByTagName("item"); IE considers the
//SC documentElement false
var items = xmlDoc.getElementsByTagName("item");
for (var i = 0; i < items.length; i++) {
var marker = createMarkerFromRSS(items[i], icon);
map.addOverlay(marker);
}
}
}
request.send(null);
}
This diff is collapsed.
<?php
function gmap_location_install() {
drupal_set_message('Installing location');
switch ($GLOBALS['db_type']) {
case 'mysql':
case 'mysqli':
db_query("
CREATE TABLE {location} (
eid int unsigned NOT NULL default '0',
type varchar(6) NOT NULL default '',
name varchar(255) default NULL,
street varchar(255) default NULL,
additional varchar(255) default NULL,
city varchar(255) default NULL,
province varchar(16) default NULL,
postal_code varchar(16) default NULL,
country char(2) default NULL,
latitude decimal(10,6) default NULL,
longitude decimal(10,6) default NULL,
source tinyint default '0',
PRIMARY KEY (type,eid)
) /*!40100 DEFAULT CHARACTER SET utf8 */;
");
$success = TRUE;
break;
case 'pgsql':
db_query("CREATE TABLE {location} (
eid int NOT NULL default '0' CHECK (eid >= 0),
type varchar(6) NOT NULL default '',
name varchar(255) default NULL,
street varchar(255) default NULL,
additional varchar(255) default NULL,
city varchar(255) default NULL,
province varchar(16) default NULL,
postal_code varchar(16) default NULL,
country char(2) default NULL,
latitude decimal(10,6) default NULL,
longitude decimal(10,6) default NULL,
source smallint default '0',
PRIMARY KEY (type,eid)
)");
$success = TRUE;
break;
default:
break;
} // End case
if ($success) {
drupal_set_message(t('GMap module installed location tables successfully.'));
}
else {
drupal_set_message(t('The installation of GMap module was unsuccessful.'), 'error');
}
}
function gmap_location_update_1() {
return _system_update_utf8(array('location'));
}
function gmap_location_update_2() {
$ret = array();
switch ($GLOBALS['db_type']) {
case 'mysql':
case 'mysqli':
$ret[] = update_sql("ALTER TABLE {location} CHANGE oid eid int unsigned NOT NULL default '0'");
break;
}
drupal_set_message("The schema for gmap module (location table) has been updated. The update is such that you may want to re-resave any views you have that may include locations.");
if(function_exists('views_invalidate_cache')) {
views_invalidate_cache();
}
return $ret;
}
/***************************************************************
PostgreSQL must be supported in all updates after this comment
***************************************************************/
This diff is collapsed.
/* $Id$ */
var map;
var mapdiv;
var colors;
if (isJsEnabled()) {
addLoadEvent(gmap_init);
}
function gmap_args(args) {
gmap_args = args;
}
function gmap_init() {
if (!GBrowserIsCompatible()) { return; }
mapdiv = $('map');
map = new GMap2(mapdiv);
keyboardhandler=new GKeyboardHandler(map);
var mycontrol = new GLargeMapControl();
map.addControl(mycontrol);
map.addControl(new GMapTypeControl());
map.setCenter(new GLatLng(0,0), 3);
// extend the map object
map.drupal = new Object();
map.drupal.mapid=$('gmap-mapid').value
map.drupal.latLongStr = $('gmap-latlong').value;
map.drupal.currentControlType = 'Large';
map.drupal.currentControl = mycontrol;
map.drupal.linecolors = colors;
map.drupal.points = new Array();
map.drupal.pointsOverlays = new Array() ;
map.drupal.line1overlay=null; map.drupal.line1points=new Array(); map.drupal.line1string=new String(); map.drupal.gmapline1=new String();
map.drupal.line2overlay=null; map.drupal.line2points=new Array(); map.drupal.line2string=new String(); map.drupal.gmapline2=new String();
map.drupal.line3overlay=null; map.drupal.line3points=new Array(); map.drupal.line3string=new String(); map.drupal.gmapline3=new String();
$('gmap-macrotext').value = map_to_macro(map);
// Event listeners
GEvent.addListener(map, "moveend", function() {
var center = map.getCenter();
map.drupal.latLongStr = center.lat() + ', ' + center.lng() ;
$('gmap-latlong').value = map.drupal.latLongStr;
$('gmap-macrotext').value = map_to_macro(map);
});
GEvent.addListener(map, "zoomend", function(previouszoom,newzoom) {
$('gmap-zoom').value = newzoom;
$('gmap-macrotext').value = map_to_macro(map);
});
GEvent.addListener(map, "maptypechanged", function() {
var maptype = map.getCurrentMapType();
if (maptype == G_NORMAL_MAP) $('gmap-maptype').value = "Map";
if (maptype == G_HYBRID_MAP) $('gmap-maptype').value = "Hybrid";
if (maptype == G_SATELLITE_MAP) $('gmap-maptype').value = "Satellite";
$('gmap-macrotext').value = map_to_macro(map);
});
GEvent.addListener(map, 'click', function(overlay, point) {
if (overlay) {
var shft=false;
for (i=0; i<map.drupal.points.length; i++){
if (overlay==map.drupal.pointsOverlays[i]) {
shft=true;
}
if (shft==true) {
if (i<map.drupal.points.length) {
map.drupal.pointsOverlays[i]=map.drupal.pointsOverlays[i+1];
map.drupal.points[i]=map.drupal.points[i+1];
}
}
}
map.drupal.points.pop();
map.drupal.pointsOverlays.pop();
map.removeOverlay(overlay);
}
else if (point) {
var selected = $('gmap-clicktype').value;
switch (selected) {
// I've got the feeling that some of the following logic could be trimmed
case 'Points':
map.addOverlay(marker=new GMarker(point));
map.drupal.pointsOverlays.push(marker);
map.drupal.points.push(point.lat() + ',' + point.lng());
break;
case 'Line1':
map.drupal.line1points.push(point);
if (map.drupal.line1overlay) map.removeOverlay(map.drupal.line1overlay);
map.drupal.line1overlay=new GPolyline(map.drupal.line1points, map.drupal.linecolors[0], 5);
map.addOverlay(map.drupal.line1overlay);
if (map.drupal.line1string.length > 0) map.drupal.line1string += ' + ';
map.drupal.line1string += point.lat() + ',' + point.lng();
map.drupal.gmapline1 = map.drupal.line1string;
break;
case 'Line2':
map.drupal.line2points.push(point);
if (map.drupal.line2overlay) map.removeOverlay(map.drupal.line2overlay);
map.drupal.line2overlay=new GPolyline(map.drupal.line2points, map.drupal.linecolors[1], 5);
map.addOverlay(map.drupal.line2overlay);
if (map.drupal.line2string.length > 0) map.drupal.line2string += ' + ';
map.drupal.line2string += point.lat() + ',' + point.lng();
map.drupal.gmapline2 = map.drupal.line2string;
break;
case 'Line3':
map.drupal.line3points.push(point);
if (map.drupal.line3overlay) map.removeOverlay(map.drupal.line3overlay);
map.drupal.line3overlay=new GPolyline(map.drupal.line3points, map.drupal.linecolors[2], 5);
map.addOverlay(map.drupal.line3overlay);
if (map.drupal.line3string.length > 0) map.drupal.line3string += ' + ';
map.drupal.line3string += point.lat() + ',' + point.lng();
map.drupal.gmapline3 = map.drupal.line3string;
break;
}
}
$('gmap-macrotext').value = map_to_macro(map);
});
//initialize default values
set_gmap_latlong($('gmap-latlong').value);
map.setZoom(parseInt($('gmap-zoom').value));
set_gmap_type($('gmap-maptype').value);
set_control_type($('gmap-controltype').value);
set_gmap_dimension($('gmap-height'), 'height');
set_gmap_dimension($('gmap-width'), 'width');
}
function gmap_set_line_colors(args) {
colors = args;
}
/**
* A generic function that takes the extended GMap object and returns a macro text.
*/
function map_to_macro(gmap) {
var zooml = ' |zoom=' + gmap.getZoom();
var centerStr = ' |center=' + gmap.drupal.latLongStr;
var width = ' |width=' + $('gmap-width').value;
var height = ' |height=' + $('gmap-height').value;
var id = ' |id=' + gmap.drupal.mapid;
var control = ' |control=' + gmap.drupal.currentControlType;
var type = ' |type=' + gmap.drupal.currentMapType;
var maptype = map.getCurrentMapType();
if (maptype == G_NORMAL_MAP) var type = ' |type=' + "Map";
if (maptype == G_HYBRID_MAP) var type = ' |type=' + "Hybrid";
if (maptype == G_SATELLITE_MAP) var type = ' |type=' + "Satellite";
// I don't know what alignment does or how to use it. Needs updating
// var alignment = ' |align=' + gmapObj.alignment;
var outpoints = new String();
if (gmap.drupal.points.length > 0) {
var outpoints = ' |markers=' + gmap.drupal.points.join(' + ');
}
line1 = gmap.drupal.gmapline1.length >0 ? ' |line1=' + gmap.drupal.gmapline1 : '';
line2 = gmap.drupal.gmapline2.length >0 ? ' |line2=' + gmap.drupal.gmapline2 : '';
line3 = gmap.drupal.gmapline3.length >0 ? ' |line3=' + gmap.drupal.gmapline3 : '';
return '[gmap' + id + centerStr + zooml + width + height + /*alignment +*/ control + type + outpoints + line1 + line2 + line3 + ']';
}
function set_gmap_mapid(instring) {
map.drupal.mapid=instring;
$('gmap-macrotext').value=map_to_macro(map);
}
function set_gmap_latlong(instring) {
var splitstring=instring.split(",");
map.panTo(new GLatLng(splitstring[0],splitstring[1]));
}
function set_control_type(incontrol) {
map.drupal.currentControlType = incontrol;
if (map.drupal.currentControl) {
map.removeControl(map.drupal.currentControl);
}
if (incontrol == "Small") map.addControl(map.drupal.currentControl = new GSmallMapControl());
if (incontrol == "Large") map.addControl(map.drupal.currentControl = new GLargeMapControl());
$('gmap-macrotext').value = map_to_macro(map);
}
function set_gmap_type(intype) {
map.drupal.currentMapType = intype;
if (intype == "Map") map.setMapType(G_NORMAL_MAP);
if (intype == "Hybrid") map.setMapType(G_HYBRID_MAP);
if (intype == "Satellite") map.setMapType(G_SATELLITE_MAP);
$('gmap-macrotext').value = map_to_macro(map);
}
function setgmapZoom(invalue) {
map.setZoom(parseInt(invalue));
$('gmap-macrotext').value = map_to_macro(map);
}
function set_gmap_dimension(elem, dimension) {
var valid_value = validate_dim(elem.value);
if (valid_value) {
container=map.getContainer();
if (dimension == 'height') {
container.style.height = valid_value;
elem.value = valid_value;
}
else if (dimension == 'width') {
container.style.width = valid_value;
elem.value = valid_value;
}
// gmap_init(map);
map.checkResize();
$('gmap-macrotext').value = map_to_macro(map);
set_gmap_latlong($('gmap-latlong').value);
}
}
function validate_dim(dim) {
return dim;
//needs to be fixed to allow either 'px' or '%'
var reg = /(\d+)/;
var ar = reg.exec(dim);
try {
valid_dim = ar[0] + 'px';
return valid_dim;
} catch (e) {alert(e);
return false;
}
}
function newid() {
var newvalue = $('gmap-id').value;
newvalue=newvalue.match(/^[0-9A-Za-z_-]+/);
if (newvalue.length==0) {
newvalue='map';
}
map.drupal.mapid = newvalue;
}
markers/big/blue.png

2.41 KiB

markers/big/red.png

2.46 KiB

markers/big/shadow.png

1006 B

markers/blank.png

988 B

markers/blue.png

3.52 KiB

markers/cluster.png

1.45 KiB

markers/drupal.png

1.28 KiB

markers/flat/x.png

354 B

markers/gray.png

3.49 KiB

markers/green.png

3.5 KiB

markers/lblue.png

3.54 KiB

0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment