Skip to content

Commit

Permalink
Modified indent spaces
Browse files Browse the repository at this point in the history
  • Loading branch information
wf9a5m75 committed Jul 11, 2014
1 parent 2beed02 commit 7a7e630
Show file tree
Hide file tree
Showing 3 changed files with 123 additions and 128 deletions.
217 changes: 106 additions & 111 deletions src/android/plugin/google/maps/GoogleMaps.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import java.lang.reflect.Constructor;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Set;
import java.util.List;
import java.util.Set;

import org.apache.cordova.CallbackContext;
import org.apache.cordova.CordovaInterface;
Expand Down Expand Up @@ -68,13 +68,14 @@
import com.google.android.gms.maps.MapsInitializer;
import com.google.android.gms.maps.model.CameraPosition;
import com.google.android.gms.maps.model.CameraPosition.Builder;
import com.google.android.gms.maps.model.Circle;
import com.google.android.gms.maps.model.GroundOverlay;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.LatLngBounds;
import com.google.android.gms.maps.model.Marker;
import com.google.android.gms.maps.model.Polygon;
import com.google.android.gms.maps.model.Circle;
import com.google.android.gms.maps.model.GroundOverlay;

@SuppressWarnings("deprecation")
public class GoogleMaps extends CordovaPlugin implements View.OnClickListener, OnMarkerClickListener,
OnInfoWindowClickListener, OnMapClickListener, OnMapLongClickListener,
OnCameraChangeListener, OnMapLoadedCallback, OnMarkerDragListener,
Expand Down Expand Up @@ -428,7 +429,6 @@ public void onClick(DialogInterface dialog,int id) {
callbackContext.success();
return;
}
@SuppressWarnings("deprecation")
private int contentToView(long d) {
return Math.round(d * webView.getScale());
}
Expand Down Expand Up @@ -458,7 +458,6 @@ private void loadPlugin(String serviceName) {
}
}

@SuppressWarnings("unused")
private Boolean getLicenseInfo(JSONArray args, CallbackContext callbackContext) {
String msg = GooglePlayServicesUtil.getOpenSourceSoftwareLicenseInfo(activity);
callbackContext.success(msg);
Expand Down Expand Up @@ -600,7 +599,6 @@ private void resizeMap(JSONArray args, CallbackContext callbackContext) throws J
callbackContext.success();
}

