Skip to content

Commit

Permalink
Merge pull request #40 from appcelerator-modules/master
Browse files Browse the repository at this point in the history
Master
  • Loading branch information
jonalter committed Apr 24, 2014
2 parents bc9abff + 9af183a commit 4b74f72
Show file tree
Hide file tree
Showing 20 changed files with 457 additions and 45 deletions.
Binary file removed android/dist/ti.map-android-2.1.3.zip
Binary file not shown.
Binary file added android/dist/ti.map-android-2.1.4.zip
Binary file not shown.
4 changes: 4 additions & 0 deletions android/documentation/changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Change Log
<pre>
v2.1.4 Implement tilt, bearing, zoom, compassEnabled properties [TIMOB-16180].
Implement maxZoomLevel, minZoomLevel, update Google Play Services SDK [TIMOB-16180].
Implement support for taking snapshots of the map [TIMOB-16180]

v2.1.3 Fixed memory leak when removing map instance from window [TIMOB-14772].
Added longClick event support [TIMOB-13989].
Added support for showInfoWindow property for annotations [TIMOB-12787].
Expand Down
3 changes: 2 additions & 1 deletion android/example/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ var top = isIOS7Plus() ? 20 : 0;
var rows = [
require('tests/multiMap'),
require('tests/annotations'),
require('tests/routes')
require('tests/routes'),
require('tests/3d')
];

