diff --git a/GoogleMaps/native/android/com/codename1/googlemaps/InternalNativeMapsImpl.java b/GoogleMaps/native/android/com/codename1/googlemaps/InternalNativeMapsImpl.java index 42bca9e..cbc9f6c 100644 --- a/GoogleMaps/native/android/com/codename1/googlemaps/InternalNativeMapsImpl.java +++ b/GoogleMaps/native/android/com/codename1/googlemaps/InternalNativeMapsImpl.java @@ -51,6 +51,8 @@ import com.codename1.io.Log; import com.codename1.ui.Display; import com.google.android.gms.maps.model.CameraPosition; +import com.google.android.gms.maps.model.MapStyleOptions; +import android.content.res.Resources; public class InternalNativeMapsImpl implements LifecycleListener { private int mapId; @@ -124,7 +126,6 @@ public static PeerImage getPeerImage(View v) { public void update(View v, final int w, final int h) { // prevent potential exception during transitions if(w < 10 || h < 10) { - return; } final MapView mv = (MapView)v; @@ -136,24 +137,20 @@ public void update(View v, final int w, final int h) { public void run() { //mv. mv.getMapAsync(new OnMapReadyCallback() { - @Override - public void onMapReady(GoogleMap googleMap) { - googleMap.snapshot(new GoogleMap.SnapshotReadyCallback() { - public void onSnapshotReady(Bitmap snapshot) { - peerImage = snapshot; - peerW = w; - peerH = h; - lastUsed = System.currentTimeMillis(); - } - }); - } - }); - - + @Override + public void onMapReady(GoogleMap googleMap) { + googleMap.snapshot(new GoogleMap.SnapshotReadyCallback() { + public void onSnapshotReady(Bitmap snapshot) { + peerImage = snapshot; + peerW = w; + peerH = h; + lastUsed = System.currentTimeMillis(); + } + }); + } + }); } - }); - } @@ -237,7 +234,6 @@ public void run() { peerImages.put(view, pe); } pe.update(view, w, h); - } }; timer.schedule(tt, 1000L); @@ -301,7 +297,6 @@ public long beginPath() { currentPath = new PolylineOptions() .color(0xFF000000 | pathStrokeColor) .width(pathStrokeWidth); - return 1; } @@ -319,7 +314,6 @@ public float getZoom() { AndroidImplementation.runOnUiThreadAndBlock(new Runnable() { public void run() { result[0] = mapInstance.getCameraPosition().zoom; - } }); return result[0]; @@ -783,6 +777,26 @@ public void run() { } }); } + + + public void setMapStyle(final String mapStyle){ + AndroidNativeUtil.getActivity().runOnUiThread(new Runnable() { + public void run() { + try { + // Customise the styling of the base map using a JSON object defined + // in a raw resource file. + boolean success = mapInstance.setMapStyle( + new MapStyleOptions(mapStyle)); + + if (!success) { + Log.p("Style parsing failed."); + } + } catch (Resources.NotFoundException e) { + Log.e(e); + } + } + }); + } /** diff --git a/GoogleMaps/native/ios/com_codename1_googlemaps_InternalNativeMapsImpl.h b/GoogleMaps/native/ios/com_codename1_googlemaps_InternalNativeMapsImpl.h index 3bd67dd..50d0104 100644 --- a/GoogleMaps/native/ios/com_codename1_googlemaps_InternalNativeMapsImpl.h +++ b/GoogleMaps/native/ios/com_codename1_googlemaps_InternalNativeMapsImpl.h @@ -75,5 +75,6 @@ GMSMapView *mapView; -(int)getPathStrokeColor; -(void)setPathStrokeWidth:(int)param; -(int)getPathStrokeWidth; +-(void)setMapStyle:(NSString*)param; @end diff --git a/GoogleMaps/native/ios/com_codename1_googlemaps_InternalNativeMapsImpl.m b/GoogleMaps/native/ios/com_codename1_googlemaps_InternalNativeMapsImpl.m index 95074b2..b21e390 100644 --- a/GoogleMaps/native/ios/com_codename1_googlemaps_InternalNativeMapsImpl.m +++ b/GoogleMaps/native/ios/com_codename1_googlemaps_InternalNativeMapsImpl.m @@ -304,4 +304,17 @@ -(void)setPathStrokeWidth:(int)param { -(int)getPathStrokeWidth { return pathStrokeWidth; } + +-(void)setMapStyle:(NSString*)param{ + NSError *error; + + // Set the map style by passing a valid JSON string. + GMSMapStyle *style = [GMSMapStyle styleWithJSONString:param error:&error]; + + if (!style) { + NSLog(@"The style definition could not be loaded: %@", error); + } + + mapView.mapStyle = style; +} @end diff --git a/GoogleMaps/native/j2me/com/codename1/googlemaps/InternalNativeMapsImpl.java b/GoogleMaps/native/j2me/com/codename1/googlemaps/InternalNativeMapsImpl.java index 7d0d909..161ea66 100644 --- a/GoogleMaps/native/j2me/com/codename1/googlemaps/InternalNativeMapsImpl.java +++ b/GoogleMaps/native/j2me/com/codename1/googlemaps/InternalNativeMapsImpl.java @@ -125,4 +125,8 @@ public void setPathStrokeWidth(int width) { public int getPathStrokeWidth() { return 1; } + + public void setMapStyle(final String mapStyle){ + + } } diff --git a/GoogleMaps/native/javase/com/codename1/googlemaps/InternalNativeMapsImpl.java b/GoogleMaps/native/javase/com/codename1/googlemaps/InternalNativeMapsImpl.java index ff1e85b..184a0ec 100644 --- a/GoogleMaps/native/javase/com/codename1/googlemaps/InternalNativeMapsImpl.java +++ b/GoogleMaps/native/javase/com/codename1/googlemaps/InternalNativeMapsImpl.java @@ -129,4 +129,8 @@ public void setPathStrokeWidth(int width) { public int getPathStrokeWidth() { return 1; } + + public void setMapStyle(final String mapStyle){ + + } } diff --git a/GoogleMaps/native/native.iml b/GoogleMaps/native/native.iml new file mode 100644 index 0000000..ac38b86 --- /dev/null +++ b/GoogleMaps/native/native.iml @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/GoogleMaps/native/rim/com/codename1/googlemaps/InternalNativeMapsImpl.java b/GoogleMaps/native/rim/com/codename1/googlemaps/InternalNativeMapsImpl.java index 75daba7..4529745 100644 --- a/GoogleMaps/native/rim/com/codename1/googlemaps/InternalNativeMapsImpl.java +++ b/GoogleMaps/native/rim/com/codename1/googlemaps/InternalNativeMapsImpl.java @@ -110,4 +110,8 @@ public int getPathStrokeWidth() { return 1; } + public void setMapStyle(final String mapStyle){ + + } + } diff --git a/GoogleMaps/src/com/codename1/googlemaps/InternalNativeMaps.java b/GoogleMaps/src/com/codename1/googlemaps/InternalNativeMaps.java index 2968903..cb68f76 100644 --- a/GoogleMaps/src/com/codename1/googlemaps/InternalNativeMaps.java +++ b/GoogleMaps/src/com/codename1/googlemaps/InternalNativeMaps.java @@ -29,6 +29,7 @@ public interface InternalNativeMaps extends NativeInterface { public void setMapType(int type); + public void setMapStyle(final String mapStyle); public int getMapType(); public int getMaxZoom(); public int getMinZoom(); diff --git a/GoogleMaps/src/com/codename1/googlemaps/MapContainer.java b/GoogleMaps/src/com/codename1/googlemaps/MapContainer.java index eae9da9..3656cb7 100644 --- a/GoogleMaps/src/com/codename1/googlemaps/MapContainer.java +++ b/GoogleMaps/src/com/codename1/googlemaps/MapContainer.java @@ -688,7 +688,17 @@ public MarkerOptions anchor(float anchorU, float anchorV) { return this; } } - + + /** + * Sets the style of the map. + * @param mapStyle The style of map. + */ + public void setMapStyle(final String mapStyle){ + if(internalNative != null){ + internalNative.setMapStyle(mapStyle); + } + } + /** * Adds a component as a marker on the map. * @param marker The component to be placed on the map.