This repository has been archived by the owner on Jun 22, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Use overlayLayer and overlayMouseTarget #518
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -100,6 +100,7 @@ function ClusterIcon(cluster, styles) { | |
this.styles_ = styles; | ||
this.center_ = null; | ||
this.div_ = null; | ||
this.eventDiv_ = null; | ||
this.sums_ = null; | ||
this.visible_ = false; | ||
|
||
|
@@ -120,31 +121,36 @@ ClusterIcon.prototype.onAdd = function () { | |
|
||
this.div_ = document.createElement("div"); | ||
this.div_.className = this.className_; | ||
this.eventDiv_ = this.div_.cloneNode(); | ||
|
||
if (this.visible_) { | ||
this.show(); | ||
} | ||
|
||
this.getPanes().overlayMouseTarget.appendChild(this.div_); | ||
var panes = this.getPanes(); | ||
|
||
panes.overlayLayer.appendChild(this.div_) | ||
panes.overlayMouseTarget.appendChild(this.eventDiv_); | ||
|
||
// Fix for Issue 157 | ||
this.boundsChangedListener_ = google.maps.event.addListener(this.getMap(), "bounds_changed", function () { | ||
cDraggingMapByCluster = cMouseDownInCluster; | ||
}); | ||
|
||
google.maps.event.addDomListener(this.div_, "mousedown", function () { | ||
google.maps.event.addDomListener(this.eventDiv_, "mousedown", function () { | ||
cMouseDownInCluster = true; | ||
cDraggingMapByCluster = false; | ||
}); | ||
|
||
// March 1, 2018: Fix for this 3.32 exp bug, https://issuetracker.google.com/issues/73571522 | ||
// But it doesn't work with earlier releases so do a version check. | ||
if (gmVersion >= 332) { // Ugly version-dependent code | ||
google.maps.event.addDomListener(this.div_, "touchstart", function (e) { | ||
google.maps.event.addDomListener(this.eventDiv_, "touchstart", function (e) { | ||
e.stopPropagation(); | ||
}); | ||
} | ||
|
||
google.maps.event.addDomListener(this.div_, "click", function (e) { | ||
google.maps.event.addDomListener(this.eventDiv_, "click", function (e) { | ||
cMouseDownInCluster = false; | ||
if (!cDraggingMapByCluster) { | ||
var theBounds; | ||
|
@@ -184,7 +190,7 @@ ClusterIcon.prototype.onAdd = function () { | |
} | ||
}); | ||
|
||
google.maps.event.addDomListener(this.div_, "mouseover", function () { | ||
google.maps.event.addDomListener(this.eventDiv_, "mouseover", function () { | ||
var mc = cClusterIcon.cluster_.getMarkerClusterer(); | ||
/** | ||
* This event is fired when the mouse moves over a cluster marker. | ||
|
@@ -195,7 +201,7 @@ ClusterIcon.prototype.onAdd = function () { | |
google.maps.event.trigger(mc, "mouseover", cClusterIcon.cluster_); | ||
}); | ||
|
||
google.maps.event.addDomListener(this.div_, "mouseout", function () { | ||
google.maps.event.addDomListener(this.eventDiv_, "mouseout", function () { | ||
var mc = cClusterIcon.cluster_.getMarkerClusterer(); | ||
/** | ||
* This event is fired when the mouse moves out of a cluster marker. | ||
|
@@ -215,13 +221,14 @@ ClusterIcon.prototype.onRemove = function () { | |
if (this.div_ && this.div_.parentNode) { | ||
this.hide(); | ||
google.maps.event.removeListener(this.boundsChangedListener_); | ||
google.maps.event.clearInstanceListeners(this.div_); | ||
google.maps.event.clearInstanceListeners(this.eventDiv_); | ||
this.div_.parentNode.removeChild(this.div_); | ||
this.eventDiv_.parentNode.removeChild(this.eventDiv_); | ||
this.div_ = null; | ||
this.eventDiv_ = null; | ||
} | ||
}; | ||
|
||
|
||
/** | ||
* Draws the icon. | ||
*/ | ||
|
@@ -231,6 +238,8 @@ ClusterIcon.prototype.draw = function () { | |
this.div_.style.top = pos.y + "px"; | ||
this.div_.style.left = pos.x + "px"; | ||
this.div_.style.zIndex = google.maps.Marker.MAX_ZINDEX + 1; // Put above all unclustered markers | ||
|
||
this.syncDivStyle(); | ||
} | ||
}; | ||
|
||
|
@@ -241,7 +250,9 @@ ClusterIcon.prototype.draw = function () { | |
ClusterIcon.prototype.hide = function () { | ||
if (this.div_) { | ||
this.div_.style.display = "none"; | ||
this.syncDivStyle(); | ||
} | ||
|
||
this.visible_ = false; | ||
}; | ||
|
||
|
@@ -286,6 +297,11 @@ ClusterIcon.prototype.show = function () { | |
this.div_.title = this.sums_.title; | ||
} | ||
this.div_.style.display = ""; | ||
|
||
this.syncDivStyle({ | ||
title: this.div_.title, | ||
innerHTML: this.div_.innerHTML, | ||
}); | ||
} | ||
this.visible_ = true; | ||
}; | ||
|
@@ -361,6 +377,19 @@ ClusterIcon.prototype.getPosFromLatLng_ = function (latlng) { | |
return pos; | ||
}; | ||
|
||
/** | ||
* Sync the eventDiv_ size and position with the display div_ | ||
*/ | ||
ClusterIcon.prototype.syncDivStyle = function (vars) { | ||
if (vars) { | ||
Object.assign(this.eventDiv_, vars); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This line is used to sync any other DOMElement props outside of CSS. The only property I found that needed this was the |
||
} | ||
if (this.eventDiv_ && this.div_) { | ||
this.eventDiv_.style.cssText = this.div_.style.cssText; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The overlayDiv, |
||
this.eventDiv_.style.opacity = 0; | ||
} | ||
} | ||
|
||
|
||
/** | ||
* Creates a single cluster that manages a group of proximate markers. | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just before this line you should also be setting the innerHTML of the overlayMouseTarget div to the same as that of the overlayLayer div. This ensures the overlayMouseTarget div has exactly the same size as the overlayLayer div.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why wouldn't copying the height and width from the overlayDiv work without duplicating innerHTML?
I'm open to setting it and adding
opacity: 0
to line 388; it just seems unnecessary.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm just being cautious.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Syncing innerHTML to event div and setting opacity when css is updated (in
syncDivStyle
method)