var gmaps = { options: { 'boundBoxOffset': 0.03, 'useFilter' : true, 'max_results' : 8000, 'maxLimit' : 30, //Kilometers limit to drag based on the center variable; 'service_prefix': '/', 'service_path' : 'map/(limit)/(caption)/.json' }, map : null, markerClusterer : null, center : null, //Point used to calculate the distance between the center point and the mouse position; lastLatLng : null, markers : [], gmaps_path : '/static/img/common/gmaps/', markerData : null, currentMarker : null, currentCaption : null, currentPlan : null, currentBound : null, odometerTitle : '', total : 0, filters : { 'physician' : { 'icon' : { 'up': 'pin-medicos-up.png', 'down' : 'pin-medicos-down.png' }, 'styles' : [ { url: 'group-medicos-1.gif', width: 36, height: 20, opt_anchor: [-18, -10], opt_textColor: '#ac1632' }, { url: 'group-medicos-2.png', width: 41, height: 20, opt_anchor: [-20, -10], opt_textColor: '#ac1632' }, { url: 'group-medicos-3.png', width: 47, height: 20, opt_anchor: [-23, -10], opt_textColor: '#ac1632' } ] }, 'hospitals' : { 'icon' : { 'up': 'pin-hospital-up.png', 'down' : 'pin-hospital-down.png' }, 'styles' : [ { url: 'group-hospital-1.png', width: 36, height: 20, opt_anchor: [-18, -10], opt_textColor: '#ac1632' }, { url: 'group-hospital-2.png', width: 41, height: 20, opt_anchor: [-20, -10], opt_textColor: '#ac1632' }, { url: 'group-hospital-3.png', width: 47, height: 20, opt_anchor: [-23, -10], opt_textColor: '#ac1632' } ] }, 'er' : { 'icon' : { 'up': 'pin-atendimento-up.png', 'down' : 'pin-atendimento-down.png' }, 'styles' : [ { url: 'group-atendimento-1.png', width: 36, height: 20, opt_anchor: [-18, -10], opt_textColor: '#ac1632' }, { url: 'group-atendimento-2.png', width: 41, height: 20, opt_anchor: [-20, -10], opt_textColor: '#ac1632' }, { url: 'group-atendimento-3.png', width: 47, height: 20, opt_anchor: [-23, -10], opt_textColor: '#ac1632' } ] }, 'labs' : { 'icon' : { 'up': 'pin-lab-up.png', 'down' : 'pin-lab-down.png' }, 'styles' : [ { url: 'group-lab-1.png', width: 36, height: 20, opt_anchor: [-18, -10], opt_textColor: '#ac1632' }, { url: 'group-lab-2.png', width: 41, height: 20, opt_anchor: [-20, -10], opt_textColor: '#ac1632' }, { url: 'group-lab-3.png', width: 47, height: 20, opt_anchor: [-23, -10], opt_textColor: '#ac1632' } ] }, 'odontology' : { 'icon' : { 'up': 'pin-odonto-up.png', 'down' : 'pin-odonto-down.png' }, 'styles' : [ { url: 'group-odonto-1.png', width: 36, height: 20, opt_anchor: [-18, -10], opt_textColor: '#ac1632' }, { url: 'group-odonto-2.png', width: 41, height: 20, opt_anchor: [-20, -10], opt_textColor: '#ac1632' }, { url: 'group-odonto-3.png', width: 47, height: 20, opt_anchor: [-23, -10], opt_textColor: '#ac1632' } ] }, 'circuit' : { 'icon' : { 'up': 'pin-circuito-up.png', 'down' : 'pin-circuito-down.png' }, 'styles' : [ { url: 'group-circuito-1.png', width: 36, height: 20, opt_anchor: [-18, -10], opt_textColor: '#ac1632' }, { url: 'group-circuito-2.png', width: 41, height: 20, opt_anchor: [-20, -10], opt_textColor: '#ac1632' }, { url: 'group-circuito-3.png', width: 47, height: 20, opt_anchor: [-23, -10], opt_textColor: '#ac1632' } ] } }, init : function( options ) { this.renderLandmarkCount(); $('#map-loading').show(); this.options = jQuery.extend(this.options , options); if (!GBrowserIsCompatible()) return; gmaps.map = new GMap2( $(this).get(0) ); gmaps.map.setCenter(new GLatLng(-22.9840, -43.222), 14); gmaps.center = new GLatLng(-22.940000, -43.38000); gmaps.lastLatLng = new GLatLng(0,0); if(this.options.useFilter){ gmaps.map.addControl(new GMapFilters()); } gmaps.map.addControl(new GMapScroll()); gmaps.map.enableContinuousZoom(); gmaps.map.disableDoubleClickZoom(); gmaps.map.disableScrollWheelZoom(); gmaps.map.setMapType(G_SATELLITE_MAP); /* Show Google Earth *** //map.addControl( new GMapTypeControl() ); //map.addMapType(G_SATELLITE_3D_MAP); */ GEvent.addListener(gmaps.map, "move", function(){ gmaps.mapMoveHandler(); } ); GEvent.addListener(gmaps.map, "dragend", function(){ gmaps.mapDragEndHandler(); }); gmaps.createBound(gmaps.map.getBounds()); /** * Add Rounded Corners **/ if( !$.browser.msie ) { $('#gmap-scroll').cornerz({ radius: 6 }); } // $('#gmap-filters').cornerz({ radius: 6, corners: 'tl tr' }); $('#medic-guide').cornerz({ radius: 6, corners: 'bl br' }); $('.map-tooltip').cornerz({ radius : 6, corners : 'tl tr bl', background : '#09181D' }); $('.map-tooltip').appendTo(gmaps.map.getPane(G_MAP_FLOAT_SHADOW_PANE)); /** * Set path to group icons. */ for(var c in gmaps.filters){ for(var k = 0; k < gmaps.filters[c].styles.length; k++){ gmaps.filters[c].styles[k].url = this.gmaps_path + gmaps.filters[c].styles[k].url; } } $('#medic-guide > a').attr('href', '/sou-cliente/guia-medico/'); $('#medic-guide', '.holder-map #gmap-foot').mouseenter(function() { $(this).stop().animate( { backgroundColor:'#33796b' },300); }).mouseleave(function() { $(this).stop().animate( { backgroundColor:'#005746' },300); }).click(function() { //window.location.href = $('> a', $(this)).attr('href'); window.location.href = "/guia-medico"; return false; }); return this; }, mapMoveHandler : function() { var centerMap = gmaps.map.getCenter(); var miledistance = gmaps.center.distanceFrom(new GLatLng(centerMap.lat(), centerMap.lng()), 3959).toFixed(1); var kmdistance = (miledistance * 1.609344).toFixed(1); if (kmdistance < gmaps.options.maxLimit) { gmaps.lastLatLng = new GLatLng(centerMap.lat(), centerMap.lng()); } else {flashMovie.setOdometerNumber(value, gmaps.odometerTitle); gmaps.map.setCenter(gmaps.lastLatLng); } $('.map-tooltip').hide(); }, mapDragEndHandler : function() { if((gmaps.map.getBounds().getSouthWest().lat() > gmaps.currentBound.getSouthWest().lat() && gmaps.map.getBounds().getNorthEast().lat() < gmaps.currentBound.getNorthEast().lat()) && (gmaps.map.getBounds().getSouthWest().lng() > gmaps.currentBound.getSouthWest().lng() && gmaps.map.getBounds().getNorthEast().lng() < gmaps.currentBound.getNorthEast().lng())) return; $('#map-loading').show(); gmaps.createBound(gmaps.map.getBounds()); setTimeout(function(){ gmaps.callService(); }, 500); }, getIcon : function() { var icon = new GIcon(); icon.image = gmaps.gmaps_path + gmaps.filters[gmaps.currentCaption].icon.up; icon.iconSize = new GSize(20, 26); icon.iconAnchor = new GPoint(20,26); return icon; }, loadMarkersData : function(obj){ if(gmaps.currentCaption == obj.caption) return; gmaps.odometerTitle = obj.odometerTitle; gmaps.currentCaption = obj.caption; gmaps.currentPlan = obj.plan; if(this.options.useFilter){ this.options.service_path = 'map/' + this.options.max_results + '/'+ obj.caption + '.json'; } $('#map-loading').show(); setTimeout(function(){ gmaps.callService(); }, 500); }, renderLandmarkCount : function () { var t = helpers.getTimestamp(); swfobject.embedSWF( "/static/swf/home_landmarkcount.swf?timestamp=" + t, "landmark-count", "245", "110", "10.1.53.64", "/static/swf/playerProductInstall.swf", "", { wmode : "transparent" }, null, helpers.checkSWFHasEmbedded ); }, getFlashMovieObject : function(movie) { if (window.document[movie]){ return window.document[movie]; } if (navigator.appName.indexOf("Microsoft Internet")==-1){ if (document.embeds && document.embeds[movie]) return document.embeds[movie]; } else // if (navigator.appName.indexOf("Microsoft Internet")!=-1) { return document.getElementById(movie); } }, sendDataToFlash : function(value) { value = (value) ? value : gmaps.total; var flashMovie = gmaps.getFlashMovieObject("landmark-count"); //set value from a constant var in base template: TOTAL_MEDICALS //if(gmaps.currentCaption == 'physician'){ // value = TOTAL_MEDICALS.replace('.', ''); //} var odometerNum = value; if(flashMovie.setOdometerNumber){ flashMovie.setOdometerNumber(odometerNum, gmaps.odometerTitle); } }, callService : function(obj) { var self = this; //Hide tooltip $('.map-tooltip').hide(); /* * Get the service JSON URI */ var url = self.options.service_prefix + self.options.service_path; url = url.replace(/\(limit\)/, self.options.max_results); url = url.replace(/\(caption\)/, gmaps.currentCaption); var coords = gmaps.currentBound.toString(); //console.log(gmaps.currentBound); url = encodeURI(url); $.ajax({ url: url, // data: JSON.stringify( { 'bb': { 'x': gmaps.currentBound.getSouthWest().lat(), 'y': gmaps.currentBound.getSouthWest().lng(), // 'u': gmaps.currentBound.getNorthEast().lat(), 'v': gmaps.currentBound.getNorthEast().lng() }, // 'max_results': this.options.max_results, // 'plan': gmaps.currentPlan } ), type: 'GET', dataType: 'json', contentType: 'application/json', async: false, complete: function(){ $('#map-loading').hide(); }, success: function(data) { //Clear current Markers gmaps.markers = []; gmaps.clearMarkers(); gmaps.total = data.total; // setTimeout(function(){ // gmaps.sendDataToFlash(data.total); // }, 500); gmaps.sendDataToFlash(data.total); gmaps.markerData = data[gmaps.currentCaption]; var i; var t = gmaps.markerData.length; for(i = 0; i < t; i++) { gmaps.addMarker(gmaps.markerData[i]); } gmaps.markerClusterer = new MarkerClusterer(gmaps.map, gmaps.markers, { maxZoom: 17, gridSize: 40, styles: gmaps.filters[gmaps.currentCaption].styles }); }, error: function(){ //alert("Erro de conexão, recarregue a página, pois houve um problema de conexão."); $('#map-loading').hide(); } }); }, addMarker : function(markerData) { var marker = new GMarker(new GLatLng(markerData.geo.lat, markerData.geo.lng), {icon:gmaps.getIcon()}); var data = { name : markerData.name, speciality : markerData.speciality, address : markerData.address, neighbourhood : markerData.neighbourhood, fone : markerData.fone }; marker['data'] = data; GEvent.addListener(marker, 'click', function(marker, i){ gmaps.currentMarker = this; var toolTip = $('.map-tooltip'); var markerOffset = gmaps.map.fromLatLngToDivPixel(gmaps.currentMarker.getLatLng()); toolTip.find('h3').html( this.data.name); toolTip.find('h4').html(this.data.speciality); toolTip.find('p').html( this.data.address + '
' + this.data.neighbourhood + '
' + this.data.fone); toolTip.fadeIn() .css({ top:markerOffset.y - gmaps.getIcon().iconSize.height, left:markerOffset.x}); var moveEnd = GEvent.addListener(gmaps.map, "moveend", function(){ toolTip.fadeIn() .css({ top:markerOffset.y - gmaps.getIcon().iconSize.height, left:markerOffset.x}); GEvent.removeListener(moveEnd); }); gmaps.map.panTo(marker); }); GEvent.addListener(marker, 'mouseover', function(marker, i) { this.setImage(gmaps.gmaps_path + gmaps.filters[gmaps.currentCaption].icon.down); }); GEvent.addListener(marker, 'mouseout', function(marker, i) { this.setImage(gmaps.gmaps_path + gmaps.filters[gmaps.currentCaption].icon.up); }); gmaps.markers.push(marker); }, clearMarkers : function() { if (gmaps.markerClusterer != null) gmaps.markerClusterer.clearMarkers(); return true; }, createBound : function(bound) { var sw = new GLatLng(bound.getSouthWest().lat() - gmaps.options.boundBoxOffset, bound.getSouthWest().lng() - gmaps.options.boundBoxOffset); var ne = new GLatLng(bound.getNorthEast().lat() + gmaps.options.boundBoxOffset, bound.getNorthEast().lng() + gmaps.options.boundBoxOffset); gmaps.currentBound = new GLatLngBounds(sw, ne); } } /***************************************************************************** * Map Slider component can changes the zoom of map and listen zoom map events. * * @version 0.1 * @author Jan Cassio | janio@gringo.nu */ /** * Prototype initialization */ GMapScroll = function () {}; GMapScroll.prototype = new GControl(); /** ui place holder */ GMapScroll.prototype.container = null; /** slider div holder */ GMapScroll.prototype.slider = null; /** zoom increase button */ GMapScroll.prototype.upBtn = null; /** zoom decrease button */ GMapScroll.prototype.downBtn = null; /** * GMaps executes this automatically on object is instantiated * @param {Object} map */ GMapScroll.prototype.initialize = function (map) { this.container = $("#gmap-scroll"); this.upBtn = $("#gmap-zoom-in"); this.downBtn = $("#gmap-zoom-out"); this.slider = $("#gmap-slider"); this.slider.slider({ orientation : "vertical", min : 13, max : 17, value : map.getZoom(), range : "false", slide : function(event, ui) { map.setZoom( ui.value ); } }); this.downBtn.click( function(){ if( map.getZoom() > 13 ) map.zoomOut(); } ); this.upBtn.click( function(){ if( map.getZoom() < 17 ) map.zoomIn(); } ); GEvent.bind(map, "zoomend", this, function(old, current){ this.slider.slider("value", current); }); this.container.appendTo( map.getContainer() ); return this.container.get(0); }; /** * Called for maps to checks ui position. */ GMapScroll.prototype.getDefaultPosition = function() { return new GControlPosition(G_ANCHOR_TOP_LEFT, new GSize(5, 5)); } GMapFilters = function () {}; GMapFilters.prototype = new GControl(); /** ui place holder */ GMapFilters.prototype.container = null; GMapFilters.prototype.initialize = function (map) { this.container = $("#gmap-filters"); this.container.appendTo( map.getContainer() ); return this.container.get(0); } GMapFilters.prototype.getDefaultPosition = function () { return new GControlPosition(G_ANCHOR_TOP_LEFT, new GSize(0, 274)); }