Created
June 13, 2017 09:08
-
-
Save geoffroycochard/43246249854501f8250bb2c48cbf6274 to your computer and use it in GitHub Desktop.
Spider effect custo
This file contains hidden or 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
// No spider effect until zoom 18 | |
if (this.map.zoom < 18) { | |
return; | |
} | |
// Group markers by position | |
var groups = _.groupBy(this.map.markers, function (marker) { | |
return marker.latitude + ';' + marker.longitude; | |
}); | |
// Offsets | |
var lngOffset = 0.0001; | |
var latOffset = 0.00006; | |
if (this.map.zoom === 22) { | |
lngOffset = 0.00005; | |
latOffset = 0.00003; | |
} | |
// Move markers at the same position on a circle having for center the common position | |
_.forEach(groups, function (group) { | |
if (group.length > 1) { | |
_.forEach(group, function (marker, index) { | |
// Compute new position | |
var longitude = marker.longitude + lngOffset * Math.cos(2 * Math.PI / group.length * (index + 1)); | |
var latitude = marker.latitude + latOffset * Math.sin(2 * Math.PI / group.length * (index + 1)); | |
// Add polyline between old and new position | |
this.map.polylines.push([ | |
{ lat: marker.latitude, lng: marker.longitude }, | |
{ lat: latitude, lng: longitude } | |
]); | |
// Set new position on marker | |
marker.longitude = longitude; | |
marker.latitude = latitude; | |
}.bind(this)) | |
} | |
}.bind(this)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment