| | 78 | function simple_maps_form_alter($form_id, &$form) { |
|---|
| | 79 | |
|---|
| | 80 | /* Try to get the nid. */ |
|---|
| | 81 | $nid = $form["nid"]["#value"]; |
|---|
| | 82 | if (!$nid) { |
|---|
| | 83 | return; |
|---|
| | 84 | } |
|---|
| | 85 | |
|---|
| | 86 | // Try to get location of node. |
|---|
| | 87 | $loc = _get_node_location($nid); |
|---|
| | 88 | if (!$loc) { |
|---|
| | 89 | return; |
|---|
| | 90 | } |
|---|
| | 91 | |
|---|
| | 92 | // Look for the address field |
|---|
| | 93 | $addressField = variable_get("simplemap.addressfield", "field_address"); |
|---|
| | 94 | |
|---|
| | 95 | $form[] = _location_form($loc); |
|---|
| | 96 | |
|---|
| | 97 | //d("form", $form[$addressField]); |
|---|
| | 98 | } |
|---|
| | 107 | |
|---|
| | 108 | function _location_form($loc) { |
|---|
| | 109 | $form = array(); |
|---|
| | 110 | |
|---|
| | 111 | $form['coordinates'] = array( |
|---|
| | 112 | '#type' => 'fieldset', |
|---|
| | 113 | '#title' => t('Location'), |
|---|
| | 114 | '#weight' => 5, |
|---|
| | 115 | '#collapsible' => $type!='user', |
|---|
| | 116 | '#collapsed' => FALSE, |
|---|
| | 117 | ); |
|---|
| | 118 | |
|---|
| | 119 | // Reserve spot for map. |
|---|
| | 120 | $form['coordinates']['gmap_node'] = array(); |
|---|
| | 121 | |
|---|
| | 122 | $form['coordinates']['gmap_location_latitude'] = array( |
|---|
| | 123 | '#type' => 'textfield', |
|---|
| | 124 | '#title' => t('Latitude'), |
|---|
| | 125 | '#default_value' => $loc['latitude'], |
|---|
| | 126 | '#size' => 30, |
|---|
| | 127 | '#maxlength' => 120, |
|---|
| | 128 | ); |
|---|
| | 129 | |
|---|
| | 130 | $form['coordinates']['gmap_location_longitude'] = array( |
|---|
| | 131 | '#type' => 'textfield', |
|---|
| | 132 | '#title' => t('Longitude'), |
|---|
| | 133 | '#default_value' => $loc['longitude'], |
|---|
| | 134 | '#size' => 30, |
|---|
| | 135 | '#maxlength' => 120, |
|---|
| | 136 | '#description' => t('The latitude and longitude will be entered here when you double-click on a location in the interactive map above. You can also fill in the values manually.'), |
|---|
| | 137 | ); |
|---|
| | 138 | |
|---|
| | 139 | $map = gmap_defaults(); |
|---|
| | 140 | $map["width"] = "300px"; |
|---|
| | 141 | $map["height"] = "300px"; |
|---|
| | 142 | |
|---|
| | 143 | $form['coordinates']['gmap_node']['#value'] = gmap_set_location($map, $form['coordinates'], array('latitude' => 'gmap_location_latitude', 'longitude' => 'gmap_location_longitude')); |
|---|
| | 144 | |
|---|
| | 145 | return $form; |
|---|
| | 146 | } |
|---|