Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 | 11x 11x 1x 1x 1x 1x 1x | import { loadModules } from 'esri-loader'; import { Drawer } from './drawer'; import { MapComponent } from '../map.component'; import { DrawActionEvent, getDefaultOutline } from './utils'; export class LineDrawer extends Drawer { private lastId = 0; /** * Draw a line on a map. * * @param map The MapComponent on which the line must be drawn. */ async draw( map: MapComponent ) { const [Draw] = await loadModules(['esri/views/2d/draw/Draw']); this.clearListeners(); const draw: __esri.Draw = new Draw({ view: map.mapView }); const drawAction = draw.create('polyline', {}); this.drawActionListeners.push( drawAction.on( 'vertex-add', async (event) => await this.createLine(event, map) ), drawAction.on( 'vertex-remove', async (event) => await this.createLine(event, map) ), drawAction.on( 'cursor-update', async (event) => await this.createLine(event, map) ), drawAction.on( 'draw-complete', async (event) => { await this.createLine(event, map); this.currentGraphic = null; this.draw(map); } ), ); } /** * Generate a polyline for the vertices captured by the DrawActionEvent which * triggered the line's drawing and add it to the drawingsLayer of a MapComponent. * * @param event The DrawActionEvent which triggered the line's drawing. * @param map The MapComponent to which the line must be added. */ private async createLine( event: DrawActionEvent, map: MapComponent ) { const [ Graphic, Polyline, SimpleLineSymbol ] = await loadModules([ 'esri/Graphic', 'esri/geometry/Polyline', 'esri/symbols/SimpleLineSymbol' ]); if (this.currentGraphic != null) { map.drawingsLayer.remove(this.currentGraphic); } const polyline: __esri.Polyline = new Polyline({ spatialReference: map.mapView.spatialReference.clone(), paths: event.vertices }); let drawingSymbol: __esri.SimpleLineSymbol; if (event.type === 'draw-complete') { drawingSymbol = new SimpleLineSymbol({ color: '#000000', width: 2, style: 'dash', }); this.lastId++; /* Add a white background behind the line to make it visible both on black and white surfaces. */ await this.setBackground(map, this.lastId, polyline); } else { drawingSymbol = await getDefaultOutline(); } this.currentGraphic = new Graphic({ geometry: polyline, symbol: drawingSymbol, attributes: { id: this.lastId, background: false } }); if (this.currentGraphic != null) { map.drawingsLayer.add(this.currentGraphic); } } /** * Add a white background behind a line. * * @param map The map on which the line and background are being drawn. * @param lineId The id of the line behind which a ackground must be added. * @param polyline The geometry of the line behind which a background must be added. */ async setBackground( map: MapComponent, lineId: number, polyline: __esri.Geometry ) { const [ SimpleLineSymbol, Graphic ] = await loadModules([ 'esri/symbols/SimpleLineSymbol', 'esri/Graphic', ]); const backgroundSymbol = new SimpleLineSymbol({ color: '#ffffff', width: 8, style: 'solid' }); const background = new Graphic({ geometry: polyline, symbol: backgroundSymbol, attributes: { id: lineId, background: true } }); map.drawingsLayer.add(background); } /** * Retrieve the background associated to a line. * * @param map The MapComponent on which the line and background are displayed. * @param polyline The line for which the background must be retrieved. * * @returns The Esri Graphic containing the input line's background. */ getBackground( map: MapComponent, polyline: __esri.Graphic, ): __esri.Graphic { let background: __esri.Graphic = {} as __esri.Graphic; map.drawingsLayer.graphics.forEach( (graphic) => { if (graphic.attributes && graphic.attributes.id === polyline.attributes.id && graphic.attributes.background) { background = graphic; } } ); return background; } } |