ngmap
Version:
The Simplest AngularJS Google Maps V3 Directive
37 lines (35 loc) • 1.25 kB
HTML
<html ng-app="myApp">
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<script src="script-tags-for-development.js"></script>
<script>
var app = angular.module('myApp', ['ngMap']);
app.controller('CustomControlCtrl', function(NgMap) {
var vm=this;
NgMap.getMap().then(function(map) {
vm.map = map;
});
vm.home = new google.maps.LatLng(41.850033, -87.6500523);
vm.goHome = function() {
vm.map.setCenter(vm.home);
}
vm.setHome = function() {
vm.home = vm.map.getCenter();
}
});
</script>
</head>
<body ng-controller="CustomControlCtrl as vm">
Adding state to controls<br/>
Adds a control to the map that returns the user to the control's defined home
<br/>
<ng-map center="41.850033, -87.6500523" zoom="6" default-style="true">
<custom-control id="go-home" position="TOP_RIGHT" index="1" on-click="vm.goHome()">
<div style="background-color: black; color:#fff;cursor:pointer; margin:10px">Go Home</div>
</custom-control>
<custom-control id="set-home" position="TOP_RIGHT" index="1" on-click="vm.setHome()">
<div style="background-color: black; color:#fff;cursor:pointer; margin:10px">Set Home</div>
</custom-control>
</ng-map>
</body>
</html>