Fraser
Thanks for the references. I'm using your GEPluginCtrls components in
my c# application (by theway really useful, thanks) including
addEventListener and removeEventListener. For the reasons we have
discussed above I altered the c# code to be
/// <summary>
/// Wrapper for the the google.earth.addEventListener method
/// </summary>
/// <param name="feature">The target object</param>
/// <param name="action">The event Id</param>
/// <returns>Object containing javascript function</returns>
public object AddEventListener(object feature, string action)
{
return this.InvokeJavascript(
"jsAddEventListener",
new object[] { feature, action });
}
/// <summary>
/// Wrapper for the the google.earth.removeEventListener
method
/// </summary>
/// <param name="feature">The target kml object</param>
/// <param name="action">The event Id</param>
/// <param name="eventFunction">Event function to remove</
param>
public void RemoveEventListener(object feature, string action,
object eventFunction)
{
this.InvokeJavascript(
"jsRemoveEventListener",
new object[] { feature, action, eventFunction});
}
with corresponding javascript
var jsAddEventListener = function(feature, action)
{
if (ge)
{
var eventFunction = function(kmlEvent)
{
if (kmlEvent)
{
application.KmlEventCallBack(kmlEvent,
action);
}
}
google.earth.addEventListener(feature, action,
eventFunction);
return eventFunction;
}
else
{
return null
}
}
var jsRemoveEventListener = function(feature, action,
eventFunction)
{
if (ge)
{
google.earth.removeEventListener(feature, action,
eventFunction);
}
}
so that the event function can be removed thanks to the function
closure in javascript. Perhaps this may be useful to those who are
developing mixed c# and js applications - comments welcome.
Regards
Andy
On Nov 24, 3:28 pm, fraser (Earth API Guru) wrote:
> Hi,
>
> Just to point out this is covered in the documentation in a couple of
> places.
>
> "You must pass in the exact same function object as was passed to
> addEventListener. If you are using an anonymous function callback, it
> will need to be refactored into its own variable."
>
>
http://code.google.com/apis/earth/documentation/events.html#removing_...http://code.google.com/apis/earth/documentation/reference/google_eart...
>
> Cheers,
>
> F.
>
> On Nov 23, 11:49 am, Darren James wrote:
>
>
>
> > Many, many thanks Andy and Matthew. I had a feeling I was missing a
> > trick somewhere. All sorted now :)
>
> > If you are interested, the demo I was working on is available athttp://
is.gd/51Ko6Beaware it plots around 30,000 lat/lng coords from
> > > > thanks.- Hide quoted text -
>
> - Show quoted text -