default map location
kreativepk - November 24, 2007 - 09:03
| Project: | cck_map |
| Version: | 5.x-3.2-1 |
| Component: | Miscellaneous |
| Category: | support request |
| Priority: | normal |
| Assigned: | kreativepk |
| Status: | active |
Jump to:
Description
how can i define default location zoom level and Map option (satellite), cause by default it start with full map

#1
Just found out how to change the default location. I know really know that much about coding so this might not be the right way to do it.
1. Open modules\cck_map\cck_map.js
2. go to line 12 -> « this.map.setCenter(new GLatLng(0, 0), 1); »
3. The numerical values are the latitude the longitude and the zoom level. Change to your liking :)
ex: this.map.setCenter(new GLatLng(40, -8), 5); sets the map to show Portugal and Spain
#2
This is a workaround, but it'd be nice for it to be configurable in the settings ui so that novice Drupal users and lazy Drupal experts can easily configure it.
#3
Another way of doing it (without hacking the module) is to add some customized javascript code in a custom module.
The following snippet assumes your cck_map field is called "field_map" (then the javascript object is "field_mapmap").
You'll also need to ensure that this code snippet gets called after cck_map's initialization code is run. I used hook_form_alter and the "drupal_add_js()" function with $type = 'inline' as shown below.
function mymodule_form_alter($form_id, &$form) {if ($form_id == 'my_cck_map_content_type') {
$cck_map_stuff = <<<EOD
if (Drupal.jsEnabled) {
$(document).ready(function () {
if ((field_mapmap.map.getCenter().lat() == 0) &&
(field_mapmap.map.getCenter().lng() == 0)) {
field_mapmap.map.setCenter(new GLatLng(39.833322799504, -98.583068847656), 3);
}
});
}
EOD;
drupal_add_js($cck_map_stuff, 'inline');
}
}
(The coordinates used above center the map on the United States)
The if-statement ensures that the map doesn't already have another center defined (this happens when editing an existing node).
-mike