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

Pull DRUPAL-5--1-0-BETA3 into HEAD.

parent 4a594a95
No related branches found
No related tags found
No related merge requests found
API.txt 0 → 100644
$Id$
API.txt
GMap API Documentation
The GMap API is a simple way to create Google Maps from a macro or PHP code. It allows other modules to integrate Google Maps into their Drupal site. Among other things, the GMap API can be used by theme developers to integrate Google maps into portions of their theme, or by developers to insert a map into any block of PHP.
--------
CONCEPTS
--------
Baselayer
The actual map (Street map, topological map, satellite imagery, etc.) that everything is being displayed upon. This may also be referred to as the "map type".
GMap macro
A GMap-specific text-based representation of a Google Map.
Overlay
A transparent layer drawn on top of the baselayer.
---------------
PROGRAMMING API
---------------
There are two methods of inserting a Google Map using the GMap API. You may either describe your map with an associative array, or you may use a GMap macro (introduced in README.txt). GMap macros are appropriate for creating maps via the web interface; GMap arrays are more appropriate if you are writing code to generate a complex map.
------
Macros
------
Each attribute of a macro is separated by a "|" and uses an "=" to define that attribute. Possible attributes are center, width, height, zoom, type, control, align, id, markers, feed, line, circle, polygon, and rpolygon.
**See the MACRO-DICTIONARY.txt for an explaination of each of these attributes.
You can convert a macro into a GMap array with the function gmap_parse_macro(). If you need to parse a macro generated with an old version of GMap where the point format was longitude, latitude, set $version to 1: gmap_parse_macro($my_macro, 1); otherwise, you may omit it.
<?php
/**
* function gmap_parse_macro()
* Convert a macro string into a GMap array.
*
* @param $macro_text
* Macro to process.
* @param $version
* Version to treat macro as.
* Set to 1 when processing very old macros, otherwise leave as is.
* @return
* A GMap array.
*/
// usage
$macro_text = "[gmap zoom=7 |center=41.9023,-87.5391 |width=600px |height=400px |control=Small |type=Map]";
$map_array = gmap_parse_macro($macro_text);
?>
----------
GMap Array
----------
The main map array is quite complex. Most of the features have a macro equivilent, but some of the more powerful constructs do not. The map array is processed and converted to a javascript object. Shapes are parsed by gmap_shapes.js and loaded by shapeloader_static.js.
Using the GMap Array
Once you build a GMap array, you can render it as a map using a theme function provided by GMap. Anything left out of your GMap array will be filled in with the default map settings, which can be changed on the GMap settings page at admin/settings/GMap
**See GMAP-ARRAY-DICTIONARY.txt for explainations of each of the GMap array options.
<?php
// a simple GMap array
$map_array1 = array(
'id' => "my-map", // id attribute for the map
'width' => "100%", // map width in pixels or %
'height' => "400px", // map height in pixels
'latitude' => 41.9023, // map center latitude
'longitude' => -87.5391, // map center longitude
'zoom' => 7, // zoom level
'maptype' => "Map", // baselayer type
'controltype' => "Small" // size of map controls
);
$output1 = theme('gmap', $map_array);
// a more elaborate example
$map_array2 = array(
'id' => 'example',
'maptype' => 'Terrain',
'width' => '400px',
'height' => '400px',
'latitude' => 12.345,
'longitude' => 12.345,
'zoom' => 4,
'align' => 'left',
'controltype' => 'Small',
'mtc' => 'standard',
'behavior' => array(
'locpick' => FALSE,
'nodrag' => FALSE,
'nokeyboard' => TRUE,
'overview' => TRUE,
'scale' => TRUE,
),
'markers' => array(
array(
'text' => 'First Marker',
'longitude' => 39.3739522204,
'latitude' => -81.5681648254,
'markername' => "Light Blue",
),
array(
'text' => 'Second Marker',
'longitude' => 44.205835001,
'latitude' => -70.3674316406,
'markername' => "Orange",
),
),
'shapes' => array(
array(
'type' => "polygon",
'style' => array("000000", 3, 25, "ffff00", 45),
'points' => array(
array(43.667871610117494,-70.675048828125),
array(43.43696596521823,-70.0927734375),
array(43.9058083561574,-69.202880859375),
array(44.512176171071054,-69.796142578125),
array(43.667871610117494,-70.675048828125),
),
array(
'type' => "circle",
'style' => array("000000", 3, 25, "ffff00", 45),
'radius' => 0.7622248729082767,
'center' => array(39.3739522204, -81.5681648254),
),
),
'feeds' => array(
array(
'url' => 'http://earthquake.usgs.gov/eqcenter/catalogs/eqs7day-M5.xml',
'markername' => 'red',
),
),
);
$output2 = theme('GMap', $map_array2);
?>
------- STUFF ABOVE THIS POINT HAS BEEN REVIEWED AND UPDATED -------
------------------ FOR THE UPCOMING GMAP RELEASE -------------------
--------------------------- JULY 7 2008 ----------------------------
GMAP VIEWS API
--------------
The GMap_views module also provides a small API for providing additional
overlay data to the produced map. By defining:
function hook_GMap_views_handle_field($phases, $data)
You can tell GMap which fields contain the geographic information it
needs to plot the nodes on the map.
There are two phases to the hook, 'discovery' and 'process'. During the
discovery phase, your hook will be called once for each field in the
view. If your module can transform this field into latitude and
longitude coordinates, you should return a value. This value will be
store and returned to you during the 'process' phase. This can be use-
ful in caching information, such has how to process the data, etc.
If your module cannot process this field, return NULL (the norm in most
cases).
In the 'process' phase, the $data arugment will contain two keys:
- 'module' => this will hold the name of the field, the module that is
being invoked (your module) and an 'extra' field, containing whatever
you returned during the 'discovery' phase.
- 'entry' => the views "entry" containing all the fields returned from
the database/
From this data you should return an array with keys "lat" and "lon".
Gmap_views will use this array to plot the node on the map.
----------- STUFF AFTER THIS POINT IS MISCELLANEOUS DOCS -----------
--------- PRESUMABLY CREATED FOR THE UPCOMING GMAP RELEASE ---------
------------------------ STILL NEEDS REVIEW ------------------------
HOOK_GMAP
---------
*hook_GMap()* is a general hook for easily extending GMap.
function hook_GMap($op, &$map)
###$op 'macro'###
Test test test
###$op 'pre_theme_map'###
Test test test
###$op 'macro_multiple'###
Test test test
###$op 'behaviors'###
Test test test
GMAP_VIEWS EXTENSIONS
---------------------
In Views 1.x, you need to use the "argument handling code" box to apply settings to a map view.
You can set a custom macro with $view->GMap_macro.
$view->GMap_macro = '[GMap |behavior=+autozoom]';
You can set the map object directly with $view->GMap_map.
$view->GMap_map = $map;
Extensions to core map object:
$map = array(
'#settings' => array(
'behavior' => array(
// Fatmarkers is used to pass the raw views data in as markers.
// This is useful if you are doing custom processing on the javascript side.
'fatmarkers' => FALSE,
),
'GMap_views' => array( // @@@ TODO: Actually *implement* this functionality!
// Set all markers to the same thing.
'forcemarkername' => 'drupal',
// Lookup table for marker names.
// Use in combination with markername.
'markername_map' => array(
'blog' => 'blue',
'story' => 'green',
'page' => 'pink',
),
// OR
//
'markername_map' => 'my_custom_map_function',
// Views fields
// ============
// The field to use to determine the marker name.
// Use in combination with markername_map if the field doesn't contain
// marker names.
'markername' => 'my_custom_field',
// The field to use to determine the marker offset.
// If not set, it will be automatically tracked.
'markeroffset' => 'my_custom_field',
// Latitude and longitude.
'lat' => 'my_custom_field',
'lon' => 'my_custom_field',
'popup_theme' => 'my_custom_popup',
),
),
);
(parse macro header, integrate back into docs.)
/**
*
* Returns a variable based on .
*
* @param $instring
* A string with the settings of GMap insertion in the format var=setting|var2=setting2
* The possible variables are
* id - the id of the map every map on a page must have a unique id
* width - width of the map
* height - height of the map
* center - a string of the longitude and latitude 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'
* 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 +
* The following shape types require XMaps:
* 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
*
* Each of the shapes types can optionally have charecteristics of colour,
* width, opacity, pattern, text, fill colour, fill opacity. Pattern, text
* and fill are all only used by xmaps.
* color - hexadecimal for the colour include the '#'
*
*
* @return
* A string with the google map ready to be inserted into a node.
*
*/
UPDATING OLD MACROS
-------------------
This section still needs to be written.
GMAP-ARRAY-DICTIONARY.txt
This file defines the attributes available in GMap arrays. This is fairly similar to the GMAP-MACRO-DICTIONARY.txt, but distinct in that it addresses array keys and syntax specific to GMap arrays.
Defaults for map attributes can be set on the GMap settings page, located at admin/settings/gmap
----------------
BASIC ATTRIBUTES
----------------
The top level of a GMap array will look something like this:
<?php
$map = array(
'id' => // id attribute for the map
'width' => // map width in pixels or %
'height' => // map height in pixels
'latitude' => // map center latitude
'longitude' => // map center longitude
'zoom' => // zoom level
'maptype' => // baselayer type
'controltype' => // size of map controls
'behavior' => array(),// various map behavior flags
'markers' => array(), // array of points on the map
'shapes' => array(), // array of shapes to overlay on the map
);
?>
Attribute: id
Values: id attribute name
Description: id for the rendered map element, to distinguish the map from other maps on the same page. Any controls that are synced with the map require a map id.
Example: "mymap"
Notes: use if you need to access the map from a script, or if you plan to have multiple maps on a page. As of Gmap 1.0, this is no longer required.
Attribute: width
Values: css dimension
Description: map width, in valid css dimensions (generally pixels or percent)
Example: "100%"
Attribute: height
Values: css dimension
Description: map height, in valid css dimensions (generally pixels)
Example: "400px"
Attribute: latitude
Values: a latitude
Description: the latitude of the initial map center point
Example: 39.36827914916013
Attribute: longitude
Values: a longitude
Description: the longitude of the initial map center point
Example: -81.5625
Attribute: zoom
Values: 0-17
Description: the initial zoom level of the map
Example: 7
Attribute: maxzoom
Values: 0-17
Description: the maximum initial zoom level of the map if the 'autozoom' behavior flag is on.
Example: 7
Attribute: maptype
Values: "Map", "Satellite", "Hybrid", "Terrain"
Description: default baselayer
Example: "Map"
Notes: The most common value is "Map".
Attribute: controltype
Values: "None", "Large", "Small"
Description: zoom and pan controls
Example: "Small"
Attribute: align
Values: "Right", "Left", "Center"
Description: alignment of map on page
Example: align=Center
Attribute: mtc
Values: "none", "standard", "hier", "menu"
Description: the "map type control" widget used to select different baselayers.
Example: "standard"
Notes: 'standard': buttons ('GMapTypeControl' widget)
'hier': buttons + dropdowns ('GHierarchicalMapTypeControl' widget)
'menu': dropdown menu ('GMenuMapTypeControl' widget)
Attribute: baselayers
Values: array("Map", "Satellite", "Hybrid", "Physical", ...)
Description: an array of enabled baselayer names
Example: array("Map", "Satellite", "Hybrid")
Notes: Other modules may define additional baselayers; GMap provides the 4 listed above.
Attribute: styles
Values: array('style1' => array(...), 'style2' => array(...), ...)
Description: an array of style names and definitions
Example: array('line_default' => array('0000ff',5,45,'',0,0), 'poly_default' => array('000000',3,25,'ff0000',45),)
Notes: Currently, 'line_default' and 'poly_default' are defined. In the future, there may be the ability to store styles to apply to shapes easily, but it is not yet implemented.
Attribute: behavior
Values: array()
Description: an array that contains flags for various map behaviors
Attribute: locpic
Values: TRUE, FALSE
Description: set the map up for being used to select a coordinate
Example: FALSE
Notes: Used for incombination with the latitude, longitude, or latlon fields
Attribute: nodrag
Values: TRUE, FALSE
Description: disable dragging
Example: FALSE
Notes: If dragging is disabled, keyboard shortcuts will also be disabled. This replaces the old 'drag' attribute. FALSE allows dragging; TRUE disables dragging.
Attribute: nokeyboard
Values: TRUE, FALSE
Description: disable keyboard shortcuts
Example: TRUE
Notes: FALSE allows keyboard shortcuts; TRUE disables keyboard shortcuts.
Attribute: overview
Values: TRUE, FALSE
Description: enables the 'overview' map control in the bottom right corner
Example: TRUE
Attribute: scale
Values: TRUE, FALSE
Description: displays the map scale indicator
Example: TRUE
Notes: FALSE hides the map scale; TRUE shows the map scale.
Attribute: nomousezoom
Attribute: autozoom
Attribute: dynmarkers
Attribute: collapsehack
Attribute: fatmarkers
--------
OVERLAYS
--------
There are three types of overlays you can place on a map: markers, shapes, and feeds. Each of these classes is represented by a sub-array in the GMap array.
Attribute: markers
Values: array()
Description: an array of markers to place on the map
An array describing an individual marker will look like this:
<?php
$marker = array(
'options' => array(),
'text' => 'popup text',
'longitude' => 0.000,
'latitude' => 0.000,
'markername' =>
'offset' => 0,
);
?>
Attribute: latitude
Values: a latitude
Description: the latitude of the point
Example: 39.36827914916013
Attribute: longitude
Values: a longitude
Description: the longitude of the point
Example: -81.5625
Attribute: markername
Values: the name of a marker icon
Description: marker icons are located in the GMap module's 'marker' directory; names are defined in the .ini files. Optional.
Example: "Light Blue"
Notes: sequential markers are available; for example, if the markername 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.
Attribute: text
Values: "map bubble text"
Description: text and/or HTML to be displayed in the map bubble when the marker is clicked
Example: "Point A"
Notes: @@@ Bdragon mentioned an "array tabs trick"??
Attribute: shapes
Values: array()
Description: an array of shapes to place on the map
A "line" or "polygon" shape will be described by an array that looks like this:
<?php
$shape = array(
'type' => "polygon",
'points' => array(
array(0.000, 0.000),
array(0.000, 0.000),
array(0.000, 0.000),
),
'style' => array("ff0000", 5, 80, "00ff00", 60),
);
?>
Attribute: type
Values: "line", "polygon", "circle", "rpolygon"
Description: the type of shape to draw
Example: "line"
Notes: "line" is drawn as a GPolyline.
"polygon" is drawn as a GPolygon.
"circle" and "rpolygon" (regular polygon) are special cases of "polygon"; points are calculated on the fly. The array defining circles and regular polygons looks different from the arrays defining lines and polygons; see below.
Attribute: points
Values: array(array(lat1, lon1), array(lat2, lon2), ... , array(latN, lonN))
Description: an array of points defining the shape
Example: array(array(44.205835001, -70.3674316406), array(44.3159879052, -68.6096191406))
Notes: Each point itself is an array with two elements (latitude, longitude). The different shapes have different requirements with respect to points.
"line" must have at least two points. It is best to break up long lines into shorter segments, because long lines can be buggy--sometimes beginning and ending points are switched.
"polygon" should have at least three points; the first and last points should have the same coordinates.
Attribute: style
Values: array(stroke color, stroke weight, stroke opacity, fill color, fill opacity)
Description: a "style array"
Example: array("ff0000", 5, 80, "00ff00", 60)
Notes: The elements of this array MUST be in the specified order.
Stroke and fill colors should be hex color codes (without the leading "#"); Google Maps does not accept named colors.
The stroke weight is the width of the line or polygon border in pixels.
Stroke and fill opacities should be a percentage between 0 and 100.
Fill color and fill opacity are not used for type "line".
If shapes of type "line" don't have styles defined, the 'line_default' style will be used; shapes of type "polygon", "circle", and "rpolygon" will use 'poly_defalt'.
In previous versions of GMap, opacity was specified as a number between 0 and 1; it is now a number between 0 and 100.
On backwards compatibility: there were originally more style options, but they were dependant on xmaps; xmaps is no longer compatible with Google Maps, so these options are now ignored. They are: 'pattern', 'text', 'fillcolor', 'fillopacity'; all except for 'pattern' are now available with different syntax.
Circles and regular polygons are special cases of "polygon" and have significantly different shape arrays:
<?php
$shape1 = array(
'type' => 'circle',
'center' => array(0.000, 0.000), // center coordinate of the circle
'radius' => 100, // radius of the circle in kilmeters
'style' => array(), // uses 'poly_default' if not defined
);
$shape2 = array(
'type' => 'rpolygon',
'center' => array(0.000, 0.000), // center coordinate of the circle
'numpoints' => 4, // number of vertices the polygon should have
'point2' => array(0.000, 0.000), // one vertice of the polygon
'style' => array(), // uses 'poly_default' if not defined
);
?>
GMAP-MACRO-DICTIONARY.txt
This file defines the attributes available in GMap macros.
----------------
BASIC ATTRIBUTES
----------------
Attribute: center
Values: lat,lon
Description: map center
Example: center=39.36827914916013,-81.5625
Attribute: width
Values: css dimension
Description: map width, in valid css dimensions (generally pixels or percent)
Example: width=100%
Attribute: height
Values: css dimension
Description: map height, in valid css dimensions (generally pixels)
Example: height=400px
Attribute: zoom
Values: 0-17
Description: the initial zoom level of the map
Example: 7
Attribute: type
Values: "Map", "Satellite", "Hybrid", "Terrain"
Description: baselayer
Example: type=Map
Attribute: control
Values: "None", "Large", "Small"
Description: zoom and pan controls
Example: control=Small
Attribute: align
Values: "Right", "Left", "Center"
Description: alignment of map on page
Example: align=Center
Attribute: id
Values: id attribute name
Description: id for the rendered map element, to distinguish the map from other maps on the same page. Any controls that are synced with the map require a map id.
Example: id=mymap
Notes: use if you need to access the map from a script, or if you plan to have multiple maps on a page. As of Gmap 1.0, this is no longer required.
--------
OVERLAYS
--------
Each of these attributes may be repeated within a GMap macro. You would repeat attributes if you wanted multiple overlays of the same type on one map.
Attribute: markers
Values: marker name::lat1,lon1:popup1 text + lat2,lon2:popup2 text + … + latN,lonN:popupN text
Description: place a point or series of points on the map
Example: markers=blue::39.367383358933125,-81.56906604766846 + 39.36675298114445,-81.5561056137085
Notes: Repeat for each different marker type that you want to use. The "marker name" may be the name of a series of markers. Popup text may contain plain text or HTML, as long as it does not have the symbols "|", "+", or "]". Use the HTML entities for these characters (&#0124;, &#0043;, and &#0093; respectively).
Attribute: feed
Values: GeoRSS feed
Description: an RSS feed with geo:lat information to be overlaid on the map. **local feeds only?
Example: feed=blue::/my-location-rss
Notes: Location.module automatically adds GeoRSS information to RSS feeds. This means that RSS feeds created with Views can be directly overlaid onto your GMaps.
You can set some style attributes for lines and shapes. Where these are not set, the defaults for google are used. These styles are written directly after the "=" in a specific order, separated by a "/", and are followed by a ":". Previous versions of GMap could use Xmaps to create dashed lines and text labels for lines and polygons, but those options are no longer supported. Opacity also used to be specified as a number between 0 and 1; it is now a number between 0 and 100.
Attribute: line
Values: line color in hex/line width in pixels/line percent opacity:lat1,lon1 + lat2,lon2 + … + latN,lonN
Description: place a line on the map
Example: line=#0000ff/5/45:39.361942015870724,-81.5711259841919 + 39.369506694882396,-81.56558990478516 + 39.3664212010754,-81.56172752380371 + 39.368146440221935,-81.55773639678955
Notes: It is best to break up long lines into shorter segments, because long lines can be buggy--sometimes beginning and ending points are switched.
Attribute: circle
Values: line color in hex/line width in pixels/line percent opacity/fill color in hex/fill percent opacity:lat1,lon1 + lat2,lon2 + … + latN,lonN
Description: place a circle on the map
Example: circle=#000000/3/25/#ffff00/45:39.37395222041742 , -81.56816482543945 + 0.7622248729082767 |markers=big blue::47.040182144806664,-90 + 39.36827914916013,-81.5625 + 39.36827914916013,-81.5625
Notes: if you draw a large circle on the map, it will not appear as a perfect circle--2D maps of the globe are necessarily distorted.
Attribute: polygon
Values: line color in hex/line width in pixels/line percent opacity/fill color in hex/fill percent opacity:lat1,lon1 + lat2,lon2 + … + latN,lonN
Description: place a filled polygon on the map
Example: polygon=#000000/3/25/#ff0000/45:39.37202807246466,-81.56992435455322 + 39.373686823852424,-81.55782222747803 + 39.37099962681384,-81.55486106872559 + 39.37046881022853,-81.56636238098145 + 39.37202807246466,-81.56992435455322 |markers=big blue::47.040182144806664,-90 + 39.36827914916013,-81.5625 + 39.36827914916013,-81.5625
Attribute: rpolygon
Values: line color in hex/line width in pixels/line percent opacity/fill color in hex/fill percent opacity: center lat,center lon + vertex lat,vertex lon + num sides
Description: place a filled regular polygon on the map
Example: rpolygon=#000000/3/25/#ff0000/45:44.20583500104184,-70.367431640625 + 44.315987905196906,-68.609619140625 + 4
$Id$
General notes for getting the most out of gmap.
COMMONLY USED COORDINATES
-------------------------
37.0625,-95.677068 -- Center of US according to Google
THINGS TO WATCH OUT FOR
-----------------------
A) Be careful when using extremely long line segments. Due to the way distance computation works in the Google Maps API,
long segments have a tendency to "invert" themselves (i.e. come onto the screen from the opposite east/west direction.)
You can work around this issue by adding additional points.
\ No newline at end of file
$Id$
Description
-----------
GMap is an API and a related set of modules which allows the integration of Google Maps with a Drupal site.
gmap.module: The main module. Contains the API, the basic map functions, and an input filter to create macros into working maps with minimal effort.
gmap_location.module: Provides map features for Location.module (v2 and v3).
gmap_macro_builder.module: End-user UI for easily creating GMap macros.
gmap_taxonomy.module: API and utility for changing map markers of for points from Location.module based on taxonomy terms.
gmap_views.module: GMap <-> Views.module interface. Provides a "GMap View" view type (like "Teaser List" or "Table View") to display items in a View on a Google Map.
Installation
------------
* To install, follow the general directions available at:
http://drupal.org/getting-started/5/install-contrib/modules
* You will need a Google Maps API key for your website. You can get one at:
http://www.google.com/apis/maps/signup.html
Enter your Google Maps API key in the GMap settings page (admin/settings/gmap).
* You may need to make changes to your theme so that Google Maps can display correctly. See the section on "Google Maps and XHTML" below.
* If you would like to use GMap macros directly in nodes, you will need to add the GMap Macro filter to an input format (or create a new input format that includes it). Read http://drupal.org/node/213156 for more information on input formats.
If you are using the HTML filter, it will need to appear BEFORE the GMap filter; otherwise the HTML filter will remove the GMap code. To modify the order of filters in an input format, go to the "Rearrange" tab on the input format's configuration page (Administer > Site configuration > Input formats, then click "Configure" by your format).
* If you would like to use third party functionality such as mouse wheel support
or Clusterer, read thirdparty/README.txt for download links and instructions.
Google Maps and XHTML
---------------------
* Google Maps may have rendering issues when not using an XHTML doctype; Google recommends that your theme be standards-compliant XHTML, and suggests the following DOCTYPE:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
**editor's note: remove notes on VML when the api version is forced to >= 2.91.
* For polylines to work in Internet Explorer, you will need to add
the VML namespace to your <html> tag. Google recommends the following:
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:v="urn:schemas-microsoft-com:vml">
See http://code.google.com/apis/maps/documentation/index.html#XHTML_and_VML
for more information. This won't affect you unless you're displaying lines on your Google Maps.
Macro
-----
**NOTE: This section needs revision still!**
**does it though? --bec
"GMap macros" are text-based representations of Google Maps. A GMap macro can be created with the GMap Macro Builder tool or by hand. Any map parameter not specified by a macro will use the defaults from the GMap settings page (Administer > Site configuration > GMap). There are several places where you may use Gmap macros, mainly:
1) GMap settings, like the GMap Location module's settings page.
2) Any node where the GMap filter is enabled (as part of the input format).
A GMap macro will look something like this (see API.txt for syntax details):
[gmap markers=blue::41.902277040963696,-87.6708984375 |zoom=5 |center=42.94033923363183,-88.857421875 |width=300px |height=200px |control=Small |type=Map]
The GMap Macro Builder is a GUI for creating GMap macros; you may use it to create a map with points, lines, polygons, and circles, and then copy and paste the resulting macro text. After you insert the macro into a node, you can edit it using raw values that you get from elsewhere to create a different set of points or lines on the map.
If you've enabled the gmap_macro_builder.module, you can access the GMap macro builder at the 'map/macro' path (there will be "Build a GMap macro" link in your Navigation menu).
Note that there are many more options you can set on your maps if you are willing to edit macros by hand. For example, you may add KML or GeoRSS overlays to GMaps, but this option isn't available through the macro builder. Again, see API.txt for syntax details.
User and node maps
------------------
User and node location maps are made available by gmap_location.module, and work in conjunction with location.module. Any user that has the 'show user map' or 'show node map' permission can see the user or node maps, respectively. These are maps with a marker for every user or node, and are located at the 'map/user' and 'map/node' paths (links to these maps are placed in the Navigation menu).
Users with the 'user locations' permission can click markers on the User map to see information on individual users.
GMap Location also provides two map blocks that work with node locations: a "Location map" block that displays the location markers associated with the node being viewed, and an "Author map" block that displays a marker representing the node author's location.
GMap Location provides an interactive Google Map to the Location module for setting the latitude and longitude; users must have Location's "submit latitude/longitude" to use this feature.
Markers
-------
The 'markers' directory contains many useful markers, and you can add custom markers by placing PNG files (markers must be in PNG format) in the markers directory and creating a ".ini" file for them. Use the existing .ini files as a guide--start with "markers/colors.ini".
If you have created custom markers and are willing to release them under the GPL for inclusion in GMap, please file an issue in the issue queue at: http://drupal.org/project/issues/gmap
Demo
----
GMap Macros (GMap module):
http://www.webgeer.com/gmapdemo
GMap Macro Builder module:
http://gmap.chicagotech.org/map/macro
GMap Location module:
http://photo-tips.ca/
GMap Location module user map:
http://www.webgeer.com/map/users
Credit
------
Gmap for Drupal is part of the Mapedelic suite - a collection of Drupal modules providing a variety of mapping and geographic information functionality. Work on Gmap for Drupal is sponsored by the Chicago Technology Cooperative.
http://chicagotech.org
GMap was refactored and updated for Drupal 5 by Brandon Bergren (Bdragon).
http://drupal.org/user/53081
GMap for Drupal 4.6-4.7 was written by James Blake
http://www.webgeer.com/James
Thanks to the following for their contributions:
* Robert Douglass, who revamped crucial parts and cleaned up many smaller things.
* Paul Rollo, who explained 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.
** Work in progress **
Node Markers:
function theme_{nodetype}_gmapnodelabel($node, $opt);
function theme_gmapnodelabel($node, $opt);
$opt is an extra parameter passed by the dynamic info box loader.
Example:
<?php
function theme_image_gmapnodelabel($n) {
$out = '<a href="'. url('node/'. $n->nid) .'">'. check_plain($n->title) .'</a> <br>';
$out .= image_display($n, 'thumbnail');
return $out;
}
?>
\ No newline at end of file
TODO.txt 0 → 100644
$Id$
Drupal 5 todo:
* Lots more documentation
* QA triage
* Final release!
Legacy 4.7 todo:
- 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.
gmap.css 0 → 100644
/* IE VML Security issue fix.
* For more details, see:
* http://googlemapsapi.blogspot.com/2006/09/vml-security-issue.html
*/
v\:* {
behavior:url(#default#VML);
}
.gmap-popup{
}
.gmap-tooltip{
padding: 2px;
margin: 0;
border: solid black 1px;
}
.gmap-left {
float: left;
}
.gmap-center {
margin-left: auto;
margin-right: auto;
}
.gmap-right {
float: right;
}
; $Id$
name = GMap
description = Filter to allow insertion of a google map into a node
package = Location
<?php
// $Id$
/**
* @file
* GMap install file
*/
/**
* Implementation of hook_uninstall().
*/
function gmap_uninstall() {
variable_del('gmap_method');
variable_del('gmap_wms');
variable_del('gmap_default');
variable_del('gmap_mm_type');
variable_del('gmap_load_zoom_plugin');
variable_del('gmap_markermanager');
variable_del('gmap_markerfiles');
variable_del('gmap_node_markers');
variable_del('googlemap_api_key');
}
/**
* Updates from 5.x-1.0alpha1 to 5.x-1.0.
* Do some tidying up of the settings.
*/
function gmap_update_5000() {
$ret = array();
$d = variable_get('gmap_default', array());
// Add the previous implicit baselayers back in.
if (!isset($d['baselayers'])) {
$d['baselayers'] = array(
// Default map type
'maptype' => isset($d['maptype']) ? $d['maptype'] : 'Map',
'Map' => 1,
'Satellite' => 1,
'Hybrid' => 1,
'Physical' => 0,
);
}
// Default maptype was moved into baselayers.
unset($d['maptype']);
// Determine the map type control that was in use.
if (!isset($d['mtc'])) {
// User had the notype behavior flag set.
if (!empty($d['behavior']['notype'])) {
$d['mtc'] = 'none';
}
else {
$d['mtc'] = 'standard';
}
}
// notype is gone, mtc is more generic.
if (isset($d['behavior']['notype'])) {
unset($d['behavior']['notype']);
}
variable_set('gmap_default', $d);
return $ret;
}
/**
* Post 5.x-1.0beta2 update 1.
* We added a menu callback, force a rebuild.
*/
function gmap_update_5001() {
$ret = array();
menu_rebuild();
return $ret;
}
gmap.module 0 → 100644
This diff is collapsed.
gmap.php 0 → 100644
<?php
// $Id$
/**
* @file
* These functions are used to implement a plugin for gmap.
*/
/**
* @addtogroup hooks
* @{
*/
/**
* Change the way gmap works.
*
* @param $op
* The operation to be performed. Possible values:
* - "macro": Add macro behaviors (Not well documented yet...)
* - "pre_theme_map": A map is being themed. This is a good place to
* drupal_add_js() any additional files needed to run the map in question.
* - "macro_multiple": Add macro behaviors (Not well documented yet...)
* - "behaviors": Define behavior flags used in your code.
* @param $map
* For the "pre_theme_map" operation, the map being themed. Not used in
* other operations.
* @return
* This varies depending on the operation.
* - "macro": An associative array. The keys are the macro keys, the values
* are an array of flags for that macro key:
* "multiple": This key can appear multiple times in a macro.
* - "pre_theme_map": None.
* - "macro_multiple": An array of macro keys that can appear multiple times.
* (Oops, this appears to be redundant... Look into this. --Bdragon)
* - "behaviors": An associative array. The keys are the names of the behavior
* flags, and the values are associative arrays in the following format:
* - "title": The title to show on the settings page.
* - "default": The default state of the flag.
* - "help": A description of the flag to show on the settings page.
* - "internal": If TRUE, the flag will be marked as map specific, and
* will not be stored in the defaults.
*/
function hook_gmap($op, &$map) {
switch ($op) {
case 'macro':
return array(
'feed' => array(
'multiple' => TRUE,
),
);
case 'pre_theme_map':
$path = drupal_get_path('module', 'gmap') .'/js/';
if (is_array($map['feed'])) {
drupal_add_js($path .'markerloader_georss.js');
}
break;
case 'macro_multiple':
return array('feed');
case 'behaviors':
return array(
'nomousezoom' => array(
'title' => t('Disable mousezoom'),
'default' => FALSE,
'help' => t('Disable using the scroll wheel to zoom the map.'),
),
);
}
}
/**
* @} End of "addtogroup hooks".
*/
; $Id$
name = GMap Location
description = Display location.module information on Google Maps
package = Location
dependencies = gmap location
<?php
// $Id$
/**
* Implementation of hook_install().
*/
function gmap_location_install() {
// Gmap no longer provides the location table.
}
function gmap_location_update_1() {
drupal_set_message(t('WARNING! Obsolete gmap_location update #@num was triggered! Please verify the schema of your location table manually!', array('@num' => '1')));
}
function gmap_location_update_2() {
drupal_set_message(t('WARNING! Obsolete gmap_location update #@num was triggered! Please verify the schema of your location table manually!', array('@num' => '2')));
}
// 5.x-0.8 first update
function gmap_location_update_5080() {
// Convert role markers to single variable.
$result = db_query("SELECT name FROM {variable} WHERE name LIKE 'gmap_role_map_marker_%'");
$markers = array();
while ($row = db_fetch_object($result)) {
$num = (int)substr($row->name, 21);
$markers[$num] = variable_get($row->name, 'drupal');
variable_del($row->name);
}
variable_set('gmap_role_markers', $markers);
// It's pointless to have a default when the roles will take effect in all cases.
variable_del('gmap_user_map_marker');
// Convert node type markers to single variable.
$result = db_query("SELECT name FROM {variable} WHERE name LIKE 'gmap_node_marker_%'");
$markers = array();
while ($row = db_fetch_object($result)) {
$type = substr($row->name, 17);
$markers[$type] = variable_get($row->name, 'drupal');
variable_del($row->name);
}
variable_set('gmap_node_markers', $markers);
// User location setting functionality is moving to location.module.
//variable_del('gmap_user');
//variable_del('gmap_user_profile_category');
// gmap_user_map is a single variable now.
$temp = array(
'macro' => variable_get('gmap_user_map', '[gmap |id=usermap|center=40,0|zoom=3|width=100%|height=400px]'),
'header' => variable_get('gmap_user_map_header', 'This map illustrates the extent of users of this website. Each marker indicates a user that has entered their locations.'),
'footer' => '',
);
variable_set('gmap_user_map', $temp);
variable_del('gmap_user_map_header');
// gmap_node_map is a single variable now.
$temp = array(
'macro' => variable_get('gmap_node_map', '[gmap |id=nodemap|center=40,0|zoom=3|width=100%|height=400px]'),
'header' => variable_get('gmap_node_map_header', 'This map illustrates the locations of the nodes on this website. Each marker indicates a node associated with a specific location.'),
'footer' => '',
);
variable_set('gmap_node_map', $temp);
variable_del('gmap_node_map_header');
return array();
}
/**
* Implementation of hook_uninstall().
*/
function gmap_location_uninstall() {
variable_del('gmap_user_map');
variable_del('gmap_node_map');
variable_del('gmap_node_markers');
variable_del('gmap_role_markers');
}
This diff is collapsed.
; $Id$
name = GMap Macro Builder
description = UI for building GMap macros.
package = Location
dependencies = gmap
\ No newline at end of file
<?php
// $Id$
/**
* @file
* GMap Macro Builder
*
* A dynamic interface to assist in the creation of gmap macro tags.
*/
/**
* Implemenation of hook_help().
*/
function gmap_macro_builder_help($section) {
switch ($section) {
case 'map/macro':
return t('You can use this interface to create a map macro suitable for pasting into a node or any other place that accepts a GMap macro.');
}
}
/**
* Implementation of hook_perm().
*/
function gmap_macro_builder_perm() {
return array('create macro');
}
/**
* Implementation of hook_menu().
*/
function gmap_macro_builder_menu($may_cache) {
if ($may_cache) {
$items = array();
$items[] = array(
'path' => 'map/macro',
'type' => MENU_NORMAL_ITEM,
'title' => t('Build a GMap macro'),
'access' => user_access('create macro'),
'callback' => 'drupal_get_form',
'callback arguments' => 'gmap_macro_builder_form',
);
return $items;
}
}
/**
* Macro builder form.
* @param $settings
* Additional settings to apply to the macro map.
* @param $hide
* Fields to hide from the map. (See code for details.)
* Suggestions for better ways of doing this welcome!
*/
function gmap_macro_builder_form($settings = array(), $hide = array()) {
$form['macroform'] = array(
'#type' => 'fieldset',
'#title' => t('Gmap macro creation'),
'#theme' => 'gmap_macro',
);
$form['macroform']['mapdiv'] = array(
'#type' => 'gmap',
'#map' => 'macro_map',
'#settings' => array_merge(array(
'points' => array(),
'pointsOverlays' => array(),
'behavior' => array(
'dynmarkers' => TRUE,
),
), $settings),
);
$defaults = array_merge(gmap_defaults(), $settings);
$form['macroform']['overlayedit'] = array(
'#type' => 'gmap_overlay_edit',
'#map' => 'macro_map',
);
$form['macroform']['mapid'] = array(
'#type' => 'textfield',
'#title' => t('Map id attribute'),
'#description' => t('If you need to access this map from a script, you can assign a map ID here.'),
'#default_value' => '',
);
gmap_widget_setup($form['macroform']['mapid'], 'mapid', 'macro_map');
// @@@ TODO: Roll this next section into an element, it's duplicated from the settings ui.
$baselayers = array();
foreach (module_implements('gmap') as $module) {
call_user_func_array($module .'_gmap', array('baselayers', &$baselayers));
}
$options = array();
foreach ($baselayers as $name => $layers) {
$options[$name] = array();
foreach ($layers as $k => $v) {
// @@@TODO: Only show the enabled ones?
$options[$name][$k] = $v['title'];
}
}
$form['macroform']['maptype'] = array(
'#type' => 'select',
'#title' => t('Map type'),
'#default_value' => $defaults['maptype'],
'#options' => $options,
);
gmap_widget_setup($form['macroform']['maptype'], 'maptype', 'macro_map');
// @@@TODO: We need to allow choosing an alternate set of baselayers...
$form['macroform']['controltype'] = array(
'#type' => 'select',
'#title' => t('Controls'),
'#options' => drupal_map_assoc(array('None', 'Small', 'Large')),
'#required' => FALSE,
'#default_value' => $defaults['controltype'],
);
gmap_widget_setup($form['macroform']['controltype'], 'controltype', 'macro_map');
$form['macroform']['address'] = array(
'#type' => 'gmap_address',
'#map' => 'macro_map',
'#title' => t('Address'),
'#default_value' => '',
);
$form['macroform']['latlong'] = array(
'#type' => 'gmap_latlon',
'#map' => 'macro_map',
'#title' => t('The Latitude and Longitude of the centre of the map'),
'#default_value' => $defaults['latlong'],
'#size' => 50,
);
$form['macroform']['width'] = array(
'#type' => 'textfield',
'#title' => t('Map width'),
'#default_value' => $defaults['width'],
'#size' => 25,
'#maxlength' => 25,
'#description' => t('The map width, as a CSS length or percentage. Examples: <em>50px</em>, <em>5em</em>, <em>2.5in</em>, <em>95%</em>'),
);
gmap_widget_setup($form['macroform']['width'], 'width', 'macro_map');
$form['macroform']['height'] = array(
'#type' => 'textfield',
'#title' => t('Map height'),
'#default_value' => $defaults['height'],
'#size' => 25,
'#maxlength' => 25,
'#description' => t('The map height, as a CSS length or percentage. Examples: <em>50px</em>, <em>5em</em>, <em>2.5in</em>, <em>95%</em>'),
);
gmap_widget_setup($form['macroform']['height'], 'height', 'macro_map');
$form['macroform']['alignment'] = array(
'#type' => 'gmap_align',
'#map' => 'macro_map',
'#title' => t('Alignment'),
);
$form['macroform']['zoom'] = array(
'#type' => 'select',
'#title' => t('The current magnification of the map'),
'#default_value' => $defaults['zoom'],
'#options' => drupal_map_assoc(range(0, 17)),
);
gmap_widget_setup($form['macroform']['zoom'], 'zoom', 'macro_map');
$form['macroform']['macro'] = array(
'#type' => 'gmap_macrotext',
'#map' => 'macro_map',
'#default_value' => '',
'#title' => t('Macro text'),
);
foreach ($hide as $field => $mode) {
if (isset($form['macroform'][$field])) {
if ($mode == 1) {
$form['macroform'][$field]['#type'] = 'hidden';
$form['macroform'][$field]['#value'] = $form['macroform'][$field]['#default_value'];
}
else if ($mode == 2) {
$form['macroform'][$field]['#prefix'] = '<div style="display: none;">';
$form['macroform'][$field]['#suffix'] = '</div>';
}
}
}
return $form;
}
<?php
// $Id$
/**
* @file
* GMap marker information routines.
*
* This file is pulled in whenever we need to refresh the marker information
* and marker name caches.
*/
/**
* Get marker icon data for constructing json object.
*/
function _gmap_get_icondata() {
$icons = array();
$imagetypes = array(
'shadow',
'printImage',
'mozPrintImage',
'printShadow',
'transparent',
);
$markerdir = variable_get('gmap_markerfiles', drupal_get_path('module', 'gmap') .'/markers');
// The following routines are designed to be easy to comprehend, not fast.
// This whole process gets cached.
// Get the ini files.
$inifiles = file_scan_directory($markerdir, '.*\.ini$');
// Parse the ini files and store by path
$inis = array();
foreach ($inifiles as $file) {
$path = substr($file->filename, strlen($markerdir), -strlen($file->basename));
if (!isset($inis[$path])) {
$inis[$path] = array();
}
$inis[$path][] = parse_ini_file($file->filename, TRUE);
}
unset($inifiles);
// Per directory..
foreach ($inis as $path => $path_inis) {
$icons[$path] = array(
'tempf' => array(),
'f' => array(),
'w' => array(),
'h' => array(),
'i' => array(), // Sets of sets
);
// Part 1: Collect image names
$filenames = array();
foreach ($path_inis as $ini) {
foreach ($ini as $k => $v) {
// Is this definition for an icon? (anything with a dot is a file)
if (strpos($k, '.') !== FALSE) {
// Add the icon name.
$filenames[$k] = TRUE;
}
else {
// Shadow / alternate search
foreach ($imagetypes as $check) {
if (isset($v[$check])) {
$filenames[$v[$check]] = TRUE;
}
}
// A sequence is a list of image names.
if (isset($v['sequence'])) {
foreach (explode(',', $v['sequence']) as $f) {
$filenames[trim($f)] = TRUE;
}
}
}
}
}
$icons[$path]['tempf'] = $filenames;
}
unset($filenames);
// Part 2: Assign ids, get width and height
foreach ($icons as $path => $v) {
$counter = 0;
foreach ($icons[$path]['tempf'] as $filename => $fv) {
// Skip empty filenames to avoid warnings.
if (empty($filename)) {
continue;
}
$size = getimagesize($markerdir . $path . $filename);
$icons[$path]['f'][$counter] = $filename;
$icons[$path]['w'][$counter] = $size[0];
$icons[$path]['h'][$counter] = $size[1];
// Store an index under tempf for the next part...
$icons[$path]['tempf'][$filename] = $counter;
$counter++;
}
_gmap_compress_array($icons[$path]['w']);
_gmap_compress_array($icons[$path]['h']);
}
// Part 3: Main ini parsing
// Per directory...
foreach ($inis as $path => $path_inis) {
// Per file...
foreach ($path_inis as $ini) {
// Compression.
foreach ($ini as $k => $v) {
// Compress sequence filenames.
if (isset($ini[$k]['sequence'])) {
$temp = array();
foreach (explode(',', $ini[$k]['sequence']) as $file) {
$temp[] = $icons[$path]['tempf'][$file];
}
$ini[$k]['sequence'] = $temp;
}
// Compress other image field filenames.
foreach ($imagetypes as $t) {
if (isset($ini[$k][$t])) {
$ini[$k][$t] = $icons[$path]['tempf'][$ini[$k][$t]];
}
}
// Setup key for compression
$ini[$k]['key'] = $k;
}
$mv = array();
$iv = array();
if (isset($ini['defaults'])) {
$mv[0] = $ini['defaults'];
unset($ini['defaults']);
}
else {
$mv[0] = array();
}
foreach ($ini as $k => $v) {
if (strpos($k, '.') === FALSE) {
$mv[] = $ini[$k];
}
else {
$iv[] = $ini[$k];
}
}
$icons[$path]['i'][] = array(
_gmap_compress_icon_def($mv),
_gmap_compress_icon_def($iv),
);
}
}
foreach ($icons as $path => $v) {
unset($icons[$path]['tempf']);
}
return $icons;
}
/**
* Make a compressed definition.
* A series of arrays with trailing holes allowed.
* Any missing values at the end of subarrays
* are equal to the last defined value.
*/
function _gmap_compress_icon_def($iconset) {
$order = array(
'key', 'name', 'sequence', 'anchorX', 'anchorY',
'infoX', 'infoY', 'shadow', 'printImage', 'mozPrintImage',
'printShadow', 'transparent',
);
$ints = array(3 => TRUE, 4 => TRUE, 5 => TRUE, 6 => TRUE);
$nulls = array('', '', array(), 0, 0, 0, 0, '', '', '', '', '', );
$a = array();
for ($c0 = 0; $c0<count($order); $c0++) {
$a[$c0] = array();
for ($c1=0; $c1<count($iconset); $c1++) {
$temp = isset($iconset[$c1][$order[$c0]]) ? $iconset[$c1][$order[$c0]] : $nulls[$c0];
// Ensure that numeric quantities are encoded as ints, not strings.
if ($ints[$c0]) {
$temp = (int)$temp;
}
$a[$c0][$c1] = $temp;
}
_gmap_compress_array($a[$c0]);
}
for ($c0--;$c0>=0;$c0--) {
if ($a[$c0] === array($nulls[$c0])) {
unset($a[$c0]);
}
else {
break;
}
}
return $a;
}
/**
* Remove trailing duplicates from an array.
*/
function _gmap_compress_array(&$arr) {
$c = count($arr) - 1;
// Walk backwards and unset duplicates...
for ($cval = $arr[$c]; $c>0; $c--) {
if ($arr[$c-1]==$cval) {
unset($arr[$c]);
}
else {
// .. until we hit a different number.
break;
}
}
}
function _gmap_get_marker_titles() {
$markerdir = variable_get('gmap_markerfiles', drupal_get_path('module', 'gmap') .'/markers');
// The following routines are designed to be easy to comprehend, not fast.
// This whole process gets cached.
// Get the ini files.
$inifiles = file_scan_directory($markerdir, '.*\.ini$');
// Parse the ini files and store by path
$inis = array();
foreach ($inifiles as $file) {
$data = parse_ini_file($file->filename, TRUE);
if (isset($data['defaults'])) {
// Ignore defaults
unset($data['defaults']);
}
foreach ($data as $k => $v) {
if (strpos($k, '.') !== FALSE) {
// Ignore files
unset($data[$k]);
}
}
$inis[] = $data;
}
unset($inifiles);
$titles = array();
foreach ($inis as $ini => $inidata) {
foreach ($inidata as $k => $v) {
$titles[$k] = $inis[$ini][$k]['name'];
}
}
return $titles;
}
<?php
// $Id$
/**
* @file
* Encoded polyline utilities.
*/
/**
* References:
* [1] http://code.google.com/apis/maps/documentation/polylinealgorithm.html
* [2] http://facstaff.unca.edu/mcmcclur/GoogleMaps/EncodePolyline/
* [3] http://mathworld.wolfram.com/
*/
/**
* Encode a numeric value (steps 3-11 of "Encoding Latitudes and Longitudes" @ [1])
*/
function gmap_polyutil_e5_to_encoded($e5) {
// As described in http://code.google.com/apis/maps/documentation/polylinealgorithm.html
$work = $e5; // Make a copy.
$work <<= 1; // 4) Shift left (Note: I have no clue what happens if PHP_INT_SIZE != 4.)
if ($e5 < 0) {
$work = ~$work; // 5) Invert if negative.
}
$out = '';
// While we are NOT on the last chunk...
while ($work >= 32) {
// This combines the rest of the steps together.
$out .= chr((32 | ($work & 31)) + 63);
$work >>= 5;
}
// Last chunk doesn't get ORed with 32.
$out .= chr(($work & 31) + 63);
return $out;
}
function gmap_polyutil_dist($p1, $p2) {
// Distance in two dimensions.
// √((x1-x0)^2 + (y1-y0)^2)
return sqrt(pow($p2[0] - $p1[0], 2) + pow($p2[1] - $p1[1], 2));
}
/**
* Distance calculation between a point and a line segment.
* @param $p
* Point to measure.
* @param $lp1
* Point 1 on line.
* @param $lp2
* Point 2 on line.
*/
function gmap_polyutil_distance($p, $lp1, $lp2) {
if ($lp1[0] == $lp2[0] && $lp1[1] == $lp2[1]) {
// The "line" is really being a point. Just use simple distance.
return gmap_polyutil_dist($p, $lp1);
}
// mathematica code: (q-p1).(p2-p1)/(p2-p1).(p2-p1);
// I asked maxima, and it said ((p2y-p1y)*(qy-p1y)+(p2x-p1x)*(qx-p1x))/((p2y-p1y)^2+(p2x-p1x)^2).
$tmp = (($lp2[1]-$lp1[1])*($p[1]-$lp1[1])+($lp2[0]-$lp1[0])*($p[0]-$lp1[0]))/(pow($lp2[1]-$lp1[1],2) + pow($lp2[0]-$lp1[0], 2));
// Point is not alongside segment, is further off in $lp1's direction.
if ($tmp <= 0) {
return gmap_polyutil_dist($lp1, $p);
}
// Point is not alongside segment, is further off in $lp2's direction.
else if ($tmp >= 1) {
return gmap_polyutil_dist($lp2, $p);
}
else {
// mathematica code: Norm[q-(p1+u (p2-p1))]
// which means q and (p1+u (p2-p1)) are the things we are calculating distance on.
// maxima sez: (p1+u*(p2-p1)) => [(p2x-p1x)*u+p1x,(p2y-p1y)*u+p1y]
return gmap_polyutil_dist($p, array(($lp2[0]-$lp1[0])*$tmp + $lp1[0], ($lp2[1]-$lp1[1])*$tmp + $lp1[1]));
}
}
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