Matlab mapping toolbox and the wmmarker function: how to change “description” from a web page to a file on the computer?

4 views (last 30 days)
I use the following matlab code to mark a point on a web map:
close all
webmap('World Imagery');
stationName = 'ST01';
description = '<a href="https://www.mathworks.com" target="_blank" rel="nofollow noopener noreferrer">https://www.mathworks.com</a>';
lat = 69.601142;
lon = 30.025769;
color = [0, 1, 0];
wmmarker(lat,lon,...
'FeatureName',stationName,...
'Description',description,...
'Color',color,...
'AutoFit',true);
The mark is clickable, with a lable containing station name and description of the point. In this minimum working example the description is an url.
How can I format the description variable to point to an image file on my pc?

Accepted Answer

Hank
Hank on 13 Nov 2019
Edited: Hank on 13 Nov 2019
According to the documentation page on wmmarker, "Description elements can be either plain text or HTML markup." HTML links to local files look like this:
<a href="file:///C:\path\to\file">Link Text</a>
So set your description as the HTML code and pass it to wmmarker just like you did:
webmap('World Imagery');
stationName = 'ST01';
description = '<a href="file:///C:\path\to\file">CLICKY</a>';
lat = 69.601142;
lon = 30.025769;
color = [0, 1, 0];
wmmarker(lat,lon,...
'FeatureName',stationName,...
'Description',description,...
'Color',color,...
'AutoFit',true);
Its possible your system will attempt to open the file in a browser, which might be weird depending on what you're trying to open.
  2 Comments
Espen Donali
Espen Donali on 13 Nov 2019
Thanks a lot. How would the file path look if it was releative to my working directory, instead of absolute, as in your answer?
Espen Donali
Espen Donali on 13 Nov 2019
The discription is shown on the label as a blue undrlined link, but nothing happends when trying to click it.

Sign in to comment.

More Answers (1)

Hank
Hank on 15 Nov 2019
I found the answer! I stumbled across this
I was wrong about the file path. The article says html links accept only http:// or matlab: protocols, the latter runs the matlab code written. So do this!
if you're on windows:
description = '<a href="matlab: winopen(''rel\path\to\file'')">CLICKY</a>'
and if you're on mac/linux
description = '<a href="matlab: unix(''xdg-open rel\path\to\file'')">CLICKY</a>'
Note, the doubled single quotes are used to escape the single quotes... read about it.
The linux bash command to open a file with the default application is xdg-open.
I hope that works! I'm not able to test it with the mapping toolbox, because I don't have it, but it worked printing links to the command line like
disp('<a href="matlab: winopen(''doc.pdf'')">CLICKY</a>')
  1 Comment
Espen Donali
Espen Donali on 18 Nov 2019
Edited: Espen Donali on 5 Dec 2019
Hi again, and thanks a lot for your efforts to help me!
Your solution works perfect in my command line as you demonstrated, but not in the web map. I have already asked a new question on this in the community. So in the command line my file was opened in a separate jpg window, but when clicking on the link on the map lable, the link does not open the same jpg file. It could be a bug within the mapping toolbox?
Never the less, your link functioned as html :)

Sign in to comment.

Categories

Find more on Debugging and Analysis in Help Center and File Exchange

Tags

Products


Release

R2019b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!