aboutsummaryrefslogtreecommitdiff
path: root/gmap_arcgis.js
diff options
context:
space:
mode:
Diffstat (limited to 'gmap_arcgis.js')
-rw-r--r--gmap_arcgis.js346
1 files changed, 256 insertions, 90 deletions
diff --git a/gmap_arcgis.js b/gmap_arcgis.js
index 15b776b..454071a 100644
--- a/gmap_arcgis.js
+++ b/gmap_arcgis.js
@@ -1,103 +1,269 @@
// $Id$
-// Global variables
-var map, mapExtension, gOverlays;
+function gmapArcgis(config) {
+ return {
+ config: config,
-// Setup custom GMap Overlays
-function gmap_arcgis() {
- /**
- * Use a timer to make sure everything is loaded upon execution time.
- * See http://drupal.org/node/223613#comment-736303
- */
- setTimeout(function() {
- // Variables
- var id = 'auto1map';
-
- // 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
- map = Drupal.gmap.getMap(id).map;
+ map: config.map,
- //gmapArcgisShowPolygons(map, Drupal.settings.gmap_arcgis.polygons);
-
- }, 5);
-}
+ deforestation: [],
-// Show all defined polygons
-function gmapArcgisShowPolygons(map, polygons) {
- for (j = 0; j < polygons.length; j++) {
- showPolygon(map, polygons[j]);
- }
-}
+ getConfig: function() {
+ return config;
+ },
-// Hide all defined polygons
-function gmapArcgisHidePolygons(map, polygons) {
- for (j = 0; j < polygons.length; j++) {
- polygons[j].overlay.setOpacity(0);
- unblockUI();
- }
-}
+ // Show all defined polygons
+ showPolygons: function(polygons) {
+ for (j = 0; j < polygons.length; j++) {
+ this.showPolygon(polygons[j]);
+ }
+ },
+
+ // Hide all defined polygons
+ hidePolygons: function(polygons) {
+ for (j = 0; j < polygons.length; j++) {
+ polygons[j].overlay.setOpacity(0);
+ unblockUI();
+ }
+ },
+
+ // Add polygons from a given ArcGIS MapServer Layer
+ showPolygon: function(params) {
+ var defaultOpacity = (params.opacity != undefined) ? params.opacity : 0.55;
+
+ if (typeof params.overlay != 'undefined') {
+ params.overlay.setOpacity(defaultOpacity);
+ this.unblockUI();
+ return;
+ }
+
+ uri = params['uri'];
+ layers = params['layers'];
+
+ params.overlay = new gmaps.ags.MapOverlay(uri, {
+ exportOptions: {
+ layerIds: layers,
+ layerOption: 'show',
+ }
+ });
+
+ params.overlay.setMap(map);
+ params.overlay.setOpacity(defaultOpacity);
+
+ if (params.callback == undefined) {
+ // Default callback: remove the blockUI once the layer is shown
+ google.maps.event.addListener(params.overlay.getMapService(), 'update', function() {
+ unblockUI();
+ });
+ }
+ else {
+ google.maps.event.addListener(params.overlay.getMapService(), 'update', function() {
+ params.callback(map, params) ; unblockUI();
+ });
+ }
+ },
+
+ // Add a KML to the map
+ showKML: function(params) {
+ params.overlay = new google.maps.KmlLayer(params.uri);
+ params.overlay.setMap(map);
+ },
-// Add polygons from a given ArcGIS MapServer Layer
-function showPolygon(map, params) {
- var defaultOpacity = (params.opacity != undefined) ? params.opacity : 0.55;
+ // Add a KML layer into the map
+ addKML: function(params) {
+ if (typeof params.overlay != 'undefined') {
+ params.overlay.setOpacity(params.opacity);
+ unblockUI();
+ return params.overlay;
+ }
+
+ if (params.overlayTime != undefined) {
+ this.showOverlay(params.overlayTime);
+ }
+
+ this.showKML(params);
+
+ return params.overlay;
+ },
+
+ // Add a layer to the map
+ addLayers: function(params) {
+ if (typeof params.overlay != 'undefined') {
+ params.overlay.setOpacity(params.opacity);
+ unblockUI();
+ return params.overlay;
+ }
+
+ if (params.overlayTime != undefined) {
+ this.showOverlay(params.overlayTime);
+ }
+
+ // TODO: support for clickable polygons
+ this.showPolygon(params);
+
+ return params.overlay;
+ },
+
+ // Add makers to the map
+ addMarkers: function(params) {
+ var bounds = map.getBounds();
+
+ if (params.overlay != undefined) {
+ this.toggleMarkers(params);
+ return;
+ } else {
+ params.overlay = [];
+ }
+
+ if (params.overlayTime != undefined) {
+ this.showOverlay(params.overlayTime);
+ }
+
+ // Query parameters
+ var query = {
+ returnGeometry: true,
+ // TODO
+ //queryGeometry: bounds,
+ where: (params.where != undefined) ? params.where : '1=1',
+ outFields: params.fields,
+ };
+
+ var layer = new gmaps.ags.Layer(params.uri);
+
+ // Execute query
+ layer.query(query, processResultSet);
+
+ // Configure infoWindow
+ params.infowindow = new google.maps.InfoWindow({
+ content: '',
+ });
+
+ // Process results
+ function processResultSet(fset) {
+ var fs = fset.features;
+ for (var i = 0, c = fs.length; i < c; i++) {
+ fset = fs[i];
+
+ params.overlay[i] = {};
+ params.overlay[i].marker = new google.maps.Marker({
+ title: (params.title != undefined) ? fset.attributes[params.title] : fset.attributes.nome,
+ icon: params.icon,
+ position: fset.geometry[0].getPosition(),
+ map: map,
+ });
+
+ // Use a closure so marker data remains available to the listeners
+ params.overlay[i].addListener = function() {
+ var marker = params.overlay[i].marker;
+ var infowindow = params.infowindow;
+ var content = params.content;
+ var attributes = fset.attributes;
+
+ google.maps.event.addListener(marker, 'click', function() {
+ infowindow.setContent(content(attributes));
+ infowindow.open(map, marker);
+ });
+ };
+
+ // Execute
+ params.overlay[i].addListener();
+ }
+
+ this.unblockUI();
+ }
+ },
- if (typeof params.overlay != 'undefined') {
- params.overlay.setOpacity(defaultOpacity);
- unblockUI();
- return;
- }
+ // UI unblocker wrapper
+ unblockUI: function() {
+ jQuery.unblockUI();
+ },
+
+ // UI blocker wrapper
+ blockUI: function() {
+ jQuery.blockUI();
+ },
- uri = params['uri'];
- layers = params['layers'];
+ toggleKML: function(params) {
+ // TODO
+ return;
+ },
+
+ toggleLayers: function(params) {
+ params.overlay.setOpacity(0);
+ },
+
+ // Toggle marker visibility
+ toggleMarkers: function(params, raw) {
+ markers = (raw == true) ? params : params.overlay;
+
+ for (i=0; i < markers.length; i++) {
+ if (markers[i].marker.getVisible()) {
+ markers[i].marker.setVisible(false);
+ } else {
+ markers[i].marker.setVisible(true);
+ }
+ }
+ },
- params.overlay = new gmaps.ags.MapOverlay(uri, {
- exportOptions: {
- layerIds: layers,
- layerOption: 'show',
- }
- });
+ showOverlay: function(t) {
+ if ($.browser.msie === false) {
+ message = this.config.overlayMessage;
+ if (t == false) {
+ $.blockUI({
+ message: message
+ });
+ } else {
+ $.blockUI({
+ message: message,
+ timeout: t
+ });
+ }
+ }
+ },
- params.overlay.setMap(map);
- params.overlay.setOpacity(defaultOpacity);
+ // Change a element in the map
+ changeElement: function(map, params, page, callback) {
+ if (config[params] == undefined || config[params]['showOn'] == undefined) {
+ return;
+ }
+
+ if (jQuery.inArray(page, config[params]['showOn']) != -1) {
+ this[callback](map, config[params]);
+ }
+ },
+
+ // Display deforestation
+ deforestationUpdate: function(layer) {
+ var defaultOpacity = 0.45;
+
+ if (this.deforestation[layer] == undefined) {
+ this.deforestation[layer] = this.addLayers({
+ uri: URL_ARCGIS_DESMATAMENTO,
+ opacity: defaultOpacity,
+ layers: [layer],
+ overlayTime: 3000,
+ callback: updateDeforestationOpacity,
+ });
+ }
+ else {
+ updateDeforestationOpacity(map, { layers: [layer] });
+ }
+
+ function updateDeforestationOpacity(map, params) {
+ for (var i in this.deforestation) {
+ if (params.layers[0] == i) {
+ this.deforestation[i].setOpacity(0.45);
+ }
+ else {
+ this.deforestation[i].setOpacity(0);
+ }
+ }
+
+ // The second and all subsequent layers shall be intialized without opacity.
+ defaultOpacity = 0;
+ }
+
+ },
- if (params.callback == undefined) {
- // Default callback: remove the blockUI once the layer is shown
- google.maps.event.addListener(params.overlay.getMapService(), 'update', function() {
- unblockUI();
- });
}
- else {
- google.maps.event.addListener(params.overlay.getMapService(), 'update', function() {
- params.callback(map, params) ; unblockUI();
- });
- }
-}
-
-// Add a KML to the map
-function showKML(map, params) {
- params.overlay = new google.maps.KmlLayer(params.uri);
- params.overlay.setMap(map);
-}
-
-// UI unblocker wrapper
-function unblockUI() {
- $.unblockUI();
-}
-
-// UI blocker wrapper
-function blockUI() {
- $.blockUI();
-}
-
-// Add map overlays
-$(document).ready(function() {
- google.setOnLoadCallback(gmap_arcgis);
- $('#edit-lista-uc').change(function() {
- $('#header').hide();
- $('#nav').hide();
- });
-});
+};