diff -rupN location_old/location.admin.inc location/location.admin.inc
--- location_old/location.admin.inc 2009-04-18 05:12:54.000000000 +1000
+++ location.admin.inc 2009-05-29 11:17:19.000000000 +1000
@@ -57,6 +57,13 @@ function location_admin_settings() {
'#description' => t('If you would like to change the macro used to generate the location chooser map, you can do so here. Note: Behaviors locpick and collapsehack are forced to be enabled and cannot be changed.'),
);
+ $form['location_copy_on_write'] = array(
+ '#type' => 'checkbox',
+ '#title' => t('Updating a location creates a new location'),
+ '#default_value' => variable_get('location_copy_on_write', TRUE),
+ '#description' => t('If checked, when you modify a location it will be created as a new location. If unckecked, modifications to a location will be made to the existing location. Uncheck this if the order of your locations is important otherwise when you update a location it will then become the last location on your node. This is very important if your locations will be used as points on a polygon. It also makes things a bit easier when dealing with a large number of locations on a single node or user.'),
+ );
+
$form['location_jit_geocoding'] = array(
'#type' => 'checkbox',
'#title' => t('Enable JIT geocoding'),
diff -rupN location_old/location.module location/location.module
--- location_old/location.module 2009-04-18 05:12:54.000000000 +1000
+++ location.module 2009-05-29 11:30:42.000000000 +1000
@@ -195,6 +195,26 @@ function location_views_api() {
}
/**
+ * Checks whether or not to use a single map
+ */
+function location_use_single_map() {
+ if (arg(0) == 'node') {
+ if (is_numeric(arg(1))) {
+ $node = node_load(arg(1));
+ $nodetype = $node->type;
+ }
+ else if (arg(1) == 'add') {
+ $nodetype = arg(2);
+ }
+ $location_settings = variable_get('location_settings_node_'. $nodetype, array());
+ }
+ else if (arg(0) == 'user') {
+ $location_settings = variable_get('location_settings_user', array());
+ }
+ return isset($location_settings['multiple']['single_map']) ? $location_settings['multiple']['single_map'] : 0;
+}
+
+/**
* Process a location element.
*/
function _location_expand_location($element) {
@@ -328,48 +348,53 @@ function _location_expand_location($elem
'#suffix' => '',
);
if (function_exists('gmap_get_auto_mapid') && variable_get('location_usegmap', FALSE)) {
- $mapid = gmap_get_auto_mapid();
- $map = gmap_parse_macro(variable_get('location_locpick_macro', '[gmap]'));
- $map['id'] = $mapid;
- $map['points'] = array();
- $map['pointsOverlays'] = array();
- $map['lines'] = array();
-
- $map['behavior']['locpick'] = TRUE;
- $map['behavior']['collapsehack'] = TRUE;
- // Use previous coordinates to center the map.
- if (location_has_coordinates($defaults, FALSE)) {
- $map['latitude'] = (float)$defaults['latitude'];
- $map['longitude'] = (float)$defaults['longitude'];
-
- $map['markers'][] = array(
- 'latitude' => $defaults['latitude'],
- 'longitude' => $defaults['longitude'],
- 'markername' => 'small gray', // @@@ Settable?
- 'offset' => 0,
- 'opts' => array(
- 'clickable' => FALSE,
- ),
+ if (!location_use_single_map()) {
+ $mapid = gmap_get_auto_mapid();
+ $map = gmap_parse_macro(variable_get('location_locpick_macro', '[gmap]'));
+ $map['id'] = $mapid;
+ $map['points'] = array();
+ $map['pointsOverlays'] = array();
+ $map['lines'] = array();
+
+ $map['behavior']['locpick'] = TRUE;
+ $map['behavior']['collapsehack'] = TRUE;
+ // Use previous coordinates to center the map.
+ if (location_has_coordinates($defaults, FALSE)) {
+ $map['latitude'] = (float)$defaults['latitude'];
+ $map['longitude'] = (float)$defaults['longitude'];
+
+ $map['markers'][] = array(
+ 'latitude' => $defaults['latitude'],
+ 'longitude' => $defaults['longitude'],
+ 'markername' => 'small gray', // @@@ Settable?
+ 'offset' => 0,
+ 'opts' => array(
+ 'clickable' => FALSE,
+ ),
+ );
+ }
+
+ $element['locpick']['map'] = array(
+ '#type' => 'gmap',
+ '#weight' => -1,
+ '#map' => $mapid,
+ '#settings' => $map,
);
+ $element['locpick']['map_instructions'] = array(
+ '#type' => 'markup',
+ '#weight' => 2,
+ '#prefix' => '
',
+ '#value' => t('You may set the location by clicking on the map, or dragging the location marker. To clear the location and cause it to be recalculated, click on the marker.'),
+ '#suffix' => '
',
+ );
+ }
+ else {
+ $mapid = 'singlemap';
}
$element['locpick']['user_latitude']['#map'] = $mapid;
gmap_widget_setup($element['locpick']['user_latitude'], 'locpick_latitude');
$element['locpick']['user_longitude']['#map'] = $mapid;
gmap_widget_setup($element['locpick']['user_longitude'], 'locpick_longitude');
-
- $element['locpick']['map'] = array(
- '#type' => 'gmap',
- '#weight' => -1,
- '#map' => $mapid,
- '#settings' => $map,
- );
- $element['locpick']['map_instructions'] = array(
- '#type' => 'markup',
- '#weight' => 2,
- '#prefix' => '',
- '#value' => t('You may set the location by clicking on the map, or dragging the location marker. To clear the location and cause it to be recalculated, click on the marker.'),
- '#suffix' => '
',
- );
}
}
@@ -763,10 +788,10 @@ function location_load_locations($id, $k
return array();
}
if ($key == 'genid') {
- $result = db_query('SELECT lid FROM {location_instance} WHERE '. db_escape_table($key) ." = '%s'", $id);
+ $result = db_query('SELECT lid FROM {location_instance} WHERE '. db_escape_table($key) ." = '%s' ORDER BY lid", $id);
}
else {
- $result = db_query('SELECT lid FROM {location_instance} WHERE '. db_escape_table($key) .' = %d', $id);
+ $result = db_query('SELECT lid FROM {location_instance} WHERE '. db_escape_table($key) .' = %d ORDER BY lid', $id);
}
$locations = array();
while ($lid = db_fetch_object($result)) {
@@ -788,8 +813,10 @@ function location_load_locations($id, $k
*/
function location_save_locations(&$locations, $criteria) {
if (isset($locations) && is_array($locations) && !empty($criteria) && is_array($criteria)) {
+ $cow = variable_get('location_copy_on_write', 1);
+
foreach (array_keys($locations) as $key) {
- location_save($locations[$key], TRUE, $criteria);
+ location_save($locations[$key], $cow, $criteria);
}
$columns = array();
$placeholders = array();
@@ -1046,12 +1073,18 @@ function location_save(&$location, $cow
$location['locpick']['user_longitude'] = trim($location['locpick']['user_longitude']);
}
// If the user location was set, convert it into lat / lon.
+ // Otherwise it was not set or was unset so make sure lon / lat is unset too.
if (!empty($location['locpick']['user_latitude']) && !empty($location['locpick']['user_longitude'])) {
$location['source'] = LOCATION_LATLON_USER_SUBMITTED;
$location['latitude'] = $location['locpick']['user_latitude'];
$location['longitude'] = $location['locpick']['user_longitude'];
$inhibit_geocode = TRUE;
}
+ else {
+ $location['source'] = LOCATION_LATLON_UNDEFINED;
+ $location['latitude'] = 0;
+ $location['longitude'] = 0;
+ }
// Pull in fields that hold data currently not editable directly by the user.
$location = array_merge($oldloc, $location);
@@ -1565,6 +1598,13 @@ function location_settings($old = FALSE)
'#default_value' => isset($old['multiple']['add']) ? $old['multiple']['add'] : 3,
'#description' => t('The number of empty location forms to show when editing.'),
);
+ $form['multiple']['single_map'] = array(
+ '#type' => 'checkbox',
+ '#title' => t('Single map'),
+ '#default_value' => isset($old['multiple']['single_map']) ? $old['multiple']['single_map'] : FALSE,
+ '#description' => t('This setting controls whether you have one map on the screen or multiple. If this option is checked, the multiple locations will display on one map, otherwise you will get a map for each location.')
+ );
+
// Thought: What about prefilled names and fixed locations that way?
// Then again, CCK would be cleaner.
@@ -1662,6 +1702,29 @@ function location_form($settings, $locat
$form['#type'] = 'markup';
}
+ // If the single map option has been chosen make the map
+ if ($settings['multiple']['single_map'] && function_exists('gmap_get_auto_mapid') && variable_get('location_usegmap', FALSE)) {
+ $defaults = location_empty_location($settings);
+ if (!empty($locations)) {
+ $defaults = location_load_location($locations[0]['lid']);
+ }
+
+ $mapid = 'singlemap';
+ $map = gmap_parse_macro(variable_get('location_locpick_macro', '[gmap]'));
+ $map['id'] = $mapid;
+ $map['points'] = array();
+ $map['pointsOverlays'] = array();
+ $map['lines'] = array();
+
+ $map['behavior']['locpick'] = TRUE;
+ $map['behavior']['collapsehack'] = TRUE;
+ // Use previous coordinates to center the map.
+ if (location_has_coordinates($defaults, FALSE)) {
+ $map['latitude'] = (float)$defaults['latitude'];
+ $map['longitude'] = (float)$defaults['longitude'];
+ }
+ }
+
for ($i = 0; $i < $numforms; $i++) {
$required = FALSE;
// Check if this is a required location.
@@ -1675,6 +1738,18 @@ function location_form($settings, $locat
'#location_settings' => $settings,
'#required' => $required,
);
+
+ if (isset($map)) {
+ $map['markers'][$i] = array(
+ 'latitude' => $locations[$i]['latitude'],
+ 'longitude' => $locations[$i]['longitude'],
+ 'markername' => 'small gray', // @@@ Settable?
+ 'offset' => 0,
+ 'opts' => array(
+ 'clickable' => FALSE,
+ ),
+ );
+ }
}
// Tidy up the form in the single location case.
@@ -1684,6 +1759,39 @@ function location_form($settings, $locat
// the collapsible / collapsed settings.
$form[0]['#collapsible'] = $form['#collapsible'];
$form[0]['#collapsed'] = $form['#collapsed'];
+
+ if (isset($map)) {
+ $form[0]['map'] = array(
+ '#type' => 'gmap',
+ '#weight' => -1,
+ '#map' => $mapid,
+ '#settings' => $map,
+ );
+ $form[0]['map_instructions'] = array(
+ '#type' => 'markup',
+ '#weight' => 2,
+ '#prefix' => '',
+ '#value' => t('You may set the location by clicking on the map, or dragging the location marker. To clear the location and cause it to be recalculated, click on the marker.'),
+ '#suffix' => '
',
+ );
+ }
+ }
+ else {
+ if (isset($map)) {
+ $form['map'] = array(
+ '#type' => 'gmap',
+ '#weight' => -1,
+ '#map' => $mapid,
+ '#settings' => $map,
+ );
+ $form['map_instructions'] = array(
+ '#type' => 'markup',
+ '#weight' => 2,
+ '#prefix' => '',
+ '#value' => t('You may set the location by clicking on the map, or dragging the location marker. To clear the location and cause it to be recalculated, click on the marker.'),
+ '#suffix' => '
',
+ );
+ }
}
return $form;