aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gmpa_arcgis.js.swpbin0 -> 20480 bytes
-rw-r--r--gmap_arcgis.info6
-rw-r--r--gmap_arcgis.js137
-rw-r--r--gmap_arcgis.module102
4 files changed, 245 insertions, 0 deletions
diff --git a/.gmpa_arcgis.js.swp b/.gmpa_arcgis.js.swp
new file mode 100644
index 0000000..73b636f
--- /dev/null
+++ b/.gmpa_arcgis.js.swp
Binary files differ
diff --git a/gmap_arcgis.info b/gmap_arcgis.info
new file mode 100644
index 0000000..eca384e
--- /dev/null
+++ b/gmap_arcgis.info
@@ -0,0 +1,6 @@
+; $Id$
+name = GMap ArcGIS integration
+description = Integrates ArcGIS Layers into a GMap
+dependencies[] = gmap
+core = 6.x
+version = "6.x-0.1"
diff --git a/gmap_arcgis.js b/gmap_arcgis.js
new file mode 100644
index 0000000..0691ad4
--- /dev/null
+++ b/gmap_arcgis.js
@@ -0,0 +1,137 @@
+// $Id$
+
+// Load Google Maps API
+google.load("maps", "2.x");
+
+// Global variables
+var map, mapExtension, gOverlays;
+
+// Setup custom ISA GMap Overlays (layers and labels)
+function gmap_arcgis() {
+
+ // Fallback setting
+ // TODO: general default settings instead of custom ISA config
+ var fallback = 'http://isamapas.socioambiental.org:8399/arcgis/rest/services/uc_isa/MapServer';
+ var polygons = [ fallback ];
+ var labels = [ fallback + '/2' ];
+ var fields = new Array();
+ var id = 'auto1map';
+
+ // Get data from Drupal
+ if (Drupal.settings.gmap_arcgis !== undefined) {
+ // Get array of polygons
+ if (Drupal.settings.gmap_arcgis.polygons !== undefined) {
+ polygons = Drupal.settings.gmap_arcgis.polygons;
+ }
+ // Get array of labels
+ if (Drupal.settings.gmap_arcgis.labels !== undefined) {
+ labels = Drupal.settings.gmap_arcgis.labels;
+ }
+ // Get Map Id
+ if (Drupal.settings.gmap_arcgis.id !== undefined) {
+ id = Drupal.settings.gmap_arcgis.id;
+ }
+ }
+
+ // Get an existing GMap instance using Drupal GMap Module API
+ // and add an ArcGIS extension to it
+ map = Drupal.gmap.getMap(id).map;
+ mapExtension = new esri.arcgis.gmaps.MapExtension(map);
+
+ for each (var label in labels) {
+ // TODO: general default settings instead of custom ISA config
+ fields = ["id_arp", "nome_uc"];
+ icon = new GIcon(G_DEFAULT_ICON);
+ if (label[1] !== undefined) {
+ // Set custom fields
+ fields = [ label[1][0], label[1][1] ];
+ }
+ if (label[2] !== undefined) {
+ // Set label icons
+ var info = label[2];
+ icon.shadow = info[0];
+ icon.image = info[1];
+ icon.infoSize = new GSize(info[2][0], info[2][1]);
+ icon.shadowSize = new GSize(info[3][0], info[3][1]);
+ icon.infoAnchor = new GPoint(info[4][0], info[4][1]);
+ icon.infoWindowAnchor = new GPoint(info[5][0], info[5][1]);
+ }
+ GEvent.addListener(map, "moveend", function() { showLabels(label[0], fields, icon); });
+ showLabels(label[0], fields, icon);
+ }
+
+ for each (var polygon in polygons) {
+ showPolygons(polygon);
+ }
+}
+
+// Add labels from a given ArcGIS MapServer Layer
+function showLabels(label, fields, icon) {
+ var bounds = map.getBounds();
+ var queryTask = new esri.arcgis.gmaps.QueryTask(label);
+ var query = new esri.arcgis.gmaps.Query();
+
+ // clear gOverlays overlays and event listeners
+ //mapExtension.removeFromMap(gOverlays);
+
+ // set query parameters
+ query.queryGeometry = bounds;
+ query.returnGeometry = true;
+ query.outFields = fields;
+
+ // set the callback
+ var callback = showLabelsCallback(icon);
+
+ // execute query task
+ queryTask.execute(query, false, callback);
+}
+
+// Callback for showLabels
+function showLabelsCallback(icon) {
+ return function(fset) {
+ // JS literal class esri.arcgis.gmaps.MarkerOptions
+ // TODO: general default settings instead of custom ISA config
+ var myMarkerOptions = { title:"{nome_uc}", icon:icon };
+
+ // JS literal class esri.arcgis.gmaps.OverlayOptions
+ var overlayOptions = { markerOptions:myMarkerOptions };
+
+ // JS literal class esri.arcgis.gmaps.InfoWindowOptions without tabs
+ var infoWindowOptions = {
+ // TODO: general default settings instead of custom ISA config
+ content:"<h2>{nome_uc}</h2><a href=\"?q=/uc/{id_arp}\">Mais informações sobre esta UC</a>"
+ };
+
+ gOverlays = mapExtension.addToMap(fset, overlayOptions, infoWindowOptions);
+ }
+}
+
+// Add polygons from a given ArcGIS MapServer Layer
+function showPolygons(uri) {
+ polygons = new esri.arcgis.gmaps.DynamicMapServiceLayer(uri, null, 0.45, showPolygonsCallback);
+}
+
+// Callback for showPolygons
+function showPolygonsCallback(mapservicelayer, error) {
+ map.addOverlay(mapservicelayer);
+}
+
+// Add custom marker
+function createMarker(point, name, html, icone) {
+ var icon = new GIcon();
+ icon.image = icone;
+ icon.shadow = "http://maps.google.com/mapfiles/ms/micons/msmarker.shadow.png";
+ icon.iconSize = new GSize(12, 20);
+ icon.shadowSize = new GSize(22, 20);
+ icon.iconAnchor = new GPoint(6, 20);
+ icon.infoWindowAnchor = new GPoint(5, 1);
+
+ var marker = new GMarker(point);
+ GEvent.addListener(marker, "click", function() { marker.openInfoWindowHtml(html); });
+ return marker;
+}
+
+// Add map overlays
+$(document).ready(function() {
+ google.setOnLoadCallback(gmap_arcgis);
+});
diff --git a/gmap_arcgis.module b/gmap_arcgis.module
new file mode 100644
index 0000000..9988676
--- /dev/null
+++ b/gmap_arcgis.module
@@ -0,0 +1,102 @@
+<?php
+// $Id$
+
+/**
+ * @file
+ * Support for ArcGIS into GMap.
+ *
+ * This module implements support for ArcGIS API
+ * into a GMap.
+ */
+
+/**
+ * Implementation of hook_install().
+ */
+function gmap_install() {
+ /**
+ * We need to make sure that this module be the last one
+ * in the hook execution order.
+ */
+ db_query("UPDATE {system} SET weight = 10 WHERE name = 'gmap_arcgis'");
+}
+
+/**
+ * Implementation of hook_gmap().
+ */
+function gmap_arcgis_gmap($op, &$map) {
+ 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 = '<script type="text/javascript" ';
+ drupal_set_html_head($script .'src="http://www.google.com/jsapi?key='. $key .'"></script>');
+
+ // Add ArcGIS js API
+ drupal_set_html_head($script .'src="http://serverapi.arcgisonline.com/jsapi/gmaps/?v=1.4"></script>');
+
+ // 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, $icon);
+ *
+ * Where $layer_uri is a MapService layer and $fields is an array with
+ * a pair of layer fields to pass to the queryand $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');
+ }
+ }
+}