Class: map

ajs.maps.gmapdraw. map

This class handles the drawing tools used to draw over a google map and allows the drawed data exportation.

The map manages also some controllers

  • clear map controller
  • export map controller
  • geocoder text field controller
  • tips controller

Moreover every drawing tool has its own controller, which may be specifically set or used in its default form.

Each map controller may be specified custom, may be removed setting the related option to null or used in its default form.

Once instantiated the class and set the tools by options or instantiating direclty the drawing tool classes and adding them to the map, see ajs.maps.gmapdraw.map#addTool, call the render method to render the widget. Then it is possible to continue configuring the widget adding or removing tools, customizing the google map instance which is returned by the ajs.maps.gmapdraw.map#gmap method.

When defining specific map controllers, be sure to make them handle the proper map methods.

Very important: be sure to load the google maps library yourself in the head of the document!

new map(canvas, options)

Google maps drawing class, provides tools for drawing over a google map instance, and export drawed data.

Parameters:
Name Type Argument Description
canvas String The id attribute of the map container
options Object <optional>
A class options object
Properties
Name Type Argument Default Description
center Array <optional>
new Array(45, 7) The initial map center coordinates, (lat, lng).
zoom Number <optional>
8 The the initial map zoom level.
tools Object <optional>
{} The object containing the tool's names and optionsa to be activated when initializing the map. It's a shortcut to easily define set and active tools objects.
Properties
Name Type Argument Default Description
point Object <optional>
undefined The point tool init object
Properties
Name Type Argument Default Description
ctrl String | Element <optional>
undefined The id attribute or the element itself which controls the tool, default the built-in menu voice
options Object <optional>
undefined The tool options object, see ajs.maps.gmapdraw.pointTool for available properties
polyline Object <optional>
undefined The polyline tool init object
Properties
Name Type Argument Default Description
ctrl String | Element <optional>
undefined The id attribute or the element itself which controls the tool, default the built-in menu voice
options Object <optional>
undefined The tool options object, see ajs.maps.gmapdraw.polylineTool for available properties
polygon Object <optional>
undefined The polygon tool init object
Properties
Name Type Argument Default Description
ctrl String | Element <optional>
undefined The id attribute or the element itself which controls the tool, default the built-in menu voice
options Object <optional>
undefined The tool options object, see ajs.maps.gmapdraw.polygonTool for available properties
circle Object <optional>
undefined The circle tool init object
Properties
Name Type Argument Default Description
ctrl String | Element <optional>
undefined The id attribute or the element itself which controls the tool, default the built-in menu voice
options Object <optional>
undefined The tool options object, see ajs.maps.gmapdraw.circleTool for available properties
clear_map_ctrl String | Element <optional>
'default' The clear map controller (clears all drawings over the map). If 'default' the built-in controller is used, if null the clear map functionality is removed. If id attribute or an element the clear map functionality is attached to the element.
export_map_ctrl String | Element <optional>
'default' The export map controller (exports all shapes drawed over the map). If 'default' the built-in controller is used, if null the export map functionality is removed. If id attribute or an element the clear map functionality is attached to the element.
export_map_callback Function <optional>
null The callback function to call when the export map button is pressed. The callback function receives one argument, the exported data as returned by the ajs.maps.gmapdraw.map#exportMap method.
geocoder_map_field Boolean <optional>
true Whether or not to add the gecoder functionality which allows to center the map in a point defined through an address, or to pass the lat,lng coordinates found to the map click handlers (exactly as click over the map in a lat,lng point).
tips_map_ctrl String | Element <optional>
'default' The help tips map controller (shows tips about drawing tools). If 'default' the built-in controller is used, if null the tips box is not shown, if id attribute or an element the functionality is attached to the element.
Source:
Example
var mymap = new ajs.maps.gmapdraw.map('my_map_canvas_id', {
	tools: {
		point: {
			options: {
				max_items: 5
			}
		},
		circle: {}	
	}
});

Methods

<protected> addControllersContainer()

Adds an empty container over the map which may contain default controllers if any

Source:
Returns:
void

addDefaultCtrl(ctrl)

Adds a controller in the default controllers container

Parameters:
Name Type Description
ctrl Element The controller to be added
Source:
Returns:
void

addTool(tool)

Adds a drawing tool

Parameters:
Name Type Description
tool ajs.maps.gmapdraw.tool The tool object
Source:
Returns:
void

clearMap()

Clears the map

Source:
Returns:
void

exportMap() → {Object}

Exports the map drawed shapes as data points

Source:
Returns:
data The drawed data in an object format
Type
Object
Example
{
	'point': [
		{lat: 45, lng: 12},
		{lat: 43, lng: 16}
	],
	'polyline': [
		[
			{lat: 45, lng: 12},
			{lat: 42, lng: 12},
			{lat: 42.6, lng: 11}
		],
		[
			{lat: 36.7, lng: 11.2},
			{lat: 39, lng: 12}
		],
	],
	'circle': [
		{lat: 45, lng: 12, radius: 10000},
		{lat: 44, lng: 11, radius: 230000}
	]
}

