根据缩放级别显示要素

时间:2017-05-31 14:34:17

标签: openlayers openlayers-3

我是openlayers图书馆的新手,我得到了一个问题。我渲染了很多功能,当地图缩小时,这些功能相互叠加,看起来非常难看,正如您在第一个屏幕截图中看到的那样。我希望缩小的地图(第一个屏幕)看起来像所有缩放级别的放大地图(第二个屏幕)。实现它的最常见方式是什么?

enter image description here

enter image description here

1 个答案:

答案 0 :(得分:1)

以下是样式函数的示例,该函数检测群集地图图层中的群组要素,并为群组对象绘制单个对象和圆的正方形:

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];
};
};

希望这有助于您的项目