-
-
Save jnachtigall/d6d59d2f55fd75b462e0 to your computer and use it in GitHub Desktop.
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
<!doctype html> | |
<html lang="en"> | |
<head> | |
<meta charset="utf-8"> | |
<meta http-equiv="X-UA-Compatible" content="chrome=1"> | |
<meta name="viewport" content="initial-scale=1.0, user-scalable=no, width=device-width"> | |
<style> | |
html, body, .map { height: 100%; width: 100%; }; | |
</style> | |
<link href="http://openlayers.org/en/v3.1.1/build/ol.css" rel='stylesheet' type='text/css' /> | |
</head> | |
<body> | |
<div id="map" class="map"></div> | |
<script src="http://openlayers.org/en/v3.1.1/build/ol.js" type="text/javascript"></script> | |
<script src="index.js" type="text/javascript"></script> | |
</body> | |
</html> |
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
var source = new ol.source.Vector({}); | |
var clusterSource = new ol.source.Cluster({ | |
distance: 40, | |
source: source | |
}); | |
var styleCache = {}; | |
var clusters = new ol.layer.Vector({ | |
source: clusterSource, | |
style: function(feature, resolution) { | |
var size = feature.get('features').length; | |
var style = styleCache[size]; | |
if (!style) { | |
style = [new ol.style.Style({ | |
image: new ol.style.Circle({ | |
radius: 10, | |
stroke: new ol.style.Stroke({ | |
color: '#fff' | |
}), | |
fill: new ol.style.Fill({ | |
color: '#3399CC' | |
}) | |
}), | |
text: new ol.style.Text({ | |
text: size.toString(), | |
fill: new ol.style.Fill({ | |
color: '#fff' | |
}) | |
}) | |
})]; | |
styleCache[size] = style; | |
} | |
return style; | |
} | |
}); | |
var raster = new ol.layer.Tile({ | |
source: new ol.source.MapQuest({layer: 'sat'}) | |
}); | |
var map = new ol.Map({ | |
layers: [raster, clusters], | |
renderer: 'canvas', | |
target: 'map', | |
view: new ol.View({ | |
center: [0, 0], | |
zoom: 2 | |
}) | |
}); | |
var e = 4500000; | |
function addFeature() { | |
var coordinates = [2 * e * Math.random() - e, 2 * e * Math.random() - e]; | |
var feature = new ol.Feature(new ol.geom.Point(coordinates)); | |
source.addFeature(feature); | |
} | |
function removeFeature() { | |
var feats = source.getFeatures(); | |
if (feats.length) { | |
var f = feats[Math.floor(Math.random() * feats.length)]; | |
source.removeFeature(f); | |
} | |
} | |
function clearFeatures() { | |
source.clear(); | |
} | |
window.setInterval(addFeature, 500); | |
window.setInterval(removeFeature, 1000); | |
window.setInterval(clearFeatures, 10000) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment