Best way to get help is to post a test case on http://mooshell.net,
then we can not only look at the code, but also execute it.
On Jan 13, 2010, at 11:18 AM, machadoug wrote:
Greetings,
I'm new to the group and I looked for posting guidelines but found
none;
I'm trying to create a class to handle Google Maps.
My problem:
The operation seems to be aborted whenever the showAddress method
calls this.loadMap();
The code is part of a Joomla component that I'm developing, therefore
I created a small page with the code:
http://ideal.fok.com.br/gmaps/
I don't know if it makes easier to post the code, it is bellow anyway:
var CEGMaps = new Class({
options: {
maplayer: 'map_canvas',
latInput: 'lat',
lngInput: 'lng',
zoomInput: 'zoom',
address: 'undefined',
language: {
txtErrorAddress: 'Address ## not found',
txtMapAddress: 'Address: <br /> ##'
}
},
initialize: function(options){
if(!GBrowserIsCompatible()) return false;
this.eventsloaded = 0;
this.setOptions(options);
this.geocoder = new GClientGeocoder();
this.maplayer = $(this.options.maplayer);
this.lat = $(this.options.latInput).value;
this.lng = $(this.options.lngInput).value;
this.zoom = $(this.options.zoomInput).value;
this.address = this.options.address;
this.map = new GMap2(this.maplayer);
// this.map.addControl(new GSmallMapControl());
//this.map.addControl(new GMapTypeControl());
this.point = new GLatLng(this.lat, this.lng);
this.marker = new GMarker(this.point, {draggable:
true});
if( (this.lat != 0 && this.lng != 0) || this.address ==
'undefined' ){
this.loadMap();
}else if(this.address != 'undefined'){
this.showAddress(this.address);
}else{
this.loadMap();
}
this.map.addOverlay(this.marker);
},
showAddress: function(address){
this.address = address;
this.geocoder.getLatLng(
address,
function(point){
if(point){
this.point = point;
this.loadMap();
}
else{
alert(this.options.language.txtErrorAddress.replace(/##/,
address) );
}
}
)},
loadMap: function(){
alert(this.point); //testing;
this.map.setCenter(this.point);
this.map.setZoom(this.zoom.toInt());
this.map.setUIToDefault();
this.marker.setLatLng(this.point);
this.marker.openInfoWindowHtml
(this.options.language.txtMapAddress.replace(/##/, this.address) );
this.loadEventListeners();
this.saveCoordinates();
this.loadEventListeners();
},
saveCoordinates: function() {
var coordinates = this.marker.getLatLng();
coordinates =
coordinates.toString().replace('(','').replace
(')','');
coordinates = coordinates.split(',');
$(this.options.latInput).setProperty('value',
trim(coordinates[0]));
$(this.options.lngInput).setProperty('value', trim(coordinates
[1]));
$(this.options.zoomInput).setProperty('value',
this.map.getZoom());
},
loadEventListeners: function(){
if(this.eventsloaded > 0){ return false;}
this.eventsloaded++;
GEvent.addListener(this.map, 'mouseout', function() {
// If I use "this" instead of "document.CEMaper" it
shows
"this.saveCoordinates() is not a function" error
document.CEMaper.saveCoordinates();
});
GEvent.addListener(this.marker, 'dragstart', function() {
document.CEMaper.map.closeInfoWindow();
});
GEvent.addListener(this.marker, 'dragend', function() {
document.CEMaper.marker.openInfoWindowHtml
(document.CEMaper.options.language.txtMapAddress.replace(/##/,
this.address));
});
}
}
);
CEGMaps.implement(new Options);
The class can also be found here:
http://ideal.fok.com.br/components/com_contact_enhanced/assets/js/gmaps.js
Any help is highly appreciated.
Kind regards,
Douglas