gpt4 book ai didi

javascript - 从基于 typescript 的 Angular Controller 调用 GoogleMap MarkerClusterer 方法

转载 作者:行者123 更新时间:2023-11-30 16:40:34 25 4
gpt4 key购买 nike

我已经开始在我的项目中研究 TypeScript 方法,目前有点困惑如何正确组织对 MarkerClusterer 方法的调用。我目前必须对引用进行类型定义:

///<reference path="../../typings/angularjs/angular.d.ts" /> 
///<reference path="../../typings/google.maps.d.ts" />

但是对于 MarkerClusterer js,我无法找到定义 ts 库。我的代码现在看起来是这样的:

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);
}
}

我应该如何正确调用 MarkerClusterer,或者我应该将它放在 Controller 逻辑之外?

最佳答案

THIS IS MY PROBLEM => var markerCluster = new MarkerClusterer(that.map, markers);

声明它:

declare var MarkerClusterer:any;

typescript 不会再提示了。

更多:http://basarat.gitbooks.io/typescript/content/docs/types/migrating.html

关于javascript - 从基于 typescript 的 Angular Controller 调用 GoogleMap MarkerClusterer 方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32070317/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com