@@ -224,44 +224,57 @@ private void getToolbarUI() {
224
224
@ Override
225
225
public void onMapReady (final MapboxMap mapboxMap ) {
226
226
this .mapboxMap = mapboxMap ;
227
- mapboxMap .setStyle (Style .MAPBOX_STREETS , style -> {
228
-
229
- if (modifyLocationButton .getVisibility () == View .VISIBLE ) {
230
- initDroppedMarker (style );
231
- adjustCameraBasedOnOptions ();
232
- enableLocationComponent (style );
233
- if (style .getLayer (DROPPED_MARKER_LAYER_ID ) != null ) {
234
- final GeoJsonSource source = style .getSourceAs ("dropped-marker-source-id" );
235
- if (source != null ) {
236
- source .setGeoJson (Point .fromLngLat (cameraPosition .target .getLongitude (),
237
- cameraPosition .target .getLatitude ()));
238
- }
239
- droppedMarkerLayer = style .getLayer (DROPPED_MARKER_LAYER_ID );
240
- if (droppedMarkerLayer != null ) {
241
- droppedMarkerLayer .setProperties (visibility (VISIBLE ));
242
- markerImage .setVisibility (View .GONE );
243
- shadow .setVisibility (View .GONE );
244
- }
227
+ mapboxMap .setStyle (Style .MAPBOX_STREETS , this ::onStyleLoaded );
228
+ }
229
+
230
+ /**
231
+ * Initializes dropped marker and layer
232
+ * Handles camera position based on options
233
+ * Enables location components
234
+ *
235
+ * @param style style
236
+ */
237
+ private void onStyleLoaded (final Style style ) {
238
+ if (modifyLocationButton .getVisibility () == View .VISIBLE ) {
239
+ initDroppedMarker (style );
240
+ adjustCameraBasedOnOptions ();
241
+ enableLocationComponent (style );
242
+ if (style .getLayer (DROPPED_MARKER_LAYER_ID ) != null ) {
243
+ final GeoJsonSource source = style .getSourceAs ("dropped-marker-source-id" );
244
+ if (source != null ) {
245
+ source .setGeoJson (Point .fromLngLat (cameraPosition .target .getLongitude (),
246
+ cameraPosition .target .getLatitude ()));
247
+ }
248
+ droppedMarkerLayer = style .getLayer (DROPPED_MARKER_LAYER_ID );
249
+ if (droppedMarkerLayer != null ) {
250
+ droppedMarkerLayer .setProperties (visibility (VISIBLE ));
251
+ markerImage .setVisibility (View .GONE );
252
+ shadow .setVisibility (View .GONE );
245
253
}
246
- } else {
247
- adjustCameraBasedOnOptions ();
248
- enableLocationComponent (style );
249
- bindListeners ();
250
254
}
251
- modifyLocationButton .setOnClickListener (v -> {
252
- placeSelectedButton .setVisibility (View .VISIBLE );
253
- modifyLocationButton .setVisibility (View .GONE );
254
- showInMapButton .setVisibility (View .GONE );
255
- droppedMarkerLayer .setProperties (visibility (NONE ));
256
- markerImage .setVisibility (View .VISIBLE );
257
- shadow .setVisibility (View .VISIBLE );
258
- largeToolbarText .setText (getResources ().getString (R .string .choose_a_location ));
259
- smallToolbarText .setText (getResources ().getString (R .string .pan_and_zoom_to_adjust ));
260
- bindListeners ();
261
- });
262
-
263
- showInMapButton .setOnClickListener (v -> showInMap ());
264
- });
255
+ } else {
256
+ adjustCameraBasedOnOptions ();
257
+ enableLocationComponent (style );
258
+ bindListeners ();
259
+ }
260
+
261
+ modifyLocationButton .setOnClickListener (v -> onClickModifyLocation ());
262
+ showInMapButton .setOnClickListener (v -> showInMap ());
263
+ }
264
+
265
+ /**
266
+ * Handles onclick event of modifyLocationButton
267
+ */
268
+ private void onClickModifyLocation () {
269
+ placeSelectedButton .setVisibility (View .VISIBLE );
270
+ modifyLocationButton .setVisibility (View .GONE );
271
+ showInMapButton .setVisibility (View .GONE );
272
+ droppedMarkerLayer .setProperties (visibility (NONE ));
273
+ markerImage .setVisibility (View .VISIBLE );
274
+ shadow .setVisibility (View .VISIBLE );
275
+ largeToolbarText .setText (getResources ().getString (R .string .choose_a_location ));
276
+ smallToolbarText .setText (getResources ().getString (R .string .pan_and_zoom_to_adjust ));
277
+ bindListeners ();
265
278
}
266
279
267
280
/**
@@ -290,6 +303,7 @@ private void initDroppedMarker(@NonNull final Style loadedMapStyle) {
290
303
iconIgnorePlacement (true )
291
304
));
292
305
}
306
+
293
307
/**
294
308
* move the location to the current media coordinates
295
309
*/
0 commit comments