Command to toggle webmap overlays?

2 ビュー (過去 30 日間)
Jennifer Loe
Jennifer Loe 2023 年 12 月 21 日
回答済み: Shubham 2024 年 12 月 3 日
Hi, I have a mapping application where I am plotting a rectangle on a webmap. My script calls
webMapObj = webmap('World Imagery');
and brings up the appropriate map. I can click the map options to toggle the overlay layers as in this link:
I like the option for the "World Boundaries (Light Text)". I would like to be able to toggle this option from my script so that it turns on automatically without having to touch the checkbox in the GUI. However, I cannot find the commands for this. What commands can I type in the Command Window and/or my script to toggle on/off the "World Boundaries"?
Thanks!

回答 (1 件)

Shubham
Shubham 2024 年 12 月 3 日
Hi Jennifer,
It seems you are looking to toggle webmap overlays in MATLAB programmatically. While MATLAB's webmap function does not directly support toggling overlays like "World Boundaries (Light Text)" from a script, you can achieve similar functionality with these workarounds:
  • Add custom overlays to a webmap using functions like wmline, wmpolygon, or wmoverlay.
% Open web map
webMapObj = webmap('World Imagery');
% Example coordinates for a rectangular boundary
lat = [40, 40, 41, 41, 40]; % Example latitudes
lon = [-75, -74, -74, -75, -75]; % Example longitudes
% Plot the boundary as a polygon
wmpolygon(lat, lon, 'FaceColor', 'none', 'EdgeColor', 'blue', 'LineWidth', 2);
  • If you have specific boundary data in shapefiles or GeoJSON, load them and overlay them:
% Load shapefile
S = shaperead('world_boundaries.shp'); % Replace with your shapefile
% Overlay each boundary
for k = 1:length(S)
wmpolygon(S(k).Lat, S(k).Lon, 'FaceColor', 'none', 'EdgeColor', 'black');
end
  • Consider creating a custom basemap with overlays baked using addCustomBasemap if you frequently use specific overlays
For more details on webmap, refer to the following documentation link:
Hope this helps.

カテゴリ

Help Center および File ExchangeExponents and Logarithms についてさらに検索

タグ

製品


リリース

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by