Skip to content

Instantly share code, notes, and snippets.

@slovely
Created January 27, 2016 22:13
Show Gist options
  • Save slovely/56605a78b4307cc80fff to your computer and use it in GitHub Desktop.
Save slovely/56605a78b4307cc80fff to your computer and use it in GitHub Desktop.
OverlappingFeatureSpiderfier.js example
<html>
<head>
<style type="text/css">
html, body { height: 100%; margin: 0; padding: 0; }
#map { height: 100%; }
</style>
</head>
<body>
<div id="map" style="width:100%;height:100%"></div>
<script src="https://code.jquery.com/jquery-2.2.0.js" ></script>
<script src="https://maps.googleapis.com/maps/api/js" ></script>
<script src="overlappingfeaturespiderfier.js"></script>
<script>
var map;
function initMap() {
map = new google.maps.Map(document.getElementById('map'), {
center: {lat: 50.397, lng: 3.644},
zoom: 6
});
var ofs = new OverlappingFeatureSpiderfier(map.data);
ofs.addListener("click", function(event) {
var theFeatureThatWasClicked = event.feature;
alert('clicked marker ' + theFeatureThatWasClicked.getProperty("title"));
});
for (var i = 0; i < 10; i++) {
var pos = new google.maps.LatLng(51, -5.2);
var geo = new google.maps.Data.Point(pos);
var opts = {};
opts.geometry = geo;
opts.id = i;
opts.properties = {
title: "marker" + i,
visible: true
};
var markerFeature = map.data.add(opts);
}
}
window.onload = function() {
initMap();
}
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment