Presenting spatial data on top of a geographic map is a desirable feature for any application to have. Ideally this map should be zoomable, meaning that more details become visible when the user zooms in. Adding functionality like this to a Matlab application has become very easy thanks to the Modelit MapViewer component.

Matlab code snippet

%Open a new figure on monitor 2:
HWIN=figure('pos',[2073 553 560 420]);

%Create the MapViewer object
m = modelit.mapviewer.MapViewer(HWIN);

%Center the map in the figure
set(m.handle,'units','normalized','pos',[.1 .1 .8 .8]);

%Select the Area to display (in this case: the Netherlands)
setVisibleRectangle(m, [ 2.4558   50.7183    5.7675    2.6999]);

%A Matlab figure with a zoomable map is now visible. 
%Its content is served by (for example)
%Continue by plotting some data of our own:

%load linedata for the Dutch Motorway&Trunk roads network: 

%Plot the data

%h is a native Matlab line object
set(h,'buttondown',@(o,e)disp('Button Pressed'))

The MapViewer object contains the methods line, patch and text to plot data on top of the map. These are used in exactlty the same manner as Matlabs native line, patch and text methods. For example, to overlay a road network we load some sample data from the dataset “highways.mat”. This dataset contains the vectors “x” and “y” being the (WGS) coordinates of each road segment, separated by NaN values. Using the line method creates a native Handle Graphics line object, so line attributes can be used to customize appearance or to add interactive properties.

Converting legacy code to Mapviewer

If you have legacy code that displays spatial data, the conversion is simple.

-1-: replace the line that creates the axes that holds your spatial data with a call to MapViewer.





-2-: Convert all coordinates that are used in line, patch and text commands to WGS coordinates.

About MapViewer 

- was created by Modelit and has been used in various applications for several years;
- is entirely coded in Matlab except for the module that communicates with the Web Map Service (WMS) provider of choice (for example Openstreetmap). Due to the multithreaded nature of this process we rely on Java code for this part. 
- comes with built in support for zooming, panning and resizing;
- has been tested with all Matlab versions 2013a onwards;
- can be compiled with the Matlab compiler, or deployed as pcode.