function geofield_map_plugin_style_map::render in Geofield 7.2
Same name and namespace in other branches
- 7 modules/geofield_map/includes/geofield_map_plugin_style_map.inc \geofield_map_plugin_style_map::render()
Renders views (map)
Overrides views_plugin_style::render
File
- modules/
geofield_map/ includes/ geofield_map_plugin_style_map.inc, line 106 - This file holds style plugin for Geofield Maps
Class
- geofield_map_plugin_style_map
- @class Extension of the Views Plugin Syle for Geofield Map
Code
function render() {
geophp_load();
$style_options = $this->view->style_plugin->options;
$geo_data = !empty($style_options['data_source']) ? 'field_' . $style_options['data_source'] : NULL;
$popup_data = !empty($style_options['popup_source']) ? $style_options['popup_source'] : NULL;
if ($geo_data) {
$this
->render_fields($this->view->result);
$data = array();
foreach ($this->view->result as $id => $result) {
$geofield_handler = $this->view->field[$style_options['data_source']];
$geofield = $geofield_handler
->get_value($result);
if (!empty($geofield[0]['geom'])) {
$description = $popup_data ? $this->rendered_fields[$id][$popup_data] : '';
$geometry = geoPHP::load($geofield[0]['geom']);
$datum = json_decode($geometry
->out('json'));
$datum->properties = array(
'description' => $description,
);
$data[] = $datum;
}
}
if (!$data && !$style_options['geofield_map_center']) {
return;
}
if (count($data) == 1) {
$data = $data[0];
}
elseif (count($data) > 1) {
$tmp = $data;
$data = array(
'type' => 'GeometryCollection',
'geometries' => $tmp,
);
}
$map_settings = geofield_map_settings_do($style_options);
$container_id = drupal_html_id($this->view->name . '_' . $this->view->current_display);
$js_settings = array(
$container_id => array(
'map_id' => $container_id,
'map_settings' => $map_settings,
'data' => $data,
),
);
drupal_add_js(array(
'geofieldMap' => $js_settings,
), 'setting');
}
// Build API url.
$api_url = geofield_map_build_api_url();
drupal_add_js($api_url, 'external');
drupal_add_js(drupal_get_path('module', 'geofield_map') . '/js/GeoJSON.js');
drupal_add_js(drupal_get_path('module', 'geofield_map') . '/js/geofield_map.js');
drupal_add_css(drupal_get_path('module', 'geofield_map') . '/css/geofield_map.css');
// defaults
$width = '100%';
$height = '300px';
if ($style_options['geofield_map_width']) {
$width = $style_options['geofield_map_width'];
}
if ($style_options['geofield_map_height']) {
$height = $style_options['geofield_map_height'];
}
return '<div style="width: ' . $width . '; height: ' . $height . '" id="' . $container_id . '" class="geofieldMap">' . $style_options['alt_text'] . '</div>';
}