2

My map tips are not showing images and instead show only paths in QGIS.

HTML image

Map tip

2
  • Welcome to GIS SE! We're a little different from other sites. We're a Q&A site, not a discussion forum. For questions that involve code we ask that you show us where you are stuck with your own code by including a code snippet in your question. There is an edit button beneath your question which will enable you to do that and a {} button that enables you to format any highlighted code (like your HTML) nicely. Please check out our short tour for more about how the site works. Thanks.
    – PolyGeo
    Mar 31, 2019 at 8:15
  • 1
    This still isn't working for me. I have the following code, and it just displays a blank window. Any ideas? <img src='file:///[% @project_home %]/name_of_folder_with_images/[% 'name_of_column_in_csv_with_imagenames' %]' width='450'></img> Mar 25, 2020 at 11:57

3 Answers 3

5

Three things needs to be addessed:

1) as @snaileater said, the path must be quoted
2) the ending </img> tag must not contain spaces, else is will be printed as text
3) a local file URL must start with file:\\

Here is a example displaying a local file:

[% concat('<img src=\'file:\\',"path", '\' width="400"></img>') %]
0
4

You should check the following points:

1) The path string must be quoted in your resulting string which is not the case in the sreenshot you provided.

2) You seem to be attempting to load local file image: your images have to be on a local or remote server.

3) (in any case u forgot it): you must activate maps tip ("Layer/Show Map Tips")

4) Here is a working example:

[% concat('<img src=\'http://localhost/images/text-letter-',right("city_name",1),'.svg\'>') %]

to have quote in the final string you must 'escape' special characters using the "\" ...

In the example I load an svg file whose name will be depending on the first letter of "city_name"

PS: a bit of formatting in the questions are always welcome ...

1
  • A nice trick while experimenting is to duplicate the internals of the <img...> tag outside of the tag so you can see what you are attempting. E.g something like this untested bit: [% concat('_img src=\'http://localhost/images/text-letter-',right("city_name",1),'.svg\'_') %] - [% concat('<img src=\'http://localhost/images/text-letter-',right("city_name",1),'.svg\'>') %] then you can see your text before if goes into the angle brackets.
    – Dave X
    Mar 30, 2023 at 18:28
0

You can experiment with the maptips to see how the string you are using parses out before you put it in the image tag. You can also construct the paths from variables like [% @project_folder %] to get relative paths.

This three-line html in map Tips produced the tip below:

explicit path: file:///Users/drf/Documents/mergin/drf-test-1/[%photo%]
<p>
Folder: file://[%  @project_folder %]/[%photo%]
<p>
ImgPaths <img src="file://[%  @project_folder %]/[%photo%]" width="100" height="100"></img>

The Map Tip HTML code within Layer/properties/Display:

Layer/properties/Display/Map tips image

hover-over maptip from the above code

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.