Main Content

Add Line, Polygon, and Marker Overlay Layers to Web Maps

This example shows how to add line, polygon, and marker overlay layers to a web map. Overlay layers can add information, such as, state borders and coast lines, to a base layer map. The toolbox includes functions to draw lines, polygons, and web markers on a web map.

For example, to draw a multifaceted line or multiple lines on a map, use the wmline function. You use latitude and longitude values to specify the points that define the line. Similarly, to draw a polygon, use the wmpolygon function, specifying latitude and longitude values that define the vertices of the polygon. You can also add markers, or map pins, to identify points of interest on a web map using the wmmarker function.

The following example illustrates these capabilities.

  1. Load latitude and longitude data. This creates two variables in the workspace: coastlat and coastlon.

    load coastlines
    
  2. Use the latitude and longitude data to define a line overlay. wmline draws the overlay on the current web map or, if none exists, it creates a new web map. The example includes several optional parameters to specify the line width and the name you want associated with the line.

    wmline(coastlat,coastlon,'LineWidth',3,'FeatureName','coastline')
    

    Web map with global coastlines outlined in black

  3. The wmline command adds the new overlay to the list of overlays in the Layer Manager. By default, this layer is called Line Overlay 1.

    Layer Manager with Line Overlay 1 at the end of the list

  4. Use the same latitude and longitude data to define a polygon overlay. wmpolygon interprets the latitudes and longitudes as the vertices of a polygon, and draws the overlay on the current web map. The example includes several optional parameters to specify the line width and the name you want associated with the line.

    wmpolygon(coastlat,coastlon,'FeatureName','coastline','FaceColor','green')
    

    Web map with global land areas shown in green

  5. The wmpolygon command adds the polygon overlay to the list of overlays in the Layer Manager. By default, this layer is called Polygon Overlay 2.

    Layer Manager with Polygon Overlay 2 at the end of the list

  6. Add a marker to the web map by using the wmmarker function. Display information about the marker by clicking on it. The wmmarker function adds the marker overlay to the list of overlays in the Layer Manager. By default, this layer is called Marker Overlay 3.

    wmmarker(10.5000,-66.8992,'FeatureName','Caracas')
    

    World map with red marker and label for Caracas

See Also

| | | |

Related Topics