function _gmap_get_icondata in GMap Module 7.2
Same name and namespace in other branches
- 5 gmap_markerinfo.inc \_gmap_get_icondata()
- 6.2 gmap_markerinfo.inc \_gmap_get_icondata()
- 6 gmap_markerinfo.inc \_gmap_get_icondata()
- 7 gmap_markerinfo.inc \_gmap_get_icondata()
Get marker icon data for constructing json object.
1 call to _gmap_get_icondata()
- gmap_get_icondata in ./
gmap.module - Get the JSON icon data for all the default markers.
File
- ./
gmap_markerinfo.inc, line 37 - GMap marker information routines.
Code
function _gmap_get_icondata() {
$icons = array();
$imagetypes = array(
'shadow',
'printImage',
'mozPrintImage',
'printShadow',
'transparent',
);
// The following routines are designed to be easy to comprehend, not fast.
// This whole process gets cached.
// Get the ini files.
$inis = array();
// Run hook_gmap_markerfiles_info()
$inifiles = module_invoke_all('gmap_markerfiles_info');
drupal_alter('gmap_markerfiles_info', $inifiles);
if (is_array($inifiles)) {
// Parse the ini files and store by path.
foreach ($inifiles as $file) {
$path = substr($file->uri, 0, -strlen($file->filename));
if (!isset($inis[$path])) {
$inis[$path] = array();
}
$inis[$path][] = parse_ini_file($file->uri, TRUE);
}
unset($inifiles);
// Per directory.
foreach ($inis as $path => $path_inis) {
$icons[$path] = array(
'tempf' => array(),
'f' => array(),
'w' => array(),
'h' => array(),
// Sets of sets.
'i' => array(),
);
// Part 1: Collect image names.
$filenames = array();
foreach ($path_inis as $ini) {
foreach ($ini as $k => $v) {
// Is this definition for an icon? (Anything with a dot is a file.)
if (strpos($k, '.') !== FALSE) {
// Add the icon name.
$filenames[$k] = TRUE;
}
else {
// Shadow / alternate search.
foreach ($imagetypes as $check) {
if (isset($v[$check])) {
$filenames[$v[$check]] = TRUE;
}
}
// A sequence is a list of image names.
if (isset($v['sequence'])) {
foreach (explode(',', $v['sequence']) as $f) {
$filenames[trim($f)] = TRUE;
}
}
}
}
}
$icons[$path]['tempf'] = $filenames;
}
unset($filenames);
}
// Part 2: Assign ids, get width and height.
foreach ($icons as $path => $v) {
$counter = 0;
foreach ($icons[$path]['tempf'] as $filename => $fv) {
// Skip empty filenames to avoid warnings.
if (empty($filename)) {
continue;
}
$size = getimagesize($path . $filename);
$icons[$path]['f'][$counter] = $filename;
$icons[$path]['w'][$counter] = $size[0];
$icons[$path]['h'][$counter] = $size[1];
// Store an index under tempf for the next part...
$icons[$path]['tempf'][$filename] = $counter;
$counter++;
}
_gmap_compress_array($icons[$path]['w']);
_gmap_compress_array($icons[$path]['h']);
}
// Part 3: Main ini parsing
// Per directory...
foreach ($inis as $path => $path_inis) {
// Per file...
foreach ($path_inis as $ini) {
// Compression.
foreach ($ini as $k => $v) {
// Compress sequence filenames.
if (isset($ini[$k]['sequence'])) {
$temp = array();
foreach (explode(',', $ini[$k]['sequence']) as $file) {
$temp[] = $icons[$path]['tempf'][$file];
}
$ini[$k]['sequence'] = $temp;
}
// Compress other image field filenames.
foreach ($imagetypes as $t) {
if (isset($ini[$k][$t])) {
$ini[$k][$t] = $icons[$path]['tempf'][$ini[$k][$t]];
}
}
// Setup key for compression.
$ini[$k]['key'] = $k;
}
$mv = array();
$iv = array();
if (isset($ini['defaults'])) {
$mv[0] = $ini['defaults'];
unset($ini['defaults']);
}
else {
$mv[0] = array();
}
foreach ($ini as $k => $v) {
if (strpos($k, '.') === FALSE) {
$mv[] = $ini[$k];
}
else {
$iv[] = $ini[$k];
}
}
$icons[$path]['i'][] = array(
_gmap_compress_icon_def($mv),
_gmap_compress_icon_def($iv),
);
}
}
foreach ($icons as $path => $v) {
unset($icons[$path]['tempf']);
}
return $icons;
}