Firstly, hopefully you are aware that if you set the image field's edit widget in QGIS to 'Photo', the images appear in your popups without any editing of code?
The rest of this answer is untested:
For an OpenLayers 3 export, you need to edit resources/qgis2web.js
in a text editor. This will only work if only one of your fields is an image. Search for the following code (around line 119):
popupField += (currentFeature.get(currentFeatureKeys[i]) != null ? '<img src="images/' + currentFeature.get(currentFeatureKeys[i]).replace(/[\\\/:]/g, '_').trim() + '" /></td>' : '');
Change it to:
popupField += (currentFeature.get(currentFeatureKeys[i]) != null ? '<a href="' + currentFeature.get('URL_COLUMN') + '"><img src="images/' + currentFeature.get(currentFeatureKeys[i]).replace(/[\\\/:]/g, '_').trim() + '" /></a></td>' : '');
Replace URL_COLUMN
with the name of the column which has the address you want to link to.
For a Leaflet export, the file you need to edit is index.html
. You need to find the function defined with the following code:
function pop_LAYER_NAME0(feature, layer) {
where LAYER_NAME
is the layer which contains your image. Within that function should be some code including the <img>
tag (it will vary according to what popup field heading layout you have specified):
<td colspan="2"><strong>IMAGE_COLUMN</strong><br />' + (feature.properties['IMAGE_COLUMN'] !== null ? '<img src="images/' + String(feature.properties['IMAGE_COLUMN']).replace(/[\\/:]/g, '_').trim() + '">' : '') + '</td>
where IMAGE_COLUMN
is the name of the field which has your image. Change this to:
<td colspan="2"><strong>IMAGE_COLUMN</strong><br />' + (feature.properties['IMAGE_COLUMN'] !== null ? '<a href="' + feature.properties['URL_COLUMN'] + '"><img src="images/' + String(feature.properties['IMAGE_COLUMN']).replace(/[\\/:]/g, '_').trim() + '"></a>' : '') + '</td>\
where IMAGE_COLUMN
is still the column with your image, and URL_COLUMN
is the column with the link address.