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 | 1x 11x 11x 11x 1x 1x 1x 1x | import { loadModules } from 'esri-loader'; import { TranslateService } from '@ngx-translate/core'; import { BsModalService, BsModalRef } from 'ngx-bootstrap'; import { Drawer } from './drawer'; import { MapComponent } from '../map.component'; import { MarkerDrawActionEvent } from './utils'; import { MarkerPromptComponent } from './marker-prompt/marker-prompt.component'; export class MarkerDrawer extends Drawer { bsModalRef: BsModalRef; constructor( private translate: TranslateService, private modalService: BsModalService ) { super(); } /** * Draw a marker on a map. * * @param map The MapComponent on which the marker 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('point', {}); this.drawActionListeners.push( drawAction.on( 'draw-complete', async (event) => { await this.createMarker(event, map); this.draw(map); } ) ); } /** * Create a marker (Esri Point) and add it to a map. * * @param event The MarkerDrawActionEvent which triggered the drawing of the marker. * @param map The MapComponent to which the marker must be added. */ private async createMarker( event: MarkerDrawActionEvent, map: MapComponent ) { const [ Graphic, Point, SimpleMarkerSymbol ] = await loadModules([ 'esri/Graphic', 'esri/geometry/Point', 'esri/symbols/SimpleMarkerSymbol' ]); const markerBackgroundSymbol = new SimpleMarkerSymbol({ color: [0, 0, 0, 1.0], size: '28px', outline: { color: [255, 255, 255, 1.0], width: '3px' } }); const drawingSymbol = new SimpleMarkerSymbol({ color: [0, 0, 0, 1.0], size: '14px', outline: { color: [255, 255, 255, 1.0], width: '3px' } }); const point = new Point({ spatialReference: map.mapView.spatialReference.clone(), x: event.coordinates[0], y: event.coordinates[1] }); const markerBackground = new Graphic({ geometry: point, symbol: markerBackgroundSymbol, visible: true }); const marker = new Graphic({ geometry: point, symbol: drawingSymbol, visible: true, attributes: { text: '' } }); const success = await this.setTextAttribute(marker); if (success) { map.drawingsLayer.addMany([markerBackground, marker]); } else { const messagePromise = this.translate.get('top-bar.marker-edition.text-error').toPromise(); const message = await messagePromise; alert(message); } } /** * Set the text associated to a marker. * * @param marker An Esri Graphic representing a marker to which text must be associated. * * @returns A boolean indicating if the text could be set for the marker or not. */ async setTextAttribute( marker: __esri.Graphic ): Promise<boolean> { const initialText = marker.attributes.text; const initialState = { confirmed: false, text: initialText }; this.bsModalRef = this.modalService.show(MarkerPromptComponent, {initialState}); return new Promise((resolve, reject) => { const waitForConfirmation = () => { if (this.bsModalRef.content.confirmed) { if (this.bsModalRef.content.text) { marker.attributes.text = this.bsModalRef.content.text; return resolve(true); } return resolve(false); } setTimeout(waitForConfirmation, 100); }; waitForConfirmation(); }); } } |