javascript - How to register event handlers for TypeScript declarations -
i've asked question on typescript's codeplex forums didn't answer i'm asking here. given typescript class declaration, example bing maps 1 (https://bingmapsts.codeplex.com/) how register event handler?
on map class (in microsoft.maps.d.ts) there couple of events declared:
viewchange: () => any; viewchangeend: () => any; viewchangestart: () => any;
and i've tried hooking function following inside typescript file never gets called:
///<reference path="bing/microsoft.maps.all.d.ts" /> window.onload = function() { var map = new microsoft.maps.map(document.getelementbyid('map'), { backgroundcolor: 0, }); map.click = () => alert('click'); map.viewchangestart = () => alert('viewchangestart'); }
in traditional javascript, use following:
microsoft.maps.events.addhandler(map, 'viewchangestart', function (e) { alert('viewchangestart'); });
but there no such method in typescript declaration , since can't seem reference virtual earth map control .ts file i'm not sure how can this.
the definition (https://bingmapsts.codeplex.com/sourcecontrol/latest#bingts.solution/bingts/bing/microsoft.maps.d.ts) wrong : http://msdn.microsoft.com/en-us/library/gg427609.aspx functions not exist. can register events via addhandler. simple definition:
declare module microsoft.maps.events{ function addhandler(map:microsoft.maps.map,event:string,func:function); }
Comments
Post a Comment