问题
I need to draw polygon on google maps using the hard coded values.I have used ngMap ( https://ngmap.github.io/ )and used drawing manager of ngMap to it, because i also want the user to draw polygon dynamically. if i use drawing manager,i am not able to draw polygon with hardcoded values. and also another thing , if the user put the marker on map. i need to get the co-ordinates of it. (for example:get the co-ordinates in alert box or console). can anyone please help me
Plunker here: http://plnkr.co/edit/keRsKthRAwX89WOWeYwZ?p=preview
<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>
回答1:
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
来源:https://stackoverflow.com/questions/34631298/how-to-draw-polygon-using-hardcoded-values-in-ngmap-using-angularjs