jQuery.noConflict();
jQuery(document).ready(function() {
var counter = 0;
var service = new google.maps.DirectionsService();
var lojasLatLng = new Array();
var texto = new Array();
var geocoder;
var markers = [];
var iterator = 0;
var map;
var ib;
var ibs = [];
var infoWindows = Array();
var MYMAP = { bounds: null, map: null,
geox: null };
//console.log(google.maps.version);
/*
var interval = setInterval(do_request, 1000);
function do_request() {
service.route({
origin: new google.maps.LatLng(48 + Math.random(), 9 + Math.random()),
destination: new google.maps.LatLng(48 + Math.random(), 9 + Math.random()),
travelMode: google.maps.DirectionsTravelMode.DRIVING
}, show_result);
}
function show_result() {
console.log(arguments, ++counter);
}
*/
jQuery.ajax({
type : "post",
dataType : "json",
url : mysandwichAjax.ajaxurl,
data : {action: "mysandwich_script", acao: 'buscarlojas'},
success: function(response) {
if(response.type == "success") {
//alert(response.lojas[0].ds_nome);
//console.log(response.lojas[0]);
jQuery.each(response.lojas, function(key, value) {
var info = "<div class='info-window-content'><h1>MySandwich</h1>" +
"<h2>"+value.ds_nome+"</h2> " +
"<h3>"+value.ds_complemento+"<br /><br />" +
value.ds_endereco+', '+value.ds_numero+' - '+value.ds_bairro+"<br />" +
value.ds_cidade+' - '+value.ds_estado+' - CEP '+value.cep+"</h3>"+
"</div><div class='arrow-win'></div> ";
texto.push(info);
geocoder = new google.maps.Geocoder();
var endereco = value.ds_endereco;
var numero = value.ds_numero;
var cidade = ", "+value.ds_cidade;
var estado = " - "+value.ds_estado;
//Av. Paulista, 155, Americana - São Paulo
//como endereço, cidade e estado são obrigatórios
//valido apenas o número
if(numero && numero != ""){
numero = ", " + numero;
}
var address = endereco + numero + cidade + estado;
//console.log(address);
//var address = value.ds_endereco+', '+value.ds_numero+', '+value.ds_bairro+', '+value.ds_cidade+','+value.ds_estado;
geocoder.geocode( { 'address': address}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
map.setCenter(results[0].geometry.location);
lojasLatLng.push(results[0].geometry.location);
addMarker(results);
}else{
alert("Não foi possível encontrar um endereço. erro : " + status);
}
});
});
}
else {
alert("Erro");
}
}
});
//-----------------------------------------------------------------------
var myLatLng = new google.maps.LatLng(-23.57030,-46.64368);
var image = 'http://localhost/criateria/clientes/tiptop/ver.2.0_WP/wp-content/themes/design-notes/images/img-balao-mapa.png';
MYMAP.init = function(selector, latLng, zoom){
var myOptions = {
zoom:zoom,
center: latLng,
mapTypeId: google.maps.MapTypeId.ROADMAP,
disableAutoPan: false,
maxWidth: 0,
pixelOffset: new google.maps.Size(-120, -130),
zIndex: null,
isHidden: false,
pane: "floatPane",
enableEventPropagation: false
};
map = new google.maps.Map(jQuery(selector)[0], myOptions);
this.bounds = new google.maps.LatLngBounds();
};
//alert('(' + valorEndereco + ')');
//alert(valorLoja);
//alert(lojasLatLng);
if ( jQuery("#map_canvas").length ) {
MYMAP.init('#map_canvas', myLatLng, 5);
}else{
MYMAP.init('#map_canvas_face', myLatLng, 5);
}
/*
function dropele() {
for (var i = 0; i < lojasLatLng.length; i++) {
setTimeout(function() {
addMarker();
}, 2000);
}
}
*/
function addMarker(results) {
var boxText = document.createElement("div");
boxText.style.cssText = "border: 0px solid white; margin-top: 8px; padding: 0px;";
boxText.innerHTML = texto[iterator];
var myOptions = {
center: results[0].geometry.location,
mapTypeId: google.maps.MapTypeId.ROADMAP,
content: boxText,
disableAutoPan: false,
maxWidth: 0,
pixelOffset: new google.maps.Size(-120, -130),
zIndex: null,
boxStyle: {
opacity: 1.0
},
closeBoxMargin: "9px 2px 2px 2px",
closeBoxURL: "http://www.google.com/intl/en_us/mapfiles/close.gif",
infoBoxClearance: new google.maps.Size(1, 1),
isHidden: false,
pane: "floatPane",
enableEventPropagation: false
};
var infoWindow = new InfoBox(myOptions);
markers.push(new google.maps.Marker({
position: results[0].geometry.location,
map: map,
title: "MySandwich ",
draggable: false,
animation: google.maps.Animation.DROP,
infoWindowIndex : iterator,
icon: image
}));
google.maps.event.addListener(markers[iterator], 'click', function(event) {
map.panTo(event.latLng);
map.setZoom(16);
map.setCenter(this.position);
infoWindows[this.infoWindowIndex].open(map, this);
});
infoWindows.push(infoWindow);
iterator++;
}
//dropele();
//console.log(dropele);
//=================
jQuery("#uf").change(function(){
// obtendo o valor do atributo value da tag option
var valorUf = jQuery("#uf option:selected").val();
// exibindo uma janela com o valor selecionado
if(valorUf != ''){
jQuery.ajax({
type : "post",
dataType : "json",
url : mysandwichAjax.ajaxurl,
data : {action: "mysandwich_script", acao: 'buscarcidade', uf: valorUf},
success: function(response) {
if(response.type == "success") {
var options = "<option value=''>...</option>";
jQuery.each(response, function(key, value){
if(value != 'success' ){
options += '<option value="' + value + '">' + value + '</option>';
}
});
jQuery("#cidade").html(options);
}
else {
alert("Erro");
}
}
});
}else{
alert('Selecione uma Estado');
}
return false;
});
jQuery("#cidade").change(function(){
// obtendo o valor do atributo value da tag option
var valorCidade = jQuery("#cidade option:selected").val();
var valorUf = jQuery("#uf option:selected").val();
// exibindo uma janela com o valor selecionado
//alert(valorUf+' ------> '+valorCidade);
if(valorCidade != ''){
jQuery.ajax({
type : "post",
dataType : "json",
url : mysandwichAjax.ajaxurl,
data : {action: "mysandwich_script", acao: 'buscarcomboloja', cidade: valorCidade, uf:valorUf},
success: function(response) {
if(response.type == "success") {
//alert('---->'+response.lojas);
var options = "<option value=''>...</option>";
jQuery.each(response.lojas, function(key, value){
//options += '<option value="' + value.lat + ', ' + value.lng + '">' + value.ds_nome + '</option>';
options += '<option value="' + value.id + '">' + value.ds_nome + '</option>';
});
jQuery("#loja").html(options);
}
else {
alert("Erro");
}
}
});
}else{
alert('Selecione uma Estado');
}
return false;
});
jQuery("#loja").change(function(){
// obtendo o valor do atributo value da tag option
var valorEndereco = jQuery("#loja option:selected").val();
var vlr = jQuery("#loja option:selected").val();
var valorLoja = jQuery("#loja option:selected").val();
//alert('(' + valorEndereco + ')');
//alert(valorLoja);
//alert(lojasLatLng);
map.setCenter(this.position);
map.setZoom(16);
map.panTo(lojasLatLng[valorLoja]);
//map.panTo(lojasLatLng[vlr]);
return false;
});
});