geocoderCenter()

Sets the map center converting the geocoder_field input address in a LatLng point

Source:
Returns:
void

geocoderDraw()

Fires a map click in a LatLng point converted from the geocoder_field input address

Source:
Returns:
void

getDrawingTool() → {ajs.maps.gmapdraw.tool}

Gets the active drawing tool

Source:
Returns:
The drawing tool
Type
ajs.maps.gmapdraw.tool

getTool(tool_name) → {ajs.maps.gmapdraw.tool|null}

Gets a tool object giving its name

Parameters:
Name Type Description
tool_name String One of the supported tools name
Source:
Returns:
The tool object if set or null
Type
ajs.maps.gmapdraw.tool | null

gmap() → {google.maps.Map}

Returns the google map instance google.maps.Map

The google map class instance allows to customize direclty some map properties using the google.maps.Map public interface
Source:
Returns:
The google map instance
Type
google.maps.Map
Example
var mygmap = ajs.maps.gmapdraw.map.gmap();
mygmap.setCenter(new google.maps.LatLng(45, 7));

importMap(data)

Imports data to the map

Data must be in the same form as the exported ones, see ajs.maps.gmapdraw.map#exportMap
Parameters:
Name Type Description
data Object The drawed data in an object format
Source:

initControllers()

Initializes all the map controllers

Source:
Returns:
void

initMap()

Initializes the google map and its events
Source:
Returns:
void

initMapTips() → {String}

Returns the init text shown in the tips controller

Source:
Returns:
text The initial tip text
Type
String

initTools()

Initializes the map set tools

Source:
Returns:
void

mapClick(point)

Handles the click event over the map, calling the active tool handler

This method is public since it has to be called by google maps api
Parameters:
Name Type Description
point Object The callback parameter returned by the google.maps event handler
Source:
Returns:
void

<protected> processOptions()

Processes the option object setting properly some class properties

Source:
Returns:
void

<protected> removeClearMapController()

Removes the clear map controller depending on the options.clear_map_ctrl value

Source:
Returns:
void

<protected> removeExportMapController()

Removes the export map controller depending on the options.clear_map_ctrl value

Source:
Returns:
void

<protected> removeGeocoderMapField()

Removes the geocoder input text field and its controllers

Source:
Returns:
void

<protected> removeTipsMapController()

Removes the tips map controller depending on the options.tips_map_ctrl value

Source:
Returns:
void

removeTool(tool_name, tool)

Removes a drawing tool

Parameters:
Name Type Description
tool_name String The name of the tool to be removed
tool ajs.maps.gmapdraw.tool The tool object
Source:
Returns:
void

render()

Renders the widget

Source:
Returns:
void

setCenter(center)

Sets the center of the map

Parameters:
Name Type Description
center Array The [lat, lng] coordinates array
Source:
Returns:
void

<protected> setClearMapController()

Sets the clear map controller depending on the options.clear_map_ctrl value

Source:
Returns:
void

setClearMapCtrl(ctrl)

Sets the clear map controller

Parameters:
Name Type Description
ctrl String | Element The clear map controller. If 'default' the built-in controller is used, if null the clear map functionality is removed. If id attribute or an element the clear map functionality is attached to the element.
Source:
Returns:
void

setDrawingTool(tool)

Sets the active drawing tool name

Parameters:
Name Type Description
tool ajs.maps.gmapdraw.tool | null The actual drawing tool, null to have no active tool
Source:
Returns:
void

<protected> setExportMapController()

Sets the export map controller depending on the options.export_map_ctrl value

Source:
Returns:
void

setExportMapCtrl(ctrl)

Sets the export map controller

Parameters:
Name Type Description
ctrl String | Element The export map controller. If 'default' the built-in controller is used, if null the export map functionality is removed. If id attribute or an element the export map functionality is attached to the element.
Source:
Returns:
void

setGeocoderMapField(set)

Sets the geocoder map field option

Parameters:
Name Type Description
set Boolean Whether or not to activate the geocoder functionality
Source:
Returns:
void

<protected> setGeocoderMapFieldController()

Sets the geocoder input text field and its controllers

Source:
Returns:
void

<protected> setTipsMapController()

Sets the help tips map controller depending on the options.tips_map_ctrl value

Source:
Returns:
void

setTipsMapCtrl(ctrl)

Sets the tips map controller

Parameters:
Name Type Description
ctrl String | Element The help tips map controller (shows tips about drawing tools). If 'default' the built-in controller is used, if null the tips box is not shown, if id attribute or an element the functionality is attached to the element.
Source:
Returns:
void

setZoom(zoom)

Sets the zoom of the map

Parameters:
Name Type Description
zoom Number The zoom level
Source:
Returns:
void

updateTips(text)

Updates the text displayed in the tips controller

Parameters:
Name Type Description
text String The tip text
Source:
Returns:
void