对于角谷歌地图如何删除折线? [英] For angular google maps how do I remove the polyline?

查看:270
本文介绍了对于角谷歌地图如何删除折线?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有关角谷歌地图如何删除折线?
我在一家指令采用了棱角分明的版本1使用JavaScript使用templateUrl。

For angular google maps how do I remove the polyline? I'm using angular version 1 with JavaScript in a directive using a templateUrl.

版本:角谷歌,地图2.1.5

Version: angular-google-maps 2.1.5

这是我目前的HTML:

 <ui-gmap-google-map center="config.map.center" zoom="config.map.zoom" options="config.map.options" events="config.map.events" draggable="true">
        <ui-gmap-polygon path="compatiblePolygon" stroke="polygonConfig.stroke" fill="polygonConfig.fill" fit="true" static="false" visible="polygonConfig.visible" editable="true" draggable="true" clickable="true" events="polygonConfig.events">
        </ui-gmap-polygon>

        <ui-gmap-markers coords="'self'" options="marker.options" models="compatiblePoints" idkey="'id'" clickable="true" click="markerClicked">
        </ui-gmap-markers>

        <ui-gmap-drawing-manager options="drawingManager" static="false" events="config.drawing.events">
        </ui-gmap-drawing-manager>
    </ui-gmap-google-map>

这是折线的IMG得出,我需要删除:

在这里输入的形象描述

到目前为止,我已经试过这对我清晰的地图按钮,点击:

scope.polygonConfig.events.setMap(null);

但后来我得到这个控制台错误:

无法读取的未定义的属性'的setMap'。

"Cannot read property 'setMap' of undefined"

我也试过这样:

                   uiGmapIsReady.promise(1).then(function (instances) {
                        const map = instances.reduce(function(previous, current) {
                            return current.map;
                        });
                        scope.mapInstance = map;
                        map.setMap(null);
                    });

但我得到这个错误:map.setMap不是一个函数

but I get this error: map.setMap is not a function

推荐答案

根据对的 UI-GMAP多边形

事件:自定义事件应用到多边形。这是一个关联数组,其中键是事件的名称和值是处理函数。见多边形的事件。处理函数有四个参数(注意ARGS正在扩大对原谷歌SDK的默认参数):搜索结果
  1.多边形:对多边形的GoogleMaps对象

events: Custom events to apply to the Polygon. This is an associative array, where keys are event names and values are handler functions. See Polygon events. The handler function takes four parameters (note the args are expanding on the original google sdk's default args):

1. Polygon: the GoogleMaps Polygon object

您可以使用事件清除折线属性 UI-GMAP多边形是这样的:

You can clear the polyline using events attribute of ui-gmap-polygon like this:

$scope.events = {
    rightclick: function(polygon) {
        polygon.setMap(null);
    }
};

结果

<ui-gmap-polygon ... events="events"></ui-gmap-polygon>

这将导致右键,从地图中删除多边形。还有,你可以用它来触发这个其他事件,并在此列出: HTTPS ://developers.google.com/maps/documentation/javascript/reference#Polygon
结果看下的事件部分

This will cause a right click to remove the polygon from the map. There are also other events you can use to trigger this, and they are listed here: https://developers.google.com/maps/documentation/javascript/reference#Polygon
Look under the Events section

编辑:下面是一个例子证明了这种功能:的http:/ /plnkr.co/edit/t7zz8e6mCJavanWf9wCC?p=info

Here is an example demonstrating this functionality: http://plnkr.co/edit/t7zz8e6mCJavanWf9wCC?p=info

这篇关于对于角谷歌地图如何删除折线?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