Skip to content

Instantly share code, notes, and snippets.

@geoffroycochard
Created June 13, 2017 09:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save geoffroycochard/43246249854501f8250bb2c48cbf6274 to your computer and use it in GitHub Desktop.
Save geoffroycochard/43246249854501f8250bb2c48cbf6274 to your computer and use it in GitHub Desktop.
Spider effect custo
// 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