This repository was archived by the owner on May 25, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 89
/
Copy pathdemo.html
112 lines (98 loc) · 4.23 KB
/
demo.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
<!-- Le directive
================================================== -->
<section id="map" ng-controller="MapCtrl" ng-cloak>
<div class="page-header">
<h1>Google Maps</h1>
</div>
<div class="well">
<div class="row">
<div class="span3">
<h4>Click to add a marker!</h4>
<p>{{zoomMessage}}</p>
<ul>
<li ng-repeat="marker in myMarkers">
<a class="btn" ng-click="myMap.panTo(marker.getPosition())">
Pan to Marker {{$index}}
</a>
</li>
</ul>
<!-- this is the confusing part. we have to point the map marker directive
at an existing google.maps.Marker object, so it can hook up events -->
<div ng-repeat="marker in myMarkers" ui-map-marker="myMarkers[$index]"
ui-event="{'map-click': 'openMarkerInfo(marker)'}">
</div>
<div ui-map-info-window="myInfoWindow">
<h1>Marker</h1>
Lat: <input ng-model="currentMarkerLat">, Lng: <input ng-model="currentMarkerLng">
<a class="btn btn-primary" ng-click="setMarkerPosition(currentMarker, currentMarkerLat, currentMarkerLng)">Set Position</a>
</div>
</div>
<!--Giving the div an id="map_canvas" fix problems with twitter bootstrap affecting
google maps-->
<div id="map_canvas" ui-map="myMap" class="span8 map"
ui-event="{'map-click': 'addMarker($event, $params)', 'map-zoom_changed': 'setZoomMessage(myMap.getZoom())' }"
ui-options="mapOptions">
</div>
</div>
</div>
<h3>How?</h3>
<p class="alert alert-info"><i class="icon-info-sign"></i> Remember that you can pass a variable containing an object to <code>ui-event</code></p>
<pre class="prettyprint">
<h4>Click to add a marker!</h4>
<p>{{zoomMessage}}</p>
<ul>
<li ng-repeat="marker in myMarkers">
<a ng-click="myMap.panTo(marker.getPosition())">Pan to Marker {{$index}}</a>
</li>
</ul>
<!-- this is the confusing part. we have to point the map marker directive
at an existing google.maps.Marker object, so it can hook up events -->
<div ng-repeat="marker in myMarkers" ui-map-marker="myMarkers[$index]"
ui-event="{'map-click': 'openMarkerInfo(marker)'}">
</div>
<div ui-map-info-window="myInfoWindow">
<h1>Marker</h1>
Lat: <input ng-model="currentMarkerLat">, Lng: <input ng-model="currentMarkerLng">
<a ng-click="setMarkerPosition(currentMarker, currentMarkerLat, currentMarkerLng)">Set Position</a>
</div>
<!-- Giving the div an id="map_canvas" fix problems with twitter bootstrap affecting
google maps -->
<div id="map_canvas" ui-map="myMap" class="map"
ui-event="{'map-click': 'addMarker($event, $params)', 'map-zoom_changed': 'setZoomMessage(myMap.getZoom())' }"
ui-options="mapOptions">
</div>
<script>
$scope.myMarkers = [];
$scope.mapOptions = {
center: new google.maps.LatLng(35.784, -78.670),
zoom: 15,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
$scope.addMarker = function($event, $params) {
$scope.myMarkers.push(new google.maps.Marker({
map: $scope.myMap,
position: $params[0].latLng
}));
};
$scope.setZoomMessage = function(zoom) {
$scope.zoomMessage = 'You just zoomed to '+zoom+'!';
console.log(zoom,'zoomed')
};
$scope.openMarkerInfo = function(marker) {
$scope.currentMarker = marker;
$scope.currentMarkerLat = marker.getPosition().lat();
$scope.currentMarkerLng = marker.getPosition().lng();
$scope.myInfoWindow.open($scope.myMap, marker);
};
$scope.setMarkerPosition = function(marker, lat, lng) {
marker.setPosition(new google.maps.LatLng(lat, lng));
};
</script>
<style>
.map {
height: 400px;
width: 600px;
}
</style>
</pre>
</section>