|
87 | 87 | //Create a layer for rendering the route line. |
88 | 88 | var routeLayer = new atlas.layer.LineLayer(routeDS, null, { |
89 | 89 | strokeColor: '#2272B9', |
90 | | - strokeWidth: 5, |
| 90 | + strokeWidth: 10, |
91 | 91 | lineJoin: 'round', |
92 | 92 | lineCap: 'round' |
93 | 93 | }); |
94 | 94 |
|
95 | 95 | //Add a mouse down event to the route line layer so that mid-point waypoints can be added to the route. |
96 | 96 | map.events.add('mousedown', routeLayer, routeMouseDown); |
| 97 | + |
| 98 | + //Use touch start event on map directly as it triggers faster than layer level touch events. |
| 99 | + map.events.add('touchstart', mapTouchStart); |
97 | 100 |
|
98 | 101 | //When the mouse is over the route layer, change the cursor to be a pointer. |
99 | 102 | map.events.add('mouseover', routeLayer, function () { |
|
120 | 123 |
|
121 | 124 | //Track the movement of the mouse on the map for better dragging of the route line with a new mid-point. |
122 | 125 | map.events.add('mousemove', mouseMoved); |
| 126 | + map.events.add('touchmove', mouseMoved); |
123 | 127 |
|
124 | 128 | //Track when the mouse event fires to clear the mouseDownOnRoute flag. |
125 | 129 | map.events.add('mouseup', mouseUp); |
| 130 | + map.events.add('touchend', mouseUp); |
126 | 131 |
|
127 | 132 | //Calculate initial directions. |
128 | 133 | calculateDirections(); |
|
206 | 211 | } |
207 | 212 |
|
208 | 213 | function markerDragged(e) { |
| 214 | + //NOTE: The next two lines below are the same as markerMouseDown event, but needed here for touch support. |
| 215 | + |
| 216 | + //Disable event bubbling so that if marker overlaps line, a new mid-point isn't also added. |
| 217 | + skipMidPointAdd = true; |
| 218 | + |
| 219 | + //Track the active waypoint index. |
| 220 | + activeWaypointIdx = e.target.properties.wpIdx; |
| 221 | + |
209 | 222 | //Update the position of the corresponding waypoint. |
210 | 223 | waypoints[activeWaypointIdx] = e.target.getOptions().position; |
211 | 224 |
|
|
347 | 360 |
|
348 | 361 | return routeIdx; |
349 | 362 | } |
| 363 | + |
| 364 | + function mapTouchStart(e) { |
| 365 | + //Check that if a route path exists. |
| 366 | + //Check to see if touch event occured on the route line. |
| 367 | + if (routePath && e.shapes && e.shapes.length > 0 && e.shapes[0] && e.shapes[0] instanceof atlas.Shape && routeDS.getShapeById(e.shapes[0].getId())) { |
| 368 | + //Now that we know the touch event happended on a route line, call the route mouse down event. |
| 369 | + routeMouseDown(e); |
| 370 | + } |
| 371 | + } |
350 | 372 | </script> |
351 | 373 | </head> |
352 | 374 | <body onload="GetMap()"> |
|
0 commit comments