if (IOS) {
Expand Down
124 changes: 124 additions & 0 deletions android/example/tests/3d.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
exports.title = '3D features';
exports.run = function(UI, Map) {
var tilt = 90;
var bearing = 45;
var zoom = 17.5;
var win = UI.createWindow({
fullscreen : false
});

var tiltButton = Ti.UI.createButton({
top : '10%',
title : 'Tilt',
left : '0%'
});

var bearingButton = Ti.UI.createButton({
top : '10%',
title : 'Bearing'
});

var zoomButton = Ti.UI.createButton({
top : '10%',
right : 0,
title : 'Zoom'
});

var compassButton = Ti.UI.createButton({
top:'20%',
title: 'Toggle Compass',
left: 0
});

var snapshotButton = Ti.UI.createButton({
top: '20%',
title: 'Snapshot',
right: 0
});

tiltButton.addEventListener('click', function(e) {
tilt = Math.random() * 90;
map.region = {
latitude : 49.261902,
longitude : -123.12494706,
tilt : tilt,
bearing : bearing,
zoom : zoom
};
});

bearingButton.addEventListener('click', function(e) {
bearing = Math.random() * 360;
map.region = {
latitude : 49.261902,
longitude : -123.12494706,
tilt : tilt,
bearing : bearing,
zoom : zoom
};

});

zoomButton.addEventListener('click', function(e) {
zoom = Math.random() * 21;
map.region = {
latitude : 49.261902,
longitude : -123.12494706,
tilt : tilt,
bearing : bearing,
zoom : zoom
};

});

compassButton.addEventListener('click', function(e) {
map.compassEnabled = !map.compassEnabled;
});

snapshotButton.addEventListener('click', function(e) {
map.snapshot();
});

var snapshotView = Ti.UI.createImageView({
top: '30%',
height: '15%',
defaultImage: 'map_pin.png'
});

var map = Map.createView({
userLocation : true,
mapType : Map.NORMAL_TYPE,
region : {
latitude : 49.261902,
longitude : -123.12494706,
tilt : tilt,
bearing : bearing,
zoom : zoom
}, //Sydney
top : '50%'
});

map.addEventListener('onsnapshotready', function(e) {
snapshotView.image = e.snapshot;
});

map.addEventListener('regionchanged', function(e) {
Ti.API.info("Latitude: " + e.latitude);
Ti.API.info("Longitude: " + e.longitude);
Ti.API.info("Type: " + e.type);
});

map.addEventListener('complete', function(e) {
Ti.API.info("Max Zoom Level: " + map.getMaxZoomLevel());
Ti.API.info("Min Zoom Level: " + map.getMinZoomLevel());
});

win.add(map);
win.add(tiltButton);
win.add(bearingButton);
win.add(zoomButton);
win.add(compassButton);
win.add(snapshotButton);
win.add(snapshotView);
win.open();
}
Binary file modified android/lib/google-play-services.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion android/manifest
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# this is your module manifest and used by Titanium
# during compilation, packaging, distribution, etc.
#
version: 2.1.3
version: 2.1.4
apiversion: 2
description: External version of Map module to support new Google Map v2 sdk
author: Hieu Pham
Expand Down
5 changes: 5 additions & 0 deletions android/src/ti/map/MapModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,13 @@ public class MapModule extends KrollModule
public static final String PROPERTY_RIGHT_PANE = "rightPane";
public static final String PROPERTY_SHOW_INFO_WINDOW = "showInfoWindow";
public static final String PROPERTY_USER_LOCATION_BUTTON = "userLocationButton";
public static final String PROPERTY_COMPASS_ENABLED = "compassEnabled";
public static final String PROPERTY_TILT = "tilt";
public static final String PROPERTY_BEARING = "bearing";
public static final String PROPERTY_ZOOM = "zoom";
public static final String PROPERTY_ZORDER_ON_TOP = "zOrderOnTop";
public static final String EVENT_PIN_CHANGE_DRAG_STATE = "pinchangedragstate";
public static final String EVENT_ON_SNAPSHOT_READY = "onsnapshotready";

@Kroll.constant public static final int NORMAL_TYPE = GoogleMap.MAP_TYPE_NORMAL;
@Kroll.constant public static final int TERRAIN_TYPE = GoogleMap.MAP_TYPE_TERRAIN;
Expand Down
67 changes: 64 additions & 3 deletions android/src/ti/map/TiUIMapView.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@
import org.appcelerator.kroll.KrollDict;
import org.appcelerator.kroll.KrollProxy;
import org.appcelerator.kroll.common.Log;
import org.appcelerator.titanium.TiBlob;
import org.appcelerator.titanium.TiC;
import org.appcelerator.titanium.proxy.TiViewProxy;
import org.appcelerator.titanium.util.TiConvert;
import org.appcelerator.titanium.view.TiUIFragment;

import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.graphics.Point;
import android.os.Build;
Expand All @@ -31,16 +33,18 @@
import com.google.android.gms.maps.CameraUpdate;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.GoogleMap.OnMapLoadedCallback;
import com.google.android.gms.maps.GoogleMapOptions;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.UiSettings;
import com.google.android.gms.maps.model.CameraPosition;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.LatLngBounds;
import com.google.android.gms.maps.model.Marker;

public class TiUIMapView extends TiUIFragment implements GoogleMap.OnMarkerClickListener, GoogleMap.OnMapClickListener,
GoogleMap.OnCameraChangeListener, GoogleMap.OnMarkerDragListener, GoogleMap.OnInfoWindowClickListener, GoogleMap.InfoWindowAdapter,
GoogleMap.OnMapLongClickListener
GoogleMap.OnMapLongClickListener, GoogleMap.OnMapLoadedCallback
{
private static final String TAG = "TiUIMapView";
private GoogleMap map;
Expand Down Expand Up @@ -113,8 +117,8 @@ protected void onViewCreated()
map.setOnInfoWindowClickListener(this);
map.setInfoWindowAdapter(this);
map.setOnMapLongClickListener(this);
map.setOnMapLoadedCallback(this);
((ViewProxy) proxy).clearPreloadObjects();
proxy.fireEvent(TiC.EVENT_COMPLETE, null);
}

@Override
Expand Down Expand Up @@ -155,6 +159,9 @@ public void processMapProperties(KrollDict d)
if (d.containsKey(TiC.PROPERTY_ENABLE_ZOOM_CONTROLS)) {
setZoomControlsEnabled(TiConvert.toBoolean(d, TiC.PROPERTY_ENABLE_ZOOM_CONTROLS, true));
}
if (d.containsKey(MapModule.PROPERTY_COMPASS_ENABLED)) {
setCompassEnabled(TiConvert.toBoolean(d, MapModule.PROPERTY_COMPASS_ENABLED, true));
}
}

