Skip to content

Commit

Permalink
Revert "Revert "Modified #442""
Browse files Browse the repository at this point in the history
This reverts commit e2cf979.
  • Loading branch information
wf9a5m75 committed Mar 20, 2015
1 parent e2cf979 commit f0ea0b9
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 46 deletions.
57 changes: 17 additions & 40 deletions src/android/plugin/google/maps/GoogleMaps.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.GoogleMap.InfoWindowAdapter;
import com.google.android.gms.maps.GoogleMap.OnCameraChangeListener;
import com.google.android.gms.maps.GoogleMap.OnIndoorStateChangeListener;
import com.google.android.gms.maps.GoogleMap.OnInfoWindowClickListener;
import com.google.android.gms.maps.GoogleMap.OnMapClickListener;
import com.google.android.gms.maps.GoogleMap.OnMapLoadedCallback;
Expand All @@ -84,16 +85,14 @@
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.IndoorBuilding;
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.PolygonOptions;
import com.google.android.gms.maps.model.Polyline;
import com.google.android.gms.maps.model.VisibleRegion;
import com.google.android.gms.maps.model.IndoorBuilding;
import com.google.android.gms.maps.model.IndoorLevel;
import com.google.android.gms.maps.GoogleMap.OnIndoorStateChangeListener;

