From 7a46bcde32fd0ba81975ac5dcbf0193fea948354 Mon Sep 17 00:00:00 2001 From: Silvio Date: Wed, 1 Feb 2012 17:34:17 -0200 Subject: Syncing with svn --- gmap_arcgis.module | 573 ++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 497 insertions(+), 76 deletions(-) (limited to 'gmap_arcgis.module') diff --git a/gmap_arcgis.module b/gmap_arcgis.module index fc68938..9a71980 100644 --- a/gmap_arcgis.module +++ b/gmap_arcgis.module @@ -1,4 +1,5 @@ '); - - // Add ArcGIS js API - drupal_set_html_head($script .'src="http://serverapi.arcgisonline.com/jsapi/gmaps/?v=1.4">'); - - // Setup Map Id - drupal_add_js(array('gmap_arcgis' => array('id' => $map['id'])), 'setting'); - - /** - * Setup polygons and labels. Labels have the following format: - * - * $map['arcgis']['labels'] = array($layer1 [, $layer2 [,... $layerN]]); - * - * Where $layer is - * - * $layer = array($layer_uri, $fields, $content, $icon); - * - * Where $layer_uri is a MapService layer, $fields is an array with - * a pair of layer fields to pass to the query, $content is a string - * with the content to display for each marker and $icon is an array - * with parameteres from a GIcon class - * - * $icon = array($shadow, $image, $info_size, $shadow_size, - * $info_anchor, $info_window_anchor); - * - * For more info on the GIcon class, see - * http://code.google.com/intl/pt-BR/apis/maps/documentation/reference.html#GIcon - * - * Example: - * - * $labels = array( - * array("http://mapservice/layer1", array('id', 'name'), array( - * NULL, 'http://path/to/icon.png', - * array(20, 34), array(37, 34), array(9, 34), array(9, 2) - * ) - * ), - * array("http://mapservice/layer2"), - * ); - */ - if (isset($map['arcgis']['polygons'])) { - drupal_add_js(array('gmap_arcgis' => array('polygons' => $map['arcgis']['polygons'])), 'setting'); - } - if (isset($map['arcgis']['labels'])) { - drupal_add_js(array('gmap_arcgis' => array('labels' => $map['arcgis']['labels'])), 'setting'); - } - - // Add custom js - $gmap_arcgis_path = drupal_get_path('module', 'gmap_arcgis') .'/'; - drupal_add_js($gmap_arcgis_path .'gmap_arcgis.js'); + if ($op == 'pre_theme_map') { + + + /** + * Use $map to change and add custom overlays into + * a given map instance. + */ + if (isset($map['arcgis'])) { + /** + * Make sure that shapes js code are loaded. + * + * This is needed as a workaround to the current GMap + * module that doesn't add shapes js if $map['shapes'] + * wasn't previously defined. + */ + if (!empty($map['shapes'])) { + $gmap_path = drupal_get_path('module', 'gmap') . '/js/'; + drupal_add_js($gmap_path . 'shapeloader_static.js'); + drupal_add_js($gmap_path . 'gmap_shapes.js'); + } + + /** + * The order to load the following js code is important. + */ + // Add Google js API + $key = variable_get('googlemap_api_key', ''); + $script = ''); + + // Add ArcGIS js API + drupal_set_html_head($script . 'src="http://serverapi.arcgisonline.com/jsapi/gmaps/?v=1.6">'); + + // Setup Map Id + drupal_add_js(array('gmap_arcgis' => array('id' => $map['id'])), 'setting'); + + + /** + * Setup polygons and labels. Labels have the following format: + * + * $map['arcgis']['labels'] = array($layer1 [, $layer2 [,... $layerN]]); + * + * Where $layer is + * + * $layer = array($layer_uri, $fields, $content, $icon); + * + * Where $layer_uri is a MapService layer, $fields is an array with + * a pair of layer fields to pass to the query, $content is a string + * with the content to display for each marker and $icon is an array + * with parameteres from a GIcon class + * + * $icon = array($shadow, $image, $info_size, $shadow_size, + * $info_anchor, $info_window_anchor); + * + * For more info on the GIcon class, see + * http://code.google.com/intl/pt-BR/apis/maps/documentation/reference.html#GIcon + * + * Example: + * + * $labels = array( + * array("http://mapservice/layer1", array('id', 'name'), array( + * NULL, 'http://path/to/icon.png', + * array(20, 34), array(37, 34), array(9, 34), array(9, 2) + * ) + * ), + * array("http://mapservice/layer2"), + * ); + */ + /** + * The code below provides titles on markers + */ + // if(is_array($map['markers'])) { + // array_walk($map['markers'], 'add_title_on_marker'); + // } + + + if (isset($map['arcgis']['polygons'])) { + drupal_add_js(array('gmap_arcgis' => array('polygons' => $map['arcgis']['polygons'])), 'setting'); + } + if (isset($map['arcgis']['labels'])) { + drupal_add_js(array('gmap_arcgis' => array('labels' => $map['arcgis']['labels'])), 'setting'); + } + + /* $map['markers'][] = array( + 'latitude' => '-22.7559207', + 'longitude' => '-48.1640625', + 'markername' => 'Eventos', + 'offset' => 0, + 'text' => 'Um teste', + 'opts' => array( + 'title' => 'Teste de evento', + 'nid' => 10853, + 'category' => 'marker_uc', + ), + + ); */ + + // print views_embed_view('eventos'); + /* + $my_content_view = views_get_view('eventos'); + $my_content_view->build('default'); + $my_content_view->execute('default'); + + $results = $my_content_view->result; + + + foreach($results AS $r) { + + //Format the Body of the ballon + $inicio = format_date($r->event_unix_event_start); + $fim = format_date($r->event_unix_event_end); + $body = '
'; + $body .= "

