Matlab mapping toolbox and the wmmarker function: how to change “description” from a web page to a file on the computer?
7 views (last 30 days)
Show older comments
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?
0 Comments
Accepted Answer
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.
More Answers (1)
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>')
See Also
Categories
Find more on Data Import and Export in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!