简体   繁体   中英

Openlayers 3 - different style/marker for each point on a MultiPoint feature

I have a MultiPoint feature with the following geo json.

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

When I draw this on map and apply any icon through a style function, its applied for all points.But I would like to show all 3 coordinates above with different icons on map. Is there any way I can add different markers for each coordinates in a Multipoint feature?

To apply different style for different coordinates in MultiPoint need to write different styles for each coordinate. I have created a view in plunker. Go through the code in this 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]);
    }
  })

In the geometry function consider a single coordinate and apply style for it.

Note: If MultiPoint has more number of points the code will be bloated.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM