Skip to content
This repository was archived by the owner on Nov 30, 2018. It is now read-only.

Commit 0cbb101

Browse files
committed
Clusterer example, and fixed bug with MarkerParentModel.
1 parent b3eb0cf commit 0cbb101

File tree

4 files changed

+40
-3
lines changed

4 files changed

+40
-3
lines changed

example/example-controller.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,25 @@ function ExampleController ($scope, $timeout, $log) {
1414
window.alert("Marker: lat: " + marker.latitude +", lon: " + marker.longitude + " clicked!!")
1515
};
1616

17+
genRandomMarkers = function(numberOfMarkers,scope){
18+
markers = []
19+
for(var i=0; i < numberOfMarkers; i++){
20+
markers.push(createRandomMarker(scope.map.bounds))
21+
}
22+
scope.map.randomMarkers = markers;
23+
};
24+
25+
createRandomMarker = function(bounds) {
26+
var lat_min = bounds.southwest.latitude,
27+
lat_range = bounds.northeast.latitude - lat_min,
28+
lng_min = bounds.southwest.longitude,
29+
lng_range = bounds.northeast.longitude - lng_min;
30+
31+
latitude = lat_min + (Math.random() * lat_range);
32+
longitude = lng_min + (Math.random() * lng_range);
33+
return {latitude:latitude,longitude:longitude};
34+
};
35+
1736
angular.extend($scope, {
1837
map: {
1938
showTraffic: true,
@@ -61,6 +80,7 @@ function ExampleController ($scope, $timeout, $log) {
6180
}
6281
],
6382
dynamicMarkers: [],
83+
randomMarkers: [],
6484
clickedMarker: {
6585
latitude: null,
6686
longitude: null
@@ -193,9 +213,14 @@ function ExampleController ($scope, $timeout, $log) {
193213
$scope.map.markers.length = 0;
194214
$scope.map.markers2.length = 0;
195215
$scope.map.dynamicMarkers.length = 0;
216+
$scope.map.randomMarkers.length = 0;
196217
$scope.map.clickedMarker = null;
197218
};
198219

220+
$scope.genRandomMarkers = function(numberOfMarkers) {
221+
genRandomMarkers(numberOfMarkers,$scope);
222+
}
223+
199224
$scope.onMarkerClicked = onMarkerClicked
200225

201226
$timeout(function () {

example/example.html

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,9 @@ <h1>angular-google-maps example</h1>
7777
events="map.events">
7878
<trafficlayer show="map.showTraffic" />
7979

80+
<markers models="map.randomMarkers" coords="'self'" icon="'icon'" click="'onClicked'" doCluster="true">
81+
</markers>
82+
8083
<markers models="map.markers2" coords="'self'" icon="'icon'" click="'onClicked'">
8184
<windows show="'showWindow'" closeClick="'closeClick'">
8285
<p ng-non-bindable >This is an info window at {{ latitude | number:4 }}, {{ longitude | number:4 }}!</p>
@@ -134,6 +137,15 @@ <h1>angular-google-maps example</h1>
134137
<input type="checkbox" text="TrafficLayer On/Off" ng-model="map.showTraffic">
135138
</td>
136139
</tr>
140+
<tr>
141+
<td>Generate Random Markers</td>
142+
<td>
143+
<div ng-init="numOfMarkers = 1000">
144+
<input type="text" text="Number of Markers" ng-model="numOfMarkers">
145+
<button ng-click="genRandomMarkers(numOfMarkers)">Generate</button>
146+
</div>
147+
</td>
148+
</tr>
137149
<tr>
138150
<td>markers</td>
139151
<td>

src/coffee/directives/api/models/parent/marker-parent-model.coffee

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
constructor: (scope, element, attrs, mapCtrl,$timeout) ->
99
super(scope, element, attrs, mapCtrl,$timeout)
1010
self = @
11-
opts = @createMarkerOptions(scope.coords,scope.icon,scope.options,mapCtrl)
11+
opts = @createMarkerOptions(scope.coords,scope.icon,scope.options,mapCtrl.getMap())
1212
#using scope.$id as the identifier for a marker as scope.$id should be unique, no need for an index (as it is the index)
1313
@gMarker = new google.maps.Marker(opts)
1414
element.data('instance', @gMarker)
@@ -48,7 +48,7 @@
4848
if scope.coords? and scope.icon? and scope.options
4949
@gMarker.setMap(null)
5050
delete @gMarker
51-
@gMarker = new google.maps.Marker(@createMarkerOptions(scope.coords,scope.icon,scope.options,@mapCtrl))
51+
@gMarker = new google.maps.Marker(@createMarkerOptions(scope.coords,scope.icon,scope.options,@mapCtrl.getMap()))
5252
else
5353

5454

src/coffee/directives/api/utils/gmap-util.coffee

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
icon: icon,
77
visible: coords.latitude? and coords.longitude?
88
})
9-
opts.map = map: map.getMap() if map?
9+
opts.map = map if map?
1010
opts
1111

1212
createWindowOptions:(gMarker,scope,content,defaults) ->

0 commit comments

Comments
 (0)