addCustomBasemap
Add custom basemap
Syntax
Description
addCustomBasemap(
adds the custom basemap specified by basemapName
,URL
)URL
to the list of basemaps
available for use with mapping functions. basemapName
is the name you
choose to call the custom basemap. Added basemaps remain available for use in future
MATLAB® sessions.
You can use custom basemaps with several types
of map displays, for example, web maps created using the webmap
function, geographic globes created using the geoglobe
function,
and geographic axes created using the geoaxes
function.
addCustomBasemap(
adds the custom basemap specified by basemapName
,mbtilesFilename
)mbtilesFilename
, an MBTiles file
containing a tile set of raster data. You can use the basemap in future MATLAB sessions, provided the MBTiles file is still on the same path as when you add
it.
Web maps do not support custom basemaps created from MBTiles files.
addCustomBasemap(___,
specifies name-value arguments that set additional parameters of the basemap.Name,Value
)
Examples
Add Basemap from OpenStreetMap
Display locations on a geographic bubble chart using a basemap from OpenStreetMap®.
Define the name that you will use to specify your custom basemap.
name = 'openstreetmap';
Specify the website that provides the map data. The first character of the URL indicates which server to use to get the data. For load balancing, the provider has three servers that you can use: a, b, or c.
url = 'a.tile.openstreetmap.org';
Create an attribution to display on the map that gives credit to the provider of the map data. Web map providers might define specific requirements for the attribution.
copyright = char(uint8(169));
attribution = copyright + "OpenStreetMap contributors";
Add the custom basemap to the list of basemap layers available.
addCustomBasemap(name,url,'Attribution',attribution)
Plot the locations over the map using a geographic bubble chart. You can specify your custom basemap when you create the geographic bubble chart.
lat = [42.3501 42.3515 42.3598 42.3584 42.3529]; lon = [-71.0870 -71.0926 -71.0662 -71.0598 -71.0662]; gb = geobubble(lat,lon,'Basemap','openstreetmap'); gb.BubbleWidthRange = 25; gb.MapLayout = 'maximized'; gb.ZoomLevel = 14;
Add Basemap from USGS National Map
Display the route of a glider in 2-D and 3-D using a topographic basemap from the USGS National Map.
Before adding the basemap, specify the location of the map tiles. To do this, specify the URL of the National Map ArcGIS REST Services Directory. Then, add the path to the map tiles from the USGS Topo basemap service.
url = "https://basemap.nationalmap.gov/ArcGIS/rest/services"; fullurl = url + "/USGSTopo/MapServer/tile/${z}/${y}/${x}";
Specify a name for the basemap and attribution text to display with it.
nm = 'usgstopo'; att = 'Credit: US Geological Survey';
Finally, add the USGS Topo basemap.
addCustomBasemap(nm,fullurl,'Attribution',att)
Plot the path of a glider over the basemap. To do this, import latitude, longitude, and geoid height values.
trk = gpxread('sample_mixed','FeatureType','track'); lat = trk.Latitude; lon = trk.Longitude; h = trk.Elevation;
Display the path in 2-D using geographic axes. Specify the basemap using the
geobasemap
function and the name of the basemap. Use the basemap
name given when you created it.
geobasemap usgstopo geoplot(lat,lon,'r')
Display the path in 3-D using a geographic globe. Specify the basemap using the
'Basemap'
name-value pair argument. By default, the view is
directly above the path. Tilt the view by holding Ctrl and
dragging.
uif = uifigure; g = geoglobe(uif,'Basemap','usgstopo'); geoplot3(g,lat,lon,h,'r')
Add Basemap from OpenTopoMap
Display the route of a glider on a web map using a basemap from OpenTopoMap.
Define the name that you will use to specify your custom basemap.
name = "opentopomap";
Specify the website that provides the map data. The first character of the URL indicates which server to use to get the data. For load balancing, the provider has three servers that you can use: a
, b
, or c
.
url = "a.tile.opentopomap.org";
Create an attribution to display on the map that gives credit to the provider of the map data. Web map providers might define specific requirements for the attribution.
copyright = char(uint8(169)); attribution = [ ... "map data: " + copyright + "OpenStreetMap contributors,SRTM", ... "map style: " + copyright + "OpenTopoMap (CC-BY-SA)"];
Define the name that will appear in the Layer Manager to represent your custom basemap.
displayName = "Open Topo Map";
Add the custom basemap to the list of available basemap layers.
addCustomBasemap(name,url,"Attribution",attribution, ... "DisplayName",displayName)
Open a web map. Specify the custom basemap using the name you defined when you added it. Then, read glider data into the workspace and plot it over the basemap.
webmap opentopomap trk = readgeotable("sample_mixed.gpx","Layer","tracks"); wmline(trk,"LineWidth",2)
Add Several Basemaps from USGS National Map
Plot the path of a glider over a variety of maps that are available from the USGS National Map site. Viewing data over several maps can help you determine which map provides the best background.
Read in the glider path track data.
GT = readgeotable("sample_mixed.gpx","Layer","tracks");
Specify the custom basemap URL. The USGS National Map supports several tiled web maps. For this example, insert the word BASEMAP
into the URL string. In this way, you can replace the word BASEMAP
with the name of one of the maps supported by the USGS National Map.
baseURL = "https://basemap.nationalmap.gov/ArcGIS/rest/services"; usgsURL = baseURL + "/BASEMAP/MapServer/tile/${z}/${y}/${x}";
Specify a list of the names of USGS basemaps that you want to use. These names will be inserted into the URL in place of BASEMAP
.
basemaps = ["USGSImageryOnly" "USGSImageryTopo" "USGSTopo" "USGSHydroCached"];
Specify a list of display names that you can use with each map. Use display names that are the same as those used by webmap
so that webmap
does not contain duplicate maps.
displayNames = ["USGS Imagery" "USGS Topographic Imagery" ... "USGS Shaded Topographic Map" "USGS Hydrography"]; maxZoomLevel = 16;
Create a map attribution to give credit to the provider of the map data.
attribution = "Credit: U.S. Geological Survey";
Create a loop in which you use each basemap with the geoplot
function, plotting the glider data on each of the USGS basemaps.
for k =1:length(basemaps) basemap = basemaps(k); name = lower(basemap); url = replace(usgsURL,"BASEMAP",basemap); displayName = displayNames(k); addCustomBasemap(name,url,"Attribution",attribution, ... "DisplayName",displayName,"MaxZoomLevel",maxZoomLevel) figure geobasemap(basemap) geoplot(GT,"r","LineWidth",5); title(displayName) end
Add Basemap from MBTiles File
Create a basemap from an MBTiles file containing USGS Imagery.
Add the USGS Imagery basemap to the list of basemaps available for use. The addCustomBasemap
function uses the attribution and maximum zoom level contained in the file.
basemap = "usgsimagery"; mbtilesFilename = "usgsimagery.mbtiles"; addCustomBasemap(basemap,mbtilesFilename)
Read worldwide land areas into the workspace as a geospatial table. Create a subtable containing only Australia.
GT = readgeotable("landareas.shp"); australia = GT(GT.Name == "Australia",:);
Display the outline of Australia over the USGS Imagery basemap.
figure geoplot(australia,"LineWidth",2,"FaceColor","none") geobasemap usgsimagery
Input Arguments
basemapName
— Name used to identify basemap programmatically
string scalar | character vector
Name used to identify basemap programmatically, specified as a string scalar or character vector.
Example: 'openstreetmap'
Data Types: string
| char
URL
— Parameterized map URL
string scalar | character vector
Parameterized map URL, specified as a string scalar or character vector. A
parameterized URL is an index of the map tiles, formatted as
${z}/${x}/${y}.png
or {z}/{x}/{y}.png
, where:
${z}
or{z}
is the tile zoom level.${x}
or{x}
is the tile column index.${y}
or{y}
is the tile row index.
Example: 'https://hostname/${z}/${x}/${y}.png'
Data Types: string
| char
mbtilesFilename
— Name of MBTiles file
character vector | string scalar
Name of an MBTiles file containing a tile set of raster data, specified as a
character vector or string scalar. You must include the extension
.mbtiles
. The form of mbtilesFilename
depends on
the location of your file.
If the file is in your current folder or in a folder on the MATLAB path, then specify the name of the file, such as
"myFile.mbtiles"
.If the file is not in the current folder or in a folder on the MATLAB path, then specify the full or relative path name, such as
"C:/myfolder/myFile.mbtiles"
or"dataDir/myFile.mbtiles"
.
Data Types: char
| string
Name-Value Arguments
Specify optional pairs of arguments as
Name1=Value1,...,NameN=ValueN
, where Name
is
the argument name and Value
is the corresponding value.
Name-value arguments must appear after other arguments, but the order of the
pairs does not matter.
Before R2021a, use commas to separate each name and value, and enclose
Name
in quotes.
Example: addCustomBasemap(basemapName,URL,"Attribution",attribution)
Attribution
— Attribution of custom basemap
string scalar | string array | character vector | cell array of character vectors
Attribution of the custom basemap, specified as a string scalar, string array, character vector, or cell array of character vectors. To create a multiline attribution, specify a string array or nonscalar cell array of character vectors.
When you create a custom basemap from a URL, the default attribution is
'Tiles courtesy of
, where
DOMAIN_NAME_OF_URL
'
is the domain
name from the DOMAIN_NAME_OF_URL
URL
input argument. If the host is
'localhost'
, or if URL
contains only IP
numbers, specify the attribution as an empty string (""
).
When you create a custom basemap from an
MBTiles file with an attribution in the metadata, the
addCustomBasemap
function gets the attribution from the file.
If the file does not contain an attribution, the default attribution is an empty
string.
Example: "Credit: U.S. Geological Survey"
Data Types: string
| char
| cell
DisplayName
— Display name of custom basemap
string scalar | character vector
Display name of the custom basemap, specified as a string scalar or character vector.
The webmap
function uses this name in the Layer Manager. The addToolbarMapButton
function uses this name in the basemap
picker.
Example: "OpenStreetMap"
Data Types: string
| char
MaxZoomLevel
— Maximum zoom level of basemap
18
(default) | integer in range [0, 25]
Maximum zoom level of the basemap, specified as an integer in the range [0, 25].
When you create a custom basemap from an
MBTiles file with the maximum zoom level in the metadata, the
addCustomBasemap
gets the maximum zoom level from the
file.
Data Types: single
| double
| int8
| int16
| int32
| int64
| uint8
| uint16
| uint32
| uint64
IsDeployable
— Map is deployable using MATLAB Compiler™
false
or 0
(default) | true
or 1
Map is deployable using MATLAB
Compiler, specified as a numeric or logical 0
(false
) or 1
(true
).
To deploy a map application that uses a
custom basemap, set IsDeployable
to true
. If you
create the custom basemap from an MBTiles file, then you must include the file in the
deployed application package, unless you deploy the application to the same computer
you used to compile the application or if the file is on a network file system that
the application can access from a different computer. You must set this argument
whether you use the addCustomBasemap
function in your application
or outside your application.
Data Types: logical
Limitations
The addCustomBasemap
function does not support adding custom basemaps
from vector map tiles.
Tips
You can find tiled web maps from various vendors, such as OpenStreetMap®, the USGS National Map, Mapbox, DigitalGlobe, Esri® ArcGIS Online, the Geospatial Information Authority of Japan (GSI), and HERE Technologies. Abide by the map vendors terms-of-service agreement and include accurate attribution with the maps you use.
To access a list of available basemaps, press Tab before specifying the basemap in your plotting function. This image shows a sample list of available basemaps, including several custom basemaps from the USGS National Map.
Version History
Introduced in R2018bR2022a: Add custom basemaps from MBTiles files
Add a custom basemap from an MBTiles file containing raster map tiles. Creating custom
basemaps from MBTiles files is useful when you do not have internet access. Mapping Toolbox™ includes an MBTiles file with low-resolution USGS imagery called
usgsimagery.mbtiles
.
MATLAB 命令
您点击的链接对应于以下 MATLAB 命令:
请在 MATLAB 命令行窗口中直接输入以执行命令。Web 浏览器不支持 MATLAB 命令。
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)