Hey,
This is my first foray into OO JS, having issues.
Ideally in this scenario, I'd have a mapLocation object, which i could just pass in coordinates, icon, the HTML to display upon click and that's it. I'd add it to my Google map on the page and I'd have something somewhat re-usable. Obviously this would be refactored later.
Also, I'm not specifically happy about how my code looks at the moment. :)
Here's the object that I'm coming up with.
function mapLocation() {
this.lat = 0;
this.lng = 0;
this.icon = '';
this.html = '';
this.getLocation = getLocation;
}
function getLocation() {
var baseIcon = new GIcon(G_DEFAULT_ICON);
baseIcon.shadow = "http://www.google.com/mapfiles/shadow50.png";
baseIcon.iconSize = new GSize(20, 34);
baseIcon.shadowSize = new GSize(37, 34);
baseIcon.iconAnchor = new GPoint(9, 34);
baseIcon.infoWindowAnchor = new GPoint(9, 2);
var letteredIcon = new GIcon(baseIcon);
letteredIcon.image = this.icon;
var point = new GLatLng(this.lat, this.lng);
var marker = new GMarker(point, { icon:letteredIcon });
function show() {
marker.openInfoWindowHtml('Lat: '+this.lat+'<br />Lng: '+this.lng+'<br /><img src="'+this.icon+'" />');
}
alert(this.lat);
GEvent.addListener(marker, "click", show);
return marker;
}
And here's my implementation.
var a = new mapLocation;
a.lat = 52.136369;
a.lng = -106.696299;
a.icon = 'http://www.google.com/mapfiles/markerA.png';
a.html = 'asdf fdsa';
var b = a.getLocation();
map.addOverlay(b);
So I get window showing up, my marker, but show() function pop up with undefined in it.
I'm curious what I'm doing wrong - how I'm thinking wrong - in this problem.
Thanks for the look.