Guest User

Untitled

a guest
Jun 19th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.31 KB | None | 0 0
  1. //so both features and color contain several hundred of value
  2. features.push(new ol.Feature(new ol.geom.Point([random_x, random_y])));
  3. color.push(random_color)
  4.  
  5. var source = new ol.source.Vector({
  6. features: features
  7. });
  8.  
  9. var clusterSource = new ol.source.Cluster({
  10. distance: 40,
  11. source: source
  12. });
  13.  
  14. var styleCache = {};
  15. var clusters = new ol.layer.Vector({
  16. name: 'clusterlayer',
  17. source: clusterSource,
  18. style: function (feature) {
  19. var size = feature.get('features').length;
  20. var style = styleCache[size];
  21. if (!style) {
  22. style = [new ol.style.Style({
  23. image: new ol.style.Circle({
  24. radius: 10,
  25. fill: new ol.style.Fill({
  26. color: '#000000'
  27. })
  28. }),
  29.  
  30. text: new ol.style.Text({
  31. font: 'bolder',
  32. text: size.toString(),
  33. fill: new ol.style.Fill({
  34. color: '#000000',
  35. })
  36. })
  37. })];
  38. styleCache[size] = style;
  39. }
  40. return style;
  41. }
  42. });
  43. this.state.map.addLayer(clusters);
Add Comment
Please, Sign In to add comment