从基于打字稿的角度控制器调用GoogleMap MarkerClusterer方法

问题描述 投票:1回答:2

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

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

但对于MarkerClusterer,我无法找到定义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,或者我应该把它放在控制器逻辑之外?

javascript angularjs google-maps typescript markerclusterer
2个回答
2
投票

这是我的问题=> var markerCluster = new MarkerClusterer(that.map,markers);

声明它:

declare var MarkerClusterer:any;

打字稿不会再抱怨了。

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


0
投票

我把它放在:

import { Component, OnInit, ViewChild, ElementRef } from '@angular/core';

declare var MarkerClusterer: any;

之前

@Component({
© www.soinside.com 2019 - 2024. All rights reserved.