Displaying features based on zoom level

安稳与你 提交于 2019-12-09 03:30:31

Here is an example of a style function that detects group features from a cluster map layer and draws a square for individual object and circle for group objects:

var styleFunction = function() {
  return function(feature,resolution) {
    var style;
    var radius;
    var offsetY = -26;
    var gotGroup = false;

    var features = feature.get('features');

    if (features.length == 1) { //length = 1 - individual object instead of combo object
      style = new ol.style.Style({
        image: new ol.style.RegularShape({
        radius: 10,
        points: 4,
        angle: Math.PI / 4,
        fill: createFillStyle(feature),
        stroke: createStrokeStyle(feature,resolution,props)
        }),
        text: createTextStyle(feature, resolution, props)
      });
    } else {
      var rad = 11;
      if (features.length > 1) { //If group of features increase radius of object
        rad = 12;
        gotGroup = true;
      }
      style = new ol.style.Style({
        image: new ol.style.Circle({
        radius: rad,
        fill: createFillStyle(feature),
        stroke: createStrokeStyle(feature,resolution,props)
      }),
      text: createTextStyle(feature, resolution, props)
    });
  }
  return [style];
};
};

Hope this helps with your project

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!