@SuppressWarnings("deprecation")
public class GoogleMaps extends CordovaPlugin implements View.OnClickListener, OnMarkerClickListener,
Expand Down Expand Up @@ -569,6 +568,7 @@ public void onMapReady(GoogleMap googleMap) {
map.setOnMarkerClickListener(GoogleMaps.this);
map.setOnMarkerDragListener(GoogleMaps.this);
map.setOnMyLocationButtonClickListener(GoogleMaps.this);
map.setOnIndoorStateChangeListener(GoogleMaps.this);

// Load PluginMap class
GoogleMaps.this.loadPlugin("Map");
Expand Down Expand Up @@ -915,25 +915,15 @@ private void isAvailable(final JSONArray args, final CallbackContext callbackCon
callbackContext.success();
}

@SuppressWarnings("unused")
private void getFocusedBuilding(final JSONArray args, final CallbackContext callbackContext) throws JSONException {
IndoorBuilding focusedBuilding = map.getFocusedBuilding();
JSONObject result = new JSONObject();
if (focusedBuilding != null) {
JSONArray levels = new JSONArray();
for(IndoorLevel level : focusedBuilding.getLevels()){
JSONObject levelInfo = new JSONObject();
levelInfo.put("name",level.getName());
levelInfo.put("shortName",level.getShortName());
levels.put(levelInfo);
}
result.put("activeLevelIndex",focusedBuilding.getActiveLevelIndex());
result.put("defaultLevelIndex",focusedBuilding.getDefaultLevelIndex());
result.put("levels",levels);
result.put("underground",focusedBuilding.isUnderground());
callbackContext.success(result);
} else {
callbackContext.success(-1);
}
IndoorBuilding focusedBuilding = map.getFocusedBuilding();
if (focusedBuilding != null) {
JSONObject result = PluginUtil.convertIndoorBuildingToJson(focusedBuilding);
callbackContext.success(result);
} else {
callbackContext.success(-1);
}
}

@SuppressWarnings("unused")
Expand Down Expand Up @@ -1560,30 +1550,17 @@ public void onCameraChange(CameraPosition position) {

@Override
public void onIndoorBuildingFocused() {
webView.loadUrl("javascript:plugin.google.maps.Map._onMapEvent('indoor_building_focused')");
webView.loadUrl("javascript:plugin.google.maps.Map._onMapEvent('indoor_building_focused')");
}

@Override
public void onIndoorLevelActivated(IndoorBuilding building) {
JSONObject params = new JSONObject();
String jsonStr = "";
try {
JSONArray levels = new JSONArray();
for(IndoorLevel level : building.getLevels()){
JSONObject levelInfo = new JSONObject();
levelInfo.put("name",level.getName());
levelInfo.put("shortName",level.getShortName());
levels.put(levelInfo);
}
params.put("activeLevelIndex",building.getActiveLevelIndex());
params.put("defaultLevelIndex",building.getDefaultLevelIndex());
params.put("levels",levels);
params.put("underground",building.isUnderground());
jsonStr = params.toString();
} catch (JSONException e) {
e.printStackTrace();
String jsonStr = "null";
JSONObject result = PluginUtil.convertIndoorBuildingToJson(building);
if (result != null) {
jsonStr = result.toString();
}
webView.loadUrl("javascript:plugin.google.maps.Map._onMapEvent('indoor_level_activated', " + jsonStr + ")");
webView.loadUrl("javascript:plugin.google.maps.Map._onMapEvent('indoor_level_activated', " + jsonStr + ")");
}

@Override
Expand Down
4 changes: 1 addition & 3 deletions src/android/plugin/google/maps/PluginMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -297,10 +297,8 @@ private void myMoveCamera(final CameraUpdate cameraUpdate, final CallbackContext
private void setMyLocationEnabled(final JSONArray args, final CallbackContext callbackContext) throws JSONException {
Boolean isEnabled = false;
isEnabled = args.getBoolean(1);
Boolean button = false;
button = args.getBoolean(2);
map.setMyLocationEnabled(isEnabled);
map.getUiSettings().setMyLocationButtonEnabled(button);
map.getUiSettings().setMyLocationButtonEnabled(isEnabled);
this.sendNoResult(callbackContext);
}

Expand Down
29 changes: 29 additions & 0 deletions src/android/plugin/google/maps/PluginUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
import android.os.Bundle;
import android.util.Base64;

import com.google.android.gms.maps.model.IndoorBuilding;
import com.google.android.gms.maps.model.IndoorLevel;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.LatLngBounds;
import com.google.android.gms.maps.model.LatLngBounds.Builder;
Expand Down Expand Up @@ -270,4 +272,31 @@ public static LatLngBounds convertToLatLngBounds(List<LatLng> points) {
}
return latLngBuilder.build();
}


public static JSONObject convertIndoorBuildingToJson(IndoorBuilding indoorBuilding) {
if (indoorBuilding == null) {
return null;
}
JSONObject result = new JSONObject();
try {
JSONArray levels = new JSONArray();
for(IndoorLevel level : indoorBuilding.getLevels()){
JSONObject levelInfo = new JSONObject();
levelInfo.put("name",level.getName());

// TODO Auto-generated catch block
levelInfo.put("shortName",level.getShortName());
levels.put(levelInfo);
}
result.put("activeLevelIndex",indoorBuilding.getActiveLevelIndex());
result.put("defaultLevelIndex",indoorBuilding.getDefaultLevelIndex());
result.put("levels",levels);
result.put("underground",indoorBuilding.isUnderground());
} catch (JSONException e) {
e.printStackTrace();
return null;
}
return result;
}
}
5 changes: 2 additions & 3 deletions www/googlemaps-cdv-plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -482,10 +482,9 @@ App.prototype.moveCamera = function(cameraPosition, callback) {
}, self.errorHandler, PLUGIN_NAME, 'exec', ['Map.moveCamera', cameraPosition]);
};

App.prototype.setMyLocationEnabled = function(enabled, button) {
App.prototype.setMyLocationEnabled = function(enabled) {
enabled = parseBoolean(enabled);
button = parseBoolean(button);
cordova.exec(null, this.errorHandler, PLUGIN_NAME, 'exec', ['Map.setMyLocationEnabled', enabled, button]);
cordova.exec(null, this.errorHandler, PLUGIN_NAME, 'exec', ['Map.setMyLocationEnabled', enabled]);
};
App.prototype.setIndoorEnabled = function(enabled) {
enabled = parseBoolean(enabled);
Expand Down

0 comments on commit f0ea0b9

Please sign in to comment.