I've started to investigate TypeScript approach in my project and currently bit confused how to correctly organize the call to MarkerClusterer method. I currently have to type-definitions references:
///<reference path="../../typings/angularjs/angular.d.ts" />
///<reference path="../../typings/google.maps.d.ts" />
But for MarkerClusterer js I was unable to find definition ts library. My code now looks so:
class paspController {
public map: any;
public markers;
public mapTab: boolean;
public currentId: number;
//Some code
showTab(tabIndex: number) {
if (tabIndex == 2) {
this.mapTab = true;
var that = this;
setTimeout(function () {
this.options = {
zoom: 2,
center: new google.maps.LatLng(1, 1),
mapTypeId: google.maps.MapTypeId.ROADMAP
};
if (!that.map) {
that.map = new google.maps.Map(document.getElementById('map'), this.options);
}
jQuery.ajax({
type: "GET",
url: 'GetDivesWithCoordinates/' + that.currentId,
success: function (data) {
that.markers = [];
var marker;
for (var i = 0; i < data.length; i++) {
marker = new google.maps.Marker({ map: that.map, draggable: false, title: data[i].Location + ": " + data[i].DiveComment, position: new google.maps.LatLng(data[i].CoordinateX, data[i].CoordinateY) });
that.markers.push(marker);
}
// THIS IS MY PROBLEM => var markerCluster = new MarkerClusterer(that.map, markers);
},
error: function (e) {
},
async: false
});
}, 100);
}
}
How should I correctly call the MarkerClusterer, or maybe I should put it outside the controller logic?
THIS IS MY PROBLEM => var markerCluster = new MarkerClusterer(that.map, markers);
Declare it :
declare var MarkerClusterer:any;
And typescript will not complain anymore.
More : http://basarat.gitbooks.io/typescript/content/docs/types/migrating.html