@SuppressWarnings("deprecation")
private void updateMapViewLayout() {
try {
int divW = contentToView(mapDivLayoutJSON.getLong("width") );
Expand Down Expand Up @@ -859,7 +857,7 @@ private void onCircleEvent(final String eventName, final Circle circle) {
*/
private void onGroundOverlayEvent(final String eventName, final GroundOverlay groundOverlay) {
String groundOverlayId = "groundOverlay_" + groundOverlay.getId();
PluginEntry groundOverlayPlugin = this.plugins.get("GroundOverlay");
PluginGroundOverlay groundOverlayClass = (PluginGroundOverlay) groundOverlayPlugin.plugin;
if (groundOverlayClass.objects.containsKey(groundOverlayId)) {
Expand Down Expand Up @@ -943,57 +941,54 @@ public void onMapLongClick(LatLng point) {
* @param point
*/
public void onMapClick(LatLng point) {
boolean hitPoly = false;

// Loop through all polygons to check if within the touch point
PluginEntry polygonPlugin = this.plugins.get("Polygon");
if(polygonPlugin != null) {
PluginPolygon polygonClass = (PluginPolygon) polygonPlugin.plugin;

for (HashMap.Entry<String, Object> entry : polygonClass.objects.entrySet()) {
String key = entry.getKey();
Polygon polygon = (Polygon) entry.getValue();
if(this.polygonContainsPoint(polygon, point)) {
hitPoly = true;
this.onPolygonEvent("overlay_click", polygon);
}
}
}

// Loop through all circles to check if within the touch point
PluginEntry circlePlugin = this.plugins.get("Circle");
if(circlePlugin != null) {
PluginCircle circleClass = (PluginCircle) circlePlugin.plugin;

for (HashMap.Entry<String, Object> entry : circleClass.objects.entrySet()) {
String key = entry.getKey();
Circle circle = (Circle) entry.getValue();
if(this.circleContainsPoint(circle, point)) {
hitPoly = true;
this.onCircleEvent("overlay_click", circle);
}
}
}

// Loop through ground overlays to check if within the touch point
PluginEntry groundOverlayPlugin = this.plugins.get("GroundOverlay");
if(groundOverlayPlugin != null) {
PluginGroundOverlay groundOverlayClass = (PluginGroundOverlay) groundOverlayPlugin.plugin;

for (HashMap.Entry<String, Object> entry : groundOverlayClass.objects.entrySet()) {
String key = entry.getKey();
GroundOverlay groundOverlay = (GroundOverlay) entry.getValue();
if(this.groundOverlayContainsPoint(groundOverlay, point)) {
hitPoly = true;
this.onGroundOverlayEvent("overlay_click", groundOverlay);
}
}
}

// Only emit click event if no polygons hit
if(!hitPoly) {
this.onMapEvent("click", point);
}
boolean hitPoly = false;

// Loop through all polygons to check if within the touch point
PluginEntry polygonPlugin = this.plugins.get("Polygon");
if(polygonPlugin != null) {
PluginPolygon polygonClass = (PluginPolygon) polygonPlugin.plugin;

for (HashMap.Entry<String, Object> entry : polygonClass.objects.entrySet()) {
Polygon polygon = (Polygon) entry.getValue();
if(this.polygonContainsPoint(polygon, point)) {
hitPoly = true;
this.onPolygonEvent("overlay_click", polygon);
}
}
}

// Loop through all circles to check if within the touch point
PluginEntry circlePlugin = this.plugins.get("Circle");
if(circlePlugin != null) {
PluginCircle circleClass = (PluginCircle) circlePlugin.plugin;

for (HashMap.Entry<String, Object> entry : circleClass.objects.entrySet()) {
Circle circle = (Circle) entry.getValue();
if(this.circleContainsPoint(circle, point)) {
hitPoly = true;
this.onCircleEvent("overlay_click", circle);
}
}
}

// Loop through ground overlays to check if within the touch point
PluginEntry groundOverlayPlugin = this.plugins.get("GroundOverlay");
if(groundOverlayPlugin != null) {
PluginGroundOverlay groundOverlayClass = (PluginGroundOverlay) groundOverlayPlugin.plugin;

for (HashMap.Entry<String, Object> entry : groundOverlayClass.objects.entrySet()) {
GroundOverlay groundOverlay = (GroundOverlay) entry.getValue();
if(this.groundOverlayContainsPoint(groundOverlay, point)) {
hitPoly = true;
this.onGroundOverlayEvent("overlay_click", groundOverlay);
}
}
}

// Only emit click event if no polygons hit
if(!hitPoly) {
this.onMapEvent("click", point);
}
}

/**
Expand All @@ -1002,26 +997,26 @@ public void onMapClick(LatLng point) {
* @param point
*/
private boolean polygonContainsPoint(Polygon polygon, LatLng point) {
int crossings = 0;
List<LatLng> path = polygon.getPoints();
for (int i = 0; i < path.size(); i++) {
LatLng a = path.get(i);
int j = i + 1;
if(j >= path.size()) {
j = 0;
}
LatLng b = path.get(j);
if(this.rayCrossesSegment(point, a, b)) {
crossings++;
}
}
return (crossings % 2 == 1);
int crossings = 0;
List<LatLng> path = polygon.getPoints();
for (int i = 0; i < path.size(); i++) {
LatLng a = path.get(i);
int j = i + 1;
if(j >= path.size()) {
j = 0;
}
LatLng b = path.get(j);
if(this.rayCrossesSegment(point, a, b)) {
crossings++;
}
}
return (crossings % 2 == 1);
}

/**
Expand All @@ -1031,21 +1026,21 @@ private boolean polygonContainsPoint(Polygon polygon, LatLng point) {
* @param b
*/
private boolean rayCrossesSegment(LatLng point, LatLng a, LatLng b) {
double pX = point.latitude;
double pY = point.longitude;
double aX = a.latitude;
double aY = a.longitude;
double bX = b.latitude;
double bY = b.longitude;
if ( (aY>pY && bY>pY) || (aY<pY && bY<pY) || (aX<pX && bX<pX) ) {
return false;
}
double m = (aY-bY) / (aX-bX);
double bee = (-aX) * m + aY;
double x = (pY - bee) / m;
double pX = point.latitude;
double pY = point.longitude;
double aX = a.latitude;
double aY = a.longitude;
double bX = b.latitude;
double bY = b.longitude;
if ( (aY>pY && bY>pY) || (aY<pY && bY<pY) || (aX<pX && bX<pX) ) {
return false;
}
double m = (aY-bY) / (aX-bX);
double bee = (-aX) * m + aY;
double x = (pY - bee) / m;

return x > pX;
return x > pX;
}

/**
Expand All @@ -1054,22 +1049,22 @@ private boolean rayCrossesSegment(LatLng point, LatLng a, LatLng b) {
* @param point
*/
private boolean circleContainsPoint(Circle circle, LatLng point) {
double r = circle.getRadius();
LatLng center = circle.getCenter();
double cX = center.latitude;
double cY = center.longitude;
double pX = point.latitude;
double pY = point.longitude;
float[] results = new float[1];
Location.distanceBetween(cX, cY, pX, pY, results);
if(results[0] < r) {
return true;
} else {
return false;
}
double r = circle.getRadius();
LatLng center = circle.getCenter();
double cX = center.latitude;
double cY = center.longitude;
double pX = point.latitude;
double pY = point.longitude;
float[] results = new float[1];
Location.distanceBetween(cX, cY, pX, pY, results);
if(results[0] < r) {
return true;
} else {
return false;
}
}

/**
Expand All @@ -1078,9 +1073,9 @@ private boolean circleContainsPoint(Circle circle, LatLng point) {
* @param point
*/
private boolean groundOverlayContainsPoint(GroundOverlay groundOverlay, LatLng point) {
LatLngBounds groundOverlayBounds = groundOverlay.getBounds();
return groundOverlayBounds.contains(point);
LatLngBounds groundOverlayBounds = groundOverlay.getBounds();
return groundOverlayBounds.contains(point);
}

@Override
Expand Down
32 changes: 16 additions & 16 deletions src/ios/GoogleMaps/GoogleMapsViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -272,19 +272,19 @@ - (BOOL)mapView:(GMSMapView *)mapView didTapMarker:(GMSMarker *)marker {
}

- (void)mapView:(GMSMapView *)mapView didTapOverlay:(GMSOverlay *)overlay {
NSString *overlayClass = NSStringFromClass([overlay class]);
if([overlayClass isEqualToString:@"GMSPolygon"]) {
[self triggerOverlayEvent:@"overlay_click" type:@"polygon" overlay:overlay];
}
if([overlayClass isEqualToString:@"GMSPolyline"]) {
[self triggerOverlayEvent:@"overlay_click" type:@"polyline" overlay:overlay];
}
if([overlayClass isEqualToString:@"GMSCircle"]) {
[self triggerOverlayEvent:@"overlay_click" type:@"circle" overlay:overlay];
}
if([overlayClass isEqualToString:@"GMSGroundOverlay"]) {
[self triggerOverlayEvent:@"overlay_click" type:@"groundOverlay" overlay:overlay];
}
NSString *overlayClass = NSStringFromClass([overlay class]);
if([overlayClass isEqualToString:@"GMSPolygon"]) {
[self triggerOverlayEvent:@"overlay_click" type:@"polygon" overlay:overlay];
}
if([overlayClass isEqualToString:@"GMSPolyline"]) {
[self triggerOverlayEvent:@"overlay_click" type:@"polyline" overlay:overlay];
}
if([overlayClass isEqualToString:@"GMSCircle"]) {
[self triggerOverlayEvent:@"overlay_click" type:@"circle" overlay:overlay];
}
if([overlayClass isEqualToString:@"GMSGroundOverlay"]) {
[self triggerOverlayEvent:@"overlay_click" type:@"groundOverlay" overlay:overlay];
}
}

/**
Expand Down Expand Up @@ -334,9 +334,9 @@ - (void)triggerMarkerEvent: (NSString *)eventName marker:(GMSMarker *)marker
*/
- (void)triggerOverlayEvent: (NSString *)eventName type:(NSString *) type overlay:(GMSOverlay *)overlay
{
NSString* jsString = [NSString stringWithFormat:@"plugin.google.maps.Map._onOverlayEvent('%@', '%@_%lu');",
eventName, type, (unsigned long)overlay.hash];
[self.webView stringByEvaluatingJavaScriptFromString:jsString];
NSString* jsString = [NSString stringWithFormat:@"plugin.google.maps.Map._onOverlayEvent('%@', '%@_%lu');",
eventName, type, (unsigned long)overlay.hash];
[self.webView stringByEvaluatingJavaScriptFromString:jsString];
}

//future support: custom info window
Expand Down
2 changes: 1 addition & 1 deletion src/ios/GoogleMaps/Polyline.m
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ -(void)createPolyline:(CDVInvokedUrlCommand *)command
polyline.zIndex = [[json valueForKey:@"zIndex"] floatValue];

polyline.tappable = YES;

NSString *id = [NSString stringWithFormat:@"polyline_%lu", (unsigned long)polyline.hash];
[self.mapCtrl.overlayManager setObject:polyline forKey: id];

Expand Down

0 comments on commit 7a7e630

Please sign in to comment.