user3186836
user3186836

Reputation:

Make one layer to not rotate with map

I have layer with pictures, I want them to stay as they are and don't rotate with map when I call map.getView().setRotation(x) . There is option to disable rotation for map, but is it possible to disable rotation for one layer?

Upvotes: 1

Views: 1183

Answers (2)

ahocevar
ahocevar

Reputation: 5647

If your "layer with pictures" is a vector layer with icon images, the icons won't rotate by default. You can control rotation of icons by configuring the icon style with the rotateWithView option. The default is false. Make sure you don't have a style like this:

new ol.style.Style({
  image: new ol.style.Icon({
    src: 'data/image.png',
    rotateWithView: true
  })
});

If you do, just remove the rotateWithView: true line.

If your layer is a WMS layer, and your images are point styles, you may be lucky to have a WMS server that supports rotation. Then you can add a vendor option (ANGLE for GeoServer and MapServer) and update that whenever the view rotation changes:

map.getView().on('change:rotation', function() {
  wmsLayer.getSource().updateParams({
    ANGLE: map.getView().getRotation() / Math.PI * 180
});

The above snippet assumes that map is your ol.Map instance and wmsLayer is your ol.layer.Image instance with an ol.source.ImageWMS.

Upvotes: 1

oterral
oterral

Reputation: 471

As far as I know, you can't disable rotation for one layer. As suggests the answer from @ahocevar the best practice should be to display your "pictures" in a separate vector layer and use the rotateWithView options in the style definition of this layer.

Upvotes: 0

Related Questions