0

I am trying to figure out a way to get actual width and height of point feature. I.e., the image + text and not just the latitude / longitude of the geometry.

So far, I learnt that I could get coordinates by using the following code:

feature.getGeometry().getCoordinates();

But this gives me the exact coordinate where the feature was added but what I want is the width and height of the feature after it has been rendered. I.e., height = height of image + height of the label.

I am doing this to start wrapping texts when two feature are very closes to each other.

node_modules
  • 4,790
  • 6
  • 21
  • 37
Vishal
  • 816
  • 11
  • 19
  • You could use `measureText` https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/measureText based on the wrapping algorithm used by ol-mapbox-style in https://github.com/openlayers/ol-mapbox-style/blob/main/src/text.js – Mike Feb 05 '23 at 00:34

1 Answers1

0

to get the height and width of an icon of a point in openlayers you can use:

feature.getStyle().getImage().getScale()
feature.getStyle().getText().getScale()

I must mention the fact that if you have not specified scales for the text and for the icon in the style, you will receive undefined