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

조회 수: 7 (최근 30일)
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?

채택된 답변

Hank
Hank 2019년 11월 13일
편집: Hank 2019년 11월 13일
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
Espen Donali
Espen Donali 2019년 11월 13일
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 2019년 11월 13일
The discription is shown on the label as a blue undrlined link, but nothing happends when trying to click it.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Hank
Hank 2019년 11월 15일
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
Espen Donali
Espen Donali 2019년 11월 18일
편집: Espen Donali 2019년 12월 5일
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 :)

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Data Import and Export에 대해 자세히 알아보기

태그

제품


릴리스

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by