// $Id$ function gmapArcgis(config) { return { config: config, map: config.map, deforestation: [], // 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(params.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); }, // Add makers to the map addMarkers: function(elements) { var bounds = this.map.getBounds(); if (this.config['markers'][element].overlay != undefined) { this.toggleMarkers(this.config['markers'][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]; 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 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() { infowindow.setContent(content(attributes)); infowindow.open(map, marker); }); }; // Execute this.config['markers'][element].overlay[i].addListener(); } this.unblockUI(); } }, // UI unblocker wrapper unblockUI: function() { jQuery.unblockUI(); }, // UI blocker wrapper blockUI: function() { jQuery.blockUI(); }, toggleKML: function(params) { // TODO return; }, toggleLayers: function(element) { this.config['layers'][element].overlay.setOpacity(0); }, // Toggle marker visibility 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()) { markers[i].marker.setVisible(false); } else { markers[i].marker.setVisible(true); } } }, 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 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; } }, setMap: function(map) { this.map = map; }, } };