3636import com .google .android .gms .maps .model .PolygonOptions ;
3737import com .google .android .gms .maps .model .Polyline ;
3838import com .google .android .gms .maps .model .PolylineOptions ;
39- import java .io .BufferedReader ;
40- import java .io .IOException ;
41- import java .io .InputStream ;
42- import java .io .InputStreamReader ;
43- import java .net .HttpURLConnection ;
44- import java .net .URL ;
4539import java .util .ArrayList ;
4640import java .util .HashMap ;
4741import java .util .List ;
4842import java .util .Map ;
49- import java .util .concurrent .Executors ;
5043
5144public class MapViewController implements INavigationViewControllerProperties {
5245 private GoogleMap mGoogleMap ;
@@ -67,8 +60,6 @@ public class MapViewController implements INavigationViewControllerProperties {
6760 private final Map <String , String > groundOverlayNativeIdToEffectiveId = new HashMap <>();
6861 private final Map <String , String > circleNativeIdToEffectiveId = new HashMap <>();
6962
70- private String style = "" ;
71-
7263 // Zoom level preferences (-1 means use map's current value)
7364 private Float minZoomLevelPreference = null ;
7465 private Float maxZoomLevelPreference = null ;
@@ -770,25 +761,20 @@ public Map<String, GroundOverlay> getGroundOverlayMap() {
770761 return groundOverlayMap ;
771762 }
772763
773- public void setMapStyle (String url ) {
774- Executors .newSingleThreadExecutor ()
775- .execute (
776- () -> {
777- try {
778- style = fetchJsonFromUrl (url );
779- } catch (IOException e ) {
780- throw new RuntimeException (e );
781- }
782-
783- Activity activity = activitySupplier .get ();
784- if (activity != null ) {
785- activity .runOnUiThread (
786- () -> {
787- MapStyleOptions options = new MapStyleOptions (style );
788- mGoogleMap .setMapStyle (options );
789- });
790- }
791- });
764+ public void setMapStyle (String styleJson ) {
765+ Activity activity = activitySupplier .get ();
766+ if (activity != null ) {
767+ activity .runOnUiThread (
768+ () -> {
769+ if (styleJson == null || styleJson .isEmpty ()) {
770+ // Reset to default map style
771+ mGoogleMap .setMapStyle (null );
772+ } else {
773+ MapStyleOptions options = new MapStyleOptions (styleJson );
774+ mGoogleMap .setMapStyle (options );
775+ }
776+ });
777+ }
792778 }
793779
794780 /** Moves the position of the camera to the specified location. */
@@ -1037,29 +1023,6 @@ public void setPadding(int top, int left, int bottom, int right) {
10371023 }
10381024 }
10391025
1040- private String fetchJsonFromUrl (String urlString ) throws IOException {
1041- URL url = new URL (urlString );
1042- HttpURLConnection connection = (HttpURLConnection ) url .openConnection ();
1043- connection .setRequestMethod ("GET" );
1044-
1045- int responseCode = connection .getResponseCode ();
1046- if (responseCode == HttpURLConnection .HTTP_OK ) {
1047- InputStream inputStream = connection .getInputStream ();
1048- BufferedReader reader = new BufferedReader (new InputStreamReader (inputStream ));
1049- StringBuilder stringBuilder = new StringBuilder ();
1050- String line ;
1051- while ((line = reader .readLine ()) != null ) {
1052- stringBuilder .append (line );
1053- }
1054- reader .close ();
1055- inputStream .close ();
1056- return stringBuilder .toString ();
1057- } else {
1058- // Handle error response
1059- throw new IOException ("Error response: " + responseCode );
1060- }
1061- }
1062-
10631026 private LatLng createLatLng (Map <String , Object > map ) {
10641027 Double lat = null ;
10651028 Double lng = null ;
0 commit comments