从地图NgMap中删除折线

时间:2018-05-20 14:52:21

标签: angularjs ng-map

我想从地图中移除polyline,我正在使用NgMap模块,我尝试将地图设置为null但它没有工作 这是我的控制器

.controller('mainController', ['$scope', function ($scope, NgMap) {

    $scope.mapsApiUrl = 'AIzaSyA3ZMA6KlxboXRuA7ItNNSlJp3xcgjaB0M'; // check the ng-map docs for api url and api key



    $scope.$onInit = onInit;
    $scope.coords = [33, -7];

    function onInit() {
        NgMap.getMap().then(function (mapInstance) {
            var center = mapInstance.getCenter();

            google.maps.event.trigger(mapInstance, 'resize');
            mapInstance.setCenter(center);



            $timeout(function () {
                $scope.map = mapInstance;
            });
        });
    }


    $scope.changePosition = function(){
        $scope.map.shape.foo.setMap(null);

    }



    $scope.changePosition = function () {


        $scope.array = [
            [33.97646076222972, -6.8715220588954935 ],
            [33.97671877693391, -6.87136649077263],
            [33.977066873117344, -6.871232380321885],
            [33.97751172239542, -6.870969523838426]
          ] ;
        }   


    var i = 0;


    var show = function (coord){
        $scope.coords= [COORDONNES[i].x, COORDONNES[i].y];
        i++;
        if(i==COORDONNES.length ) i=0 ; 
        $scope.$apply(function () {
        });
    }
    setInterval(show, 1000);

}]); 

这是我的HTML代码

    <button ng-click="changePosition()">CHANGE {{coords}}</button>
    <button ng-click="cancelPosition()"> CANCEL</button>

    <shape name="polyline"  id="foo"
          path="{{array}}"
          geodesic="true"
          stroke-color="#FF0000"
          stroke-opacity="1.0"
          stroke-weight="4">
    </shape>

0 个答案:

没有答案
相关问题