aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSilvio <silvio@socioambiental.org>2013-03-27 15:36:02 -0300
committerSilvio <silvio@socioambiental.org>2013-03-27 15:36:02 -0300
commit99ca342bd59ab2669f51daebd9e6995cf69614f0 (patch)
treeff4e9746b54d3b78e4e2d39ff8ddfb46301d7b91
parentce19c2e23ee61edfa2d889b6e65c3515897ff8ad (diff)
downloadgmap_arcgis-99ca342bd59ab2669f51daebd9e6995cf69614f0.tar.gz
gmap_arcgis-99ca342bd59ab2669f51daebd9e6995cf69614f0.tar.bz2
Now gmap_arcgis.js part of a separate library
-rw-r--r--README.txt5
-rw-r--r--gmap_arcgis.js316
-rw-r--r--gmap_arcgis.module10
3 files changed, 9 insertions, 322 deletions
diff --git a/README.txt b/README.txt
index 37e0251..451c149 100644
--- a/README.txt
+++ b/README.txt
@@ -1,8 +1,9 @@
GMap ArcGIS Integration
=======================
-This module implements support for ArcGIS API into a GMap. It doesn't provide
-any custom interface or GUI for integration but includes a simple API.
+This module providers Drupal integration with gmap_arcgis JS library. It
+doesn't provide any custom interface or GUI for integration but includes a
+simple API.
It required Drupal's GMap module as it relies on hook_gmap() and allows one to
draws custom labels and polygons in a GMap instance by manipulating $map array
diff --git a/gmap_arcgis.js b/gmap_arcgis.js
deleted file mode 100644
index d0bd721..0000000
--- a/gmap_arcgis.js
+++ /dev/null
@@ -1,316 +0,0 @@
-// $Id$
-
-function gmapArcgis(config) {
- return {
- // Storable properties
- config: config,
- map: config.map,
-
- // UI unblocker wrapper
- unblockUI: function() {
- jQuery.unblockUI();
- },
-
- // UI blocker wrapper
- blockUI: function() {
- jQuery.blockUI();
- },
-
- // Set the current map
- setMap: function(map) {
- this.map = map;
- },
-
- // Get the default opacity of an layer element
- defaultOpacity: function(element, store) {
- store = (store != undefined) ? store : 'layers';
-
- if (this.config[store][element] != undefined && this.config[store][element].opacity != undefined) {
- return this.config[store][element].opacity;
- }
- else {
- return 0.55;
- }
- },
-
- // TODO: support for clickable polygons
- // Add polygons from a given ArcGIS MapServer Layer
- showPolygon: function(params, store) {
- params.overlay = new gmaps.ags.MapOverlay(params['uri'], {
- exportOptions: {
- layerIds: params['layers'],
- layerOption: 'show',
- }
- });
-
- params.overlay.setMap(this.map);
- params.overlay.setOpacity(params.opacity);
-
- if (params.callback == undefined) {
- // Default callback: remove the blockUI once the layer is shown
- google.maps.event.addListener(params.overlay.getMapService(), 'update', function() {
- this.unblockUI();
- });
- }
- else {
- google.maps.event.addListener(params.overlay.getMapService(), 'update', function() {
- params.callback(this.map, params) ; this.unblockUI();
- });
- }
-
- return params.overlay;
- },
-
- // Add a KML to the map
- showKML: function(element) {
- if (typeof this.config['kmls'][element].overlay == 'undefined') {
- this.config['kmls'][element].overlay = new google.maps.KmlLayer(this.config['kmls'][element].uri);
- }
-
- this.config['kmls'][element].overlay.setMap(this.map);
- this.config['kmls'][element].isVisible = true;
- },
-
- // Add a KML layer into the map
- addKML: function(element) {
- if (typeof this.config['kmls'][element].overlay != 'undefined') {
- this.showKML(element);
- this.unblockUI();
- return;
- }
-
- if (this.config['kmls'][element].overlayTime != undefined) {
- this.showOverlay(this.config['kmls'][element].overlayTime);
- }
-
- this.showKML(element);
- },
-
- // Add a layer to the map
- addLayers: function(element) {
- this.config['layers'][element].opacity = this.defaultOpacity(element);
-
- if (typeof this.config['layers'][element].overlay != 'undefined') {
- this.config['layers'][element].overlay.setOpacity(this.config['layers'][element].opacity);
- this.unblockUI();
- return;
- }
-
- if (this.config['layers'][element].overlayTime != undefined) {
- this.showOverlay(this.config['layers'][element].overlayTime);
- }
-
- this.config['layers'][element].overlay = this.showPolygon(this.config['layers'][element]);
- },
-
- // Add a slider layer in the map
- addSlider: function(layer, slider) {
- this.config['sliders'][slider].opacity = this.defaultOpacity(layer, 'sliders');
- this.config['sliders'][slider].callback = this.sliderUpdateOpacity;
- this.config['sliders'][slider].layers = [layer];
-
- if (typeof this.config['sliders'][slider].overlays[layer] != 'undefined') {
- this.config['sliders'][slider].overlays[layer].setOpacity(this.config['sliders'][slider].opacity);
- this.unblockUI();
- }
-
- if (this.config['sliders'][slider].overlayTime != undefined) {
- this.showOverlay(this.config['sliders'][slider].overlayTime);
- }
-
- this.config['sliders'][slider].overlays[layer] = this.showPolygon(this.config['sliders'][slider]);
- },
-
- // Add makers to the map
- addMarkers: function(element) {
- var bounds = this.map.getBounds();
- var self = this;
-
- if (this.config['markers'][element].overlay != undefined) {
- this.toggleMarkers(element);
- return;
- } else {
- this.config['markers'][element].overlay = [];
- }
-
- if (this.config['markers'][element].overlayTime != undefined) {
- this.showOverlay(this.config['markers'][element].overlayTime);
- }
-
- // Query parameters
- var query = {
- returnGeometry: true,
- geometry: bounds,
- where: (this.config['markers'][element].where != undefined) ? this.config['markers'][element].where : '1=1',
- outFields: this.config['markers'][element].fields,
- };
-
- var layer = new gmaps.ags.Layer(this.config['markers'][element].uri);
-
- // Execute query
- layer.query(query, processResultSet);
-
- // Configure infoWindow
- this.config['markers'][element].infowindow = new google.maps.InfoWindow({
- content: '',
- });
-
- // Process results
- function processResultSet(fset) {
- var fs = fset.features;
- var title;
- for (var i = 0, c = fs.length; i < c; i++) {
- fset = fs[i];
-
- if (self.config['markers'][element].title != undefined) {
- title = fset.attributes[self.config['markers'][element].title];
- }
- else {
- title = fset.attributes.nome;
- }
-
- self.config['markers'][element].overlay[i] = {};
- self.config['markers'][element].overlay[i].marker = new google.maps.Marker({
- title: title,
- icon: self.config['markers'][element].icon,
- position: fset.geometry[0].getPosition(),
- map: map,
- });
-
- // Use a closure so marker data remains available to the listeners
- self.config['markers'][element].overlay[i].addListener = function() {
- var marker = self.config['markers'][element].overlay[i].marker;
- var infowindow = self.config['markers'][element].infowindow;
- var content = self.config['markers'][element].content;
- var attributes = fset.attributes;
-
- google.maps.event.addListener(marker, 'click', function() {
- infowindow.setContent(content(attributes));
- infowindow.open(map, marker);
- });
- };
-
- // Execute
- self.config['markers'][element].overlay[i].addListener();
- }
-
- self.unblockUI();
- }
- },
-
- // Toggle KML visibility
- toggleKML: function(element) {
- if (this.config['kmls'][element].overlay == undefined) {
- return;
- } else if (this.config['kmls'][element].isVisible == true) {
- this.config['kmls'][element].isVisible = false;
- this.config['kmls'][element].overlay.setMap();
- } else {
- this.config['kmls'][element].isVisible = true;
- this.config['kmls'][element].overlay.setMap(this.map);
- }
- },
-
- // Toggle layer visibility
- toggleLayers: function(element) {
- this.config['layers'][element].overlay.setOpacity(0);
- },
-
- // Toggle marker visibility
- toggleMarkers: function(element, raw) {
- var markers = (raw == true) ? element : this.config['markers'][element].overlay;
-
- for (i=0; i < markers.length; i++) {
- if (markers[i].marker.getVisible()) {
- markers[i].marker.setVisible(false);
- } else {
- markers[i].marker.setVisible(true);
- }
- }
- },
-
- // Block the UI and show an overlay
- showOverlay: function(t) {
- if ($.browser.msie === false) {
- message = this.config.overlayMessage;
-
- if (this.config.overlayCss != undefined) {
- css = this.config.overlayCss;
- }
- else {
- css = { };
- }
-
- if (t == false) {
- $.blockUI({
- message: message,
- css: css,
- });
- } else {
- $.blockUI({
- message: message,
- css: css,
- timeout: t,
- });
- }
- }
- },
-
- // Change a element in the map
- changeElement: function(type, element, callback) {
- if (this.config[type][element] == undefined || this.config[type][element]['showOn'] == undefined) {
- return;
- }
-
- if (jQuery.inArray(this.config.mapName, this.config[type][element]['showOn']) != -1) {
- this[callback](element);
- }
- },
-
- // Display slider
- sliderUpdate: function(layer, slider) {
- if (this.config['sliders'][slider].overlays == undefined) {
- this.config['sliders'][slider].overlays = [ ];
- }
-
- if (this.config['sliders'][slider].overlays[layer] == undefined) {
- this.addSlider(layer, slider);
- }
-
- this.sliderUpdateOpacity(layer, slider);
- },
-
- // Fix slider opacity
- sliderUpdateOpacity: function(layer, slider) {
- for (var i in this.config['sliders'][slider].overlays) {
- if (i == layer) {
- this.config['sliders'][slider].overlays[i].setOpacity(this.defaultOpacity(slider, 'sliders'));
- }
- else {
- this.config['sliders'][slider].overlays[i].setOpacity(0);
- }
- }
-
- // The second and all subsequent layers shall be intialized without opacity.
- this.sliderOpacity = 0;
- },
-
- // jQuery slider wrapper
- slider: function(element, slider) {
- var self = this;
-
- // Max is the number of layers in the service
- $(element).slider({
- value: 1,
- min: -1,
- max: 11,
- step: 1,
- animate: true,
- change: function(event, ui) {
- self.sliderUpdate.apply(self, [ ui.value, slider ]);
- },
- });
- },
-
- }
-};
diff --git a/gmap_arcgis.module b/gmap_arcgis.module
index dba9aae..1c0a093 100644
--- a/gmap_arcgis.module
+++ b/gmap_arcgis.module
@@ -45,12 +45,13 @@ function gmap_arcgis_gmap($op, &$map) {
* The order to load the following js code is important.
*/
// Add Google js API
- $key = variable_get('gmap_api_key', '');
- $script = '<script type="text/javascript" ';
+ $key = variable_get('gmap_api_key', '');
+ $script = '<script type = "text/javascript" ';
drupal_set_html_head($script . 'src="http://www.google.com/jsapi?key=' . $key . '&sensor=true&language=pt-BR"></script>');
// Add ArcGIS js API
- drupal_set_html_head($script . 'src="'. $base_url .'/sites/all/libraries/google-maps-utility-library-v3/arcgislink/src/arcgislink_compiled.js"></script>');
+ drupal_add_js($base_url .'/sites/all/libraries/google-maps-utility-library-v3/arcgislink/src/arcgislink_compiled.js');
+ drupal_add_js($base_url .'/sites/all/libraries/gmap_arcgis_js/gmap_arcgis.js');
// Setup Map Id
drupal_add_js(array('gmap_arcgis' => array('id' => $map['id'])), 'setting');
@@ -58,12 +59,13 @@ function gmap_arcgis_gmap($op, &$map) {
// Add custom js
$gmap_arcgis_path = drupal_get_path('module', 'gmap_arcgis') . '/';
drupal_add_js($gmap_arcgis_path . 'gmap_arcgis.js');
+
+ // TODO: move somewhere else
//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');
}