You are here

function getlocations_leaflet_entity_type_map in Get Locations 7.2

Same name and namespace in other branches
  1. 7 modules/getlocations_leaflet/getlocations_leaflet.module \getlocations_leaflet_entity_type_map()
1 string reference to 'getlocations_leaflet_entity_type_map'
getlocations_leaflet_menu in modules/getlocations_leaflet/getlocations_leaflet.module
Implements hook_menu().

File

modules/getlocations_leaflet/getlocations_leaflet.module, line 3842
getlocations_leaflet.module @author Bob Hutchinson http://drupal.org/user/52366 @copyright GNU GPL

Code

function getlocations_leaflet_entity_type_map($type, $entity_id) {
  $entity_type = getlocations_get_entity_type_from_path($type);
  $locations = getlocations_load_locations($entity_id, $entity_type);
  $settings = variable_get('getlocations_leaflet_defaults', '');
  $entity_get_info = entity_get_info($entity_type);
  $load_hook = $entity_get_info['load hook'];
  $object = $load_hook($entity_id);
  $entity_link = '';
  $uri_callback = '';
  if (isset($entity_get_info['uri callback'])) {
    $uri_callback = $entity_get_info['uri callback'];
    $entity_link = $uri_callback($object);
  }
  $entity_title = '';
  $title = 'name';
  if (isset($entity_get_info['entity keys']['label'])) {
    $title = $entity_get_info['entity keys']['label'];
  }
  if (isset($object->{$title})) {
    $entity_title = $object->{$title};
  }
  $entity_key = '';
  if (isset($entity_get_info['entity keys']['id'])) {
    $entity_key = $entity_get_info['entity keys']['id'];
  }
  $getlocations_defaults = getlocations_defaults();
  $getlocations_leaflet_defaults = getlocations_leaflet_defaults();

  // awesome
  $marker = '';
  $vector = '';
  if ($getlocations_leaflet_defaults['awesome'] && $getlocations_leaflet_defaults['marker_type'] == 'fa') {
    $per_field_markers = FALSE;
    $getlocations_markers = variable_get('getlocations_markers', array());
    if (isset($getlocations_markers[$entity_type]['enable']) && $getlocations_markers[$entity_type]['enable']) {
      $type_markers = getlocations_get_type_markers();
      foreach ($type_markers as $et => $bundles) {
        if ($et == $entity_type) {
          foreach ($bundles as $bundle => $field_names) {
            foreach ($field_names as $field_name => $marker_data) {
              if (isset($getlocations_markers[$entity_type][$bundle][$field_name]['marker']) && $getlocations_markers[$entity_type][$bundle][$field_name]['marker']) {
                $per_field_markers = TRUE;
                $m = $entity_type . '__' . $bundle . '__' . $fieldname;
                $vicon = getlocations_leaflet_awesome_marker_get($settings, $m);
              }
            }
          }
        }
      }
    }
    if (!$per_field_markers) {
      if (isset($getlocations_defaults[$entity_type . '_map_marker'])) {
        $vicon = getlocations_leaflet_awesome_marker_get($getlocations_leaflet_defaults, $entity_type);
      }
      else {
        $vicon = getlocations_leaflet_awesome_marker_get($getlocations_leaflet_defaults);
      }
    }
    $vector = $vicon;
  }
  else {
    $marker = $getlocations_defaults['map_marker'];
    if (isset($getlocations_defaults[$entity_type . '_map_marker'])) {
      $marker = $getlocations_defaults[$entity_type . '_map_marker'];
    }
    if (isset($getlocations_leaflet_defaults[$entity_type . '_map_marker'])) {
      $marker = $getlocations_leaflet_defaults[$entity_type . '_map_marker'];
    }
    $getlocations_markers = variable_get('getlocations_markers', array());
    if (isset($getlocations_markers[$entity_type]['enable']) && $getlocations_markers[$entity_type]['enable']) {
      $type_markers = getlocations_get_type_markers();
      foreach ($type_markers as $et => $bundles) {
        if ($et == $entity_type) {
          foreach ($bundles as $bundle => $field_names) {
            foreach ($field_names as $field_name => $marker_data) {
              if (isset($getlocations_markers[$entity_type][$bundle][$field_name]['marker']) && $getlocations_markers[$entity_type][$bundle][$field_name]['marker']) {
                $marker = $getlocations_markers[$entity_type][$bundle][$field_name]['marker'];
              }
            }
          }
        }
      }
    }
  }
  $returnlink = FALSE;
  $links = array();
  if ($entity_type && $entity_link) {

    #if ($getlocations_defaults['returnlink_' . $entity_type . '_enable']) {
    if ($settings['returnlink_' . $entity_type . '_enable']) {
      if (is_object($object)) {

        #$linktext = $getlocations_defaults['returnlink_' . $entity_type . '_link'];
        $linktext = $settings['returnlink_' . $entity_type . '_link'];
        if (preg_match("/%t/", $linktext)) {
          $linktext = preg_replace("/%t/", $entity_title, $linktext);
        }

        #$returnlink = '<div class="getlocations_returnlink">' . l($linktext, $entity_link['path']) . '</div>';
        $returnlink = l($linktext, $entity_link['path']);
      }
    }
    if ($returnlink) {
      $links['returnlink'] = $returnlink;
    }
  }
  $latlons = array();
  $minmaxes = array(
    'minlat' => 0,
    'minlon' => 0,
    'maxlat' => 0,
    'maxlon' => 0,
  );
  $ct = 0;
  if (count($locations)) {

    // we should loop over them and dump bummers with no lat/lon
    foreach ($locations as $key => $location) {
      if ($latlon = getlocations_latlon_check($location['latitude'] . ',' . $location['longitude'])) {
        $ll = explode(',', $latlon);
        $location['latitude'] = $ll[0];
        $location['longitude'] = $ll[1];
        $minmaxes = getlocations_do_minmaxes($ct, $location, $minmaxes);
        $lid = isset($location['glid']) ? $location['glid'] : (isset($location['lid']) ? $location['lid'] : 0);
        if (!isset($location['key'])) {
          $location['key'] = '';
        }
        else {
          $location['lid'] = $entity_id;
        }

        // node only
        if ($entity_type == 'node') {

          // term markers
          $marker = getlocations_get_term_marker($entity_id, $marker);
        }

        // per location marker
        if (isset($location['marker']) && !empty($location['marker'])) {
          $marker = $location['marker'];
        }
        if ($lid && $settings['markeraction'] == 'popup') {
          $extra = FALSE;
          if (isset($getlocations_leaflet_defaults['getdirections_link'])) {
            $extra['gdlink'] = $getlocations_leaflet_defaults['getdirections_link'];
          }
          $markeraction = array(
            'type' => 'popup',
            'data' => getlocations_getinfo($lid, $entity_key, $extra),
          );
        }
        elseif ($lid && $settings['markeraction'] == 'link') {
          $markeraction = array(
            'type' => 'link',
            'data' => getlocations_getlidinfo($lid, $entity_key),
          );
        }
        else {
          $markeraction = array();
        }
        $name = htmlspecialchars_decode($location['name'] ? strip_tags($location['name']) : strip_tags($entity_title), ENT_QUOTES);
        $latlons[$ct] = array(
          $location['latitude'],
          $location['longitude'],
          $entity_key,
          $entity_id,
          $lid,
          $entity_title,
          $marker,
          $vector,
          $markeraction,
          '',
        );
        $iconlist[$marker] = getlocations_leaflet_get_marker($marker);
        $ct++;
      }
    }

    // end foreach
    if ($ct < 2) {
      unset($minmaxes);
      $minmaxes = '';
    }
    $map_settings = getlocations_leaflet_map_get_info('Getlocations OSM');
    $map_settings = getlocations_leaflet_get_map_layers($map_settings);
    if (!empty($settings['baselayers'])) {
      $map_layers = array();
      foreach ($settings['baselayers'] as $k => $v) {
        if (isset($map_settings['map_layers'][$k]) && $settings['baselayers'][$k]) {
          $map_layers[$k] = $map_settings['map_layers'][$k];
        }
      }
      if (!empty($map_layers)) {
        $map_settings['map_layers'] = $map_layers;
      }
    }
    $nodezoom = FALSE;
    if ($ct == 1 && $settings['nodezoom']) {
      $nodezoom = $settings['nodezoom'];
      $map_settings['map_opts']['center'] = array(
        $location['latitude'],
        $location['longitude'],
      );
      $map_settings['map_opts']['zoom'] = $nodezoom;
    }
    elseif ($ct < 1) {
      $ll = explode(',', $settings['latlong']);
      $map_settings['map_opts']['center'] = array(
        $ll[0],
        $ll[1],
      );
      $map_settings['map_opts']['zoom'] = $settings['zoom'];
    }
    $mapid = getlocations_setup_map('', FALSE, FALSE, TRUE);

    // add in some more
    $map_settings = getlocations_leaflet_map_settings_do($map_settings, $settings, $latlons, $mapid);
    $map_settings['map_settings']['nodezoom'] = $nodezoom ? $nodezoom : $settings['nodezoom'];
    $map_settings['map_settings']['minmaxes'] = empty($minmaxes) ? FALSE : implode(',', $minmaxes);
    $map_settings['icons'] = $iconlist;
    $map_settings['datanum'] = $ct;
    $map_settings['latlons'] = $latlons;
    $output = theme('getlocations_leaflet_map', array(
      'width' => $settings['width'],
      'height' => $settings['height'],
      'map_settings' => $map_settings,
      'mapid' => $mapid,
      'links' => $links,
    ));
    return $output;
  }
}