@Override
Expand All @@ -175,6 +182,8 @@ public void propertyChanged(String key, Object oldValue, Object newValue, KrollP
animate = TiConvert.toBoolean(newValue);
} else if (key.equals(TiC.PROPERTY_ANNOTATIONS)) {
updateAnnotations((Object[]) newValue);
} else if (key.equals(MapModule.PROPERTY_COMPASS_ENABLED)) {
setCompassEnabled(TiConvert.toBoolean(newValue, true));
} else if (key.equals(TiC.PROPERTY_ENABLE_ZOOM_CONTROLS)) {
setZoomControlsEnabled(TiConvert.toBoolean(newValue, true));
} else {
Expand All @@ -196,12 +205,27 @@ protected void setUserLocationEnabled(boolean enabled)
{
map.setMyLocationEnabled(enabled);
}

protected void setCompassEnabled(boolean enabled)
{
map.getUiSettings().setCompassEnabled(enabled);
}

protected void setUserLocationButtonEnabled(boolean enabled)
{
map.getUiSettings().setMyLocationButtonEnabled(enabled);
}

public float getMaxZoomLevel()
{
return map.getMaxZoomLevel();
}

public float getMinZoomLevel()
{
return map.getMinZoomLevel();
}

protected void setMapType(int type)
{
map.setMapType(type);
Expand All @@ -223,6 +247,9 @@ public void updateCamera(HashMap<String, Object> dict)
double longitudeDelta = 0;
double latitude = 0;
double latitudeDelta = 0;
float bearing = 0;
float tilt = 0;
float zoom = 0;

// In the setLocation() method, the old map module allows the user to provide two more properties - "animate" and "regionFit".
// In this map module, no matter "regionFit" is set to true or false, we will always make sure the specified
Expand All @@ -231,7 +258,15 @@ public void updateCamera(HashMap<String, Object> dict)
if (dict.containsKey(TiC.PROPERTY_ANIMATE)) {
anim = TiConvert.toBoolean(dict, TiC.PROPERTY_ANIMATE);
}

if (dict.containsKey(MapModule.PROPERTY_BEARING)) {
bearing = TiConvert.toFloat(dict, MapModule.PROPERTY_BEARING);
}
if (dict.containsKey(MapModule.PROPERTY_TILT)) {
tilt = TiConvert.toFloat(dict, MapModule.PROPERTY_TILT);
}
if (dict.containsKey(MapModule.PROPERTY_ZOOM)) {
zoom = TiConvert.toFloat(dict, MapModule.PROPERTY_ZOOM);
}
if (dict.containsKey(TiC.PROPERTY_LATITUDE)) {
latitude = TiConvert.toDouble(dict, TiC.PROPERTY_LATITUDE);
}
Expand All @@ -242,6 +277,9 @@ public void updateCamera(HashMap<String, Object> dict)
CameraPosition.Builder cameraBuilder = new CameraPosition.Builder();
LatLng location = new LatLng(latitude, longitude);
cameraBuilder.target(location);
cameraBuilder.bearing(bearing);
cameraBuilder.tilt(tilt);
cameraBuilder.zoom(zoom);

if (dict.containsKey(TiC.PROPERTY_LATITUDE_DELTA)) {
latitudeDelta = TiConvert.toDouble(dict, TiC.PROPERTY_LATITUDE_DELTA);
Expand Down Expand Up @@ -636,4 +674,27 @@ protected boolean interceptTouchEvent(MotionEvent ev)
}
return false;
}

public void snapshot()
{
map.snapshot(new GoogleMap.SnapshotReadyCallback()
{

@Override
public void onSnapshotReady(Bitmap snapshot)
{
TiBlob sblob = TiBlob.blobFromImage(snapshot);
KrollDict data = new KrollDict();
data.put("snapshot", sblob);
data.put("source", proxy);
proxy.fireEvent(MapModule.EVENT_ON_SNAPSHOT_READY, data);
}
});
}

@Override
public void onMapLoaded()
{
proxy.fireEvent(TiC.EVENT_COMPLETE, null);
}
}
Loading

0 comments on commit 4b74f72

Please sign in to comment.