Question

I'm trying to add a KML layer to an existing google maps object without having control over the object instance (and initializing).

So far I figured out that the object is at (DOM): window.google.maps... (okay, this is just the constructor, not the rendered Map object itself)

This is what i want to add to the existing(?) instance of the google.maps.Map object:

var kmlUrl = 'http://.../polygon-simple.kml';

var kmlOptions = {
  suppressInfoWindows: false,
  preserveViewport: true
};

var kmlLayer = new window.google.maps.KmlLayer(kmlUrl, kmlOptions);

The page including the Map object is delivered by a hosting company and uses it's own jQuery widget to generate the object. I can add my javascript inside the html-body (where the "server-side" creation of the map also takes place).

Since I can't change the sources of the used JS-files and CMS-added JS, I need to address the existing object and do something like:

kmlLayer.set(obj.Map);

to apply my additions and update the Map object. But it doesn't work, obviously.

I firebug'd the whole website and tried to find the Map instance, generated by the jQuery widget - nothing. I traversed through every object on the site - nothing.

Writing the code for the Google Map completely on my own is no option, because I need to keep it configurable in the back-end for non-devs.

I guess the problem moves towards a jQuery widget issue... Thanks in advance!

No correct solution

OTHER TIPS

window.google.maps.Map is not the map object, it is the constructor of said object. The object itself is in another castle (variable).

obj instanceof google.maps.Map 

should return true if the object is a googlemaps Map object. If you really can't find the variable you can write a loop that goes through all objects on your page recursively to find the object that returns true to this line.

As a side note in the chrome debugger the Map object appears like this: map

It says that the map type is "em" which is rather odd, this is because the GoogleMaps library is minified

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top