function geofield_ymap_plugin_style_geofield_ymap::render in Geofield Yandex Maps 7
Render the display in this style.
Overrides views_plugin_style::render
File
- ./
geofield_ymap_plugin_style_geofield_ymap.inc, line 195
Class
Code
function render() {
$geofield = '';
foreach ($this->view->field as $field_name => $field_handler) {
if (isset($field_handler->real_field) && preg_match('#_geom$#', $field_handler->real_field)) {
$geofield = $field_name;
break;
}
}
if (!$geofield) {
return t('Add geofield to fields list.');
}
$this->view->field[$geofield]->options['exclude'] = TRUE;
$this
->render_fields($this->view->result);
if ($this->view->result) {
geophp_load();
}
elseif ($this->options['map_hide_empty']) {
return NULL;
}
$features = array();
// Additional object options without tokens
$object_options = array();
if ($this->options['additional_settings']['object_options'] && !$this->options['additional_settings']['object_options_use_tokens']) {
$object_options = json_decode($this->options['additional_settings']['object_options'], TRUE);
}
foreach ($this->view->result as $row_index => $row) {
$this->view->row_index = $row_index;
$geofield_value = $this->view->field[$geofield]
->get_value($row);
if (!$geofield_value) {
continue;
}
$baloon_content = trim($this->row_plugin
->render($row));
$hint_content = $this->options['hint_content_field'] ? trim($this
->get_field($row_index, $this->options['hint_content_field'])) : '';
$icon_content = $this->options['icon_content_field'] ? trim($this
->get_field($row_index, $this->options['icon_content_field'])) : '';
$cluster_caption = $this->options['cluster_caption_field'] ? trim($this
->get_field($row_index, $this->options['cluster_caption_field'])) : '';
$preset = $this->options['preset_field'] ? trim($this
->get_field($row_index, $this->options['preset_field'])) : '';
// Additional object options with tokens
if ($this->options['additional_settings']['object_options'] && $this->options['additional_settings']['object_options_use_tokens']) {
$object_options = $this
->safe_tokenize_value($this->options['additional_settings']['object_options'], $row_index);
$object_options = json_decode($object_options, TRUE);
}
$geoms = array();
// For views_handler_field_field
if (is_array($geofield_value)) {
foreach ($geofield_value as $value) {
$geom = geoPHP::load($value['geom']);
$geoms = array_merge($geoms, geofield_ymap_split_objects($geom));
}
}
else {
$geom = geoPHP::load($geofield_value, 'wkb');
$geoms = array_merge($geoms, geofield_ymap_split_objects($geom));
}
foreach ($geoms as $geom) {
$feature = array(
'type' => 'Feature',
'geometry' => $geom
->out('json', TRUE),
);
if ($baloon_content) {
$feature['properties']['balloonContent'] = $baloon_content;
}
if ($hint_content) {
$feature['properties']['hintContent'] = $hint_content;
}
if ($icon_content) {
$feature['properties']['iconContent'] = $icon_content;
$feature['options']['preset'] = 'islands#blueStretchyIcon';
}
if ($cluster_caption) {
$feature['properties']['clusterCaption'] = $cluster_caption;
}
if ($preset) {
$feature['options']['preset'] = $preset;
}
if ($object_options) {
$feature_options = isset($feature['options']) ? $feature['options'] : array();
$feature['options'] = $object_options + $feature_options;
}
$features[] = $feature;
}
}
unset($this->view->row_index);
return array(
'#theme' => 'geofield_ymap',
'#map_objects' => $features ? array(
'type' => 'FeatureCollection',
'features' => $features,
) : array(),
'#map_type' => $this->options['map_type'],
'#map_center' => $this->options['map_center'],
'#map_zoom' => $this->options['map_zoom'],
'#map_auto_centering' => $this->options['map_auto_centering'],
'#map_auto_zooming' => $this->options['map_auto_zooming'],
'#map_clusterize' => $this->options['map_clusterize'],
'#map_object_preset' => $this->options['map_object_preset'],
'#map_controls' => $this->options['map_controls'],
'#map_behaviors' => $this->options['map_behaviors'],
'#map_save_state' => $this->options['map_save_state'],
'#id' => drupal_html_id('geofield-ymap-' . $this->view->name . '-' . $this->view->current_display),
);
}