From 95864022378bdb4f9029c14aa87ae4f3894e3839 Mon Sep 17 00:00:00 2001 From: Silvio Date: Tue, 12 Mar 2013 10:53:36 -0300 Subject: Cleanup and fixes after refactoring --- gmap_arcgis.js | 145 +++++++++++++++++++++++++-------------------------------- 1 file changed, 63 insertions(+), 82 deletions(-) diff --git a/gmap_arcgis.js b/gmap_arcgis.js index 454071a..78a664e 100644 --- a/gmap_arcgis.js +++ b/gmap_arcgis.js @@ -8,115 +8,92 @@ function gmapArcgis(config) { deforestation: [], - getConfig: function() { - return config; - }, - - // 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; + showPolygon: function(element) { + var defaultOpacity = (this.config['layers'][element].opacity != undefined) ? this.config['layers'][element].opacity : 0.55; - if (typeof params.overlay != 'undefined') { - params.overlay.setOpacity(defaultOpacity); + if (typeof this.config['layers'][element].overlay != 'undefined') { + this.config['layers'][element].overlay.setOpacity(defaultOpacity); this.unblockUI(); return; } - uri = params['uri']; - layers = params['layers']; + uri = this.config['layers'][element]['uri']; + layers = this.config['layers'][element]['layers']; - params.overlay = new gmaps.ags.MapOverlay(uri, { + this.config['layers'][element].overlay = new gmaps.ags.MapOverlay(uri, { exportOptions: { layerIds: layers, layerOption: 'show', } }); - params.overlay.setMap(map); - params.overlay.setOpacity(defaultOpacity); + this.config['layers'][element].overlay.setMap(this.map); + this.config['layers'][element].overlay.setOpacity(defaultOpacity); - if (params.callback == undefined) { + if (this.config['layers'][element].callback == undefined) { // Default callback: remove the blockUI once the layer is shown - google.maps.event.addListener(params.overlay.getMapService(), 'update', function() { - unblockUI(); + google.maps.event.addListener(this.config['layers'][element].overlay.getMapService(), 'update', function() { + this.unblockUI(); }); } else { google.maps.event.addListener(params.overlay.getMapService(), 'update', function() { - params.callback(map, params) ; unblockUI(); + this.config['layers'][element].callback(this.map, this.config['layers'][element]) ; this.unblockUI(); }); } }, // Add a KML to the map - showKML: function(params) { - params.overlay = new google.maps.KmlLayer(params.uri); - params.overlay.setMap(map); + showKML: function(element) { + this.config['kmls'][element].overlay = new google.maps.KmlLayer(this.config['kmls'][element].uri); + this.config['kmls'][element].overlay.setMap(this.map); }, // Add a KML layer into the map - addKML: function(params) { - if (typeof params.overlay != 'undefined') { - params.overlay.setOpacity(params.opacity); + addKML: function(element) { + if (typeof this.config['kmls'][element].overlay != 'undefined') { + this.config['kmls'][element].overlay.setOpacity(this.config['kmls'][element].opacity); unblockUI(); - return params.overlay; + return this.config['kmls'][element].overlay; } - if (params.overlayTime != undefined) { - this.showOverlay(params.overlayTime); + if (this.config['kmls'][element].overlayTime != undefined) { + this.showOverlay(this.config['kmls'][element].overlayTime); } - this.showKML(params); - - return params.overlay; + this.showKML(element); }, // Add a layer to the map - addLayers: function(params) { - if (typeof params.overlay != 'undefined') { - params.overlay.setOpacity(params.opacity); - unblockUI(); - return params.overlay; + addLayers: function(element) { + if (typeof this.config['layers'][element].overlay != 'undefined') { + this.config['layers'][element].overlay.setOpacity(this.config['layers'][element].opacity); + this.unblockUI(); + return this.config['layers'][element].overlay; } - if (params.overlayTime != undefined) { - this.showOverlay(params.overlayTime); + if (this.config['layers'][element].overlayTime != undefined) { + this.showOverlay(this.config['layers'][element].overlayTime); } // TODO: support for clickable polygons - this.showPolygon(params); - - return params.overlay; + this.showPolygon(element); }, // Add makers to the map - addMarkers: function(params) { - var bounds = map.getBounds(); + addMarkers: function(elements) { + var bounds = this.map.getBounds(); - if (params.overlay != undefined) { - this.toggleMarkers(params); + if (this.config['markers'][element].overlay != undefined) { + this.toggleMarkers(this.config['markers'][element]); return; } else { - params.overlay = []; + this.config['markers'][element].overlay = []; } - if (params.overlayTime != undefined) { - this.showOverlay(params.overlayTime); + if (this.config['markers'][element].overlayTime != undefined) { + this.showOverlay(this.config['markers'][element].overlayTime); } // Query parameters @@ -124,17 +101,17 @@ function gmapArcgis(config) { returnGeometry: true, // TODO //queryGeometry: bounds, - where: (params.where != undefined) ? params.where : '1=1', - outFields: params.fields, + 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(params.uri); + var layer = new gmaps.ags.Layer(this.config['markers'][element].uri); // Execute query layer.query(query, processResultSet); // Configure infoWindow - params.infowindow = new google.maps.InfoWindow({ + this.config['markers'][element].infowindow = new google.maps.InfoWindow({ content: '', }); @@ -144,19 +121,19 @@ function gmapArcgis(config) { 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, + this.config['markers'][element].overlay[i] = {}; + this.config['markers'][element].overlay[i].marker = new google.maps.Marker({ + title: (this.config['markers'][element].title != undefined) ? fset.attributes[this.config['markers'][element].title] : fset.attributes.nome, + icon: this.config['markers'][element].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; + this.config['markers'][element].overlay[i].addListener = function() { + var marker = this.config['markers'][element].overlay[i].marker; + var infowindow = this.config['markers'][element].infowindow; + var content = this.config['markers'][element].content; var attributes = fset.attributes; google.maps.event.addListener(marker, 'click', function() { @@ -166,7 +143,7 @@ function gmapArcgis(config) { }; // Execute - params.overlay[i].addListener(); + this.config['markers'][element].overlay[i].addListener(); } this.unblockUI(); @@ -188,13 +165,13 @@ function gmapArcgis(config) { return; }, - toggleLayers: function(params) { - params.overlay.setOpacity(0); + toggleLayers: function(element) { + this.config['layers'][element].overlay.setOpacity(0); }, // Toggle marker visibility - toggleMarkers: function(params, raw) { - markers = (raw == true) ? params : params.overlay; + toggleMarkers: function(element, raw) { + markers = (raw == true) ? element : this.config['markers'][element].overlay; for (i=0; i < markers.length; i++) { if (markers[i].marker.getVisible()) { @@ -222,13 +199,13 @@ function gmapArcgis(config) { }, // Change a element in the map - changeElement: function(map, params, page, callback) { - if (config[params] == undefined || config[params]['showOn'] == undefined) { + changeElement: function(type, element, callback) { + if (this.config[type][element] == undefined || this.config[type][element]['showOn'] == undefined) { return; } - if (jQuery.inArray(page, config[params]['showOn']) != -1) { - this[callback](map, config[params]); + if (jQuery.inArray(this.config.mapName, this.config[type][element]['showOn']) != -1) { + this[callback](element); } }, @@ -265,5 +242,9 @@ function gmapArcgis(config) { }, + setMap: function(map) { + this.map = map; + }, + } }; -- cgit v1.2.3