As per hutch's comment, and my experiments, I managed to solve it. I wrote it down here: https://drupal.org/node/2082137#comment-7832139.
I created a separate function for the task:
/**
* Load a map from multiple node ids with the appropriate markers
*
* @param array $nids The node ids of the nodes you want to get displayed on the map.
* @param array $getlocations_extra_settings Some extra settings you want to override the default values with.
* @see https:// drupal.org/node/2082137
* @todo Patch for getlocations_setlocations() to accept settings which override the defaults, or figure out an alternative solution.
*/
function getlocations_nodemap_multiple($nids = array(), $getlocations_extra_settings = array()) {
$latlons = array();
$minmaxes = array('minlat' => 0, 'minlon' => 0, 'maxlat' => 0, 'maxlon' => 0);
$count_nids = 0;
// override default settings
$getlocations_settings = array_merge(getlocations_defaults(), $getlocations_extra_settings);
$marker = $getlocations_settings['node_map_marker'];
$typemarkers = getlocations_get_markertypes('node');
foreach ($nids as $nid) {
// maybe a less resource consuming method should be used
// btw., what about entity_load()? (https://api.drupal.org/api/drupal/includes!common.inc/function/entity_load/7)
$node = node_load($nid);
$locations = getlocations_load_locations($node->vid);
if (isset($typemarkers[$node->type]) && $typemarkers[$node->type]) {
$marker = $typemarkers[$node->type];
}
if (count($locations)) {
// we should loop over them and dump bummers with no lat/lon
foreach ($locations AS $key => $location) {
$latlon = getlocations_latlon_check($location['latitude'] . ',' . $location['longitude']);
if ($latlon) {
$minmaxes = getlocations_do_minmaxes($count_nids, $location, $minmaxes);
if (!isset($location['key'])) {
$location['key'] = '';
}
else {
if ($location['key'] == 'nid') {
$location['lid'] = $nid;
}
elseif ($location['key'] == 'vid') {
// not vid?
$location['lid'] = $nid;
}
}
// term markers
$marker = getlocations_get_term_marker($nid, $marker);
// per location marker
if (isset($location['marker']) && ! empty($location['marker'])) {
$marker = $location['marker'];
}
$count_nids++;
$name = htmlspecialchars_decode($location['name'] ? strip_tags($location['name']) : strip_tags($node->title), ENT_QUOTES);
$latlons[] = array($location['latitude'], $location['longitude'], $location['lid'], $name, $marker, $location['key']);
}
}
}
}
if ($count_nids < 2 ) {
$minmaxes = NULL;
}
return getlocations_setlocations($latlons, $minmaxes);
}
And now I can call it like this:
function testmodule_any_custom_page_callback_you_want_to_use($blabla) {
$output = '';
$nids_array = array(41, 45, 52, 73, 219); // of course, this array is generated
$getlocations_extra_settings = array();
$getlocations_extra_settings['extcontrol'] = 'testmodule';
$getlocations_extra_settings['fullscreen'] = 1;
$getlocations_extra_settings['streetview_show'] = 1;
$getlocations_extra_settings['maptype'] = 'Map';
$getlocations_extra_settings['visual_refresh'] = 1;
$output = getlocations_nodemap_multiple($nids_array, $getlocations_extra_settings);
return $output;
}
This solution currently has its limitations, because unfortunately the default settings are hardcoded to getlocations_setlocations
(the values of getlocations_defaults()
are currently hardcoded). I hope hutch will develop this part further. :)