How to draw polygon using hardcoded values in ngMap using angularjs

我怕爱的太早我们不能终老 提交于 2019-12-03 17:24:04

1. How to draw a polygon

To display a polygon use a shape directive with name attribute set to polygon:

<shape path="{{vm.paths}}"  name="polygon" ></shape>

2. How to get a marker position via Google Maps Drawing Manager

vm.onMapOverlayCompleted = function (e) {
    if (e.type == google.maps.drawing.OverlayType.MARKER) {
        var pos = e.overlay.getPosition();  //get marker position
        alert(pos.toString());
    }
};  

Modified example

var app = angular.module('myapp', ['ngMap']);
app.controller('DrawingManagerCtrl', function () {
    var vm = this;
    vm.paths = "[[28.646359, 77.259623],[28.645153, 77.207438],[28.680098, 77.120921],[28.680098, 77.259623]]";


    vm.onMapOverlayCompleted = function (e) {
        if (e.type == google.maps.drawing.OverlayType.MARKER) {
            var pos = e.overlay.getPosition();
            alert(pos.toString());
        }
    };
});
 <script src="https://maps.google.com/maps/api/js?libraries=placeses,visualization,drawing,geometry,places"></script>
 <script src="https://code.angularjs.org/1.3.15/angular.js"></script>
 <script src="https://rawgit.com/allenhwkim/angularjs-google-maps/master/build/scripts/ng-map.js"></script>

<div ng-app="myapp" ng-controller="DrawingManagerCtrl as vm">
        <ng-map zoom="12" center="28.623457, 77.196452"
                map-type-id="ROADMAP"
                street-view-control-options="{position: 'LEFT_CENTER'}">
            <drawing-manager on-overlaycomplete="vm.onMapOverlayCompleted()"
                             drawing-control-options="{position: 'TOP_CENTER',drawingModes:['polygon','marker']}"
                             drawingControl="true"
                             drawingMode="null"
                             rectangleOptions="{fillColor:'red'}"
                             circleOptions="{fillColor: '#FFFF00',fillOpacity: 1,strokeWeight: 5,clickable: false,zIndex: 1,editable: true}">
            </drawing-manager>


            <shape path="{{vm.paths}}"  name="polygon" ></shape>
        </ng-map>
</div>

Plunker

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!