灰色框谷歌地图和角度2

时间:2016-04-05 17:14:16

标签: google-maps google-maps-api-3 angular angular2-routing angular2-directives

我有角度2和谷歌地图的API v3的问题,问题是当我通过路由器插座加载页面时,地图是一个灰色的框,但是当我刷新页面时,地图正确加载,我在索引页面上使用js库导入,并且映射被加载到组件中。

this is the view of the map

我尝试使用触发器rezise但不起作用。我认为这是库加载或类似问题。

这是代码:

    import {Component, OnInit} from "angular2/core";
import {MapsService} from "../maps/maps.service";
import {mapsIconService} from "./maps.icon.service";
import {BrowserDomAdapter} from 'angular2/platform/browser';


@Component({
    selector: "div-map",
    template: `
    <div id="map" style="height: 500px" class="maps"> </div> `,
    providers: [MapsService, mapsIconService, BrowserDomAdapter],
    style: `
        .maps{
            overflow:visible;
        }
    `

})

export class Maps {
    map;
    snappedCoordinates = [];
    points:string = "";
    map:Map;
    drawingManager;
    placeIdArray = [];
    polylines = [];
    markers = [];
    placeIds = [];
    infoWindows = [];
    snappedPolyline;
    showMap = false;

    lineSymbol = {
        path: google.maps.SymbolPath.CIRCLE,
        scale: 8,
        strokeColor: '#005db5',
        strokeWidth: '#005db5'
    };

    mapOptions = {
        zoom: 15,
        center: {lat: 37.38658313258027, lng: -122.05207727132837},

    };

    constructor(private _dom:BrowserDomAdapter, private _mapService:MapsService, private _mapIconService:mapsIconService) {
        // google.maps.visualRefresh = true;
    }


    drawSnappedPolyline(snappedCoordinates) {
        this.snappedPolyline = new google.maps.Polyline({
            path: snappedCoordinates,
            strokeColor: 'black',
            strokeWeight: 3
        });
        this.polylines.push(this.snappedPolyline);
    }


    animateCircle(polyline) {
        var count = 0;
        // fallback icon if the poly has no icon to animate
        var defaultIcon = [
            {
                icon: this.lineSymbol,
                offset: '100%'
            }
        ];
        window.setInterval(function () {
            count = (count + 1) % 300;
            var icons = defaultIcon;
            icons[0].offset = (count / 3) + '%';
            polyline.set('icons', icons);
        }, 300);
    }

    setMarker(lat, lng, id) {
        var marker = new google.maps.Marker({
            position: this.map.getCenter()/*new google.maps.LatLng(lat, lng)*/,
            icon: {url: 'data:image/svg+xml;charset=UTF-8,' + encodeURIComponent(this._mapIconService.getIcon(id))},
            draggable: false,
            map: this.map
        });
    }

    SetAllMarkers(points) {
        for (var i in points) {
            this.setMarker(points[i].lat, points[i].lng, points[i].id);
        }
    }


    ngOnInit() {


        this.map = new google.maps.Map(this._dom.query("#map"), this.mapOptions);
        google.maps.event.trigger(this.map, 'resize');

        this._mapService.goData().subscribe(data=> {
         this.drawSnappedPolyline(this._mapService.processSnapToRoadResponse(data));
         this.setMarker(37.38658313258027, -122.05207727132837, 0);
         this.snappedPolyline.setMap(this.map);
         this.animateCircle(this.snappedPolyline);
         });

    }


}

任何人都对此有所了解?提前谢谢

1 个答案:

答案 0 :(得分:0)

问题是语义UI,因为他将代码插入到&#34; pusher&#34;这会导致所有元素出现问题

相关问题