route_planner.module in Route Planner 6
Same filename and directory in other branches
The Route Planner module create blocks to show a route from any address to a fixed point.
File
route_planner.moduleView source
<?php
/**
* @file
* The Route Planner module create blocks to show a route from any address
* to a fixed point.
*/
/**
* Implements hook_menu().
*/
function route_planner_menu() {
$items = array();
// Module settings.
$items['admin/settings/routeplanner'] = array(
'title' => 'Route planner settings',
'description' => 'Route planner settings',
'page callback' => 'drupal_get_form',
'page arguments' => array(
'route_planner_settings_form',
),
'access arguments' => array(
'access administration pages',
),
'file' => 'route_planner.admin.inc',
'file path' => drupal_get_path('module', 'route_planner'),
);
return $items;
}
/**
* Implementation of hook_block().
*/
function route_planner_block($op = 'list', $delta = 0, $edit = array()) {
$blocks = array(
'route_target' => array(
'info' => t('Route Planner Address Field'),
'cache' => BLOCK_NO_CACHE,
),
'map' => array(
'info' => t('Route Planner Map Display'),
'cache' => BLOCK_NO_CACHE,
),
);
switch ($op) {
// Block listing
case 'list':
return $blocks;
// Block viewing
case 'view':
// By default the block subject equals block info
$block['subject'] = $blocks[$delta]['info'];
switch ($delta) {
case 'route_target':
$block['content'] = route_planner_get_address_form();
break;
case 'map':
$block['content'] = route_planner_map_display();
break;
}
return $block;
}
}
/**
* The Address-Form.
*
* A form to input a address and get.
* The driving time and distance will automatically set after clicken the button.
*
* @return
* The address form.
*/
function route_planner_address_form(&$form_state) {
$form['start'] = array(
'#type' => 'textfield',
'#title' => t('Address'),
'#default_value' => '',
'#size' => 20,
);
$form['distance'] = array(
'#type' => 'textfield',
'#title' => t('Distance'),
'#default_value' => '0.00',
'#size' => 20,
'#disabled' => TRUE,
);
$form['time'] = array(
'#type' => 'textfield',
'#title' => t('Driving time'),
'#default_value' => '0.00',
'#size' => 20,
'#disabled' => TRUE,
);
$form['button'] = array(
'#type' => 'button',
'#value' => t('Calculate route'),
'#attributes' => array(
'onClick' => 'return Drupal.myRoutePlanner.calcRoute();',
),
);
return $form;
}
/**
* Get Address-Form Block
*
* Helper function to add several stuff to the Block.
*
* @return
* The address form.
*/
function route_planner_get_address_form() {
// Get the address form.
$output = drupal_get_form('route_planner_address_form');
return $output;
}
/**
* Show a Google Map with a POI or a route.
*
* @return
* HTML output for the map.
*/
function route_planner_map_display() {
// Add google maps api.
drupal_set_html_head('<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=false"></script>');
// Add some custom javascript to display the map.
drupal_add_js(drupal_get_path('module', 'route_planner') . '/route_planner.js');
$address = variable_get('route_planner_address', 'Hamburg, Germany');
// Set variables from Route Planner settings page.
drupal_add_js(array(
'routePlanner' => array(
'zoomlevel' => intval(variable_get('route_planner_map_zoom', 10)),
'end' => $address,
),
), 'setting');
// Output the map.
$output = '<div id="map_canvas" style="height:' . check_plain(variable_get('route_planner_map_height', '300px')) . '; width:' . check_plain(variable_get('route_planner_map_width', '100%')) . ';"></div>';
return $output;
}
Functions
Name | Description |
---|---|
route_planner_address_form | The Address-Form. |
route_planner_block | Implementation of hook_block(). |
route_planner_get_address_form | Get Address-Form Block |
route_planner_map_display | Show a Google Map with a POI or a route. |
route_planner_menu | Implements hook_menu(). |