【问题标题】:Openlayers 3 - different style/marker for each point on a MultiPoint featureOpenlayers 3 - MultiPoint 功能上每个点的不同样式/标记
【发布时间】:2016-12-21 07:01:03
【问题描述】:

我有一个带有以下地理 json 的多点功能。

{
    "type": "Feature",
    "geometry": {
        "type": "MultiPoint",
        "coordinates": [
            [
                -123,
                58
            ],
            [
                -152.32,
                17.5
            ],
            [
                52.02,
                42.64
            ]
        ]
    }
}

当我在地图上绘制它并通过样式函数应用任何图标时,它适用于所有点。但我想在地图上用不同的图标显示上面的所有 3 个坐标。有什么方法可以为多点特征中的每个坐标添加不同的标记?

【问题讨论】:

标签: javascript gis openlayers-3 geojson multipoint


【解决方案1】:

要在MultiPoint中为不同的坐标应用不同的样式需要为每个坐标编写不同的样式。我在 plunker 中创建了一个视图。遍历这个link中的代码

new ol.style.Style({
    image: new ol.style.Circle({
      radius: 5,
      fill: new ol.style.Fill({
        color: 'orange'
      })
    }),
    geometry: function(feature) {
      var coordinates = feature.getGeometry().getCoordinates();
      return new ol.geom.Point(coordinates[0]);
    }
  })

在几何函数中考虑单个坐标并为其应用样式。

注意:如果 MultiPoint 的点数较多,代码会臃肿。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多