$r->node_title

"; + $body .= " +

+ $r->node_revisions_body +

+ + "; + $body .= '
'; + + + + + $data['latitude'] = $r->location_latitude; + $data['longitude'] = $r->location_longitude; + $data['title'] = $r->node_title; + $data['offset'] = 0; + $data['nid'] = $r->nid; + $data['body'] = $body; + $data['category'] = 'marker_uc'; + + __addMarker(&$map, $data); + + } */ + + + // Add custom js + $gmap_arcgis_path = drupal_get_path('module', 'gmap_arcgis') . '/'; + drupal_add_js($gmap_arcgis_path . 'gmap_arcgis.js'); + //jquery_ui_add('ui.dialog'); + jquery_ui_add('effects.fold'); + jquery_ui_add('effects.explode'); + jquery_ui_add('effects.core'); + jquery_ui_add('ui.slider'); + + $path_ui_css = drupal_get_path('module', 'jquery_ui'); + //drupal_add_css($path_ui_css . '/jquery.ui/themes/default/ui.all.css'); + + drupal_add_js('showOverlay();', 'inline', 'footer'); + } } - } } + +/** + * Set the title of the marker; + * @param array $marker + */ +function add_title_on_marker(&$marker) { + + if (!empty($marker['text'])) { + $dom = new DOMDocument(); + $dom->loadHTML($marker['text']); + //$dom->preserveWhiteSpace = false; + // print_r($marker['text']); + + $divs = $dom->getElementsByTagName('div'); + if ($divs) { + foreach ($divs AS $div) { + + if ($div->getAttribute('id') === 'nid') { + + $x = node_load($div->nodeValue); + + $titulo = $x->field_categoria[0]['value'] . ' ' . $x->field_preposicao[0]['value'] . ' ' . $x->title; + $marker['opts'] = array('title' => $titulo, 'nid' => $div->nodeValue, 'category' => 'marker_uc'); + } + } + } + } +} + +/** + * Wrapper to add custom markers on map. Need to be out somewhere + * @param array marker + */ +function __addMarker(&$map, $data) { + $map['markers'][] = array( + 'latitude' => $data['latitude'], + 'longitude' => $data['longitude'], + 'markername' => $data['markername'], + 'offset' => $data['offset'], + 'text' => $data['body'], + 'opts' => array( + 'title' => $data['title'], + 'nid' => $data['nid'], + 'category' => $data['category'], + ), + ); +} + +/** + * Implementation of hook_form() + */ +function uc_form($form_state) { + + $text = t('Choose a protected area on the list below'); + + $view = views_get_view('mapa'); + + //$view->execute('default'); + + $view->execute_display('default'); + //firep($view->result, 'lsita de uc'); + + $i = 0; + $opcoes[-1] = $text; + + foreach ($view->result AS $res) { + + $opcoes[$i] = $res->node_title . ' (' . $res->node_data_field_categoria_field_categoria_value . ')'; + $i++; + } + + asort($opcoes); + + $form['div_tag'] = array( + '#type' => 'markup', + '#value' => '
', + '#weight' => -5, + ); // + + $form['markers'] = array( + '#type' => 'checkbox', + '#prefix' => '
', + '#title' => t('Conservational Units markers'), + '#suffix' => '
', + '#default_value' => 1, + '#weight' => -4, + ); + + /* $form['ucs'] = array( + '#type' => 'checkbox', + '#title' => t('Conservational Units limits'), + '#default_value' => 1, + '#weight' => -3, + ); */ +//['.t('hide markers').'] + $form['tis'] = array( + '#type' => 'checkbox', + '#title' => t('Indigenous Lands'), + '#weight' => -2, + ); + $form['focos'] = array( + '#type' => 'checkbox', + '#title' => t('Heat sources'), + '#weight' => -1, + ); + + $form['energia'] = array( + '#type' => 'checkbox', + '#title' => t('Energy'), + '#weight' => 0, + ); + + $form['cavernas'] = array( + '#type' => 'checkbox', + '#title' => t('Caves'), + '#weight' => 1, + ); + + $form['mineracao'] = array( + '#type' => 'checkbox', + '#title' => t('Mining'), + '#weight' => 2, + ); + + $form['biomas'] = array( + '#type' => 'checkbox', + '#title' => t('Biomes'), + '#weight' => 3, + ); + + $form['fitofisionomia'] = array( + '#type' => 'checkbox', + '#title' => t('Vegetation'), + '#weight' => 4, + ); + $form['baciashidrograficas'] = array( + '#type' => 'checkbox', + '#title' => t('Watersheds'), + '#weight' => 5, + ); + + $form['ramsar'] = array( + '#type' => 'checkbox', + '#title' => t('Ramsar Sites'), + '#weight' => 6, + ); + + + $form['lista_uc'] = array( + '#type' => 'select', + '#title' => $text, + '#default_value' => array(-1, $text), + '#options' => $opcoes, + '#weight' => 7, + '#attributes' => array('class' => 'selectmenu'), + ); + + + $form['div_tag2'] = array( + '#type' => 'markup', + '#value' => '

