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

4 visualizzazioni (ultimi 30 giorni)
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?

Risposta accettata

Hank
Hank il 13 Nov 2019
Modificato: Hank il 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 Commenti
Espen Donali
Espen Donali il 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 il 13 Nov 2019
The discription is shown on the label as a blue undrlined link, but nothing happends when trying to click it.

Accedi per commentare.

Più risposte (1)

Hank
Hank il 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 Commento
Espen Donali
Espen Donali il 18 Nov 2019
Modificato: Espen Donali il 5 Dic 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 :)

Accedi per commentare.

Categorie

Scopri di più su Debugging and Analysis in Help Center e File Exchange

Tag

Prodotti


Release

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by