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

Commit 5decb99

Browse files
authored
Update markerclusterer - moved to GitHub from SVN. (#433)
* Update markerclusterer - moved to GitHub from SVN. Added also images m1-m5. * Correct path to markers.
1 parent c881805 commit 5decb99

File tree

6 files changed

+40
-35
lines changed

6 files changed

+40
-35
lines changed

static/img/m1.png

2.93 KB
Loading

static/img/m2.png

3.18 KB
Loading

static/img/m3.png

3.86 KB
Loading

static/img/m4.png

5.57 KB
Loading

static/img/m5.png

6.68 KB
Loading

static/js/markerclusterer.js

Lines changed: 40 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
// ==ClosureCompiler==
22
// @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
44
// ==/ClosureCompiler==
55

66
/**
77
* @name MarkerClusterer for Google Maps v3
8-
* @version version 1.0.1
8+
* @version version 1.0
99
* @author Luke Mahe
1010
* @fileoverview
1111
* The library creates and manages per-zoom-level clusters for large amounts of
@@ -17,6 +17,9 @@
1717
*/
1818

1919
/**
20+
* @license
21+
* Copyright 2010 Google Inc. All Rights Reserved.
22+
*
2023
* Licensed under the Apache License, Version 2.0 (the "License");
2124
* you may not use this file except in compliance with the License.
2225
* You may obtain a copy of the License at
@@ -43,7 +46,7 @@
4346
* cluster.
4447
* 'zoomOnClick': (boolean) Whether the default behaviour of clicking on a
4548
* 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
4750
* the average of all markers in the cluster.
4851
* 'minimumClusterSize': (number) The minimum number of markers to be in a
4952
* cluster before the markers are hidden and a count
@@ -56,6 +59,7 @@
5659
* 'textColor': (string) The text color.
5760
* 'textSize': (number) The text size.
5861
* 'backgroundPosition': (string) The position of the backgound x, y.
62+
* 'iconAnchor': (Array) The anchor position of the icon x, y.
5963
* @constructor
6064
* @extends google.maps.OverlayView
6165
*/
@@ -161,12 +165,7 @@ function MarkerClusterer(map, opt_markers, opt_options) {
161165
// Add the map event listeners
162166
var that = this;
163167
google.maps.event.addListener(this.map_, 'zoom_changed', function() {
164-
// Determines map type and prevent illegal zoom levels
165168
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);
170169

171170
if (that.prevZoom_ != zoom) {
172171
that.prevZoom_ = zoom;
@@ -179,7 +178,7 @@ function MarkerClusterer(map, opt_markers, opt_options) {
179178
});
180179

181180
// Finally, add the markers
182-
if (opt_markers && (opt_markers.length || Object.keys(opt_markers).length)) {
181+
if (opt_markers && opt_markers.length) {
183182
this.addMarkers(opt_markers, false);
184183
}
185184
}
@@ -191,9 +190,7 @@ function MarkerClusterer(map, opt_markers, opt_options) {
191190
* @type {string}
192191
* @private
193192
*/
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';
197194

198195

199196
/**
@@ -404,14 +401,8 @@ MarkerClusterer.prototype.getCalculator = function() {
404401
* @param {boolean=} opt_nodraw Whether to redraw the clusters.
405402
*/
406403
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);
415406
}
416407
if (!opt_nodraw) {
417408
this.redraw();
@@ -1052,12 +1043,14 @@ function ClusterIcon(cluster, styles, opt_padding) {
10521043

10531044
/**
10541045
* Triggers the clusterclick event and zoom's if the option is set.
1046+
*
1047+
* @param {google.maps.MouseEvent} event The event to propagate
10551048
*/
1056-
ClusterIcon.prototype.triggerClusterClick = function() {
1049+
ClusterIcon.prototype.triggerClusterClick = function(event) {
10571050
var markerClusterer = this.cluster_.getMarkerClusterer();
10581051

10591052
// Trigger the clusterclick event.
1060-
google.maps.event.trigger(markerClusterer, 'clusterclick', this.cluster_);
1053+
google.maps.event.trigger(markerClusterer, 'clusterclick', this.cluster_, event);
10611054

10621055
if (markerClusterer.isZoomOnClick()) {
10631056
// Zoom into the cluster.
@@ -1082,8 +1075,18 @@ ClusterIcon.prototype.onAdd = function() {
10821075
panes.overlayMouseTarget.appendChild(this.div_);
10831076

10841077
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;
10871090
});
10881091
};
10891092

@@ -1097,8 +1100,14 @@ ClusterIcon.prototype.onAdd = function() {
10971100
*/
10981101
ClusterIcon.prototype.getPosFromLatLng_ = function(latlng) {
10991102
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+
}
11021111
return pos;
11031112
};
11041113

@@ -1194,6 +1203,7 @@ ClusterIcon.prototype.useStyle = function() {
11941203
this.anchor_ = style['anchor'];
11951204
this.textSize_ = style['textSize'];
11961205
this.backgroundPosition_ = style['backgroundPosition'];
1206+
this.iconAnchor_ = style['iconAnchor'];
11971207
};
11981208

11991209

@@ -1224,6 +1234,10 @@ ClusterIcon.prototype.createCss = function(pos) {
12241234
this.anchor_[0] < this.height_) {
12251235
style.push('height:' + (this.height_ - this.anchor_[0]) +
12261236
'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;');
12271241
} else {
12281242
style.push('height:' + this.height_ + 'px; line-height:' + this.height_ +
12291243
'px;');
@@ -1299,12 +1313,3 @@ Cluster.prototype['getMarkers'] = Cluster.prototype.getMarkers;
12991313
ClusterIcon.prototype['onAdd'] = ClusterIcon.prototype.onAdd;
13001314
ClusterIcon.prototype['draw'] = ClusterIcon.prototype.draw;
13011315
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

Comments
 (0)