' . t('Subtitles') . '

+ + +

' . t('Ramsar Sites') . '

+
'.gmap_arcgis_link_nota_tecnica(), + '#weight' => 8, + ); + + return $form; +} + +/** + * Implementation of hook_block() + */ +function gmap_arcgis_block($op='list', $delta=0, $edit=array()) { + + global $map; + switch ($op) { + case 'list': + + $blocks[0]['info'] = t('Protected areas list'); + return $blocks; + + case 'view': + + drupal_add_js('$(window).load(function() { + $("#slider").slider( + { + value:1, + min: -1, + max: 10, + step: 1, + start: function(event,ui) { + + //$.blockUI({ message: "

Just a moment...

" }); + }, + animate: true, + change: function(event, ui) { + + Desmatamento(ui.value) + }, + slide: function(event,ui) { + + //$("#yy").html(ui.value); + } + }); + }); + ', + 'inline', 'header'); + + drupal_add_js('$("#clickmapa").click(function() { + var options = {}; + $("#uc-form").toggle("fold",options,500); + if($("#abrefecha").hasClass("close_gmap_arcgis")) { + $("#abrefecha").switchClass("open_gmap_arcgis","close_gmap_arcgis"); + } else { + $("#abrefecha").switchClass("close_gmap_arcgis","open_gmap_arcgis"); + + } + return false; + }); +', 'inline', 'footer'); + $blocks['subject'] = t('Protected areas list'); + $blocks['content'] = drupal_get_form('uc_form') . + '
X
'; + + return $blocks; + + case 'configure': + + case 'save': + } +} + + +function gmap_arcgis_link_nota_tecnica() { + // global $base_url; + //$str = http://uc.socioambiental.org/quem-somos# + + return l(t('More information about the map'),'quem-somos',array('fragment' => 'middle-tab-5', 'external' => TRUE)); + +} + -- cgit v1.2.3