Skip to content

Commit d0441cd

Browse files
authored
Merge pull request #98620 from rbrundritt/master
drawing tools and accessibility doc improvements
2 parents fc4144f + c75089a commit d0441cd

9 files changed

+435
-46
lines changed
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
---
2+
title: Add a drawing toolbar to Azure Maps| Microsoft Docs
3+
description: How to add a drawing toolbar to a map using Azure Maps Web SDK
4+
author: rbrundritt
5+
ms.author: richbrun
6+
ms.date: 12/05/2019
7+
ms.topic: conceptual
8+
ms.service: azure-maps
9+
services: azure-mapss
10+
manager: cpendleton
11+
---
12+
13+
# Drawing tool events
14+
15+
When using drawing tools on a map, it is often useful to react to certain events as the user draws on the map. The following table lists all of the events supported by the `DrawingManager` class.
16+
17+
| Event | Description |
18+
|-------|-------------|
19+
| `drawingchanged` | Fired when any coordinate in a shape has been added or changed. |
20+
| `drawingchanging` | Fired when any preview coordinate for a shape is being displayed. For example, will fire multiple times as a coordinate is dragged. |
21+
| `drawingcomplete` | Fired when a shape has finished being drawn or taken out of edit mode. |
22+
| `drawingmodechanged` | Fired when the drawing mode has changed. The new drawing mode is passed into the event handler. |
23+
| `drawingstarted` | Fired when the user starts drawing a shape or puts a shape into edit mode. |
24+
25+
The following code shows how the events in the Drawing Tools module work. Draw shapes on the map and watch as the events fire.
26+
27+
<iframe height="500" style="width: 100%;" scrolling="no" title="Drawing tools events" src="https://codepen.io/azuremaps/embed/dyPMRWo?height=500&theme-id=default&default-tab=js,result" frameborder="no" allowtransparency="true" allowfullscreen="true">
28+
See the Pen <a href='https://codepen.io/azuremaps/pen/dyPMRWo'>Drawing tools events</a> by Azure Maps
29+
(<a href='https://codepen.io/azuremaps'>@azuremaps</a>) on <a href='https://codepen.io'>CodePen</a>.
30+
</iframe>
31+
32+
<br/>
33+
34+
## Examples
35+
36+
The following are examples of some common scenarios that use the drawing tools events.
37+
38+
### Select points in polygon area
39+
40+
The following code shows how to monitor the drawing of shapes that represent polygon areas (polygons, rectangles, and circles), and determine which data points on the map are within the drawn area. The `drawingcomplete` event is used to trigger the select logic. In the select logic, all data points on the map are looped through and tested for intersection with the polygon area of the drawn shape. This example makes use of the open-source [Turf.js](http://turfjs.org/) library to perform a spatial intersection calculation.
41+
42+
<iframe height="500" style="width: 100%;" scrolling="no" title="Select data in drawn polygon area" src="https://codepen.io/azuremaps/embed/XWJdeja?height=500&theme-id=default&default-tab=result" frameborder="no" allowtransparency="true" allowfullscreen="true">
43+
See the Pen <a href='https://codepen.io/azuremaps/pen/XWJdeja'>Select data in drawn polygon area</a> by Azure Maps
44+
(<a href='https://codepen.io/azuremaps'>@azuremaps</a>) on <a href='https://codepen.io'>CodePen</a>.
45+
</iframe>
46+
47+
<br/>
48+
49+
### Draw and search in polygon area
50+
51+
The following code shows how to perform a search for points of interests inside a shape area after the user has finished drawing the shape. The `drawingcomplete` event is used to trigger the search logic. If the user draws a rectangle or polygon, a search inside geometry is performed. If a circle is drawn, the radius and center position is used to perform a point of interest search. The `drawingmodechanged` event is used to determine when the user is switching into a drawing mode, and clears the drawing canvas.
52+
53+
<iframe height="500" style="width: 100%;" scrolling="no" title="Draw and search in polygon area" src="https://codepen.io/azuremaps/embed/eYmZGNv?height=500&theme-id=default&default-tab=js,result" frameborder="no" allowtransparency="true" allowfullscreen="true">
54+
See the Pen <a href='https://codepen.io/azuremaps/pen/eYmZGNv'>Draw and search in polygon area</a> by Azure Maps
55+
(<a href='https://codepen.io/azuremaps'>@azuremaps</a>) on <a href='https://codepen.io'>CodePen</a>.
56+
</iframe>
57+
58+
<br/>
59+
60+
### Create a measuring tool
61+
62+
The following code shows how the drawing events can be used to create a measuring tool. The `drawingchanging` is used to monitor the shape as it is being drawn. As the user moves the mouse, the dimensions of the shape are calculated. The `drawingcomplete` event is used to do a final calculation on the shape after it has been drawn. The `drawingmodechanged` event is used to determine when the user is switching into a drawing mode, and clears the drawing canvas and old measurement information.
63+
64+
<iframe height="500" style="width: 100%;" scrolling="no" title="Measuring tool" src="https://codepen.io/azuremaps/embed/RwNaZXe?height=500&theme-id=default&default-tab=js,result" frameborder="no" allowtransparency="true" allowfullscreen="true">
65+
See the Pen <a href='https://codepen.io/azuremaps/pen/RwNaZXe'>Measuring tool</a> by Azure Maps
66+
(<a href='https://codepen.io/azuremaps'>@azuremaps</a>) on <a href='https://codepen.io'>CodePen</a>.
67+
</iframe>
68+
69+
<br/>
70+
71+
## Next steps
72+
73+
Learn more about the Services module:
74+
75+
> [!div class="nextstepaction"]
76+
> [Services module](how-to-use-services-module.md)
77+
78+
Check out more code samples:
79+
80+
> [!div class="nextstepaction"]
81+
> [Code sample page](https://aka.ms/AzureMapsSamples)
Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
---
2+
title: Drawing tools interaction types and keyboard shortcuts in Azure Maps| Microsoft Docs
3+
description: How to draw and edit shapes using a mouse, touch screen, or keyboard in the Azure Maps Web SDK
4+
author: rbrundritt
5+
ms.author: richbrun
6+
ms.date: 12/05/2019
7+
ms.topic: conceptual
8+
ms.service: azure-maps
9+
services: azure-mapss
10+
manager: cpendleton
11+
---
12+
13+
# Interaction types and keyboard shortcuts in the drawing tools module
14+
15+
This article outlines all the different ways to draw and edit shapes on a map using a mouse, a touch screen, or keyboard shortcuts.
16+
17+
The drawing manager supports three different ways of interacting with the map to draw shapes.
18+
19+
* `click` - Coordinates are added when the mouse or touch is clicked.
20+
* `freehand ` - Coordinates are added when the mouse or touch is dragged on the map.
21+
* `hybrid` - Coordinates are added when the mouse or touch is clicked or dragged.
22+
23+
## How to draw shapes
24+
25+
The following outlines all the different ways that shapes can be drawn on the map. Before any shape can be drawn, the `drawingMode` option of the drawing manager needs to be set to a supported drawing setting. This can be done programmatically, or by pressing a one of the drawing buttons on the toolbar. The drawing mode stays enabled, even after a shape has been drawn, making it easy to draw additional shapes of the same type. The drawing mode can be put into an idle state programmatically, or by clicking the current drawing modes button on the toolbar.
26+
27+
### How to draw a point
28+
29+
When the drawing manager is in `draw-point` drawing mode, the following actions can be done to draw points on the map. These methods work with all interaction modes.
30+
31+
**Start drawing**
32+
- Click the left mouse button or touch the map to add a point to the map.
33+
- If the mouse is over the map, press the `F` key, and a point will be added using the coordinate of where the mouse pointer is. This will provide a higher accuracy method of adding a point to the map as there will be less movement on the mouse due to the pressing motion of the left mouse button.
34+
- Keep clicking, touching, or pressing `F` to add more points to the map.
35+
36+
**Finish drawing**
37+
- Click on any button in the drawing toolbar.
38+
- Programmatically set the drawing mode.
39+
- Press the `C` key.
40+
41+
**Cancel drawing**
42+
- Press the `Escape` key.
43+
44+
### How to draw a line
45+
46+
When the drawing manager is in `draw-line` mode, the following actions can be done to draw points on the map depending on what the interaction mode is set to.
47+
48+
**Start drawing**
49+
- Click mode
50+
* Click the left mouse button or touch the map to add each point of a line on the map. A coordinate is added to the line for each click/touch.
51+
* If the mouse is over the map, press the `F` key, and a point will be added using the coordinate of where the mouse pointer is. This will provide a higher accuracy method of adding a point to the map as there will be less movement on the mouse due to the pressing motion of the left mouse button.
52+
* Keep clicking until all the desired points have been added to the line.
53+
- Freehand mode
54+
* Press down the left mouse button or touch-down on the map and drag the mouse or touch point around. Coordinates are added to the line as the mouse or touch point moves around the map. As soon as the mouse or touch-up event is triggered, the drawing is completed. The frequency at which coordinates are added is defined by the drawing managers `freehandInterval` option.
55+
- Hybrid mode
56+
* Alternate between click and freehand methods as desired while drawing a single line. For example, click a few points, then hold and drag the mouse to add a bunch of points, then click a few more.
57+
58+
**Finish drawing**
59+
- Hybrid/Click mode
60+
* Double-click the map at the last point.
61+
* Click on any button in the drawing toolbar.
62+
* Programmatically set the drawing mode.
63+
- Freehand mode
64+
* Release the mouse button or touch point.
65+
- Press the `C` key.
66+
67+
**Cancel drawing**
68+
- Press the `Escape` key.
69+
70+
### How to draw a polygon
71+
72+
When the drawing manager is in `draw-polygon` mode, the following actions can be done to draw points on the map depending on what the interaction mode is set to.
73+
74+
**Start drawing**
75+
- Click mode
76+
* Click the left mouse button or touch the map to add each point of a polygon on the map. A coordinate is added to the polygon for each click/touch.
77+
* If the mouse is over the map, press the `F` key, and a point will be added using the coordinate of where the mouse pointer is. This will provide a higher accuracy method of adding a point to the map as there will be less movement on the mouse due to the pressing motion of the left mouse button.
78+
* Keep clicking until all the desired points have been added to the polygon.
79+
- Freehand mode
80+
* Press down the left mouse button or touch-down on the map and drag the mouse or touch point around. Coordinates are added to the polygon as the mouse or touch point moves around the map. As soon as the mouse or touch-up event is triggered, the drawing is completed. Note that the frequency at which coordinates are added is defined by the drawing managers `freehandInterval` option.
81+
- Hybrid mode
82+
* Alternate between click and freehand methods as desired while drawing a single polygon. For example, click a few points, then hold and drag the mouse to add a bunch of points, then click a few more.
83+
84+
**Finish drawing**
85+
- Hybrid/Click mode
86+
* Double-click the map at the last point.
87+
* Click on the first point in the polygon.
88+
* Click on any button in the drawing toolbar.
89+
* Programmatically set the drawing mode.
90+
- Freehand mode
91+
* Release the mouse button or touch point.
92+
- Press the `C` key.
93+
94+
**Cancel drawing**
95+
- Press the `Escape` key.
96+
97+
### How to draw a rectangle
98+
99+
When the drawing manager is in `draw-rectangle` mode, the following actions can be done to draw points on the map depending on what the interaction mode is set to. The generated shape will follow the [extended GeoJSON specification for rectangles](extend-geojson.md#rectangle).
100+
101+
**Start drawing**
102+
- Press down the left mouse button or touch-down on the map to add the first corner of the rectangle and drag to create the rectangle.
103+
104+
**Finish drawing**
105+
- Release the mouse button or touch point.
106+
- Programmatically set the drawing mode.
107+
- Press the `C` key.
108+
109+
**Cancel drawing**
110+
- Press the `Escape` key.
111+
112+
### How to draw a circle
113+
114+
When the drawing manager is in `draw-circle` mode, the following actions can be done to draw points on the map depending on what the interaction mode is set to. The generated shape will follow the [extended GeoJSON specification for circles](extend-geojson.md#circle).
115+
116+
**Start drawing**
117+
- Press down the left mouse button or touch-down on the map to add the center of the circle and drag give the circles a radius.
118+
119+
**Finish drawing**
120+
- Release the mouse button or touch point.
121+
- Programmatically set the drawing mode.
122+
- Press the `C` key.
123+
124+
**Cancel drawing**
125+
- Press the `Escape` key.
126+
127+
## Keyboard shortcuts
128+
129+
The drawing tools support keyboard shortcuts that make it easier to draw and edit shapes on the map. These keyboard shortcuts are functional when the map has focus.
130+
131+
| Key | Action |
132+
|----------|-----------------------------------|
133+
| `C` | Completes any drawing that is in progress and sets the drawing mode to idle. Focus will move to top-level map element. |
134+
| `Escape` | Cancels any drawing that is in progress and sets the drawing mode to idle. Focus will move to top-level map element. |
135+
| `F` | Adds a coordinate to a point, line, or polygon if the mouse is over the map. Equivalent action of clicking the map when in click or hybrid mode. This shortcut allows for more precise and faster drawings as you can use one hand to position the mouse and other to press the button without the mouse moving from the press gesture. |
136+
137+
## Next steps
138+
139+
Learn more about the classes in the drawing tools module:
140+
141+
> [!div class="nextstepaction"]
142+
> [Drawing manager](https://docs.microsoft.com/javascript/api/azure-maps-drawing-tools/atlas.drawing.drawingmanager?view=azure-node-latest)
143+
144+
> [!div class="nextstepaction"]
145+
> [Drawing toolbar](https://docs.microsoft.com/javascript/api/azure-maps-drawing-tools/atlas.control.drawingtoolbar?view=azure-node-latest)

articles/azure-maps/how-to-render-custom-data.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ This article explains how to use the [static image service](https://docs.microso
1717

1818
To render custom pushpins, labels, and geometry overlays, you can use the Postman application. You can use Azure Maps [Data Service APIs](https://docs.microsoft.com/rest/api/maps/data) to store and render overlays.
1919

20+
> [!Tip]
21+
> It is often much more cost effective to use the Azure Maps Web SDK to show a simple map on a web page than to use the static image service. The web SDK uses map tiles and unless the user pans and zooms the map, they will often generate only a fraction of a transaction per map load. Note that the Azure Maps web SDK has options for disabling panning and zooming. Additionally, the Azure Maps web SDK provides a richer set of data visualization options than a static map web service does.
2022
2123
## Prerequisites
2224

articles/azure-maps/how-to-use-map-control.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ You can embed a map in a web page by using the Map Control client-side Javascrip
3131

3232
b. Alternatively, load the Azure Maps Web SDK source code locally using the [azure-maps-control](https://www.npmjs.com/package/azure-maps-control) NPM package and host it with your app. This package also includes TypeScript definitions.
3333

34-
> npm install azure-maps-control
34+
> **npm install azure-maps-control**
3535

3636
Then add references to the Azure Maps stylesheet and script source references to the `<head>` element of the file:
3737

articles/azure-maps/how-to-use-services-module.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,14 @@ The Azure Maps Web SDK provides a *services module*. This module is a helper lib
2424
<script src="https://atlas.microsoft.com/sdk/javascript/service/2/atlas-service.min.js"></script>
2525
```
2626

27-
- Alternatively, load the Azure Maps Web SDK source code locally by using the [azure-maps-rest](https://www.npmjs.com/package/azure-maps-rest) npm package, and then host it with your app. This package also includes TypeScript definitions. Use this command:
27+
- Alternatively, load the services module for the Azure Maps Web SDK source code locally by using the [azure-maps-rest](https://www.npmjs.com/package/azure-maps-rest) npm package, and then host it with your app. This package also includes TypeScript definitions. Use this command:
2828

2929
> **npm install azure-maps-rest**
3030

3131
Then, add a script reference to the `<head>` element of the file:
3232

3333
```html
34-
<script src="node_modules/azure-maps-rest/dist/js/atlas-service.min.js"></script>
34+
<script src="node_modules/azure-maps-rest/dist/atlas-service.min.js"></script>
3535
```
3636

3737
1. Create an authentication pipeline. You must create the pipeline before you can initialize a service URL client endpoint. Use your own Azure Maps account key or Azure Active Directory (Azure AD) credentials to authenticate an Azure Maps Search service client. In this example, the Search service URL client will be created.

0 commit comments

Comments
 (0)