1
1
// ==ClosureCompiler==
2
2
// @compilation_level ADVANCED_OPTIMIZATIONS
3
- // @externs_url http ://closure-compiler.googlecode .com/svn/trunk/ contrib/externs/maps/google_maps_api_v3_3 .js
3
+ // @externs_url https ://raw.githubusercontent .com/google/closure-compiler/master/ contrib/externs/maps/google_maps_api_v3 .js
4
4
// ==/ClosureCompiler==
5
5
6
6
/**
7
7
* @name MarkerClusterer for Google Maps v3
8
- * @version version 1.0.1
8
+ * @version version 1.0
9
9
* @author Luke Mahe
10
10
* @fileoverview
11
11
* The library creates and manages per-zoom-level clusters for large amounts of
17
17
*/
18
18
19
19
/**
20
+ * @license
21
+ * Copyright 2010 Google Inc. All Rights Reserved.
22
+ *
20
23
* Licensed under the Apache License, Version 2.0 (the "License");
21
24
* you may not use this file except in compliance with the License.
22
25
* You may obtain a copy of the License at
43
46
* cluster.
44
47
* 'zoomOnClick': (boolean) Whether the default behaviour of clicking on a
45
48
* cluster is to zoom into it.
46
- * 'averageCenter': (boolean) Wether the center of each cluster should be
49
+ * 'averageCenter': (boolean) Whether the center of each cluster should be
47
50
* the average of all markers in the cluster.
48
51
* 'minimumClusterSize': (number) The minimum number of markers to be in a
49
52
* cluster before the markers are hidden and a count
56
59
* 'textColor': (string) The text color.
57
60
* 'textSize': (number) The text size.
58
61
* 'backgroundPosition': (string) The position of the backgound x, y.
62
+ * 'iconAnchor': (Array) The anchor position of the icon x, y.
59
63
* @constructor
60
64
* @extends google.maps.OverlayView
61
65
*/
@@ -161,12 +165,7 @@ function MarkerClusterer(map, opt_markers, opt_options) {
161
165
// Add the map event listeners
162
166
var that = this ;
163
167
google . maps . event . addListener ( this . map_ , 'zoom_changed' , function ( ) {
164
- // Determines map type and prevent illegal zoom levels
165
168
var zoom = that . map_ . getZoom ( ) ;
166
- var minZoom = that . map_ . minZoom || 0 ;
167
- var maxZoom = Math . min ( that . map_ . maxZoom || 100 ,
168
- that . map_ . mapTypes [ that . map_ . getMapTypeId ( ) ] . maxZoom ) ;
169
- zoom = Math . min ( Math . max ( zoom , minZoom ) , maxZoom ) ;
170
169
171
170
if ( that . prevZoom_ != zoom ) {
172
171
that . prevZoom_ = zoom ;
@@ -179,7 +178,7 @@ function MarkerClusterer(map, opt_markers, opt_options) {
179
178
} ) ;
180
179
181
180
// Finally, add the markers
182
- if ( opt_markers && ( opt_markers . length || Object . keys ( opt_markers ) . length ) ) {
181
+ if ( opt_markers && opt_markers . length ) {
183
182
this . addMarkers ( opt_markers , false ) ;
184
183
}
185
184
}
@@ -191,9 +190,7 @@ function MarkerClusterer(map, opt_markers, opt_options) {
191
190
* @type {string }
192
191
* @private
193
192
*/
194
- MarkerClusterer . prototype . MARKER_CLUSTER_IMAGE_PATH_ =
195
- 'http://google-maps-utility-library-v3.googlecode.com/svn/trunk/markerclusterer/' +
196
- 'images/m' ;
193
+ MarkerClusterer . prototype . MARKER_CLUSTER_IMAGE_PATH_ = '../img/m' ;
197
194
198
195
199
196
/**
@@ -404,14 +401,8 @@ MarkerClusterer.prototype.getCalculator = function() {
404
401
* @param {boolean= } opt_nodraw Whether to redraw the clusters.
405
402
*/
406
403
MarkerClusterer . prototype . addMarkers = function ( markers , opt_nodraw ) {
407
- if ( markers . length ) {
408
- for ( var i = 0 , marker ; marker = markers [ i ] ; i ++ ) {
409
- this . pushMarkerTo_ ( marker ) ;
410
- }
411
- } else if ( Object . keys ( markers ) . length ) {
412
- for ( var marker in markers ) {
413
- this . pushMarkerTo_ ( markers [ marker ] ) ;
414
- }
404
+ for ( var i = 0 , marker ; marker = markers [ i ] ; i ++ ) {
405
+ this . pushMarkerTo_ ( marker ) ;
415
406
}
416
407
if ( ! opt_nodraw ) {
417
408
this . redraw ( ) ;
@@ -1052,12 +1043,14 @@ function ClusterIcon(cluster, styles, opt_padding) {
1052
1043
1053
1044
/**
1054
1045
* Triggers the clusterclick event and zoom's if the option is set.
1046
+ *
1047
+ * @param {google.maps.MouseEvent } event The event to propagate
1055
1048
*/
1056
- ClusterIcon . prototype . triggerClusterClick = function ( ) {
1049
+ ClusterIcon . prototype . triggerClusterClick = function ( event ) {
1057
1050
var markerClusterer = this . cluster_ . getMarkerClusterer ( ) ;
1058
1051
1059
1052
// Trigger the clusterclick event.
1060
- google . maps . event . trigger ( markerClusterer , 'clusterclick' , this . cluster_ ) ;
1053
+ google . maps . event . trigger ( markerClusterer , 'clusterclick' , this . cluster_ , event ) ;
1061
1054
1062
1055
if ( markerClusterer . isZoomOnClick ( ) ) {
1063
1056
// Zoom into the cluster.
@@ -1082,8 +1075,18 @@ ClusterIcon.prototype.onAdd = function() {
1082
1075
panes . overlayMouseTarget . appendChild ( this . div_ ) ;
1083
1076
1084
1077
var that = this ;
1085
- google . maps . event . addDomListener ( this . div_ , 'click' , function ( ) {
1086
- that . triggerClusterClick ( ) ;
1078
+ var isDragging = false ;
1079
+ google . maps . event . addDomListener ( this . div_ , 'click' , function ( event ) {
1080
+ // Only perform click when not preceded by a drag
1081
+ if ( ! isDragging ) {
1082
+ that . triggerClusterClick ( event ) ;
1083
+ }
1084
+ } ) ;
1085
+ google . maps . event . addDomListener ( this . div_ , 'mousedown' , function ( ) {
1086
+ isDragging = false ;
1087
+ } ) ;
1088
+ google . maps . event . addDomListener ( this . div_ , 'mousemove' , function ( ) {
1089
+ isDragging = true ;
1087
1090
} ) ;
1088
1091
} ;
1089
1092
@@ -1097,8 +1100,14 @@ ClusterIcon.prototype.onAdd = function() {
1097
1100
*/
1098
1101
ClusterIcon . prototype . getPosFromLatLng_ = function ( latlng ) {
1099
1102
var pos = this . getProjection ( ) . fromLatLngToDivPixel ( latlng ) ;
1100
- pos . x -= parseInt ( this . width_ / 2 , 10 ) ;
1101
- pos . y -= parseInt ( this . height_ / 2 , 10 ) ;
1103
+
1104
+ if ( typeof this . iconAnchor_ === 'object' && this . iconAnchor_ . length === 2 ) {
1105
+ pos . x -= this . iconAnchor_ [ 0 ] ;
1106
+ pos . y -= this . iconAnchor_ [ 1 ] ;
1107
+ } else {
1108
+ pos . x -= parseInt ( this . width_ / 2 , 10 ) ;
1109
+ pos . y -= parseInt ( this . height_ / 2 , 10 ) ;
1110
+ }
1102
1111
return pos ;
1103
1112
} ;
1104
1113
@@ -1194,6 +1203,7 @@ ClusterIcon.prototype.useStyle = function() {
1194
1203
this . anchor_ = style [ 'anchor' ] ;
1195
1204
this . textSize_ = style [ 'textSize' ] ;
1196
1205
this . backgroundPosition_ = style [ 'backgroundPosition' ] ;
1206
+ this . iconAnchor_ = style [ 'iconAnchor' ] ;
1197
1207
} ;
1198
1208
1199
1209
@@ -1224,6 +1234,10 @@ ClusterIcon.prototype.createCss = function(pos) {
1224
1234
this . anchor_ [ 0 ] < this . height_ ) {
1225
1235
style . push ( 'height:' + ( this . height_ - this . anchor_ [ 0 ] ) +
1226
1236
'px; padding-top:' + this . anchor_ [ 0 ] + 'px;' ) ;
1237
+ } else if ( typeof this . anchor_ [ 0 ] === 'number' && this . anchor_ [ 0 ] < 0 &&
1238
+ - this . anchor_ [ 0 ] < this . height_ ) {
1239
+ style . push ( 'height:' + this . height_ + 'px; line-height:' + ( this . height_ + this . anchor_ [ 0 ] ) +
1240
+ 'px;' ) ;
1227
1241
} else {
1228
1242
style . push ( 'height:' + this . height_ + 'px; line-height:' + this . height_ +
1229
1243
'px;' ) ;
@@ -1299,12 +1313,3 @@ Cluster.prototype['getMarkers'] = Cluster.prototype.getMarkers;
1299
1313
ClusterIcon . prototype [ 'onAdd' ] = ClusterIcon . prototype . onAdd ;
1300
1314
ClusterIcon . prototype [ 'draw' ] = ClusterIcon . prototype . draw ;
1301
1315
ClusterIcon . prototype [ 'onRemove' ] = ClusterIcon . prototype . onRemove ;
1302
-
1303
- Object . keys = Object . keys || function ( o ) {
1304
- var result = [ ] ;
1305
- for ( var name in o ) {
1306
- if ( o . hasOwnProperty ( name ) )
1307
- result . push ( name ) ;
1308
- }
1309
- return result ;
1310
- } ;
0 commit comments