hook24
07-12-2011, 09:11 AM
Hi, I have a function which work correctly, except when i use in on popup.
when is called from the main poage work correctly, but if no doesn´t.
It supposed to draw the google map in the div of the popup when is clicked an image, I don´t know why, cause if is from the main page and i click a button it works :mad:
I don´t know if for reference to the div of the popup i need something different or what.
Any helps, thanks
$(document).ready(function() {
var popup;
$('#imagegoogle').click(function() {
popup = window.open('', 'ventana1', 'scrollbar=no,resizable=no,width=800,height=800,statusbar=no');
setTimeout(dibujar, 6000);
});
///2971810DG8427B0006YP
$('#BuscarCoordenadas').click(function() {
$("#divCoordenadas").load("ajax_google.php",{'RefCatastralGoogle': $("#RefCatastralGoogle").val()}).fadeIn('slow');
setTimeout(dibujar, 6000);
});
function dibujar(){
var latlng = new google.maps.LatLng(41.9749, 2.7928);
var geocoder = new google.maps.Geocoder();
// Obtenemos la dirección y la asignamos a una variable
var address = $('#nom_carrer').val()+" "+$('#num_carrer').val()+",Salt,17190";
alert(address);
// Creamos el Objeto Geocoder
var geocoder = new google.maps.Geocoder();
// Hacemos la petición indicando la dirección e invocamos la función
// geocodeResult enviando todo el resultado obtenido
geocoder.geocode({ 'address': address}, geocodeResult);
}
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
var MERCATOR_RANGE = 256;
function bound(value, opt_min, opt_max) {
if (opt_min != null) value = Math.max(value, opt_min);
if (opt_max != null) value = Math.min(value, opt_max);
return value;
}
function degreesToRadians(deg) {
return deg * (Math.PI / 180);
}
function radiansToDegrees(rad) {
return rad / (Math.PI / 180);
}
function MercatorProjection() {
this.pixelOrigin_ = new google.maps.Point(
MERCATOR_RANGE / 2, MERCATOR_RANGE / 2);
this.pixelsPerLonDegree_ = MERCATOR_RANGE / 360;
this.pixelsPerLonRadian_ = MERCATOR_RANGE / (2 * Math.PI);
};
MercatorProjection.prototype.fromLatLngToPoint = function(latLng, opt_point) {
var me = this;
var point = opt_point || new google.maps.Point(0, 0);
var origin = me.pixelOrigin_;
point.x = origin.x + latLng.lng() * me.pixelsPerLonDegree_;
// NOTE(appleton): Truncating to 0.9999 effectively limits latitude to
// 89.189. This is about a third of a tile past the edge of the world tile.
var siny = bound(Math.sin(degreesToRadians(latLng.lat())), -0.9999, 0.9999);
point.y = origin.y + 0.5 * Math.log((1 + siny) / (1 - siny)) * -me.pixelsPerLonRadian_;
return point;
};
MercatorProjection.prototype.fromDivPixelToLatLng = function(pixel, zoom) {
var me = this;
var origin = me.pixelOrigin_;
var scale = Math.pow(2, zoom);
var lng = (pixel.x / scale - origin.x) / me.pixelsPerLonDegree_;
var latRadians = (pixel.y / scale - origin.y) / -me.pixelsPerLonRadian_;
var lat = radiansToDegrees(2 * Math.atan(Math.exp(latRadians)) - Math.PI / 2);
return new google.maps.LatLng(lat, lng);
};
MercatorProjection.prototype.fromDivPixelToSphericalMercator = function(pixel, zoom) {
var me = this;
var coord = me.fromDivPixelToLatLng(pixel, zoom);
var r= 6378137.0;
var x = r* degreesToRadians(coord.lng());
var latRad = degreesToRadians(coord.lat());
var y = (r/2) * Math.log((1+Math.sin(latRad))/ (1-Math.sin(latRad)));
return new google.maps.Point(x,y);
};
function loadWMS() {
var tileHeight = 256;
var tileWidth = 256;
var opacityLevel = 0.75;
var isPng = true;
var minZoomLevel = 2;
var maxZoomLevel = 28;
var baseURL = "http://ovc.catastro.meh.es/Cartografia/WMS/ServidorWMS.aspx?";
var wmsParams = [
"REQUEST=GetMap",
"SERVICE=WMS",
"VERSION=1.1.1",
"TRANSPARENT=TRUE",
"SRS=EPSG:3785", // 3395?
"WIDTH="+ tileWidth,
"HEIGHT="+ tileHeight
];
var parcelParams = wmsParams.concat([
"FORMAT=image/png",
"LAYERS=catastro",
"REFCAT="+$("#RefCatastralGoogle").val()
]);
var overlayOptions =
{
getTileUrl: function(coord, zoom)
{
var lULP = new google.maps.Point(coord.x*256,(coord.y+1)*256);
var lLRP = new google.maps.Point((coord.x+1)*256,coord.y*256);
var projectionMap = new MercatorProjection();
var lULg = projectionMap.fromDivPixelToSphericalMercator(lULP, zoom);
var lLRg = projectionMap.fromDivPixelToSphericalMercator(lLRP, zoom);
var lUL_Latitude = lULg.y;
var lUL_Longitude = lULg.x;
var lLR_Latitude = lLRg.y;
var lLR_Longitude = lLRg.x;
var urlResult = baseURL + parcelParams.join("&") + "&bbox=" + lUL_Longitude + "," + lUL_Latitude + "," + lLR_Longitude + "," + lLR_Latitude;
// window.status = urlResult;
return urlResult;
},
tileSize: new google.maps.Size(tileHeight, tileWidth),
minZoom: minZoomLevel,
maxZoom: maxZoomLevel,
opacity: opacityLevel,
isPng: isPng
};
overlayWMS = new google.maps.ImageMapType(overlayOptions);
map.overlayMapTypes.insertAt(0, overlayWMS);
map.setOptions({
mapTypeControlOptions: {
mapTypeIds: [
'wms',
google.maps.MapTypeId.ROADMAP,
google.maps.MapTypeId.TERRAIN,
google.maps.MapTypeId.SATELLITE,
google.maps.MapTypeId.HYBRID
],
style: google.maps.MapTypeControlStyle.DROPDOWN_MENU
}
});
}
function geocodeResult(results, status) {
// Verificamos el estatus
if (status == 'OK') {
// Si hay resultados encontrados, centramos y repintamos el mapa
// esto para eliminar cualquier pin antes puesto
var myOptions = {
zoom: 18,
center: results[0].geometry.location,
mapTypeId: google.maps.MapTypeId.ROADMAP,
mapTypeControl: true,
mapTypeControlOptions: {style: google.maps.MapTypeControlStyle.DROPDOWN_MENU},
navigationControlOptions: {style: google.maps.NavigationControlStyle.ZOOM_PAN}
};
map = new google.maps.Map(document.getElementById("map"), myOptions);
lastWidth = document.documentElement.clientWidth;
lastHeight = document.documentElement.clientHeight;
document.getElementById('map').style.height = '500 px';
document.getElementById('map').style.width = '500 px';
// fitBounds acercará el mapa con el zoom adecuado de acuerdo a lo buscado
map.fitBounds(results[0].geometry.viewport);
loadWMS();
var marker = new google.maps.Marker({
map:map,
draggable:true,
animation: google.maps.Animation.DROP,
position: results[0].geometry.location
});
marker.setAnimation(google.maps.Animation.BOUNCE);
} else {
// En caso de no haber resultados o que haya ocurrido un error
// lanzamos un mensaje con el error
alert("Geocoding no tuvo éxito debido a: " + status);
}
}
});
when is called from the main poage work correctly, but if no doesn´t.
It supposed to draw the google map in the div of the popup when is clicked an image, I don´t know why, cause if is from the main page and i click a button it works :mad:
I don´t know if for reference to the div of the popup i need something different or what.
Any helps, thanks
$(document).ready(function() {
var popup;
$('#imagegoogle').click(function() {
popup = window.open('', 'ventana1', 'scrollbar=no,resizable=no,width=800,height=800,statusbar=no');
setTimeout(dibujar, 6000);
});
///2971810DG8427B0006YP
$('#BuscarCoordenadas').click(function() {
$("#divCoordenadas").load("ajax_google.php",{'RefCatastralGoogle': $("#RefCatastralGoogle").val()}).fadeIn('slow');
setTimeout(dibujar, 6000);
});
function dibujar(){
var latlng = new google.maps.LatLng(41.9749, 2.7928);
var geocoder = new google.maps.Geocoder();
// Obtenemos la dirección y la asignamos a una variable
var address = $('#nom_carrer').val()+" "+$('#num_carrer').val()+",Salt,17190";
alert(address);
// Creamos el Objeto Geocoder
var geocoder = new google.maps.Geocoder();
// Hacemos la petición indicando la dirección e invocamos la función
// geocodeResult enviando todo el resultado obtenido
geocoder.geocode({ 'address': address}, geocodeResult);
}
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
var MERCATOR_RANGE = 256;
function bound(value, opt_min, opt_max) {
if (opt_min != null) value = Math.max(value, opt_min);
if (opt_max != null) value = Math.min(value, opt_max);
return value;
}
function degreesToRadians(deg) {
return deg * (Math.PI / 180);
}
function radiansToDegrees(rad) {
return rad / (Math.PI / 180);
}
function MercatorProjection() {
this.pixelOrigin_ = new google.maps.Point(
MERCATOR_RANGE / 2, MERCATOR_RANGE / 2);
this.pixelsPerLonDegree_ = MERCATOR_RANGE / 360;
this.pixelsPerLonRadian_ = MERCATOR_RANGE / (2 * Math.PI);
};
MercatorProjection.prototype.fromLatLngToPoint = function(latLng, opt_point) {
var me = this;
var point = opt_point || new google.maps.Point(0, 0);
var origin = me.pixelOrigin_;
point.x = origin.x + latLng.lng() * me.pixelsPerLonDegree_;
// NOTE(appleton): Truncating to 0.9999 effectively limits latitude to
// 89.189. This is about a third of a tile past the edge of the world tile.
var siny = bound(Math.sin(degreesToRadians(latLng.lat())), -0.9999, 0.9999);
point.y = origin.y + 0.5 * Math.log((1 + siny) / (1 - siny)) * -me.pixelsPerLonRadian_;
return point;
};
MercatorProjection.prototype.fromDivPixelToLatLng = function(pixel, zoom) {
var me = this;
var origin = me.pixelOrigin_;
var scale = Math.pow(2, zoom);
var lng = (pixel.x / scale - origin.x) / me.pixelsPerLonDegree_;
var latRadians = (pixel.y / scale - origin.y) / -me.pixelsPerLonRadian_;
var lat = radiansToDegrees(2 * Math.atan(Math.exp(latRadians)) - Math.PI / 2);
return new google.maps.LatLng(lat, lng);
};
MercatorProjection.prototype.fromDivPixelToSphericalMercator = function(pixel, zoom) {
var me = this;
var coord = me.fromDivPixelToLatLng(pixel, zoom);
var r= 6378137.0;
var x = r* degreesToRadians(coord.lng());
var latRad = degreesToRadians(coord.lat());
var y = (r/2) * Math.log((1+Math.sin(latRad))/ (1-Math.sin(latRad)));
return new google.maps.Point(x,y);
};
function loadWMS() {
var tileHeight = 256;
var tileWidth = 256;
var opacityLevel = 0.75;
var isPng = true;
var minZoomLevel = 2;
var maxZoomLevel = 28;
var baseURL = "http://ovc.catastro.meh.es/Cartografia/WMS/ServidorWMS.aspx?";
var wmsParams = [
"REQUEST=GetMap",
"SERVICE=WMS",
"VERSION=1.1.1",
"TRANSPARENT=TRUE",
"SRS=EPSG:3785", // 3395?
"WIDTH="+ tileWidth,
"HEIGHT="+ tileHeight
];
var parcelParams = wmsParams.concat([
"FORMAT=image/png",
"LAYERS=catastro",
"REFCAT="+$("#RefCatastralGoogle").val()
]);
var overlayOptions =
{
getTileUrl: function(coord, zoom)
{
var lULP = new google.maps.Point(coord.x*256,(coord.y+1)*256);
var lLRP = new google.maps.Point((coord.x+1)*256,coord.y*256);
var projectionMap = new MercatorProjection();
var lULg = projectionMap.fromDivPixelToSphericalMercator(lULP, zoom);
var lLRg = projectionMap.fromDivPixelToSphericalMercator(lLRP, zoom);
var lUL_Latitude = lULg.y;
var lUL_Longitude = lULg.x;
var lLR_Latitude = lLRg.y;
var lLR_Longitude = lLRg.x;
var urlResult = baseURL + parcelParams.join("&") + "&bbox=" + lUL_Longitude + "," + lUL_Latitude + "," + lLR_Longitude + "," + lLR_Latitude;
// window.status = urlResult;
return urlResult;
},
tileSize: new google.maps.Size(tileHeight, tileWidth),
minZoom: minZoomLevel,
maxZoom: maxZoomLevel,
opacity: opacityLevel,
isPng: isPng
};
overlayWMS = new google.maps.ImageMapType(overlayOptions);
map.overlayMapTypes.insertAt(0, overlayWMS);
map.setOptions({
mapTypeControlOptions: {
mapTypeIds: [
'wms',
google.maps.MapTypeId.ROADMAP,
google.maps.MapTypeId.TERRAIN,
google.maps.MapTypeId.SATELLITE,
google.maps.MapTypeId.HYBRID
],
style: google.maps.MapTypeControlStyle.DROPDOWN_MENU
}
});
}
function geocodeResult(results, status) {
// Verificamos el estatus
if (status == 'OK') {
// Si hay resultados encontrados, centramos y repintamos el mapa
// esto para eliminar cualquier pin antes puesto
var myOptions = {
zoom: 18,
center: results[0].geometry.location,
mapTypeId: google.maps.MapTypeId.ROADMAP,
mapTypeControl: true,
mapTypeControlOptions: {style: google.maps.MapTypeControlStyle.DROPDOWN_MENU},
navigationControlOptions: {style: google.maps.NavigationControlStyle.ZOOM_PAN}
};
map = new google.maps.Map(document.getElementById("map"), myOptions);
lastWidth = document.documentElement.clientWidth;
lastHeight = document.documentElement.clientHeight;
document.getElementById('map').style.height = '500 px';
document.getElementById('map').style.width = '500 px';
// fitBounds acercará el mapa con el zoom adecuado de acuerdo a lo buscado
map.fitBounds(results[0].geometry.viewport);
loadWMS();
var marker = new google.maps.Marker({
map:map,
draggable:true,
animation: google.maps.Animation.DROP,
position: results[0].geometry.location
});
marker.setAnimation(google.maps.Animation.BOUNCE);
} else {
// En caso de no haber resultados o que haya ocurrido un error
// lanzamos un mensaje con el error
alert("Geocoding no tuvo éxito debido a: " + status);
}
}
});