@@ -15,8 +15,9 @@ require([
15
15
GraphicsLayer ,
16
16
Graphic
17
17
) {
18
- esriConfig . apiKey = apiKey ;
19
-
18
+ //esriConfig.apiKey = apiKey;
19
+ esriConfig . apiKey =
20
+ "AAPK87580e590af24ff4a112832c43dbb704_CtPugq6Hs7TGTKzl-hgwybVFmduOYi9arnEQy3D2VJdsZz0Qns4n6tlJRIhtAcE" ;
20
21
// Search widget which includes the locator. We will get the location from the results.
21
22
const search = new Search ( {
22
23
container : document . getElementById ( "search-box" ) ,
@@ -149,5 +150,56 @@ require([
149
150
symbol : simpleMarkerSymbol ,
150
151
} ) ;
151
152
graphicsLayer . add ( pointGraphic ) ;
153
+ const buttonsDiv = document . getElementById ( "buttons-box" ) ;
154
+ //Add a button to show change the location on the map
155
+ const buttonChangeLocation = document . createElement ( "button" ) ;
156
+ buttonChangeLocation . innerHTML = "Cambiar localización" ;
157
+ buttonsDiv . appendChild ( buttonChangeLocation ) ;
158
+ //If we click on 'Cambiar localización', the text changes giving the instructions: click on the map to change the location.
159
+ buttonChangeLocation . onclick = function ( ) {
160
+ changeLocation (
161
+ graphicsLayer ,
162
+ pointGraphic ,
163
+ buttonChangeLocation ,
164
+ view ,
165
+ simpleMarkerSymbol
166
+ ) ;
167
+ } ;
168
+ } ;
169
+
170
+ changeLocation = (
171
+ graphicsLayer ,
172
+ pointGraphic ,
173
+ buttonChangeLocation ,
174
+ view ,
175
+ simpleMarkerSymbol
176
+ ) => {
177
+ console . log ( "ChangeLocation" ) ;
178
+ graphicsLayer . remove ( pointGraphic ) ;
179
+ buttonChangeLocation . innerHTML =
180
+ "Haz click en el mapa para cambiar la localización." ;
181
+ //If we click on the map, we capture the coordinates and do the reserve geocoding.
182
+ view . on ( "click" , function ( event ) {
183
+ // Get the coordinates of the click on the view
184
+ //Create a new point using the new coordinates
185
+ const point = {
186
+ type : "point" ,
187
+ longitude : event . mapPoint . longitude ,
188
+ latitude : event . mapPoint . latitude ,
189
+ } ;
190
+
191
+ const newLocationLongitude = event . mapPoint . longitude ;
192
+ const newLocationLatitude = event . mapPoint . latitude ;
193
+ //Create the graphic for the point
194
+ const pointGraphic = new Graphic ( {
195
+ geometry : point ,
196
+ symbol : simpleMarkerSymbol ,
197
+ } ) ;
198
+ //Add new graphic to the map
199
+ graphicsLayer . add ( pointGraphic ) ;
200
+ buttonChangeLocation . innerHTML = "Cambiar localización" ;
201
+ view . goTo ( { center : [ newLocationLongitude , newLocationLatitude ] } ) ;
202
+ view . zoom = 16 ;
203
+ } ) ;
152
204
} ;
153
205
} ) ;
0 commit comments