3

I would like to know if it is possible to create a polygon or even just add some text that will stay in the same place on the screen even when I pan the map (in the same way that a legend is always visible on the display regardless of the panning of the map).

I am using QGIS but I need to save the file in a way that GeoServer can publish it (it would be best if I can do this using a shapefile).

Random example to make the question clear: example

I am very new to this, so I am sorry if something doesn't make sense. I tried researching this but I think I am missing the keywords because I couldn't find relevant information.

TomazicM
  • 25,601
  • 22
  • 29
  • 39

2 Answers2

5

Building this in QGIS won't help when it comes to GeoServer's WMS, you need to look at the WMS Decorators that GeoServer provides for this. I think the text decorator should do most of what you want.

Ian Turton
  • 81,417
  • 6
  • 84
  • 185
5

Solution: Geometry Generator

You can use Geometry Generator to create the boxes, based on the variable @map_extent that generates a polygon representing the current extent of the map canvas. Form the upper left point of this polygon (corner of map canvas), create a rectangular box with a length/width and distance from top/left border dependent on the canvas extent of the current zoom level. If you e.g. set the length of to polygon to one fifth of the width of the map canvas, on your screen it will always appear in the same size.

One created the box, multiply this box with a certain space in between using array_foreach() and convert the array of geometries to a geometry collection (multipart geometry) with collect_geometries().

enter image description here

enter image description here

Implementation: the expression

  1. Create a new polygon layer, covering the whole extent of your project.

  2. Set the layer's symbol layer type to Geometry Generator of Geomtry type Polygon and paste the following expression - in lines 4 to 7, you can change the position and size of the rectancles; in line 3, you can change to number of rectangles to be created:

     collect_geometries(
         array_foreach (
             generate_series (0,2), -- change here for the number of rectangles: there will be one more rectangle than the last number indicates - here, you'll get 2+1=3 rectangles
         with_variable ('long', (x_max(@map_extent)-x_min(@map_extent ))/5, -- length of rectangles
         with_variable( 'width', @long/4,  -- width of rectangle (fragment of length)
         with_variable ('top', @map_scale*-0.05,  -- distance from top border of map canvas
         with_variable ('left', @map_scale*-0.01, -- distance from left border of map canvas
         with_variable ('point', make_point ( 
             x_min (buffer (@map_extent, @left)),
             y_max (buffer (@map_extent, @top)) -@element*1.3*@width
             ),
             make_polygon( 
                 make_line(
                     @point,
                     project (@point, @long, radians (90)),
                     project (
                         project (@point, @long, radians (90)),
                         @width,
                         radians (180)
                     ),
                     project (@point, @width, radians (180))
     )))))))))
    
  3. To add a label, in the Placement tab activate Geometry Generator and insert the same expression and select mode Offset from Point. In the Rendering tab, Check the box Label every part of multi-part feature.

Babel
  • 71,072
  • 14
  • 78
  • 208