I have a Silverlight application that generates a lot of Google Maps objects on the Silverlight site. For example a Map is created like this:
var map = HtmlPage.Window.CreateInstance(@"google.maps.Map", container, mapOptions);
var center = (ScriptObject)_map.Invoke("getCenter");
Everything works fine. But now I need to access the map object from Javascript directly. I think it could be done by exposing a map property as ScriptableMember and use it from Javascript. But that”s a bit odd because the map object lives already in the browser. But how do I access it?
Update
Just to make clearer what I’m talking about
Let’s say I have created my map as shown above. Now I have a loaded Javasript file with this function:
function ReadMapCenter()
{
//Need the map object in Javascript
map.getCenter();
}
How can I access the existing map Object from Javascript?
If you just expose it as type
ScriptObjectI think the bridge will simply unpack the scripted object rather than create yet another layer of wrapping for it.Alternative
Don’t use
CreateInstanceIn your javascript at the global leve use:-
now your javascript has a
mapglobal it can use.In silverlight use:-