// $Id$ function gmapArcgis(config) { return { config: config, map: config.map, slider: [], // Set the current map setMap: function(map) { this.map = map; }, // Add polygons from a given ArcGIS MapServer Layer showPolygon: function(element) { var defaultOpacity = (this.config['layers'][element].opacity != undefined) ? this.config['layers'][element].opacity : 0.55; if (typeof this.config['layers'][element].overlay != 'undefined') { this.config['layers'][element].overlay.setOpacity(defaultOpacity); this.unblockUI(); return; } uri = this.config['layers'][element]['uri']; layers = this.config['layers'][element]['layers']; this.config['layers'][element].overlay = new gmaps.ags.MapOverlay(uri, { exportOptions: { layerIds: layers, layerOption: 'show', } }); this.config['layers'][element].overlay.setMap(this.map); this.config['layers'][element].overlay.setOpacity(defaultOpacity); if (this.config['layers'][element].callback == undefined) { // Default callback: remove the blockUI once the layer is shown google.maps.event.addListener(this.config['layers'][element].overlay.getMapService(), 'update', function() { this.unblockUI(); }); } else { google.maps.event.addListener(this.config['layers'][element].overlay.getMapService(), 'update', function() { this.config['layers'][element].callback(this.map, this.config['layers'][element]) ; this.unblockUI(); }); } }, // Add a KML to the 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(element) { if (typeof this.config['kmls'][element].overlay != 'undefined') { this.config['kmls'][element].overlay.setOpacity(this.config['kmls'][element].opacity); unblockUI(); return this.config['kmls'][element].overlay; } 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) { 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 (this.config['layers'][element].overlayTime != undefined) { this.showOverlay(this.config['layers'][element].overlayTime); } // TODO: support for clickable polygons this.showPolygon(element); return this.config['layers'][element].overlay; }, // 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, // TODO //queryGeometry: 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; for (var i = 0, c = fs.length; i < c; i++) { fset = fs[i]; self.config['markers'][element].overlay[i] = {}; self.config['markers'][element].overlay[i].marker = new google.maps.Marker({ title: (self.config['markers'][element].title != undefined) ? fset.attributes[self.config['markers'][element].title] : fset.attributes.nome, 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(); } }, // UI unblocker wrapper unblockUI: function() { jQuery.unblockUI(); }, // UI blocker wrapper blockUI: function() { jQuery.blockUI(); }, // Toggle KML visibility toggleKML: function(params) { // TODO return; }, // 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 (t == false) { $.blockUI({ message: message }); } else { $.blockUI({ message: message, 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) { this.sliderOpacity = 0.45; if (this.slider[layer] == undefined) { this.config['layers']['slider'].layers = [layer]; this.config['layers']['slider'].opacity = this.sliderOpacity; this.config['layers']['slider'].callback = this.sliderUpdateOpacity; this.slider[layer] = this.addLayers('slider'); } else { this.sliderUpdateOpacity(layer); } }, // Fix slider opacity sliderUpdateOpacity: function(layer) { for (var i in this.slider) { if (i == layer) { this.slider[i].setOpacity(0.45); } else { this.slider[i].setOpacity(0); } } // The second and all subsequent layers shall be intialized without opacity. this.sliderOpacity = 0; }, // Setup slider activateSlider: function() { var self = this; // Max is the number of layers in the service $("#slider").slider({ value: 1, min: -1, max: 11, step: 1, animate: true, //change: sliderUpdate, change: function(event, ui) { self.sliderUpdate.call(self, ui.value); }, }); }, } };