I have the following (simplified) object literal. The icon method uses closure to hide the icon variable that I would like to have as an associative array for subsequent searches.
var MapListings = {
icons: function () {
var allIcons = [] ;
return {
add: function (iconType, iconImage) {
var icon = new GIcon(MapListings.baseIcon);
icon.image = iconImage;
allIcons[iconType] = icon;
},
get: function () {
return allIcons;
}
};
} ()
}
I add elements to the icon object as follows:
MapListings.icons.add("c7", "/images/maps/blue.png");
MapListings.icons.add("c8", "/images/maps/red.png");
The following does not work:
allIcons[iconType] = icon;
But it does:
allIcons.push(icon);
Outside of closure, the associative array style works fine, maybe there is a conflict with jQuery? The error I get in firebug a, undefined , looks from the library. I would like to maintain an associative array style.
Any ideas?
Update
This conflict seems to come from Google maps. Strange, not sure about that.
Dumbass Update
, GIcon(), . , .
baseIcon: function () {
var base = new GIcon();
base.shadow = '/images/maps/shadow.png';
base.iconSize = new GSize(12, 20);
base.shadowSize = new GSize(22, 20);
base.iconAnchor = new GPoint(6, 20);
base.infoWindowAnchor = new GPoint(5, 1);
return base;
}
MapListings.baseIcon MapListings.baseIcon()! D'