Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added the option to change the style of the map. #39

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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();
}
});
}
});
}

});

}


Expand Down Expand Up @@ -237,7 +234,6 @@ public void run() {
peerImages.put(view, pe);
}
pe.update(view, w, h);

}
};
timer.schedule(tt, 1000L);
Expand Down Expand Up @@ -301,7 +297,6 @@ public long beginPath() {
currentPath = new PolylineOptions()
.color(0xFF000000 | pathStrokeColor)
.width(pathStrokeWidth);

return 1;
}

Expand All @@ -319,7 +314,6 @@ public float getZoom() {
AndroidImplementation.runOnUiThreadAndBlock(new Runnable() {
public void run() {
result[0] = mapInstance.getCameraPosition().zoom;

}
});
return result[0];
Expand Down Expand Up @@ -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);
}
}
});
}


/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,5 +75,6 @@ GMSMapView *mapView;
-(int)getPathStrokeColor;
-(void)setPathStrokeWidth:(int)param;
-(int)getPathStrokeWidth;
-(void)setMapStyle:(NSString*)param;

@end
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -125,4 +125,8 @@ public void setPathStrokeWidth(int width) {
public int getPathStrokeWidth() {
return 1;
}

public void setMapStyle(final String mapStyle){

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -129,4 +129,8 @@ public void setPathStrokeWidth(int width) {
public int getPathStrokeWidth() {
return 1;
}

public void setMapStyle(final String mapStyle){

}
}
15 changes: 15 additions & 0 deletions GoogleMaps/native/native.iml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/android" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/j2me" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/javase" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/rim" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="lib" level="project" />
</component>
</module>
Original file line number Diff line number Diff line change
Expand Up @@ -110,4 +110,8 @@ public int getPathStrokeWidth() {
return 1;
}

public void setMapStyle(final String mapStyle){

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
12 changes: 11 additions & 1 deletion GoogleMaps/src/com/codename1/googlemaps/MapContainer.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down