From 0c00ace8690769c969d3c1487198718e49be6cf4 Mon Sep 17 00:00:00 2001 From: ZhanGSKen Date: Mon, 24 Feb 2025 04:30:26 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B3=A8=E9=87=8A=E9=97=AE=E9=A2=98=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- positions/build.properties | 4 +- .../positions/demo/AbsListActivity.java | 1 + .../studio/positions/demo/AbsMapActivity.java | 79 +-- .../demo/basic/IndoorMapActivity.java | 316 +++++---- .../demo/basic/MapStyleDemoActivity.java | 354 +++++----- .../demo/basic/OverseaMapActivity.java | 178 ++--- .../demo/basic/SetMapTypeActivity.java | 75 +- .../basic/SupportMapFragmentActivity.java | 62 +- .../demo/basic/UiSettingsActivity.java | 144 ++-- .../demo/camera/MapAnchorZoomActivity.java | 72 +- .../demo/camera/MapBoundActivity.java | 104 +-- .../demo/camera/MapCameraCenterActivity.java | 80 +-- .../positions/demo/circle/ArcActivity.java | 252 +++---- .../demo/circle/CircleOptionsActivity.java | 48 +- .../demo/circle/DrawCircleActivity.java | 24 +- .../demo/gesture/GestureSettingsActivity.java | 156 ++--- .../gesture/MapGestureListenActivity.java | 125 +++- .../demo/gesture/MapListenActivity.java | 36 +- .../demo/gesture/MapLongClickActivity.java | 122 ++-- .../AggregationOverlayActivity.java | 394 +++++------ .../heatoverlay/ArcLineLayerActivity.java | 364 +++++----- .../heatoverlay/DrawHeatOverlayActivity.java | 203 +++--- .../demo/heatoverlay/GLModelActivity.java | 332 ++++----- .../HeatMapVectorOverlayActivity.java | 342 ++++----- .../ScatterPlotOverlayActivity.java | 360 +++++----- .../heatoverlay/TrailOverlayActivity.java | 294 ++++---- .../heatoverlay/VectorHeatMapActivity.java | 294 ++++---- .../demo/location/LocationLayerActivity.java | 433 ++++++------ .../demo/location/LocationPointActivity.java | 310 ++++---- .../demo/marker/CustomRenderActivity.java | 558 +++++++-------- .../demo/marker/GroundOverlayActivity.java | 254 +++---- .../positions/demo/marker/MarkerActivity.java | 108 +-- .../demo/marker/MarkerAnimation.java | 384 +++++----- .../demo/marker/MarkerClickActivity.java | 46 +- .../demo/marker/MarkerClusterActivity.java | 660 +++++++++--------- .../demo/marker/MarkerCollisions.java | 232 +++--- .../demo/marker/MarkerDragActivity.java | 59 +- .../demo/marker/MarkerInfoWindowActivity.java | 458 ++++++------ .../demo/marker/MarkerOptionsActivity.java | 104 +-- .../demo/marker/SimpleMarkerActivity.java | 166 ++--- .../positions/demo/poi/PoiClickActivity.java | 83 +-- .../demo/polygon/DrawPolygonActivity.java | 72 +- .../demo/polygon/PolylonOptionsActivity.java | 142 ++-- .../demo/polygon/TileOverlayActivity.java | 356 +++++----- .../demo/polyline/DrawLineActivity.java | 384 +++++----- .../demo/polyline/LineTextActivity.java | 224 +++--- .../polyline/MutablePolylineActivity.java | 530 +++++++------- .../polyline/PolylineOptionsActivity.java | 170 ++--- .../demo/search/DistrictActivity.java | 298 ++++---- .../demo/search/DrivingRouteActivity.java | 104 +-- .../demo/search/GeoCoderActivity.java | 316 ++++----- .../demo/search/SearchBasicActivity.java | 536 +++++++------- .../demo/search/TransitRouteActivity.java | 186 ++--- .../demo/search/TruckingRouteActivity.java | 154 ++-- .../demo/search/WalkingRouteActivity.java | 112 +-- .../demo/smooth/SmoothMoveActivity.java | 508 +++++++------- .../transaction/AnimateCameraActivity.java | 89 +-- .../demo/transaction/MoveCameraActivity.java | 87 +-- .../demo/transaction/RotateMapActivity.java | 52 +- .../demo/transaction/ScollMapActivity.java | 131 ++-- .../transaction/ZoomCalulateActivity.java | 100 +-- .../demo/transaction/ZoomMapActivity.java | 90 +-- .../demo/utils/CoordinateActivity.java | 80 +-- .../demo/utils/SnapshotActivity.java | 268 +++---- 64 files changed, 6902 insertions(+), 6757 deletions(-) diff --git a/positions/build.properties b/positions/build.properties index c5af593..e34d75f 100644 --- a/positions/build.properties +++ b/positions/build.properties @@ -1,8 +1,8 @@ #Created by .winboll/winboll_app_build.gradle -#Sun Feb 23 19:49:38 GMT 2025 +#Sun Feb 23 20:28:40 GMT 2025 stageCount=0 libraryProject= baseVersion=1.0 publishVersion=1.0.0 -buildCount=60 +buildCount=61 baseBetaVersion=1.0.1 diff --git a/positions/src/main/java/cc/winboll/studio/positions/demo/AbsListActivity.java b/positions/src/main/java/cc/winboll/studio/positions/demo/AbsListActivity.java index 8936f6b..2d8dd0a 100644 --- a/positions/src/main/java/cc/winboll/studio/positions/demo/AbsListActivity.java +++ b/positions/src/main/java/cc/winboll/studio/positions/demo/AbsListActivity.java @@ -1,5 +1,6 @@ package cc.winboll.studio.positions.demo; +import cc.winboll.studio.positions.R; import android.content.Intent; import android.net.Uri; import android.os.Bundle; diff --git a/positions/src/main/java/cc/winboll/studio/positions/demo/AbsMapActivity.java b/positions/src/main/java/cc/winboll/studio/positions/demo/AbsMapActivity.java index 02ca5b7..30db981 100644 --- a/positions/src/main/java/cc/winboll/studio/positions/demo/AbsMapActivity.java +++ b/positions/src/main/java/cc/winboll/studio/positions/demo/AbsMapActivity.java @@ -1,5 +1,6 @@ package cc.winboll.studio.positions.demo; +import cc.winboll.studio.positions.R; import android.os.Bundle; import androidx.annotation.Nullable; import androidx.fragment.app.FragmentManager; @@ -11,43 +12,43 @@ import com.tencent.tencentmap.mapsdk.maps.TencentMap; public abstract class AbsMapActivity extends AbsActivity { - private TencentMap mTencentMap; - - protected int getLayoutId() { - return R.layout.activity_map_container; - } - - @Override - protected final void onCreate(@Nullable Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(getLayoutId()); - - FragmentManager manager = getSupportFragmentManager(); - SupportMapFragment fragment = (SupportMapFragment) manager.findFragmentById(R.id.fragment_map); - if (fragment != null) { - mTencentMap = fragment.getMap(); - } - - onCreate(savedInstanceState, mTencentMap); - } - - protected boolean checkMapInvalid() { - return mTencentMap == null || mTencentMap.isDestroyed(); - } - - protected void onCreate(@Nullable Bundle savedInstanceState, TencentMap tencentMap) { - - } - - @Override - public boolean onPrepareOptionsMenu(Menu menu) { - supportInvalidateOptionsMenu(); - return super.onPrepareOptionsMenu(menu); - } - - @Override - public boolean onOptionsItemSelected(MenuItem item) { - supportInvalidateOptionsMenu(); - return super.onOptionsItemSelected(item); - } +// private TencentMap mTencentMap; +// +// protected int getLayoutId() { +// return R.layout.activity_map_container; +// } +// +// @Override +// protected final void onCreate(@Nullable Bundle savedInstanceState) { +// super.onCreate(savedInstanceState); +// setContentView(getLayoutId()); +// +// FragmentManager manager = getSupportFragmentManager(); +// SupportMapFragment fragment = (SupportMapFragment) manager.findFragmentById(R.id.fragment_map); +// if (fragment != null) { +// mTencentMap = fragment.getMap(); +// } +// +// onCreate(savedInstanceState, mTencentMap); +// } +// +// protected boolean checkMapInvalid() { +// return mTencentMap == null || mTencentMap.isDestroyed(); +// } +// +// protected void onCreate(@Nullable Bundle savedInstanceState, TencentMap tencentMap) { +// +// } +// +// @Override +// public boolean onPrepareOptionsMenu(Menu menu) { +// supportInvalidateOptionsMenu(); +// return super.onPrepareOptionsMenu(menu); +// } +// +// @Override +// public boolean onOptionsItemSelected(MenuItem item) { +// supportInvalidateOptionsMenu(); +// return super.onOptionsItemSelected(item); +// } } diff --git a/positions/src/main/java/cc/winboll/studio/positions/demo/basic/IndoorMapActivity.java b/positions/src/main/java/cc/winboll/studio/positions/demo/basic/IndoorMapActivity.java index 4a5fd30..3a1dfc3 100644 --- a/positions/src/main/java/cc/winboll/studio/positions/demo/basic/IndoorMapActivity.java +++ b/positions/src/main/java/cc/winboll/studio/positions/demo/basic/IndoorMapActivity.java @@ -31,168 +31,184 @@ import java.util.List; public class IndoorMapActivity extends AppCompatActivity implements TencentMap.OnIndoorStateChangeListener { - private static final String TAG = "IndoorMapActivity"; - private MapView mapView; - private TencentMap tencentMap; - private IndoorFloorView indoorFloorView; - private UiSettings uiSettings; - private Handler handler = new Handler(); - private String floorName; - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.activity_indoor); - mapView = findViewById(R.id.mapView); - indoorFloorView = findViewById(R.id.indoor_floor); - if (tencentMap == null) { - tencentMap = mapView.getMap(); - } - //欧美汇室内地图,需Key开通室内地图权限 - CameraUpdate camera = - CameraUpdateFactory.newCameraPosition(new CameraPosition( - new LatLng(39.979382, 116.314106), - 18, - 0f, - 0f)); - tencentMap.moveCamera(camera); - final ArrayList markerClusters = new ArrayList<>(); - - uiSettings = tencentMap.getUiSettings(); - tencentMap.setIndoorEnabled(true); - //设置室内蒙层颜色 sdk版本4.3.5新增接口 - tencentMap.setIndoorMaskColor(R.color.color_C71585); - //设置室内图状态变化监听 - tencentMap.setOnIndoorStateChangeListener(this); - tencentMap.setMapType(TencentMap.MAP_TYPE_DARK); - //设置是否隐藏楼层控件 - uiSettings.setIndoorLevelPickerEnabled(false); - indoorFloorView.setOnIndoorFloorListener(new MyIndoorViewAdapter()); - ClusterManager markerClusterClusterManager = new ClusterManager(this, tencentMap); - NonHierarchicalDistanceBasedAlgorithm nba = new NonHierarchicalDistanceBasedAlgorithm<>(this); - nba.setMaxDistanceAtZoom(15); - markerClusterClusterManager.setAlgorithm(nba); - DefaultClusterRenderer renderer = new DefaultClusterRenderer<>(this, tencentMap, markerClusterClusterManager); - renderer.setMinClusterSize(2); - renderer.setBuckets(new int[]{5, 10, 20}); - markerClusterClusterManager.setRenderer(renderer); - //添加室内图marker - tencentMap.setOnMapPoiClickListener(new TencentMap.OnMapPoiClickListener() { - @Override - public void onClicked(MapPoi mapPoi) { - LatLng position = mapPoi.getPosition(); - MarkerOptions markerOptions = new MarkerOptions().position(position).title(mapPoi.name).infoWindowEnable(true); - if (!TextUtils.isEmpty("F3")) { - markerOptions.indoorInfo(new IndoorInfo("11000023805", "F3")); - - } - Marker marker = tencentMap.addMarker(markerOptions); - LatLng position1 = mapPoi.getPosition(); - markerClusters.add(new MarkerCluster(position1.getLatitude(), position1.getLongitude())); - - } - }); - tencentMap.setOnCameraChangeListener(markerClusterClusterManager); - - } - - @Override - protected void onStart() { - super.onStart(); - mapView.onStart(); - } - - @Override - protected void onResume() { - super.onResume(); - mapView.onResume(); - } - - @Override - protected void onPause() { - super.onPause(); - mapView.onPause(); - } - - @Override - protected void onStop() { - super.onStop(); - mapView.onStop(); - } - - @Override - protected void onDestroy() { - super.onDestroy(); - mapView.onDestroy(); - } - @Override public boolean onIndoorBuildingFocused() { - Log.d(TAG, "onIndoorBuildingFocused: 室内图场景激活回调"); return false; } @Override - public boolean onIndoorLevelActivated(final IndoorBuilding indoorBuilding) { - if (indoorBuilding != null) { - handler.post(new Runnable() { - @Override - public void run() { - indoorFloorView.setVisible(true); - if (mIndoorBuilding == null || !mIndoorBuilding.getBuidlingId().equals(indoorBuilding.getBuidlingId())) { - List levels = indoorBuilding.getLevels(); - String[] activedIndoorFloorNames1 = tencentMap.getActivedIndoorFloorNames(); - indoorFloorView.setItems(activedIndoorFloorNames1); - for (int i = 0; i < levels.size(); i++) { - floorName = levels.get(i).getName(); - indoorFloorView.setSeletion(floorName); - } - } - mIndoorBuilding = indoorBuilding; - } - }); - } else { - indoorFloorView.setVisible(false); - } + public boolean onIndoorLevelActivated(IndoorBuilding p1) { return false; } @Override public boolean onIndoorBuildingDeactivated() { - Log.d(TAG, "onIndoorBuildingDeactivated: 当前室内图处于无效状态"); return false; } + - IndoorBuilding mIndoorBuilding = null; - - private class MyIndoorViewAdapter implements IndoorFloorView.OnIndoorFloorListener { - - @Override - public void onSelected(int selectedIndex) { - if (mIndoorBuilding != null) { - - List levels = mIndoorBuilding.getLevels(); - String activedIndoorFloorName = tencentMap.getActivedIndoorFloorNames()[selectedIndex]; - String name = levels.get(selectedIndex).getName(); - name = activedIndoorFloorName; - String buidlingId = mIndoorBuilding.getBuidlingId(); - tencentMap.setIndoorFloor(buidlingId, name); - } - } - } +// private static final String TAG = "IndoorMapActivity"; +// private MapView mapView; +// private TencentMap tencentMap; +// private IndoorFloorView indoorFloorView; +// private UiSettings uiSettings; +// private Handler handler = new Handler(); +// private String floorName; +// +// @Override +// protected void onCreate(Bundle savedInstanceState) { +// super.onCreate(savedInstanceState); +// setContentView(R.layout.activity_indoor); +// mapView = findViewById(R.id.mapView); +// indoorFloorView = findViewById(R.id.indoor_floor); +// if (tencentMap == null) { +// tencentMap = mapView.getMap(); +// } +// //欧美汇室内地图,需Key开通室内地图权限 +// CameraUpdate camera = +// CameraUpdateFactory.newCameraPosition(new CameraPosition( +// new LatLng(39.979382, 116.314106), +// 18, +// 0f, +// 0f)); +// tencentMap.moveCamera(camera); +// final ArrayList markerClusters = new ArrayList<>(); +// +// uiSettings = tencentMap.getUiSettings(); +// tencentMap.setIndoorEnabled(true); +// //设置室内蒙层颜色 sdk版本4.3.5新增接口 +// tencentMap.setIndoorMaskColor(R.color.color_C71585); +// //设置室内图状态变化监听 +// tencentMap.setOnIndoorStateChangeListener(this); +// tencentMap.setMapType(TencentMap.MAP_TYPE_DARK); +// //设置是否隐藏楼层控件 +// uiSettings.setIndoorLevelPickerEnabled(false); +// indoorFloorView.setOnIndoorFloorListener(new MyIndoorViewAdapter()); +// ClusterManager markerClusterClusterManager = new ClusterManager(this, tencentMap); +// NonHierarchicalDistanceBasedAlgorithm nba = new NonHierarchicalDistanceBasedAlgorithm<>(this); +// nba.setMaxDistanceAtZoom(15); +// markerClusterClusterManager.setAlgorithm(nba); +// DefaultClusterRenderer renderer = new DefaultClusterRenderer<>(this, tencentMap, markerClusterClusterManager); +// renderer.setMinClusterSize(2); +// renderer.setBuckets(new int[]{5, 10, 20}); +// markerClusterClusterManager.setRenderer(renderer); +// //添加室内图marker +// tencentMap.setOnMapPoiClickListener(new TencentMap.OnMapPoiClickListener() { +// @Override +// public void onClicked(MapPoi mapPoi) { +// LatLng position = mapPoi.getPosition(); +// MarkerOptions markerOptions = new MarkerOptions().position(position).title(mapPoi.name).infoWindowEnable(true); +// if (!TextUtils.isEmpty("F3")) { +// markerOptions.indoorInfo(new IndoorInfo("11000023805", "F3")); +// +// } +// Marker marker = tencentMap.addMarker(markerOptions); +// LatLng position1 = mapPoi.getPosition(); +// markerClusters.add(new MarkerCluster(position1.getLatitude(), position1.getLongitude())); +// +// } +// }); +// tencentMap.setOnCameraChangeListener(markerClusterClusterManager); +// +// } +// +// @Override +// protected void onStart() { +// super.onStart(); +// mapView.onStart(); +// } +// +// @Override +// protected void onResume() { +// super.onResume(); +// mapView.onResume(); +// } +// +// @Override +// protected void onPause() { +// super.onPause(); +// mapView.onPause(); +// } +// +// @Override +// protected void onStop() { +// super.onStop(); +// mapView.onStop(); +// } +// +// @Override +// protected void onDestroy() { +// super.onDestroy(); +// mapView.onDestroy(); +// } +// +// @Override +// public boolean onIndoorBuildingFocused() { +// Log.d(TAG, "onIndoorBuildingFocused: 室内图场景激活回调"); +// return false; +// } +// +// @Override +// public boolean onIndoorLevelActivated(final IndoorBuilding indoorBuilding) { +// if (indoorBuilding != null) { +// handler.post(new Runnable() { +// @Override +// public void run() { +// indoorFloorView.setVisible(true); +// if (mIndoorBuilding == null || !mIndoorBuilding.getBuidlingId().equals(indoorBuilding.getBuidlingId())) { +// List levels = indoorBuilding.getLevels(); +// String[] activedIndoorFloorNames1 = tencentMap.getActivedIndoorFloorNames(); +// indoorFloorView.setItems(activedIndoorFloorNames1); +// for (int i = 0; i < levels.size(); i++) { +// floorName = levels.get(i).getName(); +// indoorFloorView.setSeletion(floorName); +// } +// } +// mIndoorBuilding = indoorBuilding; +// } +// }); +// } else { +// indoorFloorView.setVisible(false); +// } +// return false; +// } +// +// @Override +// public boolean onIndoorBuildingDeactivated() { +// Log.d(TAG, "onIndoorBuildingDeactivated: 当前室内图处于无效状态"); +// return false; +// } +// +// IndoorBuilding mIndoorBuilding = null; +// +// private class MyIndoorViewAdapter implements IndoorFloorView.OnIndoorFloorListener { +// +// @Override +// public void onSelected(int selectedIndex) { +// if (mIndoorBuilding != null) { +// +// List levels = mIndoorBuilding.getLevels(); +// String activedIndoorFloorName = tencentMap.getActivedIndoorFloorNames()[selectedIndex]; +// String name = levels.get(selectedIndex).getName(); +// name = activedIndoorFloorName; +// String buidlingId = mIndoorBuilding.getBuidlingId(); +// tencentMap.setIndoorFloor(buidlingId, name); +// } +// } +// } +//} +// +//class MarkerCluster implements ClusterItem { +// +// private final LatLng latLng; +// +// public MarkerCluster(double lat, double longitude) { +// latLng = new LatLng(lat, longitude); +// } +// +// @Override +// public LatLng getPosition() { +// +// return latLng; +// } } - -class MarkerCluster implements ClusterItem { - - private final LatLng latLng; - - public MarkerCluster(double lat, double longitude) { - latLng = new LatLng(lat, longitude); - } - - @Override - public LatLng getPosition() { - - return latLng; - } -} \ No newline at end of file diff --git a/positions/src/main/java/cc/winboll/studio/positions/demo/basic/MapStyleDemoActivity.java b/positions/src/main/java/cc/winboll/studio/positions/demo/basic/MapStyleDemoActivity.java index 6a06a69..94bed56 100644 --- a/positions/src/main/java/cc/winboll/studio/positions/demo/basic/MapStyleDemoActivity.java +++ b/positions/src/main/java/cc/winboll/studio/positions/demo/basic/MapStyleDemoActivity.java @@ -16,180 +16,180 @@ package cc.winboll.studio.positions.demo.basic; -import android.annotation.SuppressLint; -import android.graphics.PorterDuff; -import android.os.Bundle; -import android.util.Log; -import android.view.View; -import android.widget.AdapterView; -import android.widget.ArrayAdapter; -import android.widget.CompoundButton; -import android.widget.RadioGroup; -import android.widget.Spinner; -import android.widget.Switch; -import android.widget.TextView; - - -import androidx.fragment.app.FragmentActivity; - -import cc.winboll.studio.positions.R; -import com.tencent.tencentmap.mapsdk.maps.CameraUpdate; -import com.tencent.tencentmap.mapsdk.maps.CameraUpdateFactory; -import com.tencent.tencentmap.mapsdk.maps.MapView; -import com.tencent.tencentmap.mapsdk.maps.TencentMap; -import com.tencent.tencentmap.mapsdk.maps.model.CameraPosition; -import com.tencent.tencentmap.mapsdk.maps.model.LatLng; - -/** - * Demonstrates the different base layers of a map. - */ -@SuppressLint("NewApi") -public class MapStyleDemoActivity extends FragmentActivity implements TencentMap.OnCameraChangeListener { - private MapView mMapView; - private TextView mTextView; - private TencentMap mTencentMap; - private Switch mSwitch; - private Spinner mSpinner; - - private String[] styles = new String[]{"style1", "style2", "style3", "style4", "style5", - "normal", "traffic_navi", "traffic_navi_night", "satellite", "night", "navi", "night", "eagle_day", "eagle_night"}; - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.activity_map_style); - mMapView = findViewById(R.id.map_view); - mTextView = findViewById(R.id.tv_level); - mSwitch=findViewById(R.id.switch_open); - mTencentMap = mMapView.getMap(); - CameraUpdate cameraUpdate = CameraUpdateFactory.newCameraPosition(new CameraPosition(new LatLng(39.901268, 116.403854), 11f, 0f, 0f)); - mTencentMap.moveCamera(cameraUpdate); - //mTencentMap.moveCamera(CameraUpdateFactory.newLatLng(new LatLng(39.901268, 116.403854))); //移动地图 - mTencentMap.setOnCameraChangeListener(this); - mSpinner = findViewById(R.id.sp_style); - ArrayAdapter adapter = new ArrayAdapter(getApplicationContext(), android.R.layout.simple_spinner_dropdown_item, styles); - mSpinner.setAdapter(adapter); - mSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { - @Override - public void onItemSelected(AdapterView parent, View view, int position, long id) { - if (position < 5) { - mTencentMap.setMapStyle(position + 1); - } - switch (position) { - case 5: - mTencentMap.setMapStyle(TencentMap.MAP_TYPE_NORMAL); - break; - case 6: - mTencentMap.setMapStyle(TencentMap.MAP_TYPE_TRAFFIC_NAVI); - break; - case 7: - mTencentMap.setMapStyle(TencentMap.MAP_TYPE_TRAFFIC_NIGHT); - break; - case 8: - mTencentMap.setMapStyle(TencentMap.MAP_TYPE_SATELLITE); - break; - case 9: - mTencentMap.setMapStyle(TencentMap.MAP_TYPE_NIGHT); - break; - case 10: - mTencentMap.setMapStyle(TencentMap.MAP_TYPE_NAVI); - break; - case 11: - mTencentMap.setMapStyle(13 + 1000); - break; - case 12: - mTencentMap.setMapStyle(14 + 1000); - break; - case 13: - mTencentMap.setMapStyle(15 + 1000); - break; - } - } - - @Override - public void onNothingSelected(AdapterView parent) { - - } - }); - - RadioGroup rg = findViewById(R.id.rg_map_type); - rg.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() { - @Override - public void onCheckedChanged(RadioGroup group, int checkedId) { - switch (checkedId) { - case R.id.rb_normal_type: - if (mTencentMap != null) { - mTencentMap.setMapType(TencentMap.MAP_TYPE_NORMAL); - } - break; - case R.id.rb_dark_type: - if (mTencentMap != null) { - mTencentMap.setMapType(TencentMap.MAP_TYPE_DARK); - } - break; - case R.id.rb_sagellite_type: - if (mTencentMap != null) { - mTencentMap.setMapType(TencentMap.MAP_TYPE_SATELLITE); - } - break; - } - } - }); - mTencentMap.getUiSettings().setCompassEnabled(true); - mTencentMap.getUiSettings().setMyLocationButtonEnabled(true); - mSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { - @Override - public void onCheckedChanged(CompoundButton compoundButton, boolean b) { - PorterDuff.Mode buttonTintMode = compoundButton.getButtonTintMode(); - if(b){ - mTencentMap.setBuildingEnable(true); - }else{ - mTencentMap.setBuildingEnable(false); - } - } - }); - } - - @Override - protected void onResume() { - super.onResume(); - mMapView.onResume(); - } - - @Override - protected void onPause() { - super.onPause(); - mMapView.onPause(); - } - - @Override - protected void onDestroy() { - super.onDestroy(); - mMapView.onDestroy(); - } - - - @Override - protected void onStart() { - super.onStart(); - mMapView.onStart(); - } - - @Override - protected void onStop() { - super.onStop(); - mMapView.onStop(); - } - - @Override - public void onCameraChange(CameraPosition cameraPosition) { - Log.i("TAG","地图滑动了"); - mTextView.setText("当前缩放级别为:" + cameraPosition.zoom); - } - - @Override - public void onCameraChangeFinished(CameraPosition cameraPosition) { - Log.i("TAG","地图滑动了"); - mTextView.setText("当前缩放级别为:" + cameraPosition.zoom); - } -} +//import android.annotation.SuppressLint; +//import android.graphics.PorterDuff; +//import android.os.Bundle; +//import android.util.Log; +//import android.view.View; +//import android.widget.AdapterView; +//import android.widget.ArrayAdapter; +//import android.widget.CompoundButton; +//import android.widget.RadioGroup; +//import android.widget.Spinner; +//import android.widget.Switch; +//import android.widget.TextView; +// +// +//import androidx.fragment.app.FragmentActivity; +// +//import cc.winboll.studio.positions.R; +//import com.tencent.tencentmap.mapsdk.maps.CameraUpdate; +//import com.tencent.tencentmap.mapsdk.maps.CameraUpdateFactory; +//import com.tencent.tencentmap.mapsdk.maps.MapView; +//import com.tencent.tencentmap.mapsdk.maps.TencentMap; +//import com.tencent.tencentmap.mapsdk.maps.model.CameraPosition; +//import com.tencent.tencentmap.mapsdk.maps.model.LatLng; +// +///** +// * Demonstrates the different base layers of a map. +// */ +//@SuppressLint("NewApi") +//public class MapStyleDemoActivity extends FragmentActivity implements TencentMap.OnCameraChangeListener { +// private MapView mMapView; +// private TextView mTextView; +// private TencentMap mTencentMap; +// private Switch mSwitch; +// private Spinner mSpinner; +// +// private String[] styles = new String[]{"style1", "style2", "style3", "style4", "style5", +// "normal", "traffic_navi", "traffic_navi_night", "satellite", "night", "navi", "night", "eagle_day", "eagle_night"}; +// +// @Override +// protected void onCreate(Bundle savedInstanceState) { +// super.onCreate(savedInstanceState); +// setContentView(R.layout.activity_map_style); +// mMapView = findViewById(R.id.map_view); +// mTextView = findViewById(R.id.tv_level); +// mSwitch=findViewById(R.id.switch_open); +// mTencentMap = mMapView.getMap(); +// CameraUpdate cameraUpdate = CameraUpdateFactory.newCameraPosition(new CameraPosition(new LatLng(39.901268, 116.403854), 11f, 0f, 0f)); +// mTencentMap.moveCamera(cameraUpdate); +// //mTencentMap.moveCamera(CameraUpdateFactory.newLatLng(new LatLng(39.901268, 116.403854))); //移动地图 +// mTencentMap.setOnCameraChangeListener(this); +// mSpinner = findViewById(R.id.sp_style); +// ArrayAdapter adapter = new ArrayAdapter(getApplicationContext(), android.R.layout.simple_spinner_dropdown_item, styles); +// mSpinner.setAdapter(adapter); +// mSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { +// @Override +// public void onItemSelected(AdapterView parent, View view, int position, long id) { +// if (position < 5) { +// mTencentMap.setMapStyle(position + 1); +// } +// switch (position) { +// case 5: +// mTencentMap.setMapStyle(TencentMap.MAP_TYPE_NORMAL); +// break; +// case 6: +// mTencentMap.setMapStyle(TencentMap.MAP_TYPE_TRAFFIC_NAVI); +// break; +// case 7: +// mTencentMap.setMapStyle(TencentMap.MAP_TYPE_TRAFFIC_NIGHT); +// break; +// case 8: +// mTencentMap.setMapStyle(TencentMap.MAP_TYPE_SATELLITE); +// break; +// case 9: +// mTencentMap.setMapStyle(TencentMap.MAP_TYPE_NIGHT); +// break; +// case 10: +// mTencentMap.setMapStyle(TencentMap.MAP_TYPE_NAVI); +// break; +// case 11: +// mTencentMap.setMapStyle(13 + 1000); +// break; +// case 12: +// mTencentMap.setMapStyle(14 + 1000); +// break; +// case 13: +// mTencentMap.setMapStyle(15 + 1000); +// break; +// } +// } +// +// @Override +// public void onNothingSelected(AdapterView parent) { +// +// } +// }); +// +// RadioGroup rg = findViewById(R.id.rg_map_type); +// rg.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() { +// @Override +// public void onCheckedChanged(RadioGroup group, int checkedId) { +// switch (checkedId) { +// case R.id.rb_normal_type: +// if (mTencentMap != null) { +// mTencentMap.setMapType(TencentMap.MAP_TYPE_NORMAL); +// } +// break; +// case R.id.rb_dark_type: +// if (mTencentMap != null) { +// mTencentMap.setMapType(TencentMap.MAP_TYPE_DARK); +// } +// break; +// case R.id.rb_sagellite_type: +// if (mTencentMap != null) { +// mTencentMap.setMapType(TencentMap.MAP_TYPE_SATELLITE); +// } +// break; +// } +// } +// }); +// mTencentMap.getUiSettings().setCompassEnabled(true); +// mTencentMap.getUiSettings().setMyLocationButtonEnabled(true); +// mSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { +// @Override +// public void onCheckedChanged(CompoundButton compoundButton, boolean b) { +// PorterDuff.Mode buttonTintMode = compoundButton.getButtonTintMode(); +// if(b){ +// mTencentMap.setBuildingEnable(true); +// }else{ +// mTencentMap.setBuildingEnable(false); +// } +// } +// }); +// } +// +// @Override +// protected void onResume() { +// super.onResume(); +// mMapView.onResume(); +// } +// +// @Override +// protected void onPause() { +// super.onPause(); +// mMapView.onPause(); +// } +// +// @Override +// protected void onDestroy() { +// super.onDestroy(); +// mMapView.onDestroy(); +// } +// +// +// @Override +// protected void onStart() { +// super.onStart(); +// mMapView.onStart(); +// } +// +// @Override +// protected void onStop() { +// super.onStop(); +// mMapView.onStop(); +// } +// +// @Override +// public void onCameraChange(CameraPosition cameraPosition) { +// Log.i("TAG","地图滑动了"); +// mTextView.setText("当前缩放级别为:" + cameraPosition.zoom); +// } +// +// @Override +// public void onCameraChangeFinished(CameraPosition cameraPosition) { +// Log.i("TAG","地图滑动了"); +// mTextView.setText("当前缩放级别为:" + cameraPosition.zoom); +// } +//} diff --git a/positions/src/main/java/cc/winboll/studio/positions/demo/basic/OverseaMapActivity.java b/positions/src/main/java/cc/winboll/studio/positions/demo/basic/OverseaMapActivity.java index 0f969b9..d947126 100644 --- a/positions/src/main/java/cc/winboll/studio/positions/demo/basic/OverseaMapActivity.java +++ b/positions/src/main/java/cc/winboll/studio/positions/demo/basic/OverseaMapActivity.java @@ -1,91 +1,91 @@ package cc.winboll.studio.positions.demo.basic; -import android.content.res.AssetManager; -import android.graphics.Bitmap; -import android.graphics.BitmapFactory; -import android.os.Bundle; - -import com.tencent.tencentmap.mapsdk.maps.CameraUpdate; -import com.tencent.tencentmap.mapsdk.maps.CameraUpdateFactory; -import com.tencent.tencentmap.mapsdk.maps.TencentMapContext; -import com.tencent.tencentmap.mapsdk.maps.model.CameraPosition; -import com.tencent.tencentmap.mapsdk.maps.model.Language; -import com.tencent.tencentmap.mapsdk.maps.model.LatLng; -import com.tencent.tencentmap.mapsdk.maps.model.OverSeaTileProvider; - -import java.io.InputStream; -import java.net.MalformedURLException; -import java.net.URL; -import java.util.Locale; - -public class OverseaMapActivity extends SupportMapFragmentActivity { - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - //纽约时代广场海外地图,需Key开通海外位置服务权限 - CameraUpdate cameraSigma = - CameraUpdateFactory.newCameraPosition(new CameraPosition( - new LatLng(40.75797, -73.985542), - 11, - 0f, - 0f)); - //移动地图 - tencentMap.moveCamera(cameraSigma); - //设置自定义海外图源 - tencentMap.setOverSeaTileProvider(new CustomOverSeaTileProvider(tencentMap.getMapContext())); - } - - class CustomOverSeaTileProvider extends OverSeaTileProvider { - boolean mIsZhLanguage; - boolean mIsNight; - - /** - * 创建海外图源供应 - */ - public CustomOverSeaTileProvider(TencentMapContext context){ - //设置名称和版本号 - super("custom", 1, context); - } - - @Override - public URL getTileUrl(int x, int y, int zoom) { - String url = "https://xxxx.com/x=%d&y=%d&z=%d&s=%s&l=&s"; - String formatUrl = String.format(Locale.ENGLISH, url, x, y, zoom, mIsNight ? "dark" : "day", mIsZhLanguage ? "zh" : "en"); - try { - return new URL(formatUrl); - } catch (MalformedURLException e) { - e.printStackTrace(); - } - return null; - } - - @Override - public boolean onDayNightChange(boolean dayNight) { - mIsNight = dayNight; - return true; - } - - public boolean onLanguageChange(Language language) { - mIsZhLanguage = (language == Language.zh); - return true; - } - - @Override - public Bitmap getLogo(boolean isNight) { - AssetManager assetManager = getAssets(); - Bitmap iBitmap = null; - InputStream is = null; - try { - is = assetManager.open("logo.png"); - iBitmap = BitmapFactory.decodeStream(is); - } catch (Exception e) { - return null; - } catch (OutOfMemoryError ignored) { - } finally { - // IO.safeClose(is); - } - return iBitmap; - } - } -} - +//import android.content.res.AssetManager; +//import android.graphics.Bitmap; +//import android.graphics.BitmapFactory; +//import android.os.Bundle; +// +//import com.tencent.tencentmap.mapsdk.maps.CameraUpdate; +//import com.tencent.tencentmap.mapsdk.maps.CameraUpdateFactory; +//import com.tencent.tencentmap.mapsdk.maps.TencentMapContext; +//import com.tencent.tencentmap.mapsdk.maps.model.CameraPosition; +//import com.tencent.tencentmap.mapsdk.maps.model.Language; +//import com.tencent.tencentmap.mapsdk.maps.model.LatLng; +//import com.tencent.tencentmap.mapsdk.maps.model.OverSeaTileProvider; +// +//import java.io.InputStream; +//import java.net.MalformedURLException; +//import java.net.URL; +//import java.util.Locale; +// +//public class OverseaMapActivity extends SupportMapFragmentActivity { +// @Override +// protected void onCreate(Bundle savedInstanceState) { +// super.onCreate(savedInstanceState); +// //纽约时代广场海外地图,需Key开通海外位置服务权限 +// CameraUpdate cameraSigma = +// CameraUpdateFactory.newCameraPosition(new CameraPosition( +// new LatLng(40.75797, -73.985542), +// 11, +// 0f, +// 0f)); +// //移动地图 +// tencentMap.moveCamera(cameraSigma); +// //设置自定义海外图源 +// tencentMap.setOverSeaTileProvider(new CustomOverSeaTileProvider(tencentMap.getMapContext())); +// } +// +// class CustomOverSeaTileProvider extends OverSeaTileProvider { +// boolean mIsZhLanguage; +// boolean mIsNight; +// +// /** +// * 创建海外图源供应 +// */ +// public CustomOverSeaTileProvider(TencentMapContext context){ +// //设置名称和版本号 +// super("custom", 1, context); +// } +// +// @Override +// public URL getTileUrl(int x, int y, int zoom) { +// String url = "https://xxxx.com/x=%d&y=%d&z=%d&s=%s&l=&s"; +// String formatUrl = String.format(Locale.ENGLISH, url, x, y, zoom, mIsNight ? "dark" : "day", mIsZhLanguage ? "zh" : "en"); +// try { +// return new URL(formatUrl); +// } catch (MalformedURLException e) { +// e.printStackTrace(); +// } +// return null; +// } +// +// @Override +// public boolean onDayNightChange(boolean dayNight) { +// mIsNight = dayNight; +// return true; +// } +// +// public boolean onLanguageChange(Language language) { +// mIsZhLanguage = (language == Language.zh); +// return true; +// } +// +// @Override +// public Bitmap getLogo(boolean isNight) { +// AssetManager assetManager = getAssets(); +// Bitmap iBitmap = null; +// InputStream is = null; +// try { +// is = assetManager.open("logo.png"); +// iBitmap = BitmapFactory.decodeStream(is); +// } catch (Exception e) { +// return null; +// } catch (OutOfMemoryError ignored) { +// } finally { +// // IO.safeClose(is); +// } +// return iBitmap; +// } +// } +//} +// diff --git a/positions/src/main/java/cc/winboll/studio/positions/demo/basic/SetMapTypeActivity.java b/positions/src/main/java/cc/winboll/studio/positions/demo/basic/SetMapTypeActivity.java index 41d71b3..adc1d62 100644 --- a/positions/src/main/java/cc/winboll/studio/positions/demo/basic/SetMapTypeActivity.java +++ b/positions/src/main/java/cc/winboll/studio/positions/demo/basic/SetMapTypeActivity.java @@ -9,43 +9,48 @@ import com.tencent.tencentmap.mapsdk.maps.TencentMap; public class SetMapTypeActivity extends SupportMapFragmentActivity implements RadioGroup.OnCheckedChangeListener { - private RadioGroup radioGroup; @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - initView(); + public void onCheckedChanged(RadioGroup p1, int p2) { } - private void initView() { - radioGroup = findViewById(R.id.lay_map_type); - radioGroup.setVisibility(View.VISIBLE); - radioGroup.setOnCheckedChangeListener(this); - } - - @Override - public void onCheckedChanged(RadioGroup radioGroup, int i) { - switch (i) { - case R.id.btn_normal: //普通地图-默认地图类型 - tencentMap.setMapType(TencentMap.MAP_TYPE_NORMAL); - break; - case R.id.btn_satellite: //卫星地图 - tencentMap.setMapType(TencentMap.MAP_TYPE_SATELLITE); - break; - case R.id.btn_dark: //暗色地图 - tencentMap.setMapType(TencentMap.MAP_TYPE_DARK); - break; - case R.id.btn_traffic: - tencentMap.setTrafficEnabled(true); - break; - case R.id.style_map: - /*TencentMapOptions mapOptions = new TencentMapOptions(); - //将本地资源打包到apk的asset目录中 - mapOptions.setCustomAssetsPath("myMapStyle"); - //参数1对应的是“我的样式”中的序号 - tencentMap.setMapStyle(1); - MapView mMapView = new MapView(SetMapTypeActivity.this, mapOptions);*/ - break; - } - } +// private RadioGroup radioGroup; +// +// @Override +// protected void onCreate(Bundle savedInstanceState) { +// super.onCreate(savedInstanceState); +// initView(); +// } +// +// private void initView() { +// radioGroup = findViewById(R.id.lay_map_type); +// radioGroup.setVisibility(View.VISIBLE); +// radioGroup.setOnCheckedChangeListener(this); +// } +// +// @Override +// public void onCheckedChanged(RadioGroup radioGroup, int i) { +// switch (i) { +// case R.id.btn_normal: //普通地图-默认地图类型 +// tencentMap.setMapType(TencentMap.MAP_TYPE_NORMAL); +// break; +// case R.id.btn_satellite: //卫星地图 +// tencentMap.setMapType(TencentMap.MAP_TYPE_SATELLITE); +// break; +// case R.id.btn_dark: //暗色地图 +// tencentMap.setMapType(TencentMap.MAP_TYPE_DARK); +// break; +// case R.id.btn_traffic: +// tencentMap.setTrafficEnabled(true); +// break; +// case R.id.style_map: +// /*TencentMapOptions mapOptions = new TencentMapOptions(); +// //将本地资源打包到apk的asset目录中 +// mapOptions.setCustomAssetsPath("myMapStyle"); +// //参数1对应的是“我的样式”中的序号 +// tencentMap.setMapStyle(1); +// MapView mMapView = new MapView(SetMapTypeActivity.this, mapOptions);*/ +// break; +// } +// } } diff --git a/positions/src/main/java/cc/winboll/studio/positions/demo/basic/SupportMapFragmentActivity.java b/positions/src/main/java/cc/winboll/studio/positions/demo/basic/SupportMapFragmentActivity.java index 39cdad4..313a82d 100644 --- a/positions/src/main/java/cc/winboll/studio/positions/demo/basic/SupportMapFragmentActivity.java +++ b/positions/src/main/java/cc/winboll/studio/positions/demo/basic/SupportMapFragmentActivity.java @@ -16,35 +16,35 @@ import com.tencent.tencentmap.mapsdk.maps.model.CameraPosition; import com.tencent.tencentmap.mapsdk.maps.model.LatLng; public class SupportMapFragmentActivity extends AppCompatActivity { - - /** - * SDK提供了SupportMapFragment这个类来加载地图,这个类的方便之处就在于不用手动管理内存 - */ - - private FragmentManager fm; - protected TencentMap tencentMap; - private SupportMapFragment supportMapFragment; - protected UiSettings mapUiSettings; - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.activity_support_map_fragment); - - //创建tencentMap地图对象,可以完成对地图的几乎所有操作 - fm = getSupportFragmentManager(); - supportMapFragment = (SupportMapFragment) fm.findFragmentById(R.id.map_frag); - tencentMap = supportMapFragment.getMap(); - mapUiSettings = tencentMap.getUiSettings(); - //对地图操作类进行操作 - CameraUpdate cameraSigma = - CameraUpdateFactory.newCameraPosition(new CameraPosition( - new LatLng(39.984066, 116.307548), - 15, - 0f, - 0f)); - //移动地图 - tencentMap.moveCamera(cameraSigma); - - } +// +// /** +// * SDK提供了SupportMapFragment这个类来加载地图,这个类的方便之处就在于不用手动管理内存 +// */ +// +// private FragmentManager fm; +// protected TencentMap tencentMap; +// private SupportMapFragment supportMapFragment; +// protected UiSettings mapUiSettings; +// +// @Override +// protected void onCreate(Bundle savedInstanceState) { +// super.onCreate(savedInstanceState); +// setContentView(R.layout.activity_support_map_fragment); +// +// //创建tencentMap地图对象,可以完成对地图的几乎所有操作 +// fm = getSupportFragmentManager(); +// supportMapFragment = (SupportMapFragment) fm.findFragmentById(R.id.map_frag); +// tencentMap = supportMapFragment.getMap(); +// mapUiSettings = tencentMap.getUiSettings(); +// //对地图操作类进行操作 +// CameraUpdate cameraSigma = +// CameraUpdateFactory.newCameraPosition(new CameraPosition( +// new LatLng(39.984066, 116.307548), +// 15, +// 0f, +// 0f)); +// //移动地图 +// tencentMap.moveCamera(cameraSigma); +// +// } } diff --git a/positions/src/main/java/cc/winboll/studio/positions/demo/basic/UiSettingsActivity.java b/positions/src/main/java/cc/winboll/studio/positions/demo/basic/UiSettingsActivity.java index 4a1b8a5..416ecfd 100644 --- a/positions/src/main/java/cc/winboll/studio/positions/demo/basic/UiSettingsActivity.java +++ b/positions/src/main/java/cc/winboll/studio/positions/demo/basic/UiSettingsActivity.java @@ -11,76 +11,76 @@ import com.tencent.tencentmap.mapsdk.maps.TencentMapOptions; public class UiSettingsActivity extends SupportMapFragmentActivity { - private Switch logoControl; - private Switch compassControl; - private Switch scaleViewControl; - - @Override - protected void onCreate(Bundle savedInstanceState) { - - super.onCreate(savedInstanceState); - initView(); - } - private void initView(){ - - logoControl = findViewById(R.id.switch_logo); - compassControl = findViewById(R.id.switch_compass); - scaleViewControl = findViewById(R.id.switch_scale_view); - logoControl.setVisibility(View.VISIBLE); - logoControl.setText("logo位置"); - compassControl.setVisibility(View.VISIBLE); - compassControl.setText("指南针"); - scaleViewControl.setVisibility(View.VISIBLE); - scaleViewControl.setText("比例尺"); - - //打开缩放 - mapUiSettings.setZoomControlsEnabled(true); - //打开位置标志 - mapUiSettings.setMyLocationButtonEnabled(true); - - - logoControl.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { - @Override - public void onCheckedChanged(CompoundButton compoundButton, boolean b) { - if (b){ - //logo左下角 - mapUiSettings.setLogoPosition(TencentMapOptions.LOGO_POSITION_BOTTOM_LEFT); - }else{ - //logo右上角 - mapUiSettings.setLogoPosition(TencentMapOptions.LOGO_POSITION_TOP_RIGHT); - } - - } - }); - - compassControl.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { - @Override - public void onCheckedChanged(CompoundButton compoundButton, boolean b) { - if (b){ - //显示指南针 - mapUiSettings.setCompassEnabled(true); - }else{ - //隐藏指南针 - mapUiSettings.setCompassEnabled(false); - } - } - }); - - scaleViewControl.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { - @Override - public void onCheckedChanged(CompoundButton compoundButton, boolean b) { - if (b){ - //打开比例尺 - mapUiSettings.setScaleViewEnabled(true); - }else{ - //关闭比例尺 - mapUiSettings.setScaleViewEnabled(false); - } - } - }); - - - - - } +// private Switch logoControl; +// private Switch compassControl; +// private Switch scaleViewControl; +// +// @Override +// protected void onCreate(Bundle savedInstanceState) { +// +// super.onCreate(savedInstanceState); +// initView(); +// } +// private void initView(){ +// +// logoControl = findViewById(R.id.switch_logo); +// compassControl = findViewById(R.id.switch_compass); +// scaleViewControl = findViewById(R.id.switch_scale_view); +// logoControl.setVisibility(View.VISIBLE); +// logoControl.setText("logo位置"); +// compassControl.setVisibility(View.VISIBLE); +// compassControl.setText("指南针"); +// scaleViewControl.setVisibility(View.VISIBLE); +// scaleViewControl.setText("比例尺"); +// +// //打开缩放 +// mapUiSettings.setZoomControlsEnabled(true); +// //打开位置标志 +// mapUiSettings.setMyLocationButtonEnabled(true); +// +// +// logoControl.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { +// @Override +// public void onCheckedChanged(CompoundButton compoundButton, boolean b) { +// if (b){ +// //logo左下角 +// mapUiSettings.setLogoPosition(TencentMapOptions.LOGO_POSITION_BOTTOM_LEFT); +// }else{ +// //logo右上角 +// mapUiSettings.setLogoPosition(TencentMapOptions.LOGO_POSITION_TOP_RIGHT); +// } +// +// } +// }); +// +// compassControl.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { +// @Override +// public void onCheckedChanged(CompoundButton compoundButton, boolean b) { +// if (b){ +// //显示指南针 +// mapUiSettings.setCompassEnabled(true); +// }else{ +// //隐藏指南针 +// mapUiSettings.setCompassEnabled(false); +// } +// } +// }); +// +// scaleViewControl.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { +// @Override +// public void onCheckedChanged(CompoundButton compoundButton, boolean b) { +// if (b){ +// //打开比例尺 +// mapUiSettings.setScaleViewEnabled(true); +// }else{ +// //关闭比例尺 +// mapUiSettings.setScaleViewEnabled(false); +// } +// } +// }); +// +// +// +// +// } } diff --git a/positions/src/main/java/cc/winboll/studio/positions/demo/camera/MapAnchorZoomActivity.java b/positions/src/main/java/cc/winboll/studio/positions/demo/camera/MapAnchorZoomActivity.java index c48c07f..35c21bc 100644 --- a/positions/src/main/java/cc/winboll/studio/positions/demo/camera/MapAnchorZoomActivity.java +++ b/positions/src/main/java/cc/winboll/studio/positions/demo/camera/MapAnchorZoomActivity.java @@ -15,40 +15,40 @@ import com.tencent.tencentmap.mapsdk.maps.model.RestrictBoundsFitMode; import com.tencent.tencentmap.mapsdk.maps.model.VisibleRegion; public class MapAnchorZoomActivity extends SupportMapFragmentActivity { - private Marker marker; - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - - LatLng latLng = new LatLng(39.984108,116.307557); - - CameraUpdate cameraSigma = - CameraUpdateFactory.newCameraPosition(new CameraPosition( - latLng, - 15, - 0f, - 0f)); - //移动地图 - tencentMap.moveCamera(cameraSigma); - Projection projection = tencentMap.getProjection(); - - VisibleRegion region = projection.getVisibleRegion(); - - tencentMap.setRestrictBounds(new LatLngBounds(region.farRight, region.nearLeft), RestrictBoundsFitMode.FIT_HEIGHT); - tencentMap.setRestrictBounds(new LatLngBounds(region.farRight, region.nearLeft), RestrictBoundsFitMode.FIT_WIDTH); - setMarker(latLng); - } - /** - * 设置标注 - */ - private void setMarker(LatLng latLng){ - - MarkerOptions options = new MarkerOptions().position(latLng); - - //设置infowindow - options.title("锚点"); - marker = tencentMap.addMarker(options); - marker.setInfoWindowEnable(true); - } +// private Marker marker; +// +// @Override +// protected void onCreate(Bundle savedInstanceState) { +// super.onCreate(savedInstanceState); +// +// LatLng latLng = new LatLng(39.984108,116.307557); +// +// CameraUpdate cameraSigma = +// CameraUpdateFactory.newCameraPosition(new CameraPosition( +// latLng, +// 15, +// 0f, +// 0f)); +// //移动地图 +// tencentMap.moveCamera(cameraSigma); +// Projection projection = tencentMap.getProjection(); +// +// VisibleRegion region = projection.getVisibleRegion(); +// +// tencentMap.setRestrictBounds(new LatLngBounds(region.farRight, region.nearLeft), RestrictBoundsFitMode.FIT_HEIGHT); +// tencentMap.setRestrictBounds(new LatLngBounds(region.farRight, region.nearLeft), RestrictBoundsFitMode.FIT_WIDTH); +// setMarker(latLng); +// } +// /** +// * 设置标注 +// */ +// private void setMarker(LatLng latLng){ +// +// MarkerOptions options = new MarkerOptions().position(latLng); +// +// //设置infowindow +// options.title("锚点"); +// marker = tencentMap.addMarker(options); +// marker.setInfoWindowEnable(true); +// } } diff --git a/positions/src/main/java/cc/winboll/studio/positions/demo/camera/MapBoundActivity.java b/positions/src/main/java/cc/winboll/studio/positions/demo/camera/MapBoundActivity.java index d950834..11ad369 100644 --- a/positions/src/main/java/cc/winboll/studio/positions/demo/camera/MapBoundActivity.java +++ b/positions/src/main/java/cc/winboll/studio/positions/demo/camera/MapBoundActivity.java @@ -1,54 +1,54 @@ package cc.winboll.studio.positions.demo.camera; -import android.os.Bundle; -import android.view.View; -import android.widget.CheckBox; -import android.widget.CompoundButton; -import android.widget.RadioGroup; - -import cc.winboll.studio.positions.R; -import cc.winboll.studio.positions.demo.basic.SupportMapFragmentActivity; -import com.tencent.tencentmap.mapsdk.maps.model.LatLng; -import com.tencent.tencentmap.mapsdk.maps.model.LatLngBounds; -import com.tencent.tencentmap.mapsdk.maps.model.RestrictBoundsFitMode; - -public class MapBoundActivity extends SupportMapFragmentActivity { - private RadioGroup radioGroup; - private CheckBox fitHeight; - private CheckBox fitWidth; - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - final LatLng northeastLatLng = new LatLng(39.984066, 116.307548); - final LatLng southwestLatLng = new LatLng(39.974066, 116.297548); - radioGroup = findViewById(R.id.lay_map_bound); - radioGroup.setVisibility(View.VISIBLE); - fitWidth = findViewById(R.id.btn_fit_width); - fitWidth.setText("适应宽度"); - fitHeight = findViewById(R.id.btn_fit_height); - fitHeight.setText("适应高度"); - fitHeight.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { - @Override - public void onCheckedChanged(CompoundButton compoundButton, boolean b) { - if (b){ - tencentMap.setRestrictBounds(new LatLngBounds(northeastLatLng, southwestLatLng), RestrictBoundsFitMode.FIT_HEIGHT); - }else{ - - } - } - }); - - fitWidth.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { - @Override - public void onCheckedChanged(CompoundButton compoundButton, boolean b) { - if (b){ - tencentMap.setRestrictBounds(new LatLngBounds(northeastLatLng, southwestLatLng), RestrictBoundsFitMode.FIT_WIDTH); - }else{ - - } - } - }); - } - - -} +//import android.os.Bundle; +//import android.view.View; +//import android.widget.CheckBox; +//import android.widget.CompoundButton; +//import android.widget.RadioGroup; +// +//import cc.winboll.studio.positions.R; +//import cc.winboll.studio.positions.demo.basic.SupportMapFragmentActivity; +//import com.tencent.tencentmap.mapsdk.maps.model.LatLng; +//import com.tencent.tencentmap.mapsdk.maps.model.LatLngBounds; +//import com.tencent.tencentmap.mapsdk.maps.model.RestrictBoundsFitMode; +// +//public class MapBoundActivity extends SupportMapFragmentActivity { +// private RadioGroup radioGroup; +// private CheckBox fitHeight; +// private CheckBox fitWidth; +// @Override +// protected void onCreate(Bundle savedInstanceState) { +// super.onCreate(savedInstanceState); +// final LatLng northeastLatLng = new LatLng(39.984066, 116.307548); +// final LatLng southwestLatLng = new LatLng(39.974066, 116.297548); +// radioGroup = findViewById(R.id.lay_map_bound); +// radioGroup.setVisibility(View.VISIBLE); +// fitWidth = findViewById(R.id.btn_fit_width); +// fitWidth.setText("适应宽度"); +// fitHeight = findViewById(R.id.btn_fit_height); +// fitHeight.setText("适应高度"); +// fitHeight.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { +// @Override +// public void onCheckedChanged(CompoundButton compoundButton, boolean b) { +// if (b){ +// tencentMap.setRestrictBounds(new LatLngBounds(northeastLatLng, southwestLatLng), RestrictBoundsFitMode.FIT_HEIGHT); +// }else{ +// +// } +// } +// }); +// +// fitWidth.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { +// @Override +// public void onCheckedChanged(CompoundButton compoundButton, boolean b) { +// if (b){ +// tencentMap.setRestrictBounds(new LatLngBounds(northeastLatLng, southwestLatLng), RestrictBoundsFitMode.FIT_WIDTH); +// }else{ +// +// } +// } +// }); +// } +// +// +//} diff --git a/positions/src/main/java/cc/winboll/studio/positions/demo/camera/MapCameraCenterActivity.java b/positions/src/main/java/cc/winboll/studio/positions/demo/camera/MapCameraCenterActivity.java index 617b681..328d607 100644 --- a/positions/src/main/java/cc/winboll/studio/positions/demo/camera/MapCameraCenterActivity.java +++ b/positions/src/main/java/cc/winboll/studio/positions/demo/camera/MapCameraCenterActivity.java @@ -12,43 +12,43 @@ import com.tencent.tencentmap.mapsdk.maps.TencentMap; import com.tencent.tencentmap.mapsdk.maps.model.CameraPosition; import com.tencent.tencentmap.mapsdk.maps.model.LatLng; -public class MapCameraCenterActivity extends SupportMapFragmentActivity implements TencentMap.OnCameraChangeListener, TencentMap.OnMapClickListener { - private TextView textView; - private String info; - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - - textView = findViewById(R.id.tv_info); - textView.setVisibility(View.VISIBLE); - tencentMap.setOnCameraChangeListener(this); - tencentMap.setOnMapClickListener(this); - } - - - /** - * 地图视图改变回调 - * @param cameraPosition - */ - @Override - public void onCameraChange(CameraPosition cameraPosition) { - //获取当前地图视图信息 - info = "经纬度:"+cameraPosition.target.latitude+","+cameraPosition.target.longitude+";zoom:"+cameraPosition.zoom; - textView.setText(info); - } - - @Override - public void onCameraChangeFinished(CameraPosition cameraPosition) { - //获取当前地图视图信息 - info = "经纬度:"+cameraPosition.target.latitude+","+cameraPosition.target.longitude+";zoom:"+cameraPosition.zoom; - Toast.makeText(MapCameraCenterActivity.this,info,Toast.LENGTH_SHORT).show(); - textView.setText(info); - - } - - @Override - public void onMapClick(LatLng latLng) { - tencentMap.moveCamera(CameraUpdateFactory.newCameraPosition(new CameraPosition(latLng,15f, 0, 0))); - } -} +//public class MapCameraCenterActivity extends SupportMapFragmentActivity implements TencentMap.OnCameraChangeListener, TencentMap.OnMapClickListener { +// private TextView textView; +// private String info; +// +// @Override +// protected void onCreate(Bundle savedInstanceState) { +// super.onCreate(savedInstanceState); +// +// textView = findViewById(R.id.tv_info); +// textView.setVisibility(View.VISIBLE); +// tencentMap.setOnCameraChangeListener(this); +// tencentMap.setOnMapClickListener(this); +// } +// +// +// /** +// * 地图视图改变回调 +// * @param cameraPosition +// */ +// @Override +// public void onCameraChange(CameraPosition cameraPosition) { +// //获取当前地图视图信息 +// info = "经纬度:"+cameraPosition.target.latitude+","+cameraPosition.target.longitude+";zoom:"+cameraPosition.zoom; +// textView.setText(info); +// } +// +// @Override +// public void onCameraChangeFinished(CameraPosition cameraPosition) { +// //获取当前地图视图信息 +// info = "经纬度:"+cameraPosition.target.latitude+","+cameraPosition.target.longitude+";zoom:"+cameraPosition.zoom; +// Toast.makeText(MapCameraCenterActivity.this,info,Toast.LENGTH_SHORT).show(); +// textView.setText(info); +// +// } +// +// @Override +// public void onMapClick(LatLng latLng) { +// tencentMap.moveCamera(CameraUpdateFactory.newCameraPosition(new CameraPosition(latLng,15f, 0, 0))); +// } +//} diff --git a/positions/src/main/java/cc/winboll/studio/positions/demo/circle/ArcActivity.java b/positions/src/main/java/cc/winboll/studio/positions/demo/circle/ArcActivity.java index 77262b5..6d175f1 100644 --- a/positions/src/main/java/cc/winboll/studio/positions/demo/circle/ArcActivity.java +++ b/positions/src/main/java/cc/winboll/studio/positions/demo/circle/ArcActivity.java @@ -1,126 +1,126 @@ -package cc.winboll.studio.positions.demo.circle; - -import androidx.annotation.NonNull; -import androidx.appcompat.app.AppCompatActivity; - -import android.graphics.Color; -import android.os.Bundle; -import android.view.Menu; -import android.view.MenuItem; -import android.view.View; - -import cc.winboll.studio.positions.R; -import com.tencent.tencentmap.mapsdk.maps.CameraUpdate; -import com.tencent.tencentmap.mapsdk.maps.CameraUpdateFactory; -import com.tencent.tencentmap.mapsdk.maps.MapView; -import com.tencent.tencentmap.mapsdk.maps.TencentMap; -import com.tencent.tencentmap.mapsdk.maps.model.Arc; -import com.tencent.tencentmap.mapsdk.maps.model.ArcOptions; -import com.tencent.tencentmap.mapsdk.maps.model.BitmapDescriptor; -import com.tencent.tencentmap.mapsdk.maps.model.BitmapDescriptorFactory; -import com.tencent.tencentmap.mapsdk.maps.model.CameraPosition; -import com.tencent.tencentmap.mapsdk.maps.model.LatLng; -import com.tencent.tencentmap.mapsdk.maps.model.Marker; -import com.tencent.tencentmap.mapsdk.maps.model.MarkerCollisionItem; -import com.tencent.tencentmap.mapsdk.maps.model.MarkerOptions; - -public class ArcActivity extends AppCompatActivity { - - private MapView mapView; - private TencentMap tencentMap; - private boolean mMarkerAdded; - private Arc arc; - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.activity_arc); - init(); - } - - private void init() { - mapView = findViewById(R.id.mapView); - tencentMap = mapView.getMap(); - CameraUpdate cameraSigma = - CameraUpdateFactory.newCameraPosition(new CameraPosition( - new LatLng(32.059352, 118.796623), - 5, - 0f, - 0f)); - //移动地图 - tencentMap.moveCamera(cameraSigma); - } - - @Override - public boolean onCreateOptionsMenu(Menu menu) { - getMenuInflater().inflate(R.menu.markercol, menu); - return super.onCreateOptionsMenu(menu); - } - - @Override - public boolean onPrepareOptionsMenu(Menu menu) { - menu.findItem(R.id.menu_open_collisionsmap).setVisible(!mMarkerAdded); - menu.findItem(R.id.menu_close_collisionsmap).setVisible(mMarkerAdded); - return super.onPrepareOptionsMenu(menu); - } - - @Override - public boolean onOptionsItemSelected(@NonNull MenuItem item) { - switch (item.getItemId()) { - case R.id.menu_open_collisionsmap: - mMarkerAdded = true; - LatLng startLat = new LatLng(39.89491, 116.322056); - LatLng endtLat = new LatLng(22.547, 114.085947); - LatLng passLat = new LatLng(32.059352, 118.796623); - ArcOptions arcOptions = new ArcOptions(); - arcOptions.points(startLat, endtLat); - arcOptions.pass(passLat); - //设置起点到终点,与起点外切线逆时针旋转的夹角角度 - arcOptions.angle(30); - //设置线宽,默认5 - arcOptions.width(2); - //设置线颜色,默认黑色 - arcOptions.color(Color.BLUE); - arc = tencentMap.addArc(arcOptions); - break; - case R.id.menu_close_collisionsmap: - mMarkerAdded = false; - arc.remove(); - break; - } - - supportInvalidateOptionsMenu(); - return super.onOptionsItemSelected(item); - } - - @Override - protected void onResume() { - super.onResume(); - mapView.onResume(); - } - - @Override - protected void onPause() { - super.onPause(); - mapView.onPause(); - } - - @Override - protected void onDestroy() { - super.onDestroy(); - mapView.onDestroy(); - } - - - @Override - protected void onStart() { - super.onStart(); - mapView.onStart(); - } - - @Override - protected void onStop() { - super.onStop(); - mapView.onStop(); - } -} \ No newline at end of file +package cc.winboll.studio.positions.demo.circle; + +//import androidx.annotation.NonNull; +//import androidx.appcompat.app.AppCompatActivity; +// +//import android.graphics.Color; +//import android.os.Bundle; +//import android.view.Menu; +//import android.view.MenuItem; +//import android.view.View; +// +//import cc.winboll.studio.positions.R; +//import com.tencent.tencentmap.mapsdk.maps.CameraUpdate; +//import com.tencent.tencentmap.mapsdk.maps.CameraUpdateFactory; +//import com.tencent.tencentmap.mapsdk.maps.MapView; +//import com.tencent.tencentmap.mapsdk.maps.TencentMap; +//import com.tencent.tencentmap.mapsdk.maps.model.Arc; +//import com.tencent.tencentmap.mapsdk.maps.model.ArcOptions; +//import com.tencent.tencentmap.mapsdk.maps.model.BitmapDescriptor; +//import com.tencent.tencentmap.mapsdk.maps.model.BitmapDescriptorFactory; +//import com.tencent.tencentmap.mapsdk.maps.model.CameraPosition; +//import com.tencent.tencentmap.mapsdk.maps.model.LatLng; +//import com.tencent.tencentmap.mapsdk.maps.model.Marker; +//import com.tencent.tencentmap.mapsdk.maps.model.MarkerCollisionItem; +//import com.tencent.tencentmap.mapsdk.maps.model.MarkerOptions; +// +//public class ArcActivity extends AppCompatActivity { +// +// private MapView mapView; +// private TencentMap tencentMap; +// private boolean mMarkerAdded; +// private Arc arc; +// +// @Override +// protected void onCreate(Bundle savedInstanceState) { +// super.onCreate(savedInstanceState); +// setContentView(R.layout.activity_arc); +// init(); +// } +// +// private void init() { +// mapView = findViewById(R.id.mapView); +// tencentMap = mapView.getMap(); +// CameraUpdate cameraSigma = +// CameraUpdateFactory.newCameraPosition(new CameraPosition( +// new LatLng(32.059352, 118.796623), +// 5, +// 0f, +// 0f)); +// //移动地图 +// tencentMap.moveCamera(cameraSigma); +// } +// +// @Override +// public boolean onCreateOptionsMenu(Menu menu) { +// getMenuInflater().inflate(R.menu.markercol, menu); +// return super.onCreateOptionsMenu(menu); +// } +// +// @Override +// public boolean onPrepareOptionsMenu(Menu menu) { +// menu.findItem(R.id.menu_open_collisionsmap).setVisible(!mMarkerAdded); +// menu.findItem(R.id.menu_close_collisionsmap).setVisible(mMarkerAdded); +// return super.onPrepareOptionsMenu(menu); +// } +// +// @Override +// public boolean onOptionsItemSelected(@NonNull MenuItem item) { +// switch (item.getItemId()) { +// case R.id.menu_open_collisionsmap: +// mMarkerAdded = true; +// LatLng startLat = new LatLng(39.89491, 116.322056); +// LatLng endtLat = new LatLng(22.547, 114.085947); +// LatLng passLat = new LatLng(32.059352, 118.796623); +// ArcOptions arcOptions = new ArcOptions(); +// arcOptions.points(startLat, endtLat); +// arcOptions.pass(passLat); +// //设置起点到终点,与起点外切线逆时针旋转的夹角角度 +// arcOptions.angle(30); +// //设置线宽,默认5 +// arcOptions.width(2); +// //设置线颜色,默认黑色 +// arcOptions.color(Color.BLUE); +// arc = tencentMap.addArc(arcOptions); +// break; +// case R.id.menu_close_collisionsmap: +// mMarkerAdded = false; +// arc.remove(); +// break; +// } +// +// supportInvalidateOptionsMenu(); +// return super.onOptionsItemSelected(item); +// } +// +// @Override +// protected void onResume() { +// super.onResume(); +// mapView.onResume(); +// } +// +// @Override +// protected void onPause() { +// super.onPause(); +// mapView.onPause(); +// } +// +// @Override +// protected void onDestroy() { +// super.onDestroy(); +// mapView.onDestroy(); +// } +// +// +// @Override +// protected void onStart() { +// super.onStart(); +// mapView.onStart(); +// } +// +// @Override +// protected void onStop() { +// super.onStop(); +// mapView.onStop(); +// } +//} diff --git a/positions/src/main/java/cc/winboll/studio/positions/demo/circle/CircleOptionsActivity.java b/positions/src/main/java/cc/winboll/studio/positions/demo/circle/CircleOptionsActivity.java index 2364cfb..b5fd615 100644 --- a/positions/src/main/java/cc/winboll/studio/positions/demo/circle/CircleOptionsActivity.java +++ b/positions/src/main/java/cc/winboll/studio/positions/demo/circle/CircleOptionsActivity.java @@ -8,28 +8,28 @@ import com.tencent.tencentmap.mapsdk.maps.model.CircleOptions; import com.tencent.tencentmap.mapsdk.maps.model.LatLng; public class CircleOptionsActivity extends SupportMapFragmentActivity { - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - Circle circle = tencentMap.addCircle(circleOptions); - Circle newCircle = tencentMap.addCircle(newCircleOptions); - newCircle.setCenter(new LatLng(39.98408, 116.30701)); //重新设置圆心 - newCircle.setOptions(newCircleOptions); //重新设置圆形属性 - } - - /** - * 圆形选项 - */ - private CircleOptions circleOptions = new CircleOptions() //圆形选项 - .center(new LatLng(39.9849, 116.3977)) //圆心位置 - .clickable(true) //支持点击 - .fillColor((128 << 24) + (100 << 16) + (50 << 8) + 120) //设置填充颜色RGBA - .radius(110d) //设置半径 - .visible(true) //设置是否可见 - .zIndex(1) //设置堆叠顺序,越大优先级越高 - .strokeWidth(1) //描边宽度 - .strokeColor((128 << 24) + (128 << 16) + (128 << 8) + 128); //描边颜色 - - - private CircleOptions newCircleOptions = new CircleOptions().center(new LatLng(39.121, 116.454)).radius(90d).fillColor(0xff00ff00); +// @Override +// protected void onCreate(Bundle savedInstanceState) { +// super.onCreate(savedInstanceState); +// Circle circle = tencentMap.addCircle(circleOptions); +// Circle newCircle = tencentMap.addCircle(newCircleOptions); +// newCircle.setCenter(new LatLng(39.98408, 116.30701)); //重新设置圆心 +// newCircle.setOptions(newCircleOptions); //重新设置圆形属性 +// } +// +// /** +// * 圆形选项 +// */ +// private CircleOptions circleOptions = new CircleOptions() //圆形选项 +// .center(new LatLng(39.9849, 116.3977)) //圆心位置 +// .clickable(true) //支持点击 +// .fillColor((128 << 24) + (100 << 16) + (50 << 8) + 120) //设置填充颜色RGBA +// .radius(110d) //设置半径 +// .visible(true) //设置是否可见 +// .zIndex(1) //设置堆叠顺序,越大优先级越高 +// .strokeWidth(1) //描边宽度 +// .strokeColor((128 << 24) + (128 << 16) + (128 << 8) + 128); //描边颜色 +// +// +// private CircleOptions newCircleOptions = new CircleOptions().center(new LatLng(39.121, 116.454)).radius(90d).fillColor(0xff00ff00); } diff --git a/positions/src/main/java/cc/winboll/studio/positions/demo/circle/DrawCircleActivity.java b/positions/src/main/java/cc/winboll/studio/positions/demo/circle/DrawCircleActivity.java index 9f4bcf1..0c2ba39 100644 --- a/positions/src/main/java/cc/winboll/studio/positions/demo/circle/DrawCircleActivity.java +++ b/positions/src/main/java/cc/winboll/studio/positions/demo/circle/DrawCircleActivity.java @@ -9,16 +9,16 @@ import com.tencent.tencentmap.mapsdk.maps.model.CircleOptions; import com.tencent.tencentmap.mapsdk.maps.model.LatLng; public class DrawCircleActivity extends SupportMapFragmentActivity { - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - LatLng latLng = new LatLng(39.984059,116.307771); - Circle circle = tencentMap.addCircle(new CircleOptions(). - center(latLng). - radius(100d). - fillColor(getResources().getColor(R.color.style)). - strokeColor(getResources().getColor(R.color.colorPrimary)). - strokeWidth(1)); - } +// +// @Override +// protected void onCreate(Bundle savedInstanceState) { +// super.onCreate(savedInstanceState); +// LatLng latLng = new LatLng(39.984059,116.307771); +// Circle circle = tencentMap.addCircle(new CircleOptions(). +// center(latLng). +// radius(100d). +// fillColor(getResources().getColor(R.color.style)). +// strokeColor(getResources().getColor(R.color.colorPrimary)). +// strokeWidth(1)); +// } } diff --git a/positions/src/main/java/cc/winboll/studio/positions/demo/gesture/GestureSettingsActivity.java b/positions/src/main/java/cc/winboll/studio/positions/demo/gesture/GestureSettingsActivity.java index 683d883..e4e5c4c 100644 --- a/positions/src/main/java/cc/winboll/studio/positions/demo/gesture/GestureSettingsActivity.java +++ b/positions/src/main/java/cc/winboll/studio/positions/demo/gesture/GestureSettingsActivity.java @@ -1,80 +1,80 @@ package cc.winboll.studio.positions.demo.gesture; -import android.os.Bundle; -import android.view.View; -import android.widget.CheckBox; -import android.widget.CompoundButton; -import android.widget.RadioGroup; - -import cc.winboll.studio.positions.R; -import cc.winboll.studio.positions.demo.basic.SupportMapFragmentActivity; - -public class GestureSettingsActivity extends SupportMapFragmentActivity { - - private CheckBox scrollBox; - private CheckBox zoomBox; - private CheckBox rotateBox; - private CheckBox tiltBox; - private RadioGroup radioGroup; - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - radioGroup = findViewById(R.id.lay_checkbox); - radioGroup.setVisibility(View.VISIBLE); - initView(); - } - - private void initView(){ - scrollBox = findViewById(R.id.btn_scroll); - zoomBox = findViewById(R.id.btn_zoom); - rotateBox = findViewById(R.id.btn_rotate); - tiltBox = findViewById(R.id.btn_slope); - - - scrollBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { - @Override - public void onCheckedChanged(CompoundButton compoundButton, boolean b) { - if (b){ - mapUiSettings.setScrollGesturesEnabled(true); - }else{ - mapUiSettings.setScrollGesturesEnabled(false); - } - } - }); - - - zoomBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { - @Override - public void onCheckedChanged(CompoundButton compoundButton, boolean b) { - if (b){ - mapUiSettings.setZoomGesturesEnabled(true); - }else{ - mapUiSettings.setZoomGesturesEnabled(false); - } - } - }); - - rotateBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { - @Override - public void onCheckedChanged(CompoundButton compoundButton, boolean b) { - if (b){ - mapUiSettings.setRotateGesturesEnabled(true); - }else{ - mapUiSettings.setRotateGesturesEnabled(false); - } - } - }); - - tiltBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { - @Override - public void onCheckedChanged(CompoundButton compoundButton, boolean b) { - if (b){ - mapUiSettings.setTiltGesturesEnabled(true); - }else{ - mapUiSettings.setTiltGesturesEnabled(false); - } - } - }); - } - -} +//import android.os.Bundle; +//import android.view.View; +//import android.widget.CheckBox; +//import android.widget.CompoundButton; +//import android.widget.RadioGroup; +// +//import cc.winboll.studio.positions.R; +//import cc.winboll.studio.positions.demo.basic.SupportMapFragmentActivity; +// +//public class GestureSettingsActivity extends SupportMapFragmentActivity { +// +// private CheckBox scrollBox; +// private CheckBox zoomBox; +// private CheckBox rotateBox; +// private CheckBox tiltBox; +// private RadioGroup radioGroup; +// @Override +// protected void onCreate(Bundle savedInstanceState) { +// super.onCreate(savedInstanceState); +// radioGroup = findViewById(R.id.lay_checkbox); +// radioGroup.setVisibility(View.VISIBLE); +// initView(); +// } +// +// private void initView(){ +// scrollBox = findViewById(R.id.btn_scroll); +// zoomBox = findViewById(R.id.btn_zoom); +// rotateBox = findViewById(R.id.btn_rotate); +// tiltBox = findViewById(R.id.btn_slope); +// +// +// scrollBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { +// @Override +// public void onCheckedChanged(CompoundButton compoundButton, boolean b) { +// if (b){ +// mapUiSettings.setScrollGesturesEnabled(true); +// }else{ +// mapUiSettings.setScrollGesturesEnabled(false); +// } +// } +// }); +// +// +// zoomBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { +// @Override +// public void onCheckedChanged(CompoundButton compoundButton, boolean b) { +// if (b){ +// mapUiSettings.setZoomGesturesEnabled(true); +// }else{ +// mapUiSettings.setZoomGesturesEnabled(false); +// } +// } +// }); +// +// rotateBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { +// @Override +// public void onCheckedChanged(CompoundButton compoundButton, boolean b) { +// if (b){ +// mapUiSettings.setRotateGesturesEnabled(true); +// }else{ +// mapUiSettings.setRotateGesturesEnabled(false); +// } +// } +// }); +// +// tiltBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { +// @Override +// public void onCheckedChanged(CompoundButton compoundButton, boolean b) { +// if (b){ +// mapUiSettings.setTiltGesturesEnabled(true); +// }else{ +// mapUiSettings.setTiltGesturesEnabled(false); +// } +// } +// }); +// } +// +//} diff --git a/positions/src/main/java/cc/winboll/studio/positions/demo/gesture/MapGestureListenActivity.java b/positions/src/main/java/cc/winboll/studio/positions/demo/gesture/MapGestureListenActivity.java index df698b8..73369c8 100644 --- a/positions/src/main/java/cc/winboll/studio/positions/demo/gesture/MapGestureListenActivity.java +++ b/positions/src/main/java/cc/winboll/studio/positions/demo/gesture/MapGestureListenActivity.java @@ -8,75 +8,126 @@ import cc.winboll.studio.positions.R; import cc.winboll.studio.positions.demo.basic.SupportMapFragmentActivity; import com.tencent.tencentmap.mapsdk.maps.model.CameraPosition; import com.tencent.tencentmap.mapsdk.maps.model.TencentMapGestureListener; +import com.tencent.tencentmap.mapsdk.maps.model.TencentMapGestureListener.TwoFingerMoveAgainstStatus; +import com.tencent.tencentmap.mapsdk.maps.model.CameraPosition.Trigger; public class MapGestureListenActivity extends SupportMapFragmentActivity implements TencentMapGestureListener { - private TextView textView; @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - textView = findViewById(R.id.tv_info); - textView.setVisibility(View.VISIBLE); - tencentMap.setTencentMapGestureListener(this); + public boolean onDoubleTap(float p1, float p2) { + return false; } @Override - public boolean onDoubleTap(float v, float v1) { - textView.setText("单指双击"); - return true; + public boolean onSingleTap(float p1, float p2) { + return false; } @Override - public boolean onSingleTap(float v, float v1) { - textView.setText("单指单击"); - return true; + public boolean onFling(float p1, float p2) { + return false; } @Override - public boolean onFling(float v, float v1) { - textView.setText("单指惯性滑动"); - return true; + public boolean onScroll(float p1, float p2) { + return false; } @Override - public boolean onScroll(float v, float v1) { - textView.setText("单指滑动"); - return true; + public boolean onLongPress(float p1, float p2) { + return false; } @Override - public boolean onLongPress(float v, float v1) { - textView.setText("长按"); - return true; + public boolean onDown(float p1, float p2) { + return false; } @Override - public boolean onDown(float v, float v1) { - textView.setText("单指按下"); - return true; + public boolean onUp(float p1, float p2) { + return false; } @Override - public boolean onUp(float v, float v1) { - textView.setText("单指抬起"); - return true; - } - - @Override - public boolean onTwoFingerMoveAgainst(TwoFingerMoveAgainstStatus twoFingerMoveAgainstStatus, CameraPosition cameraPosition) { - textView.setText("双指捏合"); + public boolean onTwoFingerMoveAgainst(TencentMapGestureListener.TwoFingerMoveAgainstStatus p1, CameraPosition p2) { return false; } @Override public void onMapStable() { - textView.setText("地图稳定"); - return; } @Override - public void onMapStableBy(CameraPosition.Trigger trigger) { - textView.setText("地图稳定 by " + trigger.name()); - return; + public void onMapStableBy(CameraPosition.Trigger p1) { } + + +// private TextView textView; +// @Override +// protected void onCreate(Bundle savedInstanceState) { +// super.onCreate(savedInstanceState); +// textView = findViewById(R.id.tv_info); +// textView.setVisibility(View.VISIBLE); +// tencentMap.setTencentMapGestureListener(this); +// } +// +// @Override +// public boolean onDoubleTap(float v, float v1) { +// textView.setText("单指双击"); +// return true; +// } +// +// @Override +// public boolean onSingleTap(float v, float v1) { +// textView.setText("单指单击"); +// return true; +// } +// +// @Override +// public boolean onFling(float v, float v1) { +// textView.setText("单指惯性滑动"); +// return true; +// } +// +// @Override +// public boolean onScroll(float v, float v1) { +// textView.setText("单指滑动"); +// return true; +// } +// +// @Override +// public boolean onLongPress(float v, float v1) { +// textView.setText("长按"); +// return true; +// } +// +// @Override +// public boolean onDown(float v, float v1) { +// textView.setText("单指按下"); +// return true; +// } +// +// @Override +// public boolean onUp(float v, float v1) { +// textView.setText("单指抬起"); +// return true; +// } +// +// @Override +// public boolean onTwoFingerMoveAgainst(TwoFingerMoveAgainstStatus twoFingerMoveAgainstStatus, CameraPosition cameraPosition) { +// textView.setText("双指捏合"); +// return false; +// } +// +// @Override +// public void onMapStable() { +// textView.setText("地图稳定"); +// return; +// } +// +// @Override +// public void onMapStableBy(CameraPosition.Trigger trigger) { +// textView.setText("地图稳定 by " + trigger.name()); +// return; +// } } diff --git a/positions/src/main/java/cc/winboll/studio/positions/demo/gesture/MapListenActivity.java b/positions/src/main/java/cc/winboll/studio/positions/demo/gesture/MapListenActivity.java index 69dced4..0775dac 100644 --- a/positions/src/main/java/cc/winboll/studio/positions/demo/gesture/MapListenActivity.java +++ b/positions/src/main/java/cc/winboll/studio/positions/demo/gesture/MapListenActivity.java @@ -10,21 +10,21 @@ import cc.winboll.studio.positions.demo.basic.SupportMapFragmentActivity; import com.tencent.tencentmap.mapsdk.maps.TencentMap; import com.tencent.tencentmap.mapsdk.maps.model.LatLng; -public class MapListenActivity extends SupportMapFragmentActivity implements TencentMap.OnMapClickListener { - private TextView textView; - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - textView = findViewById(R.id.tv_info); - textView.setVisibility(View.VISIBLE); - tencentMap.setOnMapClickListener(this); - } - - @Override - public void onMapClick(LatLng latLng) { - String info = "经纬度:" + latLng.latitude + "," + latLng.longitude; - Toast.makeText(MapListenActivity.this, info, Toast.LENGTH_SHORT).show(); - textView.setText(info); - } -} +//public class MapListenActivity extends SupportMapFragmentActivity implements TencentMap.OnMapClickListener { +// private TextView textView; +// +// @Override +// protected void onCreate(Bundle savedInstanceState) { +// super.onCreate(savedInstanceState); +// textView = findViewById(R.id.tv_info); +// textView.setVisibility(View.VISIBLE); +// tencentMap.setOnMapClickListener(this); +// } +// +// @Override +// public void onMapClick(LatLng latLng) { +// String info = "经纬度:" + latLng.latitude + "," + latLng.longitude; +// Toast.makeText(MapListenActivity.this, info, Toast.LENGTH_SHORT).show(); +// textView.setText(info); +// } +//} diff --git a/positions/src/main/java/cc/winboll/studio/positions/demo/gesture/MapLongClickActivity.java b/positions/src/main/java/cc/winboll/studio/positions/demo/gesture/MapLongClickActivity.java index ff91779..1569972 100644 --- a/positions/src/main/java/cc/winboll/studio/positions/demo/gesture/MapLongClickActivity.java +++ b/positions/src/main/java/cc/winboll/studio/positions/demo/gesture/MapLongClickActivity.java @@ -1,63 +1,63 @@ package cc.winboll.studio.positions.demo.gesture; -import android.graphics.Bitmap; -import android.graphics.BitmapFactory; -import android.graphics.Matrix; -import android.os.Bundle; -import android.view.View; -import android.widget.TextView; - -import cc.winboll.studio.positions.R; -import cc.winboll.studio.positions.demo.basic.SupportMapFragmentActivity; -import com.tencent.tencentmap.mapsdk.maps.TencentMap; -import com.tencent.tencentmap.mapsdk.maps.model.BitmapDescriptor; -import com.tencent.tencentmap.mapsdk.maps.model.BitmapDescriptorFactory; -import com.tencent.tencentmap.mapsdk.maps.model.LatLng; -import com.tencent.tencentmap.mapsdk.maps.model.MarkerOptions; - -public class MapLongClickActivity extends SupportMapFragmentActivity implements TencentMap.OnMapLongClickListener { - private TextView textView; - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - textView = findViewById(R.id.tv_info); - textView.setVisibility(View.VISIBLE); - tencentMap.setOnMapLongClickListener(this); - } - - @Override - public void onMapLongClick(LatLng latLng) { - String info = "经纬度:"+latLng.latitude+","+latLng.longitude; - textView.setText(info); - setMarker(latLng); - } - - /** - * 长按添加标注 - */ - private void setMarker(LatLng latLng){ - - BitmapDescriptor bitmapDescriptor = BitmapDescriptorFactory.fromBitmap(getBitMap(R.drawable.marker)); - MarkerOptions options = new MarkerOptions().position(latLng).icon(bitmapDescriptor); - tencentMap.clear(); - tencentMap.addMarker(options); - - } - - - private Bitmap getBitMap(int resourceId){ - Bitmap bitmap = BitmapFactory.decodeResource(getResources(), resourceId); - int width = bitmap.getWidth(); - int height = bitmap.getHeight(); - int newWidth = 100; - int newHeight = 100; - float widthScale = ((float)newWidth)/width; - float heightScale = ((float)newHeight)/height; - Matrix matrix = new Matrix(); - matrix.postScale(widthScale, heightScale); - bitmap = Bitmap.createBitmap(bitmap,0,0,width,height,matrix,true); - return bitmap; - } - - -} +//import android.graphics.Bitmap; +//import android.graphics.BitmapFactory; +//import android.graphics.Matrix; +//import android.os.Bundle; +//import android.view.View; +//import android.widget.TextView; +// +//import cc.winboll.studio.positions.R; +//import cc.winboll.studio.positions.demo.basic.SupportMapFragmentActivity; +//import com.tencent.tencentmap.mapsdk.maps.TencentMap; +//import com.tencent.tencentmap.mapsdk.maps.model.BitmapDescriptor; +//import com.tencent.tencentmap.mapsdk.maps.model.BitmapDescriptorFactory; +//import com.tencent.tencentmap.mapsdk.maps.model.LatLng; +//import com.tencent.tencentmap.mapsdk.maps.model.MarkerOptions; +// +//public class MapLongClickActivity extends SupportMapFragmentActivity implements TencentMap.OnMapLongClickListener { +// private TextView textView; +// @Override +// protected void onCreate(Bundle savedInstanceState) { +// super.onCreate(savedInstanceState); +// textView = findViewById(R.id.tv_info); +// textView.setVisibility(View.VISIBLE); +// tencentMap.setOnMapLongClickListener(this); +// } +// +// @Override +// public void onMapLongClick(LatLng latLng) { +// String info = "经纬度:"+latLng.latitude+","+latLng.longitude; +// textView.setText(info); +// setMarker(latLng); +// } +// +// /** +// * 长按添加标注 +// */ +// private void setMarker(LatLng latLng){ +// +// BitmapDescriptor bitmapDescriptor = BitmapDescriptorFactory.fromBitmap(getBitMap(R.drawable.marker)); +// MarkerOptions options = new MarkerOptions().position(latLng).icon(bitmapDescriptor); +// tencentMap.clear(); +// tencentMap.addMarker(options); +// +// } +// +// +// private Bitmap getBitMap(int resourceId){ +// Bitmap bitmap = BitmapFactory.decodeResource(getResources(), resourceId); +// int width = bitmap.getWidth(); +// int height = bitmap.getHeight(); +// int newWidth = 100; +// int newHeight = 100; +// float widthScale = ((float)newWidth)/width; +// float heightScale = ((float)newHeight)/height; +// Matrix matrix = new Matrix(); +// matrix.postScale(widthScale, heightScale); +// bitmap = Bitmap.createBitmap(bitmap,0,0,width,height,matrix,true); +// return bitmap; +// } +// +// +//} diff --git a/positions/src/main/java/cc/winboll/studio/positions/demo/heatoverlay/AggregationOverlayActivity.java b/positions/src/main/java/cc/winboll/studio/positions/demo/heatoverlay/AggregationOverlayActivity.java index 887b6d8..77dd712 100644 --- a/positions/src/main/java/cc/winboll/studio/positions/demo/heatoverlay/AggregationOverlayActivity.java +++ b/positions/src/main/java/cc/winboll/studio/positions/demo/heatoverlay/AggregationOverlayActivity.java @@ -1,197 +1,197 @@ -package cc.winboll.studio.positions.demo.heatoverlay; - -import androidx.annotation.NonNull; -import androidx.appcompat.app.AppCompatActivity; - -import android.graphics.Color; -import android.os.Bundle; -import android.view.Menu; -import android.view.MenuItem; -import android.widget.CompoundButton; -import android.widget.Switch; - -import com.tencent.map.sdk.utilities.visualization.aggregation.AggregationOverlay; -import com.tencent.map.sdk.utilities.visualization.aggregation.AggregationOverlayProvider; -import com.tencent.map.sdk.utilities.visualization.aggregation.HoneyCombVectorOverlayProvider; -import com.tencent.map.sdk.utilities.visualization.datamodels.WeightedLatLng; -import cc.winboll.studio.positions.R; -import com.tencent.tencentmap.mapsdk.maps.CameraUpdateFactory; -import com.tencent.tencentmap.mapsdk.maps.MapView; -import com.tencent.tencentmap.mapsdk.maps.TencentMap; -import com.tencent.tencentmap.mapsdk.maps.model.LatLng; - -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStreamReader; -import java.util.ArrayList; - -public class AggregationOverlayActivity extends AppCompatActivity { - private MapView mMapView; - private TencentMap mTencentMap; - private AggregationOverlay aggregationOverlay; - private AggregationOverlayProvider aggregationOverlayProvider; - private Switch btnSwitch3D; - - boolean mIsSelected; - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.activity_aggregation_overlay_design); - init(); - } - - @Override - public boolean onCreateOptionsMenu(Menu menu) { - getMenuInflater().inflate(R.menu.vectorheatmap, menu); - return true; - } - - @Override - public boolean onPrepareOptionsMenu(Menu menu) { - menu.findItem(R.id.menu_open_vectorheatmap).setVisible(!mIsSelected); - menu.findItem(R.id.menu_close_vectorheatmap).setVisible(mIsSelected); - return super.onPrepareOptionsMenu(menu); - } - - @Override - public boolean onOptionsItemSelected(@NonNull MenuItem item) { - switch (item.getItemId()) { - case R.id.menu_open_vectorheatmap: - addAggregation(); - break; - case R.id.menu_close_vectorheatmap: - mIsSelected = false; - if (aggregationOverlay != null) { - aggregationOverlay.remove(); - aggregationOverlay = null; - } - break; - } - - supportInvalidateOptionsMenu(); - return super.onOptionsItemSelected(item); - } - - @Override - protected void onResume() { - super.onResume(); - mMapView.onResume(); - } - - @Override - protected void onPause() { - super.onPause(); - mMapView.onPause(); - } - - @Override - protected void onDestroy() { - super.onDestroy(); - mMapView.onDestroy(); - } - - - @Override - protected void onStart() { - super.onStart(); - mMapView.onStart(); - } - - @Override - protected void onStop() { - super.onStop(); - mMapView.onStop(); - } - - private void init() { - mMapView = findViewById(R.id.mapView); - mTencentMap = mMapView.getMap(); - mTencentMap.setMapStyle(3); - mTencentMap.moveCamera(CameraUpdateFactory.zoomTo(10f)); - btnSwitch3D = (Switch) findViewById(R.id.btn_switch_3D); - bindListener(); - } - - - private void bindListener() { - - CompoundButton.OnCheckedChangeListener onCheckedChangeListener = new CompoundButton.OnCheckedChangeListener() { - - @Override - public void onCheckedChanged(CompoundButton compoundButton, boolean b) { - switch (compoundButton.getId()) { - case R.id.btn_switch_3D: - if (aggregationOverlay != null) { - if (compoundButton.isChecked()) { - aggregationOverlayProvider.enable3D(true); - aggregationOverlayProvider.enable3D(true).setAnimateDuration(3000); - } else { - aggregationOverlayProvider.enable3D(false); - } - mTencentMap.updateVectorOverlay(aggregationOverlay, aggregationOverlayProvider); - } - break; - default: - break; - } - } - }; - - - btnSwitch3D.setOnCheckedChangeListener(onCheckedChangeListener); - - } - - protected void addAggregation() { - mIsSelected = true; - if (aggregationOverlay != null) { - return; - } - // mTencentMap.moveCamera(CameraUpdateFactory.newCameraPosition(new CameraPosition(new LatLng(39.961629, 116.355343), 12, 0, 0))); - mTencentMap.setBuildingEnable(false); - mTencentMap.setPoisEnabled(false); - BufferedReader br = null; - try { - ArrayList nodes = new ArrayList(); - br = new BufferedReader(new InputStreamReader(getResources().getAssets().open("data2k"))); - String line = null; - while ((line = br.readLine()) != null) { - String[] lines = line.split("\t"); - if (lines.length == 3) { - double value = Double.parseDouble(lines[2]); - LatLng latLng = new LatLng((Double.parseDouble(lines[1])), (Double.parseDouble(lines[0]))); - nodes.add(new WeightedLatLng(latLng, value)); - } - } - - int[] colors = { - Color.argb(255, 0x01, 0x2C, 0x4B), - Color.argb(255, 0x17, 0x3E, 0x59), - Color.argb(255, 0x3A, 0x73, 0x78), - Color.argb(255, 0x98, 0xCD, 0x9A), - Color.argb(255, 0xF6, 0xFB, 0xB6) - }; - double[] startPoints = {0.f, 0.1f, 0.15f, 0.3f, 0.5f}; - - - aggregationOverlayProvider = new HoneyCombVectorOverlayProvider() - .nodes(nodes.toArray(new WeightedLatLng[0])) - .setHeightRange(0, 4000); - aggregationOverlayProvider.colors(colors, startPoints); - aggregationOverlay = mTencentMap.addVectorOverlay(aggregationOverlayProvider); - - - } catch (Exception e) { - e.printStackTrace(); - } finally { - if (br != null) { - try { - br.close(); - } catch (IOException e) { - e.printStackTrace(); - } - } - } - } -} \ No newline at end of file +package cc.winboll.studio.positions.demo.heatoverlay; + +import androidx.annotation.NonNull; +import androidx.appcompat.app.AppCompatActivity; + +import android.graphics.Color; +import android.os.Bundle; +import android.view.Menu; +import android.view.MenuItem; +import android.widget.CompoundButton; +import android.widget.Switch; + +import com.tencent.map.sdk.utilities.visualization.aggregation.AggregationOverlay; +import com.tencent.map.sdk.utilities.visualization.aggregation.AggregationOverlayProvider; +import com.tencent.map.sdk.utilities.visualization.aggregation.HoneyCombVectorOverlayProvider; +import com.tencent.map.sdk.utilities.visualization.datamodels.WeightedLatLng; +import cc.winboll.studio.positions.R; +import com.tencent.tencentmap.mapsdk.maps.CameraUpdateFactory; +import com.tencent.tencentmap.mapsdk.maps.MapView; +import com.tencent.tencentmap.mapsdk.maps.TencentMap; +import com.tencent.tencentmap.mapsdk.maps.model.LatLng; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.ArrayList; + +public class AggregationOverlayActivity extends AppCompatActivity { +// private MapView mMapView; +// private TencentMap mTencentMap; +// private AggregationOverlay aggregationOverlay; +// private AggregationOverlayProvider aggregationOverlayProvider; +// private Switch btnSwitch3D; +// +// boolean mIsSelected; +// +// @Override +// protected void onCreate(Bundle savedInstanceState) { +// super.onCreate(savedInstanceState); +// setContentView(R.layout.activity_aggregation_overlay_design); +// init(); +// } +// +// @Override +// public boolean onCreateOptionsMenu(Menu menu) { +// getMenuInflater().inflate(R.menu.vectorheatmap, menu); +// return true; +// } +// +// @Override +// public boolean onPrepareOptionsMenu(Menu menu) { +// menu.findItem(R.id.menu_open_vectorheatmap).setVisible(!mIsSelected); +// menu.findItem(R.id.menu_close_vectorheatmap).setVisible(mIsSelected); +// return super.onPrepareOptionsMenu(menu); +// } +// +// @Override +// public boolean onOptionsItemSelected(@NonNull MenuItem item) { +// switch (item.getItemId()) { +// case R.id.menu_open_vectorheatmap: +// addAggregation(); +// break; +// case R.id.menu_close_vectorheatmap: +// mIsSelected = false; +// if (aggregationOverlay != null) { +// aggregationOverlay.remove(); +// aggregationOverlay = null; +// } +// break; +// } +// +// supportInvalidateOptionsMenu(); +// return super.onOptionsItemSelected(item); +// } +// +// @Override +// protected void onResume() { +// super.onResume(); +// mMapView.onResume(); +// } +// +// @Override +// protected void onPause() { +// super.onPause(); +// mMapView.onPause(); +// } +// +// @Override +// protected void onDestroy() { +// super.onDestroy(); +// mMapView.onDestroy(); +// } +// +// +// @Override +// protected void onStart() { +// super.onStart(); +// mMapView.onStart(); +// } +// +// @Override +// protected void onStop() { +// super.onStop(); +// mMapView.onStop(); +// } +// +// private void init() { +// mMapView = findViewById(R.id.mapView); +// mTencentMap = mMapView.getMap(); +// mTencentMap.setMapStyle(3); +// mTencentMap.moveCamera(CameraUpdateFactory.zoomTo(10f)); +// btnSwitch3D = (Switch) findViewById(R.id.btn_switch_3D); +// bindListener(); +// } +// +// +// private void bindListener() { +// +// CompoundButton.OnCheckedChangeListener onCheckedChangeListener = new CompoundButton.OnCheckedChangeListener() { +// +// @Override +// public void onCheckedChanged(CompoundButton compoundButton, boolean b) { +// switch (compoundButton.getId()) { +// case R.id.btn_switch_3D: +// if (aggregationOverlay != null) { +// if (compoundButton.isChecked()) { +// aggregationOverlayProvider.enable3D(true); +// aggregationOverlayProvider.enable3D(true).setAnimateDuration(3000); +// } else { +// aggregationOverlayProvider.enable3D(false); +// } +// mTencentMap.updateVectorOverlay(aggregationOverlay, aggregationOverlayProvider); +// } +// break; +// default: +// break; +// } +// } +// }; +// +// +// btnSwitch3D.setOnCheckedChangeListener(onCheckedChangeListener); +// +// } +// +// protected void addAggregation() { +// mIsSelected = true; +// if (aggregationOverlay != null) { +// return; +// } +// // mTencentMap.moveCamera(CameraUpdateFactory.newCameraPosition(new CameraPosition(new LatLng(39.961629, 116.355343), 12, 0, 0))); +// mTencentMap.setBuildingEnable(false); +// mTencentMap.setPoisEnabled(false); +// BufferedReader br = null; +// try { +// ArrayList nodes = new ArrayList(); +// br = new BufferedReader(new InputStreamReader(getResources().getAssets().open("data2k"))); +// String line = null; +// while ((line = br.readLine()) != null) { +// String[] lines = line.split("\t"); +// if (lines.length == 3) { +// double value = Double.parseDouble(lines[2]); +// LatLng latLng = new LatLng((Double.parseDouble(lines[1])), (Double.parseDouble(lines[0]))); +// nodes.add(new WeightedLatLng(latLng, value)); +// } +// } +// +// int[] colors = { +// Color.argb(255, 0x01, 0x2C, 0x4B), +// Color.argb(255, 0x17, 0x3E, 0x59), +// Color.argb(255, 0x3A, 0x73, 0x78), +// Color.argb(255, 0x98, 0xCD, 0x9A), +// Color.argb(255, 0xF6, 0xFB, 0xB6) +// }; +// double[] startPoints = {0.f, 0.1f, 0.15f, 0.3f, 0.5f}; +// +// +// aggregationOverlayProvider = new HoneyCombVectorOverlayProvider() +// .nodes(nodes.toArray(new WeightedLatLng[0])) +// .setHeightRange(0, 4000); +// aggregationOverlayProvider.colors(colors, startPoints); +// aggregationOverlay = mTencentMap.addVectorOverlay(aggregationOverlayProvider); +// +// +// } catch (Exception e) { +// e.printStackTrace(); +// } finally { +// if (br != null) { +// try { +// br.close(); +// } catch (IOException e) { +// e.printStackTrace(); +// } +// } +// } +// } +} diff --git a/positions/src/main/java/cc/winboll/studio/positions/demo/heatoverlay/ArcLineLayerActivity.java b/positions/src/main/java/cc/winboll/studio/positions/demo/heatoverlay/ArcLineLayerActivity.java index 0a02358..bc63935 100644 --- a/positions/src/main/java/cc/winboll/studio/positions/demo/heatoverlay/ArcLineLayerActivity.java +++ b/positions/src/main/java/cc/winboll/studio/positions/demo/heatoverlay/ArcLineLayerActivity.java @@ -1,182 +1,182 @@ -package cc.winboll.studio.positions.demo.heatoverlay; - -import androidx.annotation.NonNull; -import androidx.appcompat.app.AppCompatActivity; - -import android.graphics.Color; -import android.os.Bundle; -import android.view.Menu; -import android.view.MenuItem; -import android.view.View; -import android.widget.Button; -import android.widget.CompoundButton; -import android.widget.Switch; - -import com.tencent.map.sdk.utilities.visualization.datamodels.FromToLatLng; -import com.tencent.map.sdk.utilities.visualization.od.ArcLineOverlay; -import com.tencent.map.sdk.utilities.visualization.od.ArcLineOverlayProvider; -import cc.winboll.studio.positions.R; -import com.tencent.tencentmap.mapsdk.maps.CameraUpdateFactory; -import com.tencent.tencentmap.mapsdk.maps.MapView; -import com.tencent.tencentmap.mapsdk.maps.TencentMap; -import com.tencent.tencentmap.mapsdk.maps.model.CameraPosition; -import com.tencent.tencentmap.mapsdk.maps.model.LatLng; -import com.tencent.tencentmap.mapsdk.maps.model.VectorOverlay; - -import java.io.BufferedReader; -import java.io.InputStreamReader; -import java.util.ArrayList; - -public class ArcLineLayerActivity extends AppCompatActivity { - private MapView mMapView; - private TencentMap mTencentMap; - private VectorOverlay vectorOverlay; - private ArcLineOverlayProvider options; - private Switch btnSwitch3D; - boolean mIsSelected; - private Switch btnani3D; - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.activity_arc_line_layer_design); - init(); - } - - @Override - public boolean onCreateOptionsMenu(Menu menu) { - getMenuInflater().inflate(R.menu.vectorheatmap, menu); - return true; - } - - @Override - public boolean onPrepareOptionsMenu(Menu menu) { - menu.findItem(R.id.menu_open_vectorheatmap).setVisible(!mIsSelected); - menu.findItem(R.id.menu_close_vectorheatmap).setVisible(mIsSelected); - return super.onPrepareOptionsMenu(menu); - } - - @Override - public boolean onOptionsItemSelected(@NonNull MenuItem item) { - switch (item.getItemId()) { - case R.id.menu_open_vectorheatmap: - btnSwitch3D.setVisibility(View.VISIBLE); - addArcLineLayer(); - break; - case R.id.menu_close_vectorheatmap: - mIsSelected = false; - if (vectorOverlay != null) { - vectorOverlay.remove(); - vectorOverlay = null; - } - break; - } - - supportInvalidateOptionsMenu(); - return super.onOptionsItemSelected(item); - } - - @Override - protected void onResume() { - super.onResume(); - mMapView.onResume(); - } - - @Override - protected void onPause() { - super.onPause(); - mMapView.onPause(); - } - - @Override - protected void onDestroy() { - super.onDestroy(); - mMapView.onDestroy(); - } - - - @Override - protected void onStart() { - super.onStart(); - mMapView.onStart(); - } - - @Override - protected void onStop() { - super.onStop(); - mMapView.onStop(); - } - - private void init() { - mMapView = findViewById(R.id.mapView); - mTencentMap = mMapView.getMap(); - mTencentMap.moveCamera(CameraUpdateFactory.zoomTo(5f)); - btnSwitch3D = (Switch) findViewById(R.id.btn_switch_3D); - bindListener(); - - } - - private void bindListener() { - CompoundButton.OnCheckedChangeListener onCheckedChangeListener = new CompoundButton.OnCheckedChangeListener() { - - @Override - public void onCheckedChanged(CompoundButton compoundButton, boolean b) { - switch (compoundButton.getId()) { - case R.id.btn_switch_3D: - if (vectorOverlay != null) { - if (compoundButton.isChecked()) { - options.enable3D(true); - } else { - options.enable3D(false); - } - - mTencentMap.updateVectorOverlay(vectorOverlay, options); - } - break; - - default: - break; - } - } - }; - - btnSwitch3D.setOnCheckedChangeListener(onCheckedChangeListener); - } - - private void addArcLineLayer() { - mIsSelected = true; - if (vectorOverlay == null) { - // mTencentMap.moveCamera(CameraUpdateFactory.newCameraPosition(new CameraPosition(new LatLng(39.9229731, 116.422880668), 8, 0f, 0f))); - mTencentMap.setMapStyle(3); - - int color = Color.argb(255, 0, 255, 170); - BufferedReader br = null; - final ArrayList nodes = new ArrayList(); - try { - br = new BufferedReader(new InputStreamReader(getResources().getAssets().open("arc.dat"))); - String line = null; - while ((line = br.readLine()) != null) { - String[] lines = line.split(" "); - if (lines.length == 5) { - double arc = Double.parseDouble(lines[4]); - LatLng startLatLng = new LatLng((Double.parseDouble(lines[0])), (Double.parseDouble(lines[1]))); - LatLng endLatLng = new LatLng((Double.parseDouble(lines[2])), (Double.parseDouble(lines[3]))); - nodes.add(new FromToLatLng(startLatLng, endLatLng)); - //nodes.add(new FromToLatLng(startLatLng, endLatLng, arc)); - } - } - } catch (Exception e) { - e.printStackTrace(); - } - int[] colors = { - Color.argb(255, 0, 0xd4, 0xff), - Color.argb((int) (255 * 0.3), 0, 0xd4, 0xff), - Color.argb(255, 0, 0xd4, 0xff) - }; - options = new ArcLineOverlayProvider().data(nodes).opacity(2f).width(4).gradient(colors).setAnimateDuration(3000).setHighlightDuration(200).animateColor(Color.argb(255, 0xff, 0xff, 0xff)); - vectorOverlay = mTencentMap.addVectorOverlay(options); - mTencentMap.setPoisEnabled(false); - - } - } -} \ No newline at end of file +package cc.winboll.studio.positions.demo.heatoverlay; + +//import androidx.annotation.NonNull; +//import androidx.appcompat.app.AppCompatActivity; +// +//import android.graphics.Color; +//import android.os.Bundle; +//import android.view.Menu; +//import android.view.MenuItem; +//import android.view.View; +//import android.widget.Button; +//import android.widget.CompoundButton; +//import android.widget.Switch; +// +//import com.tencent.map.sdk.utilities.visualization.datamodels.FromToLatLng; +//import com.tencent.map.sdk.utilities.visualization.od.ArcLineOverlay; +//import com.tencent.map.sdk.utilities.visualization.od.ArcLineOverlayProvider; +//import cc.winboll.studio.positions.R; +//import com.tencent.tencentmap.mapsdk.maps.CameraUpdateFactory; +//import com.tencent.tencentmap.mapsdk.maps.MapView; +//import com.tencent.tencentmap.mapsdk.maps.TencentMap; +//import com.tencent.tencentmap.mapsdk.maps.model.CameraPosition; +//import com.tencent.tencentmap.mapsdk.maps.model.LatLng; +//import com.tencent.tencentmap.mapsdk.maps.model.VectorOverlay; +// +//import java.io.BufferedReader; +//import java.io.InputStreamReader; +//import java.util.ArrayList; +// +//public class ArcLineLayerActivity extends AppCompatActivity { +// private MapView mMapView; +// private TencentMap mTencentMap; +// private VectorOverlay vectorOverlay; +// private ArcLineOverlayProvider options; +// private Switch btnSwitch3D; +// boolean mIsSelected; +// private Switch btnani3D; +// +// @Override +// protected void onCreate(Bundle savedInstanceState) { +// super.onCreate(savedInstanceState); +// setContentView(R.layout.activity_arc_line_layer_design); +// init(); +// } +// +// @Override +// public boolean onCreateOptionsMenu(Menu menu) { +// getMenuInflater().inflate(R.menu.vectorheatmap, menu); +// return true; +// } +// +// @Override +// public boolean onPrepareOptionsMenu(Menu menu) { +// menu.findItem(R.id.menu_open_vectorheatmap).setVisible(!mIsSelected); +// menu.findItem(R.id.menu_close_vectorheatmap).setVisible(mIsSelected); +// return super.onPrepareOptionsMenu(menu); +// } +// +// @Override +// public boolean onOptionsItemSelected(@NonNull MenuItem item) { +// switch (item.getItemId()) { +// case R.id.menu_open_vectorheatmap: +// btnSwitch3D.setVisibility(View.VISIBLE); +// addArcLineLayer(); +// break; +// case R.id.menu_close_vectorheatmap: +// mIsSelected = false; +// if (vectorOverlay != null) { +// vectorOverlay.remove(); +// vectorOverlay = null; +// } +// break; +// } +// +// supportInvalidateOptionsMenu(); +// return super.onOptionsItemSelected(item); +// } +// +// @Override +// protected void onResume() { +// super.onResume(); +// mMapView.onResume(); +// } +// +// @Override +// protected void onPause() { +// super.onPause(); +// mMapView.onPause(); +// } +// +// @Override +// protected void onDestroy() { +// super.onDestroy(); +// mMapView.onDestroy(); +// } +// +// +// @Override +// protected void onStart() { +// super.onStart(); +// mMapView.onStart(); +// } +// +// @Override +// protected void onStop() { +// super.onStop(); +// mMapView.onStop(); +// } +// +// private void init() { +// mMapView = findViewById(R.id.mapView); +// mTencentMap = mMapView.getMap(); +// mTencentMap.moveCamera(CameraUpdateFactory.zoomTo(5f)); +// btnSwitch3D = (Switch) findViewById(R.id.btn_switch_3D); +// bindListener(); +// +// } +// +// private void bindListener() { +// CompoundButton.OnCheckedChangeListener onCheckedChangeListener = new CompoundButton.OnCheckedChangeListener() { +// +// @Override +// public void onCheckedChanged(CompoundButton compoundButton, boolean b) { +// switch (compoundButton.getId()) { +// case R.id.btn_switch_3D: +// if (vectorOverlay != null) { +// if (compoundButton.isChecked()) { +// options.enable3D(true); +// } else { +// options.enable3D(false); +// } +// +// mTencentMap.updateVectorOverlay(vectorOverlay, options); +// } +// break; +// +// default: +// break; +// } +// } +// }; +// +// btnSwitch3D.setOnCheckedChangeListener(onCheckedChangeListener); +// } +// +// private void addArcLineLayer() { +// mIsSelected = true; +// if (vectorOverlay == null) { +// // mTencentMap.moveCamera(CameraUpdateFactory.newCameraPosition(new CameraPosition(new LatLng(39.9229731, 116.422880668), 8, 0f, 0f))); +// mTencentMap.setMapStyle(3); +// +// int color = Color.argb(255, 0, 255, 170); +// BufferedReader br = null; +// final ArrayList nodes = new ArrayList(); +// try { +// br = new BufferedReader(new InputStreamReader(getResources().getAssets().open("arc.dat"))); +// String line = null; +// while ((line = br.readLine()) != null) { +// String[] lines = line.split(" "); +// if (lines.length == 5) { +// double arc = Double.parseDouble(lines[4]); +// LatLng startLatLng = new LatLng((Double.parseDouble(lines[0])), (Double.parseDouble(lines[1]))); +// LatLng endLatLng = new LatLng((Double.parseDouble(lines[2])), (Double.parseDouble(lines[3]))); +// nodes.add(new FromToLatLng(startLatLng, endLatLng)); +// //nodes.add(new FromToLatLng(startLatLng, endLatLng, arc)); +// } +// } +// } catch (Exception e) { +// e.printStackTrace(); +// } +// int[] colors = { +// Color.argb(255, 0, 0xd4, 0xff), +// Color.argb((int) (255 * 0.3), 0, 0xd4, 0xff), +// Color.argb(255, 0, 0xd4, 0xff) +// }; +// options = new ArcLineOverlayProvider().data(nodes).opacity(2f).width(4).gradient(colors).setAnimateDuration(3000).setHighlightDuration(200).animateColor(Color.argb(255, 0xff, 0xff, 0xff)); +// vectorOverlay = mTencentMap.addVectorOverlay(options); +// mTencentMap.setPoisEnabled(false); +// +// } +// } +//} diff --git a/positions/src/main/java/cc/winboll/studio/positions/demo/heatoverlay/DrawHeatOverlayActivity.java b/positions/src/main/java/cc/winboll/studio/positions/demo/heatoverlay/DrawHeatOverlayActivity.java index 5df2f77..e0c5041 100644 --- a/positions/src/main/java/cc/winboll/studio/positions/demo/heatoverlay/DrawHeatOverlayActivity.java +++ b/positions/src/main/java/cc/winboll/studio/positions/demo/heatoverlay/DrawHeatOverlayActivity.java @@ -20,107 +20,112 @@ import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayList; -public class DrawHeatOverlayActivity extends SupportMapFragmentActivity implements HeatMapTileProvider.OnHeatMapReadyListener{ - - private TileOverlay mHeatmapTileOverlay; - private HeatMapTileProvider mProvider; - //热力图半径 - private static final int ALT_HEATMAP_RADIUS = HeatMapTileProvider.DEFAULT_RADIUS; - //热力图透明度 - private static final double ALT_HEATMAP_OPACITY = HeatMapTileProvider.DEFAULT_OPACITY; - //热力图渐变方案 - public static final Gradient ALT_HEATMAP_GRADIENT = HeatMapTileProvider.DEFAULT_GRADIENT; - - private static final int[] CUSTOM_GRADIENT_COLORS = { - Color.argb(0,0, 225, 225), - Color.rgb(102, 125, 200), - Color.rgb(255, 0, 0) - }; - - private static final float[] CUSTOM_GRADIENT_START_POINTS = { - 0.0f, 0.2f, 1f - }; - - public static final Gradient CUSTOM_HEATMAP_GRADIENT = new Gradient(CUSTOM_GRADIENT_COLORS, - CUSTOM_GRADIENT_START_POINTS); - @Override - public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setUpMap(); - Button first = findViewById(R.id.btn_bottom); - first.setVisibility(View.VISIBLE); - first.setText("自定义热力图"); - first.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - mProvider.setHeatTileGenerator(new HeatMapTileProvider.HeatTileGenerator() { - @Override - public double[] generateKernel(int radius) { - double[] kernel = new double[radius * 2 + 1]; - for (int i = -radius; i <= radius; i++) { - kernel[i + radius] = Math.exp(-i * i / (2 * (radius / 2f) * (radius / 2f))); - } - return kernel; - } - - @Override - public int[] generateColorMap(double opacity) { - return CUSTOM_HEATMAP_GRADIENT.generateColorMap(opacity); - } - }); - mHeatmapTileOverlay.clearTileCache(); - mHeatmapTileOverlay.reload(); - } - }); - - } - private void setUpMap() { - tencentMap.moveCamera(CameraUpdateFactory.newLatLngZoom( - new com.tencent.tencentmap.mapsdk.maps.model.LatLng(39.917128, 116.399266), - 7.946870f)); - initHeatMap(); - } - private void initHeatMap() { - BufferedReader br = null; - try { - ArrayList nodes = new ArrayList<>(); - br = new BufferedReader(new InputStreamReader( - getResources().getAssets().open("data2k"))); - String line; - while ((line = br.readLine()) != null) { - String[] lines = line.split("\t"); - if (lines.length == 3) { - double value = Double.parseDouble(lines[2]); - LatLng latLng = new LatLng((Double.parseDouble(lines[1])), - (Double.parseDouble(lines[0]))); - nodes.add(new WeightedLatLng(latLng, value)); - } - } - - mProvider = new HeatMapTileProvider.Builder() - .weightedData(nodes) - .gradient(ALT_HEATMAP_GRADIENT) - .opacity(ALT_HEATMAP_OPACITY) - .radius(ALT_HEATMAP_RADIUS) - .readyListener(this) - .build(tencentMap); - mHeatmapTileOverlay = tencentMap.addTileOverlay(new TileOverlayOptions().tileProvider(mProvider)); - } catch (Exception e) { - e.printStackTrace(); - } finally { - if (br != null) { - try { - br.close(); - } catch (IOException e) { - e.printStackTrace(); - } - } - } - } +public class DrawHeatOverlayActivity extends SupportMapFragmentActivity implements HeatMapTileProvider.OnHeatMapReadyListener { @Override public void onHeatMapReady() { - mHeatmapTileOverlay.clearTileCache(); - mHeatmapTileOverlay.reload(); } + + +// private TileOverlay mHeatmapTileOverlay; +// private HeatMapTileProvider mProvider; +// //热力图半径 +// private static final int ALT_HEATMAP_RADIUS = HeatMapTileProvider.DEFAULT_RADIUS; +// //热力图透明度 +// private static final double ALT_HEATMAP_OPACITY = HeatMapTileProvider.DEFAULT_OPACITY; +// //热力图渐变方案 +// public static final Gradient ALT_HEATMAP_GRADIENT = HeatMapTileProvider.DEFAULT_GRADIENT; +// +// private static final int[] CUSTOM_GRADIENT_COLORS = { +// Color.argb(0,0, 225, 225), +// Color.rgb(102, 125, 200), +// Color.rgb(255, 0, 0) +// }; +// +// private static final float[] CUSTOM_GRADIENT_START_POINTS = { +// 0.0f, 0.2f, 1f +// }; +// +// public static final Gradient CUSTOM_HEATMAP_GRADIENT = new Gradient(CUSTOM_GRADIENT_COLORS, +// CUSTOM_GRADIENT_START_POINTS); +// @Override +// public void onCreate(Bundle savedInstanceState) { +// super.onCreate(savedInstanceState); +// setUpMap(); +// Button first = findViewById(R.id.btn_bottom); +// first.setVisibility(View.VISIBLE); +// first.setText("自定义热力图"); +// first.setOnClickListener(new View.OnClickListener() { +// @Override +// public void onClick(View v) { +// mProvider.setHeatTileGenerator(new HeatMapTileProvider.HeatTileGenerator() { +// @Override +// public double[] generateKernel(int radius) { +// double[] kernel = new double[radius * 2 + 1]; +// for (int i = -radius; i <= radius; i++) { +// kernel[i + radius] = Math.exp(-i * i / (2 * (radius / 2f) * (radius / 2f))); +// } +// return kernel; +// } +// +// @Override +// public int[] generateColorMap(double opacity) { +// return CUSTOM_HEATMAP_GRADIENT.generateColorMap(opacity); +// } +// }); +// mHeatmapTileOverlay.clearTileCache(); +// mHeatmapTileOverlay.reload(); +// } +// }); +// +// } +// private void setUpMap() { +// tencentMap.moveCamera(CameraUpdateFactory.newLatLngZoom( +// new com.tencent.tencentmap.mapsdk.maps.model.LatLng(39.917128, 116.399266), +// 7.946870f)); +// initHeatMap(); +// } +// private void initHeatMap() { +// BufferedReader br = null; +// try { +// ArrayList nodes = new ArrayList<>(); +// br = new BufferedReader(new InputStreamReader( +// getResources().getAssets().open("data2k"))); +// String line; +// while ((line = br.readLine()) != null) { +// String[] lines = line.split("\t"); +// if (lines.length == 3) { +// double value = Double.parseDouble(lines[2]); +// LatLng latLng = new LatLng((Double.parseDouble(lines[1])), +// (Double.parseDouble(lines[0]))); +// nodes.add(new WeightedLatLng(latLng, value)); +// } +// } +// +// mProvider = new HeatMapTileProvider.Builder() +// .weightedData(nodes) +// .gradient(ALT_HEATMAP_GRADIENT) +// .opacity(ALT_HEATMAP_OPACITY) +// .radius(ALT_HEATMAP_RADIUS) +// .readyListener(this) +// .build(tencentMap); +// mHeatmapTileOverlay = tencentMap.addTileOverlay(new TileOverlayOptions().tileProvider(mProvider)); +// } catch (Exception e) { +// e.printStackTrace(); +// } finally { +// if (br != null) { +// try { +// br.close(); +// } catch (IOException e) { +// e.printStackTrace(); +// } +// } +// } +// } +// +// @Override +// public void onHeatMapReady() { +// mHeatmapTileOverlay.clearTileCache(); +// mHeatmapTileOverlay.reload(); +// } } diff --git a/positions/src/main/java/cc/winboll/studio/positions/demo/heatoverlay/GLModelActivity.java b/positions/src/main/java/cc/winboll/studio/positions/demo/heatoverlay/GLModelActivity.java index 7a76b6d..6a6c381 100644 --- a/positions/src/main/java/cc/winboll/studio/positions/demo/heatoverlay/GLModelActivity.java +++ b/positions/src/main/java/cc/winboll/studio/positions/demo/heatoverlay/GLModelActivity.java @@ -1,166 +1,166 @@ -package cc.winboll.studio.positions.demo.heatoverlay; - -import androidx.appcompat.app.AppCompatActivity; - -import android.os.Bundle; -import android.util.Log; -import android.view.View; -import android.widget.AdapterView; -import android.widget.ArrayAdapter; -import android.widget.Spinner; - -import com.tencent.map.sdk.utilities.visualization.glmodel.GLModelOverlay; -import com.tencent.map.sdk.utilities.visualization.glmodel.GLModelOverlayProvider; -import cc.winboll.studio.positions.R; -import com.tencent.tencentmap.mapsdk.maps.CameraUpdateFactory; -import com.tencent.tencentmap.mapsdk.maps.MapView; -import com.tencent.tencentmap.mapsdk.maps.TencentMap; -import com.tencent.tencentmap.mapsdk.maps.TencentMapOptions; -import com.tencent.tencentmap.mapsdk.maps.model.GeneralTranslateAnimator; -import com.tencent.tencentmap.mapsdk.maps.model.IAnimatorModel; -import com.tencent.tencentmap.mapsdk.maps.model.LatLng; -import com.tencent.tencentmap.mapsdk.maps.model.LatLngBounds; -import com.tencent.tencentmap.mapsdk.maps.model.Polyline; -import com.tencent.tencentmap.mapsdk.maps.model.PolylineOptions; - -import java.io.File; -import java.util.Arrays; - -import static com.tencent.map.sdk.utilities.visualization.glmodel.GLModelOverlayProvider.CoordType.GeoGraphicType; -import static com.tencent.map.sdk.utilities.visualization.glmodel.GLModelOverlayProvider.CoordType.PixelType; - -public class GLModelActivity extends AppCompatActivity { - - /** - * 和其他覆盖物相同三维模型图也可控制图层的Level和zIndex - * 可通过 GLModelOverlayProvider的displayLevel和zIndex进行设置 - * displayLevel - 默认层级为POI之下 OverlayLevel.OverlayLevelAboveBuildings - * 相同Level内的显示层级关系通过zIndex(int)来控制,zIndex越大越靠上显示。 Level优先级高于zIndex displayLevel必须为如下值之一,否则不生效 - */ - - private MapView mapView; - protected TencentMap tencentMap; - private String mResourcePath; - private GLModelOverlay vectorOverlay; - private final String mLine = "39.98409,116.30804,39.98409,116.3081,39.98409,116.3081,39.98397,116.30809,39.9823,116.30809,39.9811,116.30817,39.9811,116.30817,39.97918,116.308266,39.97918,116.308266,39.9791,116.30827,39.9791,116.30827,39.979008,116.3083,39.978756,116.3084,39.978386,116.3086,39.977867,116.30884,39.977547,116.308914,39.976845,116.308914,39.975826,116.308945,39.975826,116.308945,39.975666,116.30901,39.975716,116.310486,39.975716,116.310486,39.975754,116.31129,39.975754,116.31129,39.975784,116.31241,39.975822,116.31327,39.97581,116.31352,39.97588,116.31591,39.97588,116.31591,39.97591,116.31735,39.97591,116.31735,39.97593,116.31815,39.975967,116.31879,39.975986,116.32034,39.976055,116.32211,39.976086,116.323395,39.976105,116.32514,39.976173,116.32631,39.976254,116.32811,39.976265,116.3288,39.976345,116.33123,39.976357,116.33198,39.976418,116.33346,39.976418,116.33346,39.97653,116.333755,39.97653,116.333755,39.978157,116.333664,39.978157,116.333664,39.978195,116.33509,39.978195,116.33509,39.978226,116.33625,39.978226,116.33625,39.97823,116.33656,39.97823,116.33656,39.978256,116.33791,39.978256,116.33791,39.978016,116.33789,39.977047,116.33791,39.977047,116.33791,39.97706,116.33768,39.97706,116.33768,39.976967,116.33706,39.976967,116.33697"; - private LatLng[] mCarLatLngArray; - private GeneralTranslateAnimator animator; - private Polyline polyline; - private Spinner mSpinner; - private String[] glmodelAnimator = new String[]{"开启平滑移动", "开启骨骼动画", "关闭骨骼动画"}; - private GLModelOverlayProvider provider; - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.activity_g_l_model); - mapView = findViewById(R.id.mapView); - tencentMap = this.mapView.getMap(); - String[] linePointsStr = mLine.split(","); - mCarLatLngArray = new LatLng[linePointsStr.length / 4]; - - for (int i = 0; i < mCarLatLngArray.length; i++) { - double latitude = Double.parseDouble(linePointsStr[i * 4]); - double longitude = Double.parseDouble(linePointsStr[i * 4 + 1]); - mCarLatLngArray[i] = new LatLng(latitude, longitude); - } - polyline = tencentMap.addPolyline(new PolylineOptions().add(mCarLatLngArray).color(R.color.colorAccent).arrow(true)); - tencentMap.animateCamera(CameraUpdateFactory.newLatLngBounds(LatLngBounds.builder().include(Arrays.asList(mCarLatLngArray)).build(), 50)); - creatglmode(); - init(); - } - - private void creatglmode() { - //gltf格式三维模型文件在assets内 - String file = "BrainStem.gltf"; - String SKELETON_PATH = "gltf-BrainStem"; - //获取外部存储 - mResourcePath = getExternalFilesDir(null).getAbsolutePath() + File.separator + SKELETON_PATH; - provider = new GLModelOverlayProvider( - mResourcePath + File.separator + file, - new LatLng(39.98409, 116.30804)).coordType(PixelType) - .pixelBounds(400, 1200).rotationX(90).rotationY(0).rotationZ(0).setClickEnable(true); - vectorOverlay = tencentMap.addVectorOverlay(provider); - } - - private void init() { - mSpinner = findViewById(R.id.sp_glmode); - ArrayAdapter adapter = new ArrayAdapter(getApplicationContext(), android.R.layout.simple_spinner_dropdown_item, glmodelAnimator); - mSpinner.setAdapter(adapter); - mSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { - @Override - public void onItemSelected(AdapterView parent, View view, int position, long id) { - switch (position) { - //开启骨骼动画 - case 0: - animator = new GeneralTranslateAnimator.Builder(vectorOverlay, 6000, - mCarLatLngArray).rotateEnabled(true).initRotate(180).modelType(GeneralTranslateAnimator.ModelType.MODEL_OVERLAY).build(); - animator.startAnimation(); - animator.addAnimatorEndListener(new IAnimatorModel.IAnimatorEndListener() { - @Override - public void onAnimatorEnd() { - Log.i("TransformActivity", "onAnimatorEnd"); - } - }); - break; - //停止骨骼动画 - case 1: - vectorOverlay.playSkeletonAnimation(0, 1, true); - break; - //模型平移 - case 2: - vectorOverlay.stopSkeletonAnimation(); - break; - } - } - - @Override - public void onNothingSelected(AdapterView parent) { - - } - }); - - } - - /** - * mapview的生命周期管理 - */ - @Override - protected void onStart() { - super.onStart(); - mapView.onStart(); - } - - @Override - protected void onResume() { - super.onResume(); - mapView.onResume(); - } - - - @Override - protected void onPause() { - super.onPause(); - mapView.onPause(); - } - - @Override - protected void onStop() { - super.onStop(); - mapView.onStop(); - } - - @Override - protected void onDestroy() { - super.onDestroy(); - mapView.onDestroy(); - vectorOverlay.remove(); - - } - - @Override - protected void onRestart() { - super.onRestart(); - mapView.onRestart(); - } -} +package cc.winboll.studio.positions.demo.heatoverlay; + +import androidx.appcompat.app.AppCompatActivity; + +import android.os.Bundle; +import android.util.Log; +import android.view.View; +import android.widget.AdapterView; +import android.widget.ArrayAdapter; +import android.widget.Spinner; + +import com.tencent.map.sdk.utilities.visualization.glmodel.GLModelOverlay; +import com.tencent.map.sdk.utilities.visualization.glmodel.GLModelOverlayProvider; +import cc.winboll.studio.positions.R; +import com.tencent.tencentmap.mapsdk.maps.CameraUpdateFactory; +import com.tencent.tencentmap.mapsdk.maps.MapView; +import com.tencent.tencentmap.mapsdk.maps.TencentMap; +import com.tencent.tencentmap.mapsdk.maps.TencentMapOptions; +import com.tencent.tencentmap.mapsdk.maps.model.GeneralTranslateAnimator; +import com.tencent.tencentmap.mapsdk.maps.model.IAnimatorModel; +import com.tencent.tencentmap.mapsdk.maps.model.LatLng; +import com.tencent.tencentmap.mapsdk.maps.model.LatLngBounds; +import com.tencent.tencentmap.mapsdk.maps.model.Polyline; +import com.tencent.tencentmap.mapsdk.maps.model.PolylineOptions; + +import java.io.File; +import java.util.Arrays; + +import static com.tencent.map.sdk.utilities.visualization.glmodel.GLModelOverlayProvider.CoordType.GeoGraphicType; +import static com.tencent.map.sdk.utilities.visualization.glmodel.GLModelOverlayProvider.CoordType.PixelType; + +public class GLModelActivity extends AppCompatActivity { +// +// /** +// * 和其他覆盖物相同三维模型图也可控制图层的Level和zIndex +// * 可通过 GLModelOverlayProvider的displayLevel和zIndex进行设置 +// * displayLevel - 默认层级为POI之下 OverlayLevel.OverlayLevelAboveBuildings +// * 相同Level内的显示层级关系通过zIndex(int)来控制,zIndex越大越靠上显示。 Level优先级高于zIndex displayLevel必须为如下值之一,否则不生效 +// */ +// +// private MapView mapView; +// protected TencentMap tencentMap; +// private String mResourcePath; +// private GLModelOverlay vectorOverlay; +// private final String mLine = "39.98409,116.30804,39.98409,116.3081,39.98409,116.3081,39.98397,116.30809,39.9823,116.30809,39.9811,116.30817,39.9811,116.30817,39.97918,116.308266,39.97918,116.308266,39.9791,116.30827,39.9791,116.30827,39.979008,116.3083,39.978756,116.3084,39.978386,116.3086,39.977867,116.30884,39.977547,116.308914,39.976845,116.308914,39.975826,116.308945,39.975826,116.308945,39.975666,116.30901,39.975716,116.310486,39.975716,116.310486,39.975754,116.31129,39.975754,116.31129,39.975784,116.31241,39.975822,116.31327,39.97581,116.31352,39.97588,116.31591,39.97588,116.31591,39.97591,116.31735,39.97591,116.31735,39.97593,116.31815,39.975967,116.31879,39.975986,116.32034,39.976055,116.32211,39.976086,116.323395,39.976105,116.32514,39.976173,116.32631,39.976254,116.32811,39.976265,116.3288,39.976345,116.33123,39.976357,116.33198,39.976418,116.33346,39.976418,116.33346,39.97653,116.333755,39.97653,116.333755,39.978157,116.333664,39.978157,116.333664,39.978195,116.33509,39.978195,116.33509,39.978226,116.33625,39.978226,116.33625,39.97823,116.33656,39.97823,116.33656,39.978256,116.33791,39.978256,116.33791,39.978016,116.33789,39.977047,116.33791,39.977047,116.33791,39.97706,116.33768,39.97706,116.33768,39.976967,116.33706,39.976967,116.33697"; +// private LatLng[] mCarLatLngArray; +// private GeneralTranslateAnimator animator; +// private Polyline polyline; +// private Spinner mSpinner; +// private String[] glmodelAnimator = new String[]{"开启平滑移动", "开启骨骼动画", "关闭骨骼动画"}; +// private GLModelOverlayProvider provider; +// +// @Override +// protected void onCreate(Bundle savedInstanceState) { +// super.onCreate(savedInstanceState); +// setContentView(R.layout.activity_g_l_model); +// mapView = findViewById(R.id.mapView); +// tencentMap = this.mapView.getMap(); +// String[] linePointsStr = mLine.split(","); +// mCarLatLngArray = new LatLng[linePointsStr.length / 4]; +// +// for (int i = 0; i < mCarLatLngArray.length; i++) { +// double latitude = Double.parseDouble(linePointsStr[i * 4]); +// double longitude = Double.parseDouble(linePointsStr[i * 4 + 1]); +// mCarLatLngArray[i] = new LatLng(latitude, longitude); +// } +// polyline = tencentMap.addPolyline(new PolylineOptions().add(mCarLatLngArray).color(R.color.colorAccent).arrow(true)); +// tencentMap.animateCamera(CameraUpdateFactory.newLatLngBounds(LatLngBounds.builder().include(Arrays.asList(mCarLatLngArray)).build(), 50)); +// creatglmode(); +// init(); +// } +// +// private void creatglmode() { +// //gltf格式三维模型文件在assets内 +// String file = "BrainStem.gltf"; +// String SKELETON_PATH = "gltf-BrainStem"; +// //获取外部存储 +// mResourcePath = getExternalFilesDir(null).getAbsolutePath() + File.separator + SKELETON_PATH; +// provider = new GLModelOverlayProvider( +// mResourcePath + File.separator + file, +// new LatLng(39.98409, 116.30804)).coordType(PixelType) +// .pixelBounds(400, 1200).rotationX(90).rotationY(0).rotationZ(0).setClickEnable(true); +// vectorOverlay = tencentMap.addVectorOverlay(provider); +// } +// +// private void init() { +// mSpinner = findViewById(R.id.sp_glmode); +// ArrayAdapter adapter = new ArrayAdapter(getApplicationContext(), android.R.layout.simple_spinner_dropdown_item, glmodelAnimator); +// mSpinner.setAdapter(adapter); +// mSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { +// @Override +// public void onItemSelected(AdapterView parent, View view, int position, long id) { +// switch (position) { +// //开启骨骼动画 +// case 0: +// animator = new GeneralTranslateAnimator.Builder(vectorOverlay, 6000, +// mCarLatLngArray).rotateEnabled(true).initRotate(180).modelType(GeneralTranslateAnimator.ModelType.MODEL_OVERLAY).build(); +// animator.startAnimation(); +// animator.addAnimatorEndListener(new IAnimatorModel.IAnimatorEndListener() { +// @Override +// public void onAnimatorEnd() { +// Log.i("TransformActivity", "onAnimatorEnd"); +// } +// }); +// break; +// //停止骨骼动画 +// case 1: +// vectorOverlay.playSkeletonAnimation(0, 1, true); +// break; +// //模型平移 +// case 2: +// vectorOverlay.stopSkeletonAnimation(); +// break; +// } +// } +// +// @Override +// public void onNothingSelected(AdapterView parent) { +// +// } +// }); +// +// } +// +// /** +// * mapview的生命周期管理 +// */ +// @Override +// protected void onStart() { +// super.onStart(); +// mapView.onStart(); +// } +// +// @Override +// protected void onResume() { +// super.onResume(); +// mapView.onResume(); +// } +// +// +// @Override +// protected void onPause() { +// super.onPause(); +// mapView.onPause(); +// } +// +// @Override +// protected void onStop() { +// super.onStop(); +// mapView.onStop(); +// } +// +// @Override +// protected void onDestroy() { +// super.onDestroy(); +// mapView.onDestroy(); +// vectorOverlay.remove(); +// +// } +// +// @Override +// protected void onRestart() { +// super.onRestart(); +// mapView.onRestart(); +// } +} diff --git a/positions/src/main/java/cc/winboll/studio/positions/demo/heatoverlay/HeatMapVectorOverlayActivity.java b/positions/src/main/java/cc/winboll/studio/positions/demo/heatoverlay/HeatMapVectorOverlayActivity.java index 60a3f98..d4abd4d 100644 --- a/positions/src/main/java/cc/winboll/studio/positions/demo/heatoverlay/HeatMapVectorOverlayActivity.java +++ b/positions/src/main/java/cc/winboll/studio/positions/demo/heatoverlay/HeatMapVectorOverlayActivity.java @@ -1,171 +1,171 @@ -package cc.winboll.studio.positions.demo.heatoverlay; - -import androidx.annotation.NonNull; -import androidx.appcompat.app.AppCompatActivity; - -import android.graphics.Color; -import android.os.Bundle; -import android.view.Menu; -import android.view.MenuItem; -import android.view.View; -import android.widget.Button; - -import com.tencent.map.sdk.utilities.visualization.datamodels.WeightedLatLng; -import com.tencent.map.sdk.utilities.visualization.heatmap.GradientVectorOverlay; -import com.tencent.map.sdk.utilities.visualization.heatmap.GradientVectorOverlayProvider; -import cc.winboll.studio.positions.R; -import com.tencent.tencentmap.mapsdk.maps.CameraUpdate; -import com.tencent.tencentmap.mapsdk.maps.CameraUpdateFactory; -import com.tencent.tencentmap.mapsdk.maps.MapView; -import com.tencent.tencentmap.mapsdk.maps.TencentMap; -import com.tencent.tencentmap.mapsdk.maps.model.CameraPosition; -import com.tencent.tencentmap.mapsdk.maps.model.LatLng; - -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStreamReader; -import java.util.ArrayList; - -public class HeatMapVectorOverlayActivity extends AppCompatActivity { - private MapView mMapView; - private TencentMap mTencentMap; - private GradientVectorOverlay heatTileOverlay; - private GradientVectorOverlayProvider heatMapTileProvider; - boolean mIsSelected; - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.activity_heat_map_vector_overlay_design); - init(); - } - - @Override - public boolean onCreateOptionsMenu(Menu menu) { - getMenuInflater().inflate(R.menu.vectorheatmap, menu); - return true; - } - - @Override - public boolean onPrepareOptionsMenu(Menu menu) { - menu.findItem(R.id.menu_open_vectorheatmap).setVisible(!mIsSelected); - menu.findItem(R.id.menu_close_vectorheatmap).setVisible(mIsSelected); - return super.onPrepareOptionsMenu(menu); - } - - @Override - public boolean onOptionsItemSelected(@NonNull MenuItem item) { - switch (item.getItemId()) { - case R.id.menu_open_vectorheatmap: - addHeatMap(); - break; - case R.id.menu_close_vectorheatmap: - mIsSelected = false; - if (heatTileOverlay != null) { - heatTileOverlay.remove(); - heatTileOverlay = null; - } - break; - } - - supportInvalidateOptionsMenu(); - return super.onOptionsItemSelected(item); - } - - @Override - protected void onResume() { - super.onResume(); - mMapView.onResume(); - } - - @Override - protected void onPause() { - super.onPause(); - mMapView.onPause(); - } - - @Override - protected void onDestroy() { - super.onDestroy(); - mMapView.onDestroy(); - } - - - @Override - protected void onStart() { - super.onStart(); - mMapView.onStart(); - } - - @Override - protected void onStop() { - super.onStop(); - mMapView.onStop(); - } - - private void init() { - mMapView = findViewById(R.id.mapView); - mTencentMap = mMapView.getMap(); - mTencentMap.setMapStyle(3); - CameraUpdate cameraSigma = - CameraUpdateFactory.newCameraPosition(new CameraPosition( - new LatLng(31.085414, 111.024319), - 4, - 20f, - 1f)); - mTencentMap.moveCamera(cameraSigma); - } - - - private void addHeatMap() { - mIsSelected = true; - if (heatTileOverlay != null) { - return; - } - mTencentMap.setBuildingEnable(false); - mTencentMap.setPoisEnabled(false); - BufferedReader br = null; - try { - ArrayList nodes = new ArrayList(); - br = new BufferedReader(new InputStreamReader(getResources().getAssets().open("data2k"))); - String line = null; - while ((line = br.readLine()) != null) { - String[] lines = line.split("\t"); - if (lines.length == 3) { - double value = Double.parseDouble(lines[2]); - LatLng latLng = new LatLng((Double.parseDouble(lines[1])), (Double.parseDouble(lines[0]))); - nodes.add(new WeightedLatLng(latLng, value)); - } - } - - // 通用配色1 - int[] colors = { - Color.argb(255, 77, 111, 255), - Color.argb(255, 0, 238, 227), - Color.argb(255, 113, 236, 80), - Color.argb(255, 255, 176, 0), - Color.argb(255, 255, 72, 0) - }; - float[] startPoints = {0.1f, 0.185f, 0.3571f, 0.6142f, 1f}; - - - heatMapTileProvider = new GradientVectorOverlayProvider() - .weightedData(nodes).enable3D(true) - .radius(56).setMaxHeight(500).setAnimateDuration(3000); - heatMapTileProvider.opacity(0.95f); - heatMapTileProvider.gradient(colors, startPoints); - heatTileOverlay = mTencentMap.addVectorOverlay(heatMapTileProvider); - - } catch (Exception e) { - e.printStackTrace(); - } finally { - if (br != null) { - try { - br.close(); - } catch (IOException e) { - e.printStackTrace(); - } - } - } - } -} \ No newline at end of file +package cc.winboll.studio.positions.demo.heatoverlay; + +import androidx.annotation.NonNull; +import androidx.appcompat.app.AppCompatActivity; + +import android.graphics.Color; +import android.os.Bundle; +import android.view.Menu; +import android.view.MenuItem; +import android.view.View; +import android.widget.Button; + +import com.tencent.map.sdk.utilities.visualization.datamodels.WeightedLatLng; +import com.tencent.map.sdk.utilities.visualization.heatmap.GradientVectorOverlay; +import com.tencent.map.sdk.utilities.visualization.heatmap.GradientVectorOverlayProvider; +import cc.winboll.studio.positions.R; +import com.tencent.tencentmap.mapsdk.maps.CameraUpdate; +import com.tencent.tencentmap.mapsdk.maps.CameraUpdateFactory; +import com.tencent.tencentmap.mapsdk.maps.MapView; +import com.tencent.tencentmap.mapsdk.maps.TencentMap; +import com.tencent.tencentmap.mapsdk.maps.model.CameraPosition; +import com.tencent.tencentmap.mapsdk.maps.model.LatLng; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.ArrayList; + +public class HeatMapVectorOverlayActivity extends AppCompatActivity { +// private MapView mMapView; +// private TencentMap mTencentMap; +// private GradientVectorOverlay heatTileOverlay; +// private GradientVectorOverlayProvider heatMapTileProvider; +// boolean mIsSelected; +// +// @Override +// protected void onCreate(Bundle savedInstanceState) { +// super.onCreate(savedInstanceState); +// setContentView(R.layout.activity_heat_map_vector_overlay_design); +// init(); +// } +// +// @Override +// public boolean onCreateOptionsMenu(Menu menu) { +// getMenuInflater().inflate(R.menu.vectorheatmap, menu); +// return true; +// } +// +// @Override +// public boolean onPrepareOptionsMenu(Menu menu) { +// menu.findItem(R.id.menu_open_vectorheatmap).setVisible(!mIsSelected); +// menu.findItem(R.id.menu_close_vectorheatmap).setVisible(mIsSelected); +// return super.onPrepareOptionsMenu(menu); +// } +// +// @Override +// public boolean onOptionsItemSelected(@NonNull MenuItem item) { +// switch (item.getItemId()) { +// case R.id.menu_open_vectorheatmap: +// addHeatMap(); +// break; +// case R.id.menu_close_vectorheatmap: +// mIsSelected = false; +// if (heatTileOverlay != null) { +// heatTileOverlay.remove(); +// heatTileOverlay = null; +// } +// break; +// } +// +// supportInvalidateOptionsMenu(); +// return super.onOptionsItemSelected(item); +// } +// +// @Override +// protected void onResume() { +// super.onResume(); +// mMapView.onResume(); +// } +// +// @Override +// protected void onPause() { +// super.onPause(); +// mMapView.onPause(); +// } +// +// @Override +// protected void onDestroy() { +// super.onDestroy(); +// mMapView.onDestroy(); +// } +// +// +// @Override +// protected void onStart() { +// super.onStart(); +// mMapView.onStart(); +// } +// +// @Override +// protected void onStop() { +// super.onStop(); +// mMapView.onStop(); +// } +// +// private void init() { +// mMapView = findViewById(R.id.mapView); +// mTencentMap = mMapView.getMap(); +// mTencentMap.setMapStyle(3); +// CameraUpdate cameraSigma = +// CameraUpdateFactory.newCameraPosition(new CameraPosition( +// new LatLng(31.085414, 111.024319), +// 4, +// 20f, +// 1f)); +// mTencentMap.moveCamera(cameraSigma); +// } +// +// +// private void addHeatMap() { +// mIsSelected = true; +// if (heatTileOverlay != null) { +// return; +// } +// mTencentMap.setBuildingEnable(false); +// mTencentMap.setPoisEnabled(false); +// BufferedReader br = null; +// try { +// ArrayList nodes = new ArrayList(); +// br = new BufferedReader(new InputStreamReader(getResources().getAssets().open("data2k"))); +// String line = null; +// while ((line = br.readLine()) != null) { +// String[] lines = line.split("\t"); +// if (lines.length == 3) { +// double value = Double.parseDouble(lines[2]); +// LatLng latLng = new LatLng((Double.parseDouble(lines[1])), (Double.parseDouble(lines[0]))); +// nodes.add(new WeightedLatLng(latLng, value)); +// } +// } +// +// // 通用配色1 +// int[] colors = { +// Color.argb(255, 77, 111, 255), +// Color.argb(255, 0, 238, 227), +// Color.argb(255, 113, 236, 80), +// Color.argb(255, 255, 176, 0), +// Color.argb(255, 255, 72, 0) +// }; +// float[] startPoints = {0.1f, 0.185f, 0.3571f, 0.6142f, 1f}; +// +// +// heatMapTileProvider = new GradientVectorOverlayProvider() +// .weightedData(nodes).enable3D(true) +// .radius(56).setMaxHeight(500).setAnimateDuration(3000); +// heatMapTileProvider.opacity(0.95f); +// heatMapTileProvider.gradient(colors, startPoints); +// heatTileOverlay = mTencentMap.addVectorOverlay(heatMapTileProvider); +// +// } catch (Exception e) { +// e.printStackTrace(); +// } finally { +// if (br != null) { +// try { +// br.close(); +// } catch (IOException e) { +// e.printStackTrace(); +// } +// } +// } +// } +} diff --git a/positions/src/main/java/cc/winboll/studio/positions/demo/heatoverlay/ScatterPlotOverlayActivity.java b/positions/src/main/java/cc/winboll/studio/positions/demo/heatoverlay/ScatterPlotOverlayActivity.java index 2655748..f63b708 100644 --- a/positions/src/main/java/cc/winboll/studio/positions/demo/heatoverlay/ScatterPlotOverlayActivity.java +++ b/positions/src/main/java/cc/winboll/studio/positions/demo/heatoverlay/ScatterPlotOverlayActivity.java @@ -1,180 +1,180 @@ -package cc.winboll.studio.positions.demo.heatoverlay; - -import androidx.annotation.NonNull; -import androidx.appcompat.app.AppCompatActivity; - -import android.graphics.Color; -import android.os.Bundle; -import android.view.Menu; -import android.view.MenuItem; -import android.view.View; -import android.widget.AdapterView; -import android.widget.ArrayAdapter; -import android.widget.CompoundButton; -import android.widget.Spinner; -import android.widget.Switch; - -import com.tencent.map.sdk.utilities.visualization.datamodels.ScatterLatLng; -import com.tencent.map.sdk.utilities.visualization.scatterplot.BitmapScatterPlotOverlayProvider; -import com.tencent.map.sdk.utilities.visualization.scatterplot.DotScatterPlotOverlayProvider; -import cc.winboll.studio.positions.R; -import com.tencent.tencentmap.mapsdk.maps.CameraUpdateFactory; -import com.tencent.tencentmap.mapsdk.maps.MapView; -import com.tencent.tencentmap.mapsdk.maps.TencentMap; -import com.tencent.tencentmap.mapsdk.maps.model.BitmapDescriptor; -import com.tencent.tencentmap.mapsdk.maps.model.BitmapDescriptorFactory; -import com.tencent.tencentmap.mapsdk.maps.model.CameraPosition; -import com.tencent.tencentmap.mapsdk.maps.model.LatLng; -import com.tencent.tencentmap.mapsdk.maps.model.MarkerOptions; -import com.tencent.tencentmap.mapsdk.maps.model.VectorOverlay; - -import java.io.BufferedReader; -import java.util.ArrayList; -import java.util.Random; - -public class ScatterPlotOverlayActivity extends AppCompatActivity { - private MapView mMapView; - private TencentMap mTencentMap; - private VectorOverlay vectorOverlay; - boolean mIsSelected; - private DotScatterPlotOverlayProvider dotScatterPlotOverlayProvider; - private BitmapScatterPlotOverlayProvider provider; - private String[] styles = new String[]{"添加点散点", "添加图片散点"}; - private Spinner mSpinner; - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.activity_scatter_plot_overlay); - init(); - } - - - @Override - protected void onResume() { - super.onResume(); - mMapView.onResume(); - } - - @Override - protected void onPause() { - super.onPause(); - mMapView.onPause(); - } - - @Override - protected void onDestroy() { - super.onDestroy(); - mMapView.onDestroy(); - } - - - @Override - protected void onStart() { - super.onStart(); - mMapView.onStart(); - } - - @Override - protected void onStop() { - super.onStop(); - mMapView.onStop(); - } - - private void init() { - mMapView = findViewById(R.id.mapView); - mTencentMap = mMapView.getMap(); - mTencentMap.moveCamera(CameraUpdateFactory.zoomTo(5f)); - mTencentMap.moveCamera(CameraUpdateFactory.newCameraPosition(new CameraPosition(new LatLng(40.040219, 116.273348), 20, 0, 0))); - mSpinner = findViewById(R.id.sp_style); - ArrayAdapter adapter = new ArrayAdapter(getApplicationContext(), android.R.layout.simple_spinner_dropdown_item, styles); - mSpinner.setAdapter(adapter); - mSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { - @Override - public void onItemSelected(AdapterView parent, View view, int position, long id) { - switch (position) { - case 0: - if (vectorOverlay != null) { - vectorOverlay.remove(); - vectorOverlay = null; - } - addDotVectorOverlay(); - mTencentMap.updateVectorOverlay(vectorOverlay, dotScatterPlotOverlayProvider); - break; - case 1: - if (vectorOverlay != null) { - vectorOverlay.remove(); - vectorOverlay = null; - } - addBitmapVectorOverlay(); - mTencentMap.updateVectorOverlay(vectorOverlay, provider); - break; - } - } - - @Override - public void onNothingSelected(AdapterView parent) { - - } - }); - - } - - - private void addDotVectorOverlay() { - mIsSelected = true; - if (vectorOverlay == null) { - BufferedReader br = null; - final ArrayList nodes = new ArrayList(); - double lat = 40.040219; - double lng = 116.273348; - double value = 100; - Random r = new Random(); - for (int i = 0; i < 2000; i++) { - double a = r.nextInt(10) * 1E-5; - double b = r.nextInt(10) * 1E-5; - LatLng latLng = new LatLng(lat + a, lng + b); - nodes.add(new ScatterLatLng(latLng, value)); - } - int[] colors = { - Color.argb(255, 0, 0xd4, 0xff), - Color.argb((int) (255 * 0.3), 0, 0xd4, 0xff), - Color.argb(255, 0, 0xd4, 0xff) - }; - - dotScatterPlotOverlayProvider = new DotScatterPlotOverlayProvider().data(nodes).opacity(2f).radius(2).animate(true).colors(colors); - - vectorOverlay = mTencentMap.addVectorOverlay(dotScatterPlotOverlayProvider); - - } - - } - - private void addBitmapVectorOverlay() { - mIsSelected = true; - if (vectorOverlay == null) { - final ArrayList nodes = new ArrayList(); - double lat = 40.040219; - double lng = 116.273348; - double value = 10; - Random r = new Random(); - for (int i = 0; i < 1000; i++) { - double a = r.nextInt(10) * 1E-5; - double b = r.nextInt(10) * 1E-5; - LatLng latLng = new LatLng(lat + a, lng + b); - nodes.add(new ScatterLatLng(latLng, value)); - } - BitmapDescriptor[] bitmaps = { - BitmapDescriptorFactory.fromAsset("21.jpg"), - BitmapDescriptorFactory.fromAsset("22.jpg"), - BitmapDescriptorFactory.fromAsset("23.jpg"), - BitmapDescriptorFactory.fromAsset("24.jpg"), - BitmapDescriptorFactory.fromAsset("25.jpg"), - BitmapDescriptorFactory.fromAsset("26.jpg"), - }; - provider = new BitmapScatterPlotOverlayProvider().data(nodes).bitmaps(bitmaps).opacity(2f).scale(20, 10); - vectorOverlay = mTencentMap.addVectorOverlay(provider); - } - - } -} \ No newline at end of file +package cc.winboll.studio.positions.demo.heatoverlay; + +import androidx.annotation.NonNull; +import androidx.appcompat.app.AppCompatActivity; + +import android.graphics.Color; +import android.os.Bundle; +import android.view.Menu; +import android.view.MenuItem; +import android.view.View; +import android.widget.AdapterView; +import android.widget.ArrayAdapter; +import android.widget.CompoundButton; +import android.widget.Spinner; +import android.widget.Switch; + +import com.tencent.map.sdk.utilities.visualization.datamodels.ScatterLatLng; +import com.tencent.map.sdk.utilities.visualization.scatterplot.BitmapScatterPlotOverlayProvider; +import com.tencent.map.sdk.utilities.visualization.scatterplot.DotScatterPlotOverlayProvider; +import cc.winboll.studio.positions.R; +import com.tencent.tencentmap.mapsdk.maps.CameraUpdateFactory; +import com.tencent.tencentmap.mapsdk.maps.MapView; +import com.tencent.tencentmap.mapsdk.maps.TencentMap; +import com.tencent.tencentmap.mapsdk.maps.model.BitmapDescriptor; +import com.tencent.tencentmap.mapsdk.maps.model.BitmapDescriptorFactory; +import com.tencent.tencentmap.mapsdk.maps.model.CameraPosition; +import com.tencent.tencentmap.mapsdk.maps.model.LatLng; +import com.tencent.tencentmap.mapsdk.maps.model.MarkerOptions; +import com.tencent.tencentmap.mapsdk.maps.model.VectorOverlay; + +import java.io.BufferedReader; +import java.util.ArrayList; +import java.util.Random; + +public class ScatterPlotOverlayActivity extends AppCompatActivity { +// private MapView mMapView; +// private TencentMap mTencentMap; +// private VectorOverlay vectorOverlay; +// boolean mIsSelected; +// private DotScatterPlotOverlayProvider dotScatterPlotOverlayProvider; +// private BitmapScatterPlotOverlayProvider provider; +// private String[] styles = new String[]{"添加点散点", "添加图片散点"}; +// private Spinner mSpinner; +// +// @Override +// protected void onCreate(Bundle savedInstanceState) { +// super.onCreate(savedInstanceState); +// setContentView(R.layout.activity_scatter_plot_overlay); +// init(); +// } +// +// +// @Override +// protected void onResume() { +// super.onResume(); +// mMapView.onResume(); +// } +// +// @Override +// protected void onPause() { +// super.onPause(); +// mMapView.onPause(); +// } +// +// @Override +// protected void onDestroy() { +// super.onDestroy(); +// mMapView.onDestroy(); +// } +// +// +// @Override +// protected void onStart() { +// super.onStart(); +// mMapView.onStart(); +// } +// +// @Override +// protected void onStop() { +// super.onStop(); +// mMapView.onStop(); +// } +// +// private void init() { +// mMapView = findViewById(R.id.mapView); +// mTencentMap = mMapView.getMap(); +// mTencentMap.moveCamera(CameraUpdateFactory.zoomTo(5f)); +// mTencentMap.moveCamera(CameraUpdateFactory.newCameraPosition(new CameraPosition(new LatLng(40.040219, 116.273348), 20, 0, 0))); +// mSpinner = findViewById(R.id.sp_style); +// ArrayAdapter adapter = new ArrayAdapter(getApplicationContext(), android.R.layout.simple_spinner_dropdown_item, styles); +// mSpinner.setAdapter(adapter); +// mSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { +// @Override +// public void onItemSelected(AdapterView parent, View view, int position, long id) { +// switch (position) { +// case 0: +// if (vectorOverlay != null) { +// vectorOverlay.remove(); +// vectorOverlay = null; +// } +// addDotVectorOverlay(); +// mTencentMap.updateVectorOverlay(vectorOverlay, dotScatterPlotOverlayProvider); +// break; +// case 1: +// if (vectorOverlay != null) { +// vectorOverlay.remove(); +// vectorOverlay = null; +// } +// addBitmapVectorOverlay(); +// mTencentMap.updateVectorOverlay(vectorOverlay, provider); +// break; +// } +// } +// +// @Override +// public void onNothingSelected(AdapterView parent) { +// +// } +// }); +// +// } +// +// +// private void addDotVectorOverlay() { +// mIsSelected = true; +// if (vectorOverlay == null) { +// BufferedReader br = null; +// final ArrayList nodes = new ArrayList(); +// double lat = 40.040219; +// double lng = 116.273348; +// double value = 100; +// Random r = new Random(); +// for (int i = 0; i < 2000; i++) { +// double a = r.nextInt(10) * 1E-5; +// double b = r.nextInt(10) * 1E-5; +// LatLng latLng = new LatLng(lat + a, lng + b); +// nodes.add(new ScatterLatLng(latLng, value)); +// } +// int[] colors = { +// Color.argb(255, 0, 0xd4, 0xff), +// Color.argb((int) (255 * 0.3), 0, 0xd4, 0xff), +// Color.argb(255, 0, 0xd4, 0xff) +// }; +// +// dotScatterPlotOverlayProvider = new DotScatterPlotOverlayProvider().data(nodes).opacity(2f).radius(2).animate(true).colors(colors); +// +// vectorOverlay = mTencentMap.addVectorOverlay(dotScatterPlotOverlayProvider); +// +// } +// +// } +// +// private void addBitmapVectorOverlay() { +// mIsSelected = true; +// if (vectorOverlay == null) { +// final ArrayList nodes = new ArrayList(); +// double lat = 40.040219; +// double lng = 116.273348; +// double value = 10; +// Random r = new Random(); +// for (int i = 0; i < 1000; i++) { +// double a = r.nextInt(10) * 1E-5; +// double b = r.nextInt(10) * 1E-5; +// LatLng latLng = new LatLng(lat + a, lng + b); +// nodes.add(new ScatterLatLng(latLng, value)); +// } +// BitmapDescriptor[] bitmaps = { +// BitmapDescriptorFactory.fromAsset("21.jpg"), +// BitmapDescriptorFactory.fromAsset("22.jpg"), +// BitmapDescriptorFactory.fromAsset("23.jpg"), +// BitmapDescriptorFactory.fromAsset("24.jpg"), +// BitmapDescriptorFactory.fromAsset("25.jpg"), +// BitmapDescriptorFactory.fromAsset("26.jpg"), +// }; +// provider = new BitmapScatterPlotOverlayProvider().data(nodes).bitmaps(bitmaps).opacity(2f).scale(20, 10); +// vectorOverlay = mTencentMap.addVectorOverlay(provider); +// } +// +// } +} diff --git a/positions/src/main/java/cc/winboll/studio/positions/demo/heatoverlay/TrailOverlayActivity.java b/positions/src/main/java/cc/winboll/studio/positions/demo/heatoverlay/TrailOverlayActivity.java index 1e67301..c7ce6cf 100644 --- a/positions/src/main/java/cc/winboll/studio/positions/demo/heatoverlay/TrailOverlayActivity.java +++ b/positions/src/main/java/cc/winboll/studio/positions/demo/heatoverlay/TrailOverlayActivity.java @@ -1,147 +1,147 @@ -package cc.winboll.studio.positions.demo.heatoverlay; - -import androidx.annotation.NonNull; -import androidx.appcompat.app.AppCompatActivity; - -import android.graphics.Color; -import android.os.Bundle; -import android.view.Menu; -import android.view.MenuItem; - -import com.tencent.map.sdk.utilities.visualization.datamodels.TimeLatLng; -import com.tencent.map.sdk.utilities.visualization.datamodels.TrailLatLng; -import com.tencent.map.sdk.utilities.visualization.trails.TrailOverlayProvider; -import cc.winboll.studio.positions.R; -import com.tencent.tencentmap.mapsdk.maps.CameraUpdateFactory; -import com.tencent.tencentmap.mapsdk.maps.MapView; -import com.tencent.tencentmap.mapsdk.maps.TencentMap; -import com.tencent.tencentmap.mapsdk.maps.model.LatLng; -import com.tencent.tencentmap.mapsdk.maps.model.VectorOverlay; - -import java.io.BufferedReader; -import java.io.InputStreamReader; -import java.util.ArrayList; -import java.util.List; - -public class TrailOverlayActivity extends AppCompatActivity { - private MapView mMapView; - private TencentMap mTencentMap; - private VectorOverlay vectorOverlay; - boolean mIsSelected; - private TrailOverlayProvider trailOverlayProvider; - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.activity_trail_overlay); - init(); - } - - @Override - public boolean onCreateOptionsMenu(Menu menu) { - getMenuInflater().inflate(R.menu.vectorheatmap, menu); - return true; - } - - @Override - public boolean onPrepareOptionsMenu(Menu menu) { - menu.findItem(R.id.menu_open_vectorheatmap).setVisible(!mIsSelected); - menu.findItem(R.id.menu_close_vectorheatmap).setVisible(mIsSelected); - return super.onPrepareOptionsMenu(menu); - } - - @Override - public boolean onOptionsItemSelected(@NonNull MenuItem item) { - switch (item.getItemId()) { - case R.id.menu_open_vectorheatmap: - addArcLineLayer(); - break; - case R.id.menu_close_vectorheatmap: - mIsSelected = false; - if (vectorOverlay != null) { - vectorOverlay.remove(); - vectorOverlay = null; - } - break; - } - - supportInvalidateOptionsMenu(); - return super.onOptionsItemSelected(item); - } - - @Override - protected void onResume() { - super.onResume(); - mMapView.onResume(); - } - - @Override - protected void onPause() { - super.onPause(); - mMapView.onPause(); - } - - @Override - protected void onDestroy() { - super.onDestroy(); - mMapView.onDestroy(); - } - - - @Override - protected void onStart() { - super.onStart(); - mMapView.onStart(); - } - - @Override - protected void onStop() { - super.onStop(); - mMapView.onStop(); - } - - private void init() { - mMapView = findViewById(R.id.mapView); - mTencentMap = mMapView.getMap(); - mTencentMap.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(39.942117, 116.33668), 11)); - } - - private void addArcLineLayer() { - mIsSelected = true; - if (vectorOverlay == null) { - - mTencentMap.setPoisEnabled(false); - BufferedReader br = null; - long currentTime = System.currentTimeMillis(); - List startLats = new ArrayList<>(); - try { - br = new BufferedReader(new InputStreamReader(getResources().getAssets().open("trailData.dat"))); - - String line = null; - while ((line = br.readLine()) != null) { - String[] oneDot = line.split(","); - TimeLatLng[] timeLatLngs = new TimeLatLng[oneDot.length]; - int i = 0; - for (String timeLatLng : oneDot) { - String[] values = timeLatLng.split("\t"); - LatLng latlng = new LatLng((Double.parseDouble(values[0])), (Double.parseDouble(values[1]))); - int timeStamp = Integer.parseInt(values[2]); - timeLatLngs[i++] = new TimeLatLng(latlng, timeStamp); - } - TrailLatLng tmp = new TrailLatLng(timeLatLngs); - startLats.add(tmp); - } - } catch (Exception e) { - e.printStackTrace(); - } - int[] colors = {Color.argb(0xff, 0x00, 0x00, 0xff), - Color.argb(0x00, 0xff, 0xff, 0x00)}; - - trailOverlayProvider = new TrailOverlayProvider().type(TrailOverlayProvider.TrailOverlayType.Trail).data(startLats).opacity(2f).width(10).gradient(colors).setHighlightDuration(8000).setAnimateStartTime(0, 25000); - vectorOverlay = mTencentMap.addVectorOverlay(trailOverlayProvider); - - - } - - } -} \ No newline at end of file +package cc.winboll.studio.positions.demo.heatoverlay; + +import androidx.annotation.NonNull; +import androidx.appcompat.app.AppCompatActivity; + +import android.graphics.Color; +import android.os.Bundle; +import android.view.Menu; +import android.view.MenuItem; + +import com.tencent.map.sdk.utilities.visualization.datamodels.TimeLatLng; +import com.tencent.map.sdk.utilities.visualization.datamodels.TrailLatLng; +import com.tencent.map.sdk.utilities.visualization.trails.TrailOverlayProvider; +import cc.winboll.studio.positions.R; +import com.tencent.tencentmap.mapsdk.maps.CameraUpdateFactory; +import com.tencent.tencentmap.mapsdk.maps.MapView; +import com.tencent.tencentmap.mapsdk.maps.TencentMap; +import com.tencent.tencentmap.mapsdk.maps.model.LatLng; +import com.tencent.tencentmap.mapsdk.maps.model.VectorOverlay; + +import java.io.BufferedReader; +import java.io.InputStreamReader; +import java.util.ArrayList; +import java.util.List; + +public class TrailOverlayActivity extends AppCompatActivity { +// private MapView mMapView; +// private TencentMap mTencentMap; +// private VectorOverlay vectorOverlay; +// boolean mIsSelected; +// private TrailOverlayProvider trailOverlayProvider; +// +// @Override +// protected void onCreate(Bundle savedInstanceState) { +// super.onCreate(savedInstanceState); +// setContentView(R.layout.activity_trail_overlay); +// init(); +// } +// +// @Override +// public boolean onCreateOptionsMenu(Menu menu) { +// getMenuInflater().inflate(R.menu.vectorheatmap, menu); +// return true; +// } +// +// @Override +// public boolean onPrepareOptionsMenu(Menu menu) { +// menu.findItem(R.id.menu_open_vectorheatmap).setVisible(!mIsSelected); +// menu.findItem(R.id.menu_close_vectorheatmap).setVisible(mIsSelected); +// return super.onPrepareOptionsMenu(menu); +// } +// +// @Override +// public boolean onOptionsItemSelected(@NonNull MenuItem item) { +// switch (item.getItemId()) { +// case R.id.menu_open_vectorheatmap: +// addArcLineLayer(); +// break; +// case R.id.menu_close_vectorheatmap: +// mIsSelected = false; +// if (vectorOverlay != null) { +// vectorOverlay.remove(); +// vectorOverlay = null; +// } +// break; +// } +// +// supportInvalidateOptionsMenu(); +// return super.onOptionsItemSelected(item); +// } +// +// @Override +// protected void onResume() { +// super.onResume(); +// mMapView.onResume(); +// } +// +// @Override +// protected void onPause() { +// super.onPause(); +// mMapView.onPause(); +// } +// +// @Override +// protected void onDestroy() { +// super.onDestroy(); +// mMapView.onDestroy(); +// } +// +// +// @Override +// protected void onStart() { +// super.onStart(); +// mMapView.onStart(); +// } +// +// @Override +// protected void onStop() { +// super.onStop(); +// mMapView.onStop(); +// } +// +// private void init() { +// mMapView = findViewById(R.id.mapView); +// mTencentMap = mMapView.getMap(); +// mTencentMap.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(39.942117, 116.33668), 11)); +// } +// +// private void addArcLineLayer() { +// mIsSelected = true; +// if (vectorOverlay == null) { +// +// mTencentMap.setPoisEnabled(false); +// BufferedReader br = null; +// long currentTime = System.currentTimeMillis(); +// List startLats = new ArrayList<>(); +// try { +// br = new BufferedReader(new InputStreamReader(getResources().getAssets().open("trailData.dat"))); +// +// String line = null; +// while ((line = br.readLine()) != null) { +// String[] oneDot = line.split(","); +// TimeLatLng[] timeLatLngs = new TimeLatLng[oneDot.length]; +// int i = 0; +// for (String timeLatLng : oneDot) { +// String[] values = timeLatLng.split("\t"); +// LatLng latlng = new LatLng((Double.parseDouble(values[0])), (Double.parseDouble(values[1]))); +// int timeStamp = Integer.parseInt(values[2]); +// timeLatLngs[i++] = new TimeLatLng(latlng, timeStamp); +// } +// TrailLatLng tmp = new TrailLatLng(timeLatLngs); +// startLats.add(tmp); +// } +// } catch (Exception e) { +// e.printStackTrace(); +// } +// int[] colors = {Color.argb(0xff, 0x00, 0x00, 0xff), +// Color.argb(0x00, 0xff, 0xff, 0x00)}; +// +// trailOverlayProvider = new TrailOverlayProvider().type(TrailOverlayProvider.TrailOverlayType.Trail).data(startLats).opacity(2f).width(10).gradient(colors).setHighlightDuration(8000).setAnimateStartTime(0, 25000); +// vectorOverlay = mTencentMap.addVectorOverlay(trailOverlayProvider); +// +// +// } +// +// } +} diff --git a/positions/src/main/java/cc/winboll/studio/positions/demo/heatoverlay/VectorHeatMapActivity.java b/positions/src/main/java/cc/winboll/studio/positions/demo/heatoverlay/VectorHeatMapActivity.java index 0d4f22c..0493afc 100644 --- a/positions/src/main/java/cc/winboll/studio/positions/demo/heatoverlay/VectorHeatMapActivity.java +++ b/positions/src/main/java/cc/winboll/studio/positions/demo/heatoverlay/VectorHeatMapActivity.java @@ -32,151 +32,151 @@ import java.util.ArrayList; */ public class VectorHeatMapActivity extends SupportMapFragmentActivity { - MapView mMapView; - TencentMap mTencentMap; - VectorHeatOverlay mOverlay; - boolean mIsSelected; - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.activity_vector_heat_map); - mMapView = findViewById(R.id.map_view); - mTencentMap = mMapView.getMap(); - mTencentMap.moveCamera(CameraUpdateFactory.newLatLngZoom( - new LatLng(36.139985, 120.402243), - 11)); - - mTencentMap.setOnMapClickListener(new TencentMap.OnMapClickListener() { - @Override - public void onMapClick(LatLng latlng) { - if (mOverlay == null) { - return; - } - VectorHeatAggregationUnit unit = mOverlay.getUnit(latlng); - if (unit == null) { - Log.e("VectorHeatMapActivity", "no unit found"); - return; - } - Log.e("VectorHeatMapActivity", "unit center:" + unit.getCenter() + - ", intensity:" + unit.getIntensity() + - ", size:" + unit.getNodes().length); - } - }); - } - - @Override - public boolean onCreateOptionsMenu(Menu menu) { - getMenuInflater().inflate(R.menu.vectorheatmap, menu); - return true; - } - - @Override - public boolean onPrepareOptionsMenu(Menu menu) { - menu.findItem(R.id.menu_open_vectorheatmap).setVisible(!mIsSelected); - menu.findItem(R.id.menu_close_vectorheatmap).setVisible(mIsSelected); - return super.onPrepareOptionsMenu(menu); - } - - @Override - public boolean onOptionsItemSelected(@NonNull MenuItem item) { - switch (item.getItemId()) { - case R.id.menu_open_vectorheatmap: - addVectorHeatMap(); - break; - case R.id.menu_close_vectorheatmap: - removeVectorHeatMap(); - break; - } - - supportInvalidateOptionsMenu(); - return super.onOptionsItemSelected(item); - } - - private ArrayList getHeatNodes() { - BufferedReader br = null; - ArrayList nodes = null; - try { - nodes = new ArrayList<>(); - br = new BufferedReader(new InputStreamReader( - getResources().getAssets().open("honeycomb.txt"))); - String line; - while ((line = br.readLine()) != null) { - String[] lines = line.split("\t"); - if (lines.length == 3) { - double value = Double.parseDouble(lines[2]); - LatLng latLng = new LatLng((Double.parseDouble(lines[1])), - (Double.parseDouble(lines[0]))); - nodes.add(new WeightedLatLng(latLng, 1)); - } - } - } catch (Exception e) { - e.printStackTrace(); - } finally { - if (br != null) { - try { - br.close(); - } catch (IOException e) { - e.printStackTrace(); - } - } - return nodes; - } - } - - @Override - protected void onResume() { - super.onResume(); - if (mMapView != null) { - mMapView.onResume(); - } - } - - @Override - protected void onPause() { - super.onPause(); - if (mMapView != null) { - mMapView.onPause(); - } - } - - @Override - protected void onStop() { - super.onStop(); - if (mMapView != null) { - mMapView.onStop(); - } - } - - @Override - protected void onDestroy() { - super.onDestroy(); - if (mMapView != null) { - mMapView.onDestroy(); - } - } - - private void addVectorHeatMap() { - mIsSelected = true; - if (mOverlay != null) { - return; - } - WeightedLatLng[] nodes = getHeatNodes().toArray(new WeightedLatLng[0]); - VectorHeatOverlayOptions options = new VectorHeatOverlayOptions() - .nodes(nodes) - .size(2000) - .gap(100) - .colors(new int[]{0x45fa4b14, 0x99fa4b14, 0xd9fa4b14}) - .startPoints(new double[]{0, 0.6, 0.8}); - mOverlay = mTencentMap.addVectorHeatOverlay(options); - } - - public void removeVectorHeatMap() { - mIsSelected = false; - if (mOverlay == null) { - return; - } - mOverlay.remove(); - mOverlay = null; - } +// MapView mMapView; +// TencentMap mTencentMap; +// VectorHeatOverlay mOverlay; +// boolean mIsSelected; +// +// @Override +// protected void onCreate(Bundle savedInstanceState) { +// super.onCreate(savedInstanceState); +// setContentView(R.layout.activity_vector_heat_map); +// mMapView = findViewById(R.id.map_view); +// mTencentMap = mMapView.getMap(); +// mTencentMap.moveCamera(CameraUpdateFactory.newLatLngZoom( +// new LatLng(36.139985, 120.402243), +// 11)); +// +// mTencentMap.setOnMapClickListener(new TencentMap.OnMapClickListener() { +// @Override +// public void onMapClick(LatLng latlng) { +// if (mOverlay == null) { +// return; +// } +// VectorHeatAggregationUnit unit = mOverlay.getUnit(latlng); +// if (unit == null) { +// Log.e("VectorHeatMapActivity", "no unit found"); +// return; +// } +// Log.e("VectorHeatMapActivity", "unit center:" + unit.getCenter() + +// ", intensity:" + unit.getIntensity() + +// ", size:" + unit.getNodes().length); +// } +// }); +// } +// +// @Override +// public boolean onCreateOptionsMenu(Menu menu) { +// getMenuInflater().inflate(R.menu.vectorheatmap, menu); +// return true; +// } +// +// @Override +// public boolean onPrepareOptionsMenu(Menu menu) { +// menu.findItem(R.id.menu_open_vectorheatmap).setVisible(!mIsSelected); +// menu.findItem(R.id.menu_close_vectorheatmap).setVisible(mIsSelected); +// return super.onPrepareOptionsMenu(menu); +// } +// +// @Override +// public boolean onOptionsItemSelected(@NonNull MenuItem item) { +// switch (item.getItemId()) { +// case R.id.menu_open_vectorheatmap: +// addVectorHeatMap(); +// break; +// case R.id.menu_close_vectorheatmap: +// removeVectorHeatMap(); +// break; +// } +// +// supportInvalidateOptionsMenu(); +// return super.onOptionsItemSelected(item); +// } +// +// private ArrayList getHeatNodes() { +// BufferedReader br = null; +// ArrayList nodes = null; +// try { +// nodes = new ArrayList<>(); +// br = new BufferedReader(new InputStreamReader( +// getResources().getAssets().open("honeycomb.txt"))); +// String line; +// while ((line = br.readLine()) != null) { +// String[] lines = line.split("\t"); +// if (lines.length == 3) { +// double value = Double.parseDouble(lines[2]); +// LatLng latLng = new LatLng((Double.parseDouble(lines[1])), +// (Double.parseDouble(lines[0]))); +// nodes.add(new WeightedLatLng(latLng, 1)); +// } +// } +// } catch (Exception e) { +// e.printStackTrace(); +// } finally { +// if (br != null) { +// try { +// br.close(); +// } catch (IOException e) { +// e.printStackTrace(); +// } +// } +// return nodes; +// } +// } +// +// @Override +// protected void onResume() { +// super.onResume(); +// if (mMapView != null) { +// mMapView.onResume(); +// } +// } +// +// @Override +// protected void onPause() { +// super.onPause(); +// if (mMapView != null) { +// mMapView.onPause(); +// } +// } +// +// @Override +// protected void onStop() { +// super.onStop(); +// if (mMapView != null) { +// mMapView.onStop(); +// } +// } +// +// @Override +// protected void onDestroy() { +// super.onDestroy(); +// if (mMapView != null) { +// mMapView.onDestroy(); +// } +// } +// +// private void addVectorHeatMap() { +// mIsSelected = true; +// if (mOverlay != null) { +// return; +// } +// WeightedLatLng[] nodes = getHeatNodes().toArray(new WeightedLatLng[0]); +// VectorHeatOverlayOptions options = new VectorHeatOverlayOptions() +// .nodes(nodes) +// .size(2000) +// .gap(100) +// .colors(new int[]{0x45fa4b14, 0x99fa4b14, 0xd9fa4b14}) +// .startPoints(new double[]{0, 0.6, 0.8}); +// mOverlay = mTencentMap.addVectorHeatOverlay(options); +// } +// +// public void removeVectorHeatMap() { +// mIsSelected = false; +// if (mOverlay == null) { +// return; +// } +// mOverlay.remove(); +// mOverlay = null; +// } } diff --git a/positions/src/main/java/cc/winboll/studio/positions/demo/location/LocationLayerActivity.java b/positions/src/main/java/cc/winboll/studio/positions/demo/location/LocationLayerActivity.java index a2bf98a..262ce9b 100644 --- a/positions/src/main/java/cc/winboll/studio/positions/demo/location/LocationLayerActivity.java +++ b/positions/src/main/java/cc/winboll/studio/positions/demo/location/LocationLayerActivity.java @@ -32,220 +32,221 @@ import com.tencent.tencentmap.mapsdk.maps.model.MyLocationStyle; import java.util.List; import pub.devrel.easypermissions.EasyPermissions; +import com.tencent.tencentmap.mapsdk.maps.LocationSource.OnLocationChangedListener; -public class LocationLayerActivity extends SupportMapFragmentActivity implements EasyPermissions.PermissionCallbacks, LocationSource, TencentLocationListener, TencentMap.OnMapLongClickListener, RadioGroup.OnCheckedChangeListener { - - private OnLocationChangedListener locationChangedListener; - - private TencentLocationManager locationManager; - private TencentLocationRequest locationRequest; - private MyLocationStyle locationStyle; - private RadioGroup radioGroup; - - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - - - //定位需要申请的权限 - String[] perms = { - Manifest.permission.ACCESS_FINE_LOCATION, - Manifest.permission.ACCESS_COARSE_LOCATION, - Manifest.permission.READ_PHONE_STATE - }; - - if (EasyPermissions.hasPermissions(this, perms)) {//检查是否获取该权限 - Log.i("location", "已获取权限"); - } else { - EasyPermissions.requestPermissions(this, "必要的权限", 0, perms); - } - //设置显示定位的图标 - mapUiSettings.setMyLocationButtonEnabled(true); - tencentMap.setOnMapLongClickListener(this); - - radioGroup = findViewById(R.id.location_type); - radioGroup.setVisibility(View.VISIBLE); - radioGroup.setOnCheckedChangeListener(this); - - //建立定位 - initLocation(); - //SDK版本4.3.5新增内置定位标点击回调监听 - tencentMap.setMyLocationClickListener(new TencentMap.OnMyLocationClickListener() { - @Override - public boolean onMyLocationClicked(LatLng latLng) { - Toast.makeText(LocationLayerActivity.this, "内置定位标点击回调", Toast.LENGTH_SHORT).show(); - return true; - } - }); - } - - /** - * 定位的一些初始化设置 - */ - private void initLocation() { - //用于访问腾讯定位服务的类, 周期性向客户端提供位置更新 - locationManager = TencentLocationManager.getInstance(this); - //设置坐标系 - locationManager.setCoordinateType(TencentLocationManager.COORDINATE_TYPE_GCJ02); - //创建定位请求 - locationRequest = TencentLocationRequest.create(); - //设置定位周期(位置监听器回调周期)为3s - locationRequest.setInterval(3000); - - //地图上设置定位数据源 - tencentMap.setLocationSource(this); - //设置当前位置可见 - tencentMap.setMyLocationEnabled(true); - //设置定位图标样式 - setLocMarkerStyle(); - tencentMap.setMyLocationStyle(locationStyle); - } - - /** - * 设置定位图标样式 - */ - private void setLocMarkerStyle() { - locationStyle = new MyLocationStyle(); - //创建图标 - BitmapDescriptor bitmapDescriptor = BitmapDescriptorFactory.fromBitmap(getBitMap(R.drawable.location_icon)); - locationStyle.icon(bitmapDescriptor); - //设置定位圆形区域的边框宽度 - locationStyle.strokeWidth(3); - //设置圆区域的颜色 - locationStyle.fillColor(R.color.style); - } - - private Bitmap getBitMap(int resourceId) { - Bitmap bitmap = BitmapFactory.decodeResource(getResources(), resourceId); - int width = bitmap.getWidth(); - int height = bitmap.getHeight(); - int newWidth = 55; - int newHeight = 55; - float widthScale = ((float) newWidth) / width; - float heightScale = ((float) newHeight) / height; - Matrix matrix = new Matrix(); - matrix.postScale(widthScale, heightScale); - bitmap = Bitmap.createBitmap(bitmap, 0, 0, width, height, matrix, true); - return bitmap; - } - - /** - * 实现位置监听 - * - * @param tencentLocation - * @param i - * @param s - */ - @Override - public void onLocationChanged(TencentLocation tencentLocation, int i, String s) { - - if (i == TencentLocation.ERROR_OK && locationChangedListener != null) { - Location location = new Location(tencentLocation.getProvider()); - //设置经纬度以及精度 - location.setLatitude(tencentLocation.getLatitude()); - location.setLongitude(tencentLocation.getLongitude()); - location.setAccuracy(tencentLocation.getAccuracy()); - locationChangedListener.onLocationChanged(location); - - //显示回调的实时位置信息 - runOnUiThread(new Runnable() { - @Override - public void run() { - //打印tencentLocation的json字符串 -// Toast.makeText(getApplicationContext(), new Gson().toJson(location), Toast.LENGTH_LONG).show(); - } - }); - } - } - - @Override - public void onStatusUpdate(String s, int i, String s1) { - //GPS, WiFi, Radio 等状态发生变化 - Log.v("State changed", s + "===" + s1); - } - - - @Override - public void activate(OnLocationChangedListener onLocationChangedListener) { - locationChangedListener = onLocationChangedListener; - - int err = locationManager.requestLocationUpdates(locationRequest, this, Looper.myLooper()); - switch (err) { - case 1: - Toast.makeText(this, "设备缺少使用腾讯定位服务需要的基本条件", Toast.LENGTH_SHORT).show(); - break; - case 2: - Toast.makeText(this, "manifest 中配置的 key 不正确", Toast.LENGTH_SHORT).show(); - break; - case 3: - Toast.makeText(this, "自动加载libtencentloc.so失败", Toast.LENGTH_SHORT).show(); - break; - - default: - break; - } - } - - @Override - public void deactivate() { - locationManager.removeUpdates(this); - locationManager = null; - locationRequest = null; - locationChangedListener = null; - } - - @Override - public void onPermissionsGranted(int requestCode, @NonNull List perms) { - Log.e("location quest: ", "success"); - } - - @Override - public void onPermissionsDenied(int requestCode, @NonNull List perms) { - Log.e("location quest: ", "failed"); - } - - @Override - public void onMapLongClick(LatLng latLng) { - Location location = new Location("LongPressLocationProvider"); - location.setLatitude(latLng.latitude); - location.setLongitude(latLng.longitude); - location.setAccuracy(20); - locationChangedListener.onLocationChanged(location); - Log.i("long click", new Gson().toJson(latLng)); - } - - @Override - public void onCheckedChanged(RadioGroup radioGroup, int i) { - switch (i) { - //连续定位,但不会移动到地图中心点,并且会跟随设备移动 - case R.id.btn_follow_no_center: - - initLocation(); - locationStyle = locationStyle.myLocationType(MyLocationStyle.LOCATION_TYPE_FOLLOW_NO_CENTER); - tencentMap.setMyLocationStyle(locationStyle); - break; - //连续定位,且将视角移动到地图中心,定位点依照设备方向旋转,并且会跟随设备移动,默认是此种类型 - case R.id.btn_location_rotate: - - initLocation(); - locationStyle = locationStyle.myLocationType(MyLocationStyle.LOCATION_TYPE_LOCATION_ROTATE); - tencentMap.setMyLocationStyle(locationStyle); - break; - //连续定位,但不会移动到地图中心点,定位点依照设备方向旋转,并且跟随设备移动 - case R.id.btn_location_rotate_no_center: - - initLocation(); - locationStyle = locationStyle.myLocationType(MyLocationStyle.LOCATION_TYPE_LOCATION_ROTATE_NO_CENTER); - tencentMap.setMyLocationStyle(locationStyle); - break; - //连续定位,但不会移动到地图中心点,地图依照设备方向旋转,并且会跟随设备移动 - case R.id.btn_map_rotate_no_center: - - initLocation(); - locationStyle = locationStyle.myLocationType(MyLocationStyle.LOCATION_TYPE_MAP_ROTATE_NO_CENTER); - tencentMap.setMyLocationStyle(locationStyle); - break; - } - } -} +//public class LocationLayerActivity extends SupportMapFragmentActivity implements EasyPermissions.PermissionCallbacks, LocationSource, TencentLocationListener, TencentMap.OnMapLongClickListener, RadioGroup.OnCheckedChangeListener { +// +// private OnLocationChangedListener locationChangedListener; +// +// private TencentLocationManager locationManager; +// private TencentLocationRequest locationRequest; +// private MyLocationStyle locationStyle; +// private RadioGroup radioGroup; +// +// +// @Override +// protected void onCreate(Bundle savedInstanceState) { +// super.onCreate(savedInstanceState); +// +// +// //定位需要申请的权限 +// String[] perms = { +// Manifest.permission.ACCESS_FINE_LOCATION, +// Manifest.permission.ACCESS_COARSE_LOCATION, +// Manifest.permission.READ_PHONE_STATE +// }; +// +// if (EasyPermissions.hasPermissions(this, perms)) {//检查是否获取该权限 +// Log.i("location", "已获取权限"); +// } else { +// EasyPermissions.requestPermissions(this, "必要的权限", 0, perms); +// } +// //设置显示定位的图标 +// mapUiSettings.setMyLocationButtonEnabled(true); +// tencentMap.setOnMapLongClickListener(this); +// +// radioGroup = findViewById(R.id.location_type); +// radioGroup.setVisibility(View.VISIBLE); +// radioGroup.setOnCheckedChangeListener(this); +// +// //建立定位 +// initLocation(); +// //SDK版本4.3.5新增内置定位标点击回调监听 +// tencentMap.setMyLocationClickListener(new TencentMap.OnMyLocationClickListener() { +// @Override +// public boolean onMyLocationClicked(LatLng latLng) { +// Toast.makeText(LocationLayerActivity.this, "内置定位标点击回调", Toast.LENGTH_SHORT).show(); +// return true; +// } +// }); +// } +// +// /** +// * 定位的一些初始化设置 +// */ +// private void initLocation() { +// //用于访问腾讯定位服务的类, 周期性向客户端提供位置更新 +// locationManager = TencentLocationManager.getInstance(this); +// //设置坐标系 +// locationManager.setCoordinateType(TencentLocationManager.COORDINATE_TYPE_GCJ02); +// //创建定位请求 +// locationRequest = TencentLocationRequest.create(); +// //设置定位周期(位置监听器回调周期)为3s +// locationRequest.setInterval(3000); +// +// //地图上设置定位数据源 +// tencentMap.setLocationSource(this); +// //设置当前位置可见 +// tencentMap.setMyLocationEnabled(true); +// //设置定位图标样式 +// setLocMarkerStyle(); +// tencentMap.setMyLocationStyle(locationStyle); +// } +// +// /** +// * 设置定位图标样式 +// */ +// private void setLocMarkerStyle() { +// locationStyle = new MyLocationStyle(); +// //创建图标 +// BitmapDescriptor bitmapDescriptor = BitmapDescriptorFactory.fromBitmap(getBitMap(R.drawable.location_icon)); +// locationStyle.icon(bitmapDescriptor); +// //设置定位圆形区域的边框宽度 +// locationStyle.strokeWidth(3); +// //设置圆区域的颜色 +// locationStyle.fillColor(R.color.style); +// } +// +// private Bitmap getBitMap(int resourceId) { +// Bitmap bitmap = BitmapFactory.decodeResource(getResources(), resourceId); +// int width = bitmap.getWidth(); +// int height = bitmap.getHeight(); +// int newWidth = 55; +// int newHeight = 55; +// float widthScale = ((float) newWidth) / width; +// float heightScale = ((float) newHeight) / height; +// Matrix matrix = new Matrix(); +// matrix.postScale(widthScale, heightScale); +// bitmap = Bitmap.createBitmap(bitmap, 0, 0, width, height, matrix, true); +// return bitmap; +// } +// +// /** +// * 实现位置监听 +// * +// * @param tencentLocation +// * @param i +// * @param s +// */ +// @Override +// public void onLocationChanged(TencentLocation tencentLocation, int i, String s) { +// +// if (i == TencentLocation.ERROR_OK && locationChangedListener != null) { +// Location location = new Location(tencentLocation.getProvider()); +// //设置经纬度以及精度 +// location.setLatitude(tencentLocation.getLatitude()); +// location.setLongitude(tencentLocation.getLongitude()); +// location.setAccuracy(tencentLocation.getAccuracy()); +// locationChangedListener.onLocationChanged(location); +// +// //显示回调的实时位置信息 +// runOnUiThread(new Runnable() { +// @Override +// public void run() { +// //打印tencentLocation的json字符串 +//// Toast.makeText(getApplicationContext(), new Gson().toJson(location), Toast.LENGTH_LONG).show(); +// } +// }); +// } +// } +// +// @Override +// public void onStatusUpdate(String s, int i, String s1) { +// //GPS, WiFi, Radio 等状态发生变化 +// Log.v("State changed", s + "===" + s1); +// } +// +// +// @Override +// public void activate(OnLocationChangedListener onLocationChangedListener) { +// locationChangedListener = onLocationChangedListener; +// +// int err = locationManager.requestLocationUpdates(locationRequest, this, Looper.myLooper()); +// switch (err) { +// case 1: +// Toast.makeText(this, "设备缺少使用腾讯定位服务需要的基本条件", Toast.LENGTH_SHORT).show(); +// break; +// case 2: +// Toast.makeText(this, "manifest 中配置的 key 不正确", Toast.LENGTH_SHORT).show(); +// break; +// case 3: +// Toast.makeText(this, "自动加载libtencentloc.so失败", Toast.LENGTH_SHORT).show(); +// break; +// +// default: +// break; +// } +// } +// +// @Override +// public void deactivate() { +// locationManager.removeUpdates(this); +// locationManager = null; +// locationRequest = null; +// locationChangedListener = null; +// } +// +// @Override +// public void onPermissionsGranted(int requestCode, @NonNull List perms) { +// Log.e("location quest: ", "success"); +// } +// +// @Override +// public void onPermissionsDenied(int requestCode, @NonNull List perms) { +// Log.e("location quest: ", "failed"); +// } +// +// @Override +// public void onMapLongClick(LatLng latLng) { +// Location location = new Location("LongPressLocationProvider"); +// location.setLatitude(latLng.latitude); +// location.setLongitude(latLng.longitude); +// location.setAccuracy(20); +// locationChangedListener.onLocationChanged(location); +// Log.i("long click", new Gson().toJson(latLng)); +// } +// +// @Override +// public void onCheckedChanged(RadioGroup radioGroup, int i) { +// switch (i) { +// //连续定位,但不会移动到地图中心点,并且会跟随设备移动 +// case R.id.btn_follow_no_center: +// +// initLocation(); +// locationStyle = locationStyle.myLocationType(MyLocationStyle.LOCATION_TYPE_FOLLOW_NO_CENTER); +// tencentMap.setMyLocationStyle(locationStyle); +// break; +// //连续定位,且将视角移动到地图中心,定位点依照设备方向旋转,并且会跟随设备移动,默认是此种类型 +// case R.id.btn_location_rotate: +// +// initLocation(); +// locationStyle = locationStyle.myLocationType(MyLocationStyle.LOCATION_TYPE_LOCATION_ROTATE); +// tencentMap.setMyLocationStyle(locationStyle); +// break; +// //连续定位,但不会移动到地图中心点,定位点依照设备方向旋转,并且跟随设备移动 +// case R.id.btn_location_rotate_no_center: +// +// initLocation(); +// locationStyle = locationStyle.myLocationType(MyLocationStyle.LOCATION_TYPE_LOCATION_ROTATE_NO_CENTER); +// tencentMap.setMyLocationStyle(locationStyle); +// break; +// //连续定位,但不会移动到地图中心点,地图依照设备方向旋转,并且会跟随设备移动 +// case R.id.btn_map_rotate_no_center: +// +// initLocation(); +// locationStyle = locationStyle.myLocationType(MyLocationStyle.LOCATION_TYPE_MAP_ROTATE_NO_CENTER); +// tencentMap.setMyLocationStyle(locationStyle); +// break; +// } +// } +//} diff --git a/positions/src/main/java/cc/winboll/studio/positions/demo/location/LocationPointActivity.java b/positions/src/main/java/cc/winboll/studio/positions/demo/location/LocationPointActivity.java index 925706a..cb6eeda 100644 --- a/positions/src/main/java/cc/winboll/studio/positions/demo/location/LocationPointActivity.java +++ b/positions/src/main/java/cc/winboll/studio/positions/demo/location/LocationPointActivity.java @@ -25,166 +25,192 @@ import com.tencent.tencentmap.mapsdk.maps.model.MyLocationStyle; import java.util.List; import pub.devrel.easypermissions.EasyPermissions; +import com.tencent.tencentmap.mapsdk.maps.LocationSource.OnLocationChangedListener; -public class LocationPointActivity extends SupportMapFragmentActivity implements EasyPermissions.PermissionCallbacks,LocationSource, TencentLocationListener{ - private LocationSource.OnLocationChangedListener locationChangedListener; - - private TencentLocationManager locationManager; - private TencentLocationRequest locationRequest; - private MyLocationStyle locationStyle; +public class LocationPointActivity extends SupportMapFragmentActivity implements EasyPermissions.PermissionCallbacks,LocationSource, TencentLocationListener { @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - - - //定位需要申请的权限 - String[] perms = { - Manifest.permission.ACCESS_FINE_LOCATION, - Manifest.permission.ACCESS_COARSE_LOCATION, - Manifest.permission.READ_PHONE_STATE - }; - - if (EasyPermissions.hasPermissions(this, perms)) {//检查是否获取该权限 - Log.i("location", "已获取权限"); - } else { - EasyPermissions.requestPermissions(this, "必要的权限", 0, perms); - } - //设置显示定位的图标 - TencentLocationManager.setUserAgreePrivacy(true); - //建立定位 - initLocation(); - } - - - /** - * 设置定位图标样式 - */ - private void setLocMarkerStyle(){ - locationStyle = new MyLocationStyle(); - //创建图标 - BitmapDescriptor bitmapDescriptor = BitmapDescriptorFactory.fromBitmap(getBitMap(R.drawable.marker)); - locationStyle.icon(bitmapDescriptor); - //设置定位圆形区域的边框宽度 - locationStyle.strokeWidth(3); - //设置圆区域的颜色 - locationStyle.fillColor(R.color.style); - - tencentMap.setMyLocationStyle(locationStyle); - } - - - - private Bitmap getBitMap(int resourceId){ - Bitmap bitmap = BitmapFactory.decodeResource(getResources(), resourceId); - int width = bitmap.getWidth(); - int height = bitmap.getHeight(); - int newWidth = 55; - int newHeight = 55; - float widthScale = ((float)newWidth)/width; - float heightScale = ((float)newHeight)/height; - Matrix matrix = new Matrix(); - matrix.postScale(widthScale, heightScale); - bitmap = Bitmap.createBitmap(bitmap,0,0,width,height,matrix,true); - return bitmap; - } - - - - /** - * 定位的一些初始化设置 - */ - private void initLocation(){ - //用于访问腾讯定位服务的类, 周期性向客户端提供位置更新 - locationManager = TencentLocationManager.getInstance(this); - //设置坐标系 - locationManager.setCoordinateType(TencentLocationManager.COORDINATE_TYPE_GCJ02); - //创建定位请求 - locationRequest = TencentLocationRequest.create(); - //设置定位周期(位置监听器回调周期)为3s - locationRequest.setInterval(3000); - - //地图上设置定位数据源 - tencentMap.setLocationSource(this); - //设置当前位置可见 - tencentMap.setMyLocationEnabled(true); - //设置定位图标样式 - setLocMarkerStyle(); -// locationStyle = locationStyle.myLocationType(MyLocationStyle.LOCATION_TYPE_LOCATION_ROTATE); - tencentMap.setMyLocationStyle(locationStyle); - } - /** - * 实现位置监听 - * @param tencentLocation - * @param i - * @param s - */ - @Override - public void onLocationChanged(TencentLocation tencentLocation, int i, String s) { - - if(i == TencentLocation.ERROR_OK && locationChangedListener != null){ - Location location = new Location(tencentLocation.getProvider()); - //设置经纬度以及精度 - location.setLatitude(tencentLocation.getLatitude()); - location.setLongitude(tencentLocation.getLongitude()); - location.setAccuracy(tencentLocation.getAccuracy()); - locationChangedListener.onLocationChanged(location); - - //显示回调的实时位置信息 - runOnUiThread(new Runnable() { - @Override - public void run() { - //打印tencentLocation的json字符串 -// Toast.makeText(getApplicationContext(), new Gson().toJson(location), Toast.LENGTH_LONG).show(); - } - }); - } + public void onPermissionsGranted(int p1, List p2) { } @Override - public void onStatusUpdate(String s, int i, String s1) { - //GPS, WiFi, Radio 等状态发生变化 - Log.v("State changed", s +"===" + s1); + public void onPermissionsDenied(int p1, List p2) { } - @Override - public void activate(OnLocationChangedListener onLocationChangedListener) { - locationChangedListener = onLocationChangedListener; - - int err = locationManager.requestLocationUpdates(locationRequest, this, Looper.myLooper()); - switch (err) { - case 1: - Toast.makeText(this,"设备缺少使用腾讯定位服务需要的基本条件",Toast.LENGTH_SHORT).show(); - break; - case 2: - Toast.makeText(this,"manifest 中配置的 key 不正确",Toast.LENGTH_SHORT).show(); - break; - case 3: - Toast.makeText(this,"自动加载libtencentloc.so失败",Toast.LENGTH_SHORT).show(); - break; - - default: - break; - } + public void activate(LocationSource.OnLocationChangedListener p1) { } @Override public void deactivate() { - locationManager.removeUpdates(this); - locationManager = null; - locationRequest = null; - locationChangedListener=null; } @Override - public void onPermissionsGranted(int requestCode, @NonNull List perms) { - Log.e("location quest: ","success"); + public void onLocationChanged(TencentLocation p1, int p2, String p3) { } @Override - public void onPermissionsDenied(int requestCode, @NonNull List perms) { - Log.e("location quest: ","failed"); + public void onStatusUpdate(String p1, int p2, String p3) { } - + +// private LocationSource.OnLocationChangedListener locationChangedListener; +// +// private TencentLocationManager locationManager; +// private TencentLocationRequest locationRequest; +// private MyLocationStyle locationStyle; +// +// @Override +// protected void onCreate(Bundle savedInstanceState) { +// super.onCreate(savedInstanceState); +// +// +// //定位需要申请的权限 +// String[] perms = { +// Manifest.permission.ACCESS_FINE_LOCATION, +// Manifest.permission.ACCESS_COARSE_LOCATION, +// Manifest.permission.READ_PHONE_STATE +// }; +// +// if (EasyPermissions.hasPermissions(this, perms)) {//检查是否获取该权限 +// Log.i("location", "已获取权限"); +// } else { +// EasyPermissions.requestPermissions(this, "必要的权限", 0, perms); +// } +// //设置显示定位的图标 +// TencentLocationManager.setUserAgreePrivacy(true); +// //建立定位 +// initLocation(); +// } +// +// +// /** +// * 设置定位图标样式 +// */ +// private void setLocMarkerStyle(){ +// locationStyle = new MyLocationStyle(); +// //创建图标 +// BitmapDescriptor bitmapDescriptor = BitmapDescriptorFactory.fromBitmap(getBitMap(R.drawable.marker)); +// locationStyle.icon(bitmapDescriptor); +// //设置定位圆形区域的边框宽度 +// locationStyle.strokeWidth(3); +// //设置圆区域的颜色 +// locationStyle.fillColor(R.color.style); +// +// tencentMap.setMyLocationStyle(locationStyle); +// } +// +// +// +// private Bitmap getBitMap(int resourceId){ +// Bitmap bitmap = BitmapFactory.decodeResource(getResources(), resourceId); +// int width = bitmap.getWidth(); +// int height = bitmap.getHeight(); +// int newWidth = 55; +// int newHeight = 55; +// float widthScale = ((float)newWidth)/width; +// float heightScale = ((float)newHeight)/height; +// Matrix matrix = new Matrix(); +// matrix.postScale(widthScale, heightScale); +// bitmap = Bitmap.createBitmap(bitmap,0,0,width,height,matrix,true); +// return bitmap; +// } +// +// +// +// /** +// * 定位的一些初始化设置 +// */ +// private void initLocation(){ +// //用于访问腾讯定位服务的类, 周期性向客户端提供位置更新 +// locationManager = TencentLocationManager.getInstance(this); +// //设置坐标系 +// locationManager.setCoordinateType(TencentLocationManager.COORDINATE_TYPE_GCJ02); +// //创建定位请求 +// locationRequest = TencentLocationRequest.create(); +// //设置定位周期(位置监听器回调周期)为3s +// locationRequest.setInterval(3000); +// +// //地图上设置定位数据源 +// tencentMap.setLocationSource(this); +// //设置当前位置可见 +// tencentMap.setMyLocationEnabled(true); +// //设置定位图标样式 +// setLocMarkerStyle(); +//// locationStyle = locationStyle.myLocationType(MyLocationStyle.LOCATION_TYPE_LOCATION_ROTATE); +// tencentMap.setMyLocationStyle(locationStyle); +// } +// /** +// * 实现位置监听 +// * @param tencentLocation +// * @param i +// * @param s +// */ +// @Override +// public void onLocationChanged(TencentLocation tencentLocation, int i, String s) { +// +// if(i == TencentLocation.ERROR_OK && locationChangedListener != null){ +// Location location = new Location(tencentLocation.getProvider()); +// //设置经纬度以及精度 +// location.setLatitude(tencentLocation.getLatitude()); +// location.setLongitude(tencentLocation.getLongitude()); +// location.setAccuracy(tencentLocation.getAccuracy()); +// locationChangedListener.onLocationChanged(location); +// +// //显示回调的实时位置信息 +// runOnUiThread(new Runnable() { +// @Override +// public void run() { +// //打印tencentLocation的json字符串 +//// Toast.makeText(getApplicationContext(), new Gson().toJson(location), Toast.LENGTH_LONG).show(); +// } +// }); +// } +// } +// +// @Override +// public void onStatusUpdate(String s, int i, String s1) { +// //GPS, WiFi, Radio 等状态发生变化 +// Log.v("State changed", s +"===" + s1); +// } +// +// +// @Override +// public void activate(OnLocationChangedListener onLocationChangedListener) { +// locationChangedListener = onLocationChangedListener; +// +// int err = locationManager.requestLocationUpdates(locationRequest, this, Looper.myLooper()); +// switch (err) { +// case 1: +// Toast.makeText(this,"设备缺少使用腾讯定位服务需要的基本条件",Toast.LENGTH_SHORT).show(); +// break; +// case 2: +// Toast.makeText(this,"manifest 中配置的 key 不正确",Toast.LENGTH_SHORT).show(); +// break; +// case 3: +// Toast.makeText(this,"自动加载libtencentloc.so失败",Toast.LENGTH_SHORT).show(); +// break; +// +// default: +// break; +// } +// } +// +// @Override +// public void deactivate() { +// locationManager.removeUpdates(this); +// locationManager = null; +// locationRequest = null; +// locationChangedListener=null; +// } +// +// @Override +// public void onPermissionsGranted(int requestCode, @NonNull List perms) { +// Log.e("location quest: ","success"); +// } +// +// @Override +// public void onPermissionsDenied(int requestCode, @NonNull List perms) { +// Log.e("location quest: ","failed"); +// } +// } diff --git a/positions/src/main/java/cc/winboll/studio/positions/demo/marker/CustomRenderActivity.java b/positions/src/main/java/cc/winboll/studio/positions/demo/marker/CustomRenderActivity.java index 0139137..63256b5 100644 --- a/positions/src/main/java/cc/winboll/studio/positions/demo/marker/CustomRenderActivity.java +++ b/positions/src/main/java/cc/winboll/studio/positions/demo/marker/CustomRenderActivity.java @@ -1,281 +1,281 @@ package cc.winboll.studio.positions.demo.marker; -import androidx.appcompat.app.AppCompatActivity; - -import android.graphics.PointF; -import android.opengl.GLES20; -import android.os.Bundle; -import android.util.Log; - -import cc.winboll.studio.positions.R; -import com.tencent.tencentmap.mapsdk.maps.CameraUpdateFactory; -import com.tencent.tencentmap.mapsdk.maps.CustomRender; -import com.tencent.tencentmap.mapsdk.maps.MapView; -import com.tencent.tencentmap.mapsdk.maps.TencentMap; -import com.tencent.tencentmap.mapsdk.maps.model.CameraPosition; -import com.tencent.tencentmap.mapsdk.maps.model.LatLng; - -import java.nio.ByteBuffer; -import java.nio.ByteOrder; -import java.nio.FloatBuffer; -import java.nio.ShortBuffer; - -/** - * OpenGL绘制 - */ -public class CustomRenderActivity extends AppCompatActivity { - - private static final String TAG = CustomRenderActivity.class.getSimpleName(); - - // 标识是否第一次绘制3D立方体 - private boolean mIsFirstDraw3DCube = true; - - // 立方体8个顶点坐标 - private float[] mVertices = { - -1, -1, -0, - 1, -1, -0, - 1, 1, -0, - -1, 1, -0, - -1, -1, 1, - 1, -1, 1, - 1, 1, 1, - -1, 1, 1, - }; - - // 3D立方体顶点绘制顺序列表 - private short[] mDrawIndices = { - 5, 4, 0, 1, 5, 0, 6, 5, 1, 2, 6, 1, - 7, 6, 2, 3, 7, 2, 4, 7, 3, 0, 4, 3, - 6, 7, 4, 5, 6, 4, 1, 0, 3, 2, 1, 3 - }; - - // 3D立方体8个顶点颜色值 - private float[] mVertexColors = { - 1f, 1f, 0f, 1f, - 0f, 1f, 1f, 1f, - 1f, 0f, 1f, 1f, - 0f, 0f, 0f, 1f, - 1f, 1f, 1f, 1f, - 1f, 0f, 0f, 1f, - 0f, 1f, 0f, 1f, - 0f, 0f, 1f, 1f - }; - - // 立方体顶点坐标Buffer - private FloatBuffer mVertexBuffer; - - // 顶点绘制顺序Buffer - private ShortBuffer mIndexBuffer; - - // 立方体顶点颜色Buffer - private FloatBuffer mColorBuffer; - - // 3D立方体着色器 - private CubeShader mCubeShader; - - private MapView mapView; - - private TencentMap mMap; - - private LatLng latlng = new LatLng(40.04199816,116.27479076); - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.activity_custom_render); - mapView = findViewById(R.id.map_view); - mMap = mapView.getMap(); - mMap.addOnMapLoadedCallback(new TencentMap.OnMapLoadedCallback() { - @Override - public void onMapLoaded() { - mMap.setCustomRender(new CubeRender()); - mMap.removeOnMapLoadedCallback(this); - } - }); - - mMap.moveCamera(CameraUpdateFactory.newCameraPosition(CameraPosition.builder() - .target(latlng).zoom(16).tilt(45).build())); - - - } - - @Override - protected void onResume() { - // TODO Auto-generated method stub - super.onResume(); - mapView.onResume(); - } - - @Override - protected void onDestroy() { - // TODO Auto-generated method stub - super.onDestroy(); - mapView.onDestroy(); - } - - private class CubeRender implements CustomRender { - - private void initCubeData(float width, float height, float depth) { - // 对标地图坐标 - initVertices(mVertices, width, height, depth); - - // 立方体顶点数据Buffer - mVertexBuffer = ByteBuffer.allocateDirect(mVertices.length * 4) - .order(ByteOrder.nativeOrder()) - .asFloatBuffer(); - mVertexBuffer.put(mVertices).position(0); - - // 立方体顶点绘制顺序Buffer - ByteBuffer byteBuffer = ByteBuffer.allocateDirect(mDrawIndices.length * 4); - byteBuffer.order(ByteOrder.nativeOrder()); - mIndexBuffer = byteBuffer.asShortBuffer(); - mIndexBuffer.put(mDrawIndices); - mIndexBuffer.position(0); - - // 立方体顶点颜色Buffer - ByteBuffer byteBuffer1 = ByteBuffer.allocateDirect(mVertexColors.length * 4); - byteBuffer1.order(ByteOrder.nativeOrder()); - mColorBuffer = byteBuffer1.asFloatBuffer(); - mColorBuffer.put(mVertexColors); - mColorBuffer.position(0); - } - - private void initCubeShader() { - mCubeShader = new CubeShader(); - mCubeShader.init(); - } - - private void initVertices(float[] vertices, float width, float height, float depth) { - for (int i = 0; i < vertices.length / 3; i++) { - int m = i * 3; - vertices[m] = vertices[m] * width; - vertices[m + 1] = vertices[m + 1] * height; - vertices[m + 2] = vertices[m + 2] * depth; - } - } - - @Override - public void onDrawFrame() { - drawCube(); - } - - private void drawCube() { - - if (mIsFirstDraw3DCube) { - float cubeWidth = 0.2f * 10000 / 2; - float cubeHeight = 0.2f * 10000 / 2; - float cubeDepth = 0.4f * 10000 / 2; - initCubeData(cubeWidth, cubeHeight, cubeDepth); - initCubeShader(); - mIsFirstDraw3DCube = false; - } - - if (null == mCubeShader) { - return; - } - - // 绑定地图移动 - PointF p1f = mMap.getProjection().glVertexForCoordinate(latlng); - float[] mvpMatrix = mMap.getProjection().glModelMatrix(p1f, 1); - - // Step2 开始绘制设置 - GLES20.glUseProgram(mCubeShader.mProgram); - checkGlError("glUseProgram"); - - GLES20.glEnable(GLES20.GL_DEPTH_TEST); - checkGlError("glEnable"); - - //对齐矩阵 - GLES20.glUniformMatrix4fv(mCubeShader.mMvpMatrix, 1, false, mvpMatrix, 0); - checkGlError("glUniformMatrix4fv"); - - GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, 0); - // 顶点指针 - GLES20.glEnableVertexAttribArray(mCubeShader.mVertex); - checkGlError("glEnableVertexAttribArray"); - GLES20.glVertexAttribPointer(mCubeShader.mVertex, 3, GLES20.GL_FLOAT, false, 0, mVertexBuffer); - checkGlError("glVertexAttribPointer"); - - // 颜色指针 - GLES20.glEnableVertexAttribArray(mCubeShader.mColor); - checkGlError("glEnableVertexAttribArray"); - GLES20.glVertexAttribPointer(mCubeShader.mColor, 4, GLES20.GL_FLOAT, false, 0, mColorBuffer); - checkGlError("glVertexAttribPointer"); - - GLES20.glBindBuffer(GLES20.GL_ELEMENT_ARRAY_BUFFER, 0); - // 开始画 - GLES20.glDrawElements(GLES20.GL_TRIANGLES, mDrawIndices.length, GLES20.GL_UNSIGNED_SHORT, mIndexBuffer); - checkGlError("glDrawElements"); - - GLES20.glDisableVertexAttribArray(mCubeShader.mVertex); - checkGlError("glDisableVertexAttribArray"); - - GLES20.glDisable(GLES20.GL_DEPTH_TEST); - checkGlError("glDisable"); - } - } - - private static class CubeShader { - int mVertex; - int mMvpMatrix; - int mColor; - int mProgram; - - String vertexShader = "precision mediump float;\n" + - " attribute vec3 mVertex;//顶点数组,三维坐标\n" + - " attribute vec4 mColor;//颜色数组,三维坐标\n" + - " uniform mat4 mMvpMatrix;//mvp矩阵\n" + - " varying vec4 color;//\n" + - " void main(){\n" + - " gl_Position = mMvpMatrix * vec4(mVertex, 1.0);\n" + - " color = mColor;\n" + - " }"; - - String fragmentShader = "//有颜色 没有纹理\n" + - " precision mediump float;\n" + - " varying vec4 color;//\n" + - " void main(){\n" + - " gl_FragColor = color;\n" + - " }"; - - public void init() { - int vertexLocation = GLES20.glCreateShader(GLES20.GL_VERTEX_SHADER); - GLES20.glShaderSource(vertexLocation, vertexShader); - checkGlError("glShaderSource"); - GLES20.glCompileShader(vertexLocation); - checkGlError("glCompileShader"); - int fragmentLocation = GLES20.glCreateShader(GLES20.GL_FRAGMENT_SHADER); - GLES20.glShaderSource(fragmentLocation, fragmentShader); - checkGlError("glShaderSource"); - GLES20.glCompileShader(fragmentLocation); - checkGlError("glCompileShader"); - - mProgram = GLES20.glCreateProgram(); - GLES20.glAttachShader(mProgram, vertexLocation); - GLES20.glAttachShader(mProgram, fragmentLocation); - GLES20.glLinkProgram(mProgram); - int[] linked = new int[1]; - GLES20.glGetProgramiv(mProgram, GLES20.GL_LINK_STATUS, linked, 0); - checkGlError("glLinkProgram"); - if (linked[0] != GLES20.GL_TRUE) { - Log.e(TAG, "Could not link program: "); - Log.e(TAG, GLES20.glGetProgramInfoLog(mProgram)); - GLES20.glDeleteProgram(mProgram); - mProgram = 0; - } - - - mVertex = GLES20.glGetAttribLocation(mProgram, "mVertex"); - mMvpMatrix = GLES20.glGetUniformLocation(mProgram, "mMvpMatrix"); - mColor = GLES20.glGetAttribLocation(mProgram, "mColor"); - } - - } - - static void checkGlError(String op) { - int error; - while ((error = GLES20.glGetError()) != GLES20.GL_NO_ERROR) { - Log.e(TAG, op + ": glError " + error); - } - } -} +//import androidx.appcompat.app.AppCompatActivity; +// +//import android.graphics.PointF; +//import android.opengl.GLES20; +//import android.os.Bundle; +//import android.util.Log; +// +//import cc.winboll.studio.positions.R; +//import com.tencent.tencentmap.mapsdk.maps.CameraUpdateFactory; +//import com.tencent.tencentmap.mapsdk.maps.CustomRender; +//import com.tencent.tencentmap.mapsdk.maps.MapView; +//import com.tencent.tencentmap.mapsdk.maps.TencentMap; +//import com.tencent.tencentmap.mapsdk.maps.model.CameraPosition; +//import com.tencent.tencentmap.mapsdk.maps.model.LatLng; +// +//import java.nio.ByteBuffer; +//import java.nio.ByteOrder; +//import java.nio.FloatBuffer; +//import java.nio.ShortBuffer; +// +///** +// * OpenGL绘制 +// */ +//public class CustomRenderActivity extends AppCompatActivity { +// +// private static final String TAG = CustomRenderActivity.class.getSimpleName(); +// +// // 标识是否第一次绘制3D立方体 +// private boolean mIsFirstDraw3DCube = true; +// +// // 立方体8个顶点坐标 +// private float[] mVertices = { +// -1, -1, -0, +// 1, -1, -0, +// 1, 1, -0, +// -1, 1, -0, +// -1, -1, 1, +// 1, -1, 1, +// 1, 1, 1, +// -1, 1, 1, +// }; +// +// // 3D立方体顶点绘制顺序列表 +// private short[] mDrawIndices = { +// 5, 4, 0, 1, 5, 0, 6, 5, 1, 2, 6, 1, +// 7, 6, 2, 3, 7, 2, 4, 7, 3, 0, 4, 3, +// 6, 7, 4, 5, 6, 4, 1, 0, 3, 2, 1, 3 +// }; +// +// // 3D立方体8个顶点颜色值 +// private float[] mVertexColors = { +// 1f, 1f, 0f, 1f, +// 0f, 1f, 1f, 1f, +// 1f, 0f, 1f, 1f, +// 0f, 0f, 0f, 1f, +// 1f, 1f, 1f, 1f, +// 1f, 0f, 0f, 1f, +// 0f, 1f, 0f, 1f, +// 0f, 0f, 1f, 1f +// }; +// +// // 立方体顶点坐标Buffer +// private FloatBuffer mVertexBuffer; +// +// // 顶点绘制顺序Buffer +// private ShortBuffer mIndexBuffer; +// +// // 立方体顶点颜色Buffer +// private FloatBuffer mColorBuffer; +// +// // 3D立方体着色器 +// private CubeShader mCubeShader; +// +// private MapView mapView; +// +// private TencentMap mMap; +// +// private LatLng latlng = new LatLng(40.04199816,116.27479076); +// +// @Override +// protected void onCreate(Bundle savedInstanceState) { +// super.onCreate(savedInstanceState); +// setContentView(R.layout.activity_custom_render); +// mapView = findViewById(R.id.map_view); +// mMap = mapView.getMap(); +// mMap.addOnMapLoadedCallback(new TencentMap.OnMapLoadedCallback() { +// @Override +// public void onMapLoaded() { +// mMap.setCustomRender(new CubeRender()); +// mMap.removeOnMapLoadedCallback(this); +// } +// }); +// +// mMap.moveCamera(CameraUpdateFactory.newCameraPosition(CameraPosition.builder() +// .target(latlng).zoom(16).tilt(45).build())); +// +// +// } +// +// @Override +// protected void onResume() { +// // TODO Auto-generated method stub +// super.onResume(); +// mapView.onResume(); +// } +// +// @Override +// protected void onDestroy() { +// // TODO Auto-generated method stub +// super.onDestroy(); +// mapView.onDestroy(); +// } +// +// private class CubeRender implements CustomRender { +// +// private void initCubeData(float width, float height, float depth) { +// // 对标地图坐标 +// initVertices(mVertices, width, height, depth); +// +// // 立方体顶点数据Buffer +// mVertexBuffer = ByteBuffer.allocateDirect(mVertices.length * 4) +// .order(ByteOrder.nativeOrder()) +// .asFloatBuffer(); +// mVertexBuffer.put(mVertices).position(0); +// +// // 立方体顶点绘制顺序Buffer +// ByteBuffer byteBuffer = ByteBuffer.allocateDirect(mDrawIndices.length * 4); +// byteBuffer.order(ByteOrder.nativeOrder()); +// mIndexBuffer = byteBuffer.asShortBuffer(); +// mIndexBuffer.put(mDrawIndices); +// mIndexBuffer.position(0); +// +// // 立方体顶点颜色Buffer +// ByteBuffer byteBuffer1 = ByteBuffer.allocateDirect(mVertexColors.length * 4); +// byteBuffer1.order(ByteOrder.nativeOrder()); +// mColorBuffer = byteBuffer1.asFloatBuffer(); +// mColorBuffer.put(mVertexColors); +// mColorBuffer.position(0); +// } +// +// private void initCubeShader() { +// mCubeShader = new CubeShader(); +// mCubeShader.init(); +// } +// +// private void initVertices(float[] vertices, float width, float height, float depth) { +// for (int i = 0; i < vertices.length / 3; i++) { +// int m = i * 3; +// vertices[m] = vertices[m] * width; +// vertices[m + 1] = vertices[m + 1] * height; +// vertices[m + 2] = vertices[m + 2] * depth; +// } +// } +// +// @Override +// public void onDrawFrame() { +// drawCube(); +// } +// +// private void drawCube() { +// +// if (mIsFirstDraw3DCube) { +// float cubeWidth = 0.2f * 10000 / 2; +// float cubeHeight = 0.2f * 10000 / 2; +// float cubeDepth = 0.4f * 10000 / 2; +// initCubeData(cubeWidth, cubeHeight, cubeDepth); +// initCubeShader(); +// mIsFirstDraw3DCube = false; +// } +// +// if (null == mCubeShader) { +// return; +// } +// +// // 绑定地图移动 +// PointF p1f = mMap.getProjection().glVertexForCoordinate(latlng); +// float[] mvpMatrix = mMap.getProjection().glModelMatrix(p1f, 1); +// +// // Step2 开始绘制设置 +// GLES20.glUseProgram(mCubeShader.mProgram); +// checkGlError("glUseProgram"); +// +// GLES20.glEnable(GLES20.GL_DEPTH_TEST); +// checkGlError("glEnable"); +// +// //对齐矩阵 +// GLES20.glUniformMatrix4fv(mCubeShader.mMvpMatrix, 1, false, mvpMatrix, 0); +// checkGlError("glUniformMatrix4fv"); +// +// GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, 0); +// // 顶点指针 +// GLES20.glEnableVertexAttribArray(mCubeShader.mVertex); +// checkGlError("glEnableVertexAttribArray"); +// GLES20.glVertexAttribPointer(mCubeShader.mVertex, 3, GLES20.GL_FLOAT, false, 0, mVertexBuffer); +// checkGlError("glVertexAttribPointer"); +// +// // 颜色指针 +// GLES20.glEnableVertexAttribArray(mCubeShader.mColor); +// checkGlError("glEnableVertexAttribArray"); +// GLES20.glVertexAttribPointer(mCubeShader.mColor, 4, GLES20.GL_FLOAT, false, 0, mColorBuffer); +// checkGlError("glVertexAttribPointer"); +// +// GLES20.glBindBuffer(GLES20.GL_ELEMENT_ARRAY_BUFFER, 0); +// // 开始画 +// GLES20.glDrawElements(GLES20.GL_TRIANGLES, mDrawIndices.length, GLES20.GL_UNSIGNED_SHORT, mIndexBuffer); +// checkGlError("glDrawElements"); +// +// GLES20.glDisableVertexAttribArray(mCubeShader.mVertex); +// checkGlError("glDisableVertexAttribArray"); +// +// GLES20.glDisable(GLES20.GL_DEPTH_TEST); +// checkGlError("glDisable"); +// } +// } +// +// private static class CubeShader { +// int mVertex; +// int mMvpMatrix; +// int mColor; +// int mProgram; +// +// String vertexShader = "precision mediump float;\n" + +// " attribute vec3 mVertex;//顶点数组,三维坐标\n" + +// " attribute vec4 mColor;//颜色数组,三维坐标\n" + +// " uniform mat4 mMvpMatrix;//mvp矩阵\n" + +// " varying vec4 color;//\n" + +// " void main(){\n" + +// " gl_Position = mMvpMatrix * vec4(mVertex, 1.0);\n" + +// " color = mColor;\n" + +// " }"; +// +// String fragmentShader = "//有颜色 没有纹理\n" + +// " precision mediump float;\n" + +// " varying vec4 color;//\n" + +// " void main(){\n" + +// " gl_FragColor = color;\n" + +// " }"; +// +// public void init() { +// int vertexLocation = GLES20.glCreateShader(GLES20.GL_VERTEX_SHADER); +// GLES20.glShaderSource(vertexLocation, vertexShader); +// checkGlError("glShaderSource"); +// GLES20.glCompileShader(vertexLocation); +// checkGlError("glCompileShader"); +// int fragmentLocation = GLES20.glCreateShader(GLES20.GL_FRAGMENT_SHADER); +// GLES20.glShaderSource(fragmentLocation, fragmentShader); +// checkGlError("glShaderSource"); +// GLES20.glCompileShader(fragmentLocation); +// checkGlError("glCompileShader"); +// +// mProgram = GLES20.glCreateProgram(); +// GLES20.glAttachShader(mProgram, vertexLocation); +// GLES20.glAttachShader(mProgram, fragmentLocation); +// GLES20.glLinkProgram(mProgram); +// int[] linked = new int[1]; +// GLES20.glGetProgramiv(mProgram, GLES20.GL_LINK_STATUS, linked, 0); +// checkGlError("glLinkProgram"); +// if (linked[0] != GLES20.GL_TRUE) { +// Log.e(TAG, "Could not link program: "); +// Log.e(TAG, GLES20.glGetProgramInfoLog(mProgram)); +// GLES20.glDeleteProgram(mProgram); +// mProgram = 0; +// } +// +// +// mVertex = GLES20.glGetAttribLocation(mProgram, "mVertex"); +// mMvpMatrix = GLES20.glGetUniformLocation(mProgram, "mMvpMatrix"); +// mColor = GLES20.glGetAttribLocation(mProgram, "mColor"); +// } +// +// } +// +// static void checkGlError(String op) { +// int error; +// while ((error = GLES20.glGetError()) != GLES20.GL_NO_ERROR) { +// Log.e(TAG, op + ": glError " + error); +// } +// } +//} diff --git a/positions/src/main/java/cc/winboll/studio/positions/demo/marker/GroundOverlayActivity.java b/positions/src/main/java/cc/winboll/studio/positions/demo/marker/GroundOverlayActivity.java index 6bc3cb2..fda3814 100644 --- a/positions/src/main/java/cc/winboll/studio/positions/demo/marker/GroundOverlayActivity.java +++ b/positions/src/main/java/cc/winboll/studio/positions/demo/marker/GroundOverlayActivity.java @@ -1,129 +1,129 @@ package cc.winboll.studio.positions.demo.marker; -import androidx.annotation.NonNull; -import androidx.appcompat.app.AppCompatActivity; -import androidx.fragment.app.FragmentActivity; - -import android.os.Bundle; -import android.view.Menu; -import android.view.MenuItem; -import android.view.View; -import android.widget.Button; -import android.widget.RadioGroup; - - -import cc.winboll.studio.positions.R; -import cc.winboll.studio.positions.demo.basic.SupportMapFragmentActivity; -import com.tencent.tencentmap.mapsdk.maps.CameraUpdateFactory; -import com.tencent.tencentmap.mapsdk.maps.MapView; -import com.tencent.tencentmap.mapsdk.maps.TencentMap; -import com.tencent.tencentmap.mapsdk.maps.model.BitmapDescriptorFactory; -import com.tencent.tencentmap.mapsdk.maps.model.GroundOverlay; -import com.tencent.tencentmap.mapsdk.maps.model.GroundOverlayOptions; -import com.tencent.tencentmap.mapsdk.maps.model.LatLng; -import com.tencent.tencentmap.mapsdk.maps.model.LatLngBounds; -import com.tencent.tencentmap.mapsdk.maps.model.OverlayLevel; - -import java.util.ArrayList; - -public class GroundOverlayActivity extends SupportMapFragmentActivity { - - private MapView mMapView; - private TencentMap mTencentMap; - private GroundOverlay groundOverlay; - GroundOverlayOptions groundOverlayOptions; - private boolean mIsSelected; - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.activity_ground_overlay); - mMapView = findViewById(R.id.map_view); - mTencentMap = mMapView.getMap(); - mTencentMap.setIndoorEnabled(true); - } - - - @Override - protected void onResume() { - super.onResume(); - mMapView.onResume(); - } - - @Override - protected void onPause() { - super.onPause(); - mMapView.onPause(); - } - - @Override - protected void onDestroy() { - super.onDestroy(); - mMapView.onDestroy(); - } - - - @Override - protected void onStart() { - super.onStart(); - mMapView.onStart(); - } - - @Override - protected void onStop() { - super.onStop(); - mMapView.onStop(); - } - - @Override - public boolean onCreateOptionsMenu(Menu menu) { - getMenuInflater().inflate(R.menu.marker_groundoverlay, menu); - return true; - } - - @Override - public boolean onPrepareOptionsMenu(Menu menu) { - menu.findItem(R.id.menu_add_groundoverlay).setVisible(!mIsSelected); - menu.findItem(R.id.menu_remove_groundoverlay).setVisible(mIsSelected); - return super.onPrepareOptionsMenu(menu); - } - - @Override - public boolean onOptionsItemSelected(@NonNull MenuItem item) { - switch (item.getItemId()) { - case R.id.menu_add_groundoverlay: - addGroundOverlays(); - break; - case R.id.menu_remove_groundoverlay: - removeGroundOverlays(); - break; - } - - supportInvalidateOptionsMenu(); - return super.onOptionsItemSelected(item); - } - - public void addGroundOverlays() { - mIsSelected = true; - LatLngBounds lb = new LatLngBounds( - new LatLng(40.045226, 116.280069), - new LatLng(40.038918, 116.271873)); - groundOverlayOptions = new GroundOverlayOptions() - .bitmap(BitmapDescriptorFactory - .fromAsset("groundoverlay.jpg")) - .latLngBounds(lb) - .alpha(10); - groundOverlay = mTencentMap.addGroundOverlay(groundOverlayOptions); - mTencentMap.moveCamera(CameraUpdateFactory.newLatLngBounds(lb, 300)); - - } - - public void removeGroundOverlays() { - mIsSelected = false; - if (groundOverlay != null) { - groundOverlay.remove(); - groundOverlay = null; - } - } - -} +//import androidx.annotation.NonNull; +//import androidx.appcompat.app.AppCompatActivity; +//import androidx.fragment.app.FragmentActivity; +// +//import android.os.Bundle; +//import android.view.Menu; +//import android.view.MenuItem; +//import android.view.View; +//import android.widget.Button; +//import android.widget.RadioGroup; +// +// +//import cc.winboll.studio.positions.R; +//import cc.winboll.studio.positions.demo.basic.SupportMapFragmentActivity; +//import com.tencent.tencentmap.mapsdk.maps.CameraUpdateFactory; +//import com.tencent.tencentmap.mapsdk.maps.MapView; +//import com.tencent.tencentmap.mapsdk.maps.TencentMap; +//import com.tencent.tencentmap.mapsdk.maps.model.BitmapDescriptorFactory; +//import com.tencent.tencentmap.mapsdk.maps.model.GroundOverlay; +//import com.tencent.tencentmap.mapsdk.maps.model.GroundOverlayOptions; +//import com.tencent.tencentmap.mapsdk.maps.model.LatLng; +//import com.tencent.tencentmap.mapsdk.maps.model.LatLngBounds; +//import com.tencent.tencentmap.mapsdk.maps.model.OverlayLevel; +// +//import java.util.ArrayList; +// +//public class GroundOverlayActivity extends SupportMapFragmentActivity { +// +// private MapView mMapView; +// private TencentMap mTencentMap; +// private GroundOverlay groundOverlay; +// GroundOverlayOptions groundOverlayOptions; +// private boolean mIsSelected; +// +// @Override +// protected void onCreate(Bundle savedInstanceState) { +// super.onCreate(savedInstanceState); +// setContentView(R.layout.activity_ground_overlay); +// mMapView = findViewById(R.id.map_view); +// mTencentMap = mMapView.getMap(); +// mTencentMap.setIndoorEnabled(true); +// } +// +// +// @Override +// protected void onResume() { +// super.onResume(); +// mMapView.onResume(); +// } +// +// @Override +// protected void onPause() { +// super.onPause(); +// mMapView.onPause(); +// } +// +// @Override +// protected void onDestroy() { +// super.onDestroy(); +// mMapView.onDestroy(); +// } +// +// +// @Override +// protected void onStart() { +// super.onStart(); +// mMapView.onStart(); +// } +// +// @Override +// protected void onStop() { +// super.onStop(); +// mMapView.onStop(); +// } +// +// @Override +// public boolean onCreateOptionsMenu(Menu menu) { +// getMenuInflater().inflate(R.menu.marker_groundoverlay, menu); +// return true; +// } +// +// @Override +// public boolean onPrepareOptionsMenu(Menu menu) { +// menu.findItem(R.id.menu_add_groundoverlay).setVisible(!mIsSelected); +// menu.findItem(R.id.menu_remove_groundoverlay).setVisible(mIsSelected); +// return super.onPrepareOptionsMenu(menu); +// } +// +// @Override +// public boolean onOptionsItemSelected(@NonNull MenuItem item) { +// switch (item.getItemId()) { +// case R.id.menu_add_groundoverlay: +// addGroundOverlays(); +// break; +// case R.id.menu_remove_groundoverlay: +// removeGroundOverlays(); +// break; +// } +// +// supportInvalidateOptionsMenu(); +// return super.onOptionsItemSelected(item); +// } +// +// public void addGroundOverlays() { +// mIsSelected = true; +// LatLngBounds lb = new LatLngBounds( +// new LatLng(40.045226, 116.280069), +// new LatLng(40.038918, 116.271873)); +// groundOverlayOptions = new GroundOverlayOptions() +// .bitmap(BitmapDescriptorFactory +// .fromAsset("groundoverlay.jpg")) +// .latLngBounds(lb) +// .alpha(10); +// groundOverlay = mTencentMap.addGroundOverlay(groundOverlayOptions); +// mTencentMap.moveCamera(CameraUpdateFactory.newLatLngBounds(lb, 300)); +// +// } +// +// public void removeGroundOverlays() { +// mIsSelected = false; +// if (groundOverlay != null) { +// groundOverlay.remove(); +// groundOverlay = null; +// } +// } +// +//} diff --git a/positions/src/main/java/cc/winboll/studio/positions/demo/marker/MarkerActivity.java b/positions/src/main/java/cc/winboll/studio/positions/demo/marker/MarkerActivity.java index 85a3772..1c2112f 100644 --- a/positions/src/main/java/cc/winboll/studio/positions/demo/marker/MarkerActivity.java +++ b/positions/src/main/java/cc/winboll/studio/positions/demo/marker/MarkerActivity.java @@ -17,58 +17,58 @@ import com.tencent.tencentmap.mapsdk.maps.model.Marker; import com.tencent.tencentmap.mapsdk.maps.model.MarkerOptions; public class MarkerActivity extends SupportMapFragmentActivity { - public Marker marker; - public Switch aSwitch; - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - aSwitch = findViewById(R.id.switch_map); - aSwitch.setVisibility(View.VISIBLE); - aSwitch.setText("添加标注"); - setMarker(); - aSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { - @Override - public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { - if(isChecked){ - setMarker(); - }else { - if(marker!=null){ - marker.remove(); - } - } - } - }); - - } - - /** - * 设置标注 - */ - private void setMarker(){ - LatLng latLng = new LatLng(39.984108,116.307557); - BitmapDescriptor bitmapDescriptor = BitmapDescriptorFactory.fromBitmap(getBitMap(R.drawable.marker)); - MarkerOptions options = new MarkerOptions().position(latLng).icon(bitmapDescriptor); - - //设置infowindow - options.title("地址"); - options.snippet("中国技术交易大厦"); - marker = tencentMap.addMarker(options); - marker.setInfoWindowEnable(true); - } - - - private Bitmap getBitMap(int resourceId){ - Bitmap bitmap = BitmapFactory.decodeResource(getResources(), resourceId); - int width = bitmap.getWidth(); - int height = bitmap.getHeight(); - int newWidth = 100; - int newHeight = 100; - float widthScale = ((float)newWidth)/width; - float heightScale = ((float)newHeight)/height; - Matrix matrix = new Matrix(); - matrix.postScale(widthScale, heightScale); - bitmap = Bitmap.createBitmap(bitmap,0,0,width,height,matrix,true); - return bitmap; - } +// public Marker marker; +// public Switch aSwitch; +// +// @Override +// protected void onCreate(Bundle savedInstanceState) { +// super.onCreate(savedInstanceState); +// aSwitch = findViewById(R.id.switch_map); +// aSwitch.setVisibility(View.VISIBLE); +// aSwitch.setText("添加标注"); +// setMarker(); +// aSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { +// @Override +// public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { +// if(isChecked){ +// setMarker(); +// }else { +// if(marker!=null){ +// marker.remove(); +// } +// } +// } +// }); +// +// } +// +// /** +// * 设置标注 +// */ +// private void setMarker(){ +// LatLng latLng = new LatLng(39.984108,116.307557); +// BitmapDescriptor bitmapDescriptor = BitmapDescriptorFactory.fromBitmap(getBitMap(R.drawable.marker)); +// MarkerOptions options = new MarkerOptions().position(latLng).icon(bitmapDescriptor); +// +// //设置infowindow +// options.title("地址"); +// options.snippet("中国技术交易大厦"); +// marker = tencentMap.addMarker(options); +// marker.setInfoWindowEnable(true); +// } +// +// +// private Bitmap getBitMap(int resourceId){ +// Bitmap bitmap = BitmapFactory.decodeResource(getResources(), resourceId); +// int width = bitmap.getWidth(); +// int height = bitmap.getHeight(); +// int newWidth = 100; +// int newHeight = 100; +// float widthScale = ((float)newWidth)/width; +// float heightScale = ((float)newHeight)/height; +// Matrix matrix = new Matrix(); +// matrix.postScale(widthScale, heightScale); +// bitmap = Bitmap.createBitmap(bitmap,0,0,width,height,matrix,true); +// return bitmap; +// } } diff --git a/positions/src/main/java/cc/winboll/studio/positions/demo/marker/MarkerAnimation.java b/positions/src/main/java/cc/winboll/studio/positions/demo/marker/MarkerAnimation.java index b8aeb35..39a58d5 100644 --- a/positions/src/main/java/cc/winboll/studio/positions/demo/marker/MarkerAnimation.java +++ b/positions/src/main/java/cc/winboll/studio/positions/demo/marker/MarkerAnimation.java @@ -39,197 +39,197 @@ import java.util.TimerTask; public class MarkerAnimation extends AbsMapActivity { - private int rotate = 0; - private int scale = 1; - private int alpha = 2; - private int translate = 3; - private int set = 4; - private boolean mHasAdded; - private Marker marker; - private IRotateAnimation rotateAnimation; - private IScaleAnimation scaleAnimation; - private IAlphaAnimation alphaAnimation; - private ITranslateAnimation translateAnimation; - private TencentMap tencentMap; - private IAnimationSet animationSet; - private LatLng latLng; - - @Override - protected void onCreate(@Nullable Bundle savedInstanceState, TencentMap mTencentMap) { - super.onCreate(savedInstanceState, mTencentMap); - tencentMap = mTencentMap; - tencentMap.moveCamera(CameraUpdateFactory.zoomTo(15)); - } - - @Override - public boolean onCreateOptionsMenu(Menu menu) { - getMenuInflater().inflate(R.menu.marker_animation, menu); - return true; - } - - @Override - public boolean onPrepareOptionsMenu(Menu menu) { - menu.findItem(R.id.menu_add_marker).setVisible(!mHasAdded); - menu.findItem(R.id.menu_delete_marker).setVisible(mHasAdded); - return super.onPrepareOptionsMenu(menu); - } - - @Override - public boolean onOptionsItemSelected(MenuItem item) { - switch (item.getItemId()) { - case R.id.menu_add_marker_rotate: - tencentMap.clear(); - marker = tencentMap.addMarker(setMarkerAnimation(rotate)); - mHasAdded = true; - marker.setAnimation(rotateAnimation); - marker.startAnimation(); - break; - - case R.id.menu_add_marker_scale: - tencentMap.clear(); - marker = tencentMap.addMarker(setMarkerAnimation(scale)); - mHasAdded = true; - marker.setAnimation(scaleAnimation); - marker.startAnimation(); - scaleAnimation.setAnimationListener(new AnimationListener() { - @Override - public void onAnimationStart() { - - } - - @Override - public void onAnimationEnd() { - marker.startAnimation(); - } - }); - - - break; - case R.id.menu_add_marker_alpha: - tencentMap.clear(); - marker = tencentMap.addMarker(setMarkerAnimation(alpha)); - mHasAdded = true; - marker.setAnimation(alphaAnimation); - marker.startAnimation(); - break; - case R.id.menu_add_marker_translate: - tencentMap.clear(); - marker = tencentMap.addMarker(setMarkerAnimation(translate)); - mHasAdded = true; - Point screenLocation = tencentMap.getProjection().toScreenLocation(latLng); - - marker.setFixingPoint(screenLocation.x, screenLocation.y); - - marker.setAnimation(translateAnimation); - marker.startAnimation(); - - translateAnimation.setAnimationListener(new AnimationListener() { - @Override - public void onAnimationStart() { - - } - - @Override - public void onAnimationEnd() { - marker.setFixingPointEnable(false); - - } - }); - break; - case R.id.menu_add_marker_set: - tencentMap.clear(); - marker = tencentMap.addMarker(setMarkerAnimation(set)); - mHasAdded = true; - marker.setAnimation(animationSet); - marker.startAnimation(); - break; - - case R.id.menu_delete_marker: - if (marker != null) { - marker.remove(); - marker = null; - mHasAdded = false; - } - break; - } - return super.onOptionsItemSelected(item); - } - - private MarkerOptions setMarkerAnimation(int type) { - latLng = new LatLng(39.984108, 116.307557); - BitmapDescriptor bitmapDescriptor = BitmapDescriptorFactory.fromBitmap(getBitMap(R.drawable.marker)); - MarkerOptions position = new MarkerOptions().position(latLng).icon(bitmapDescriptor); - switch (type) { - case 0: - //旋转动画 - rotateAnimation = tencentMap.getMapContext().createRotateAnimation(0, 360, 0, 0, 0); - rotateAnimation.setDuration(2000); - break; - case 1: - //缩放动画 - scaleAnimation = tencentMap.getMapContext().createScaleAnimation(0.0f, 1f, 0.0f, 1f); - scaleAnimation.setDuration(2000); - scaleAnimation.setInterpolator(new AccelerateDecelerateInterpolator()); - - case 2: - //渐变 - alphaAnimation = tencentMap.getMapContext().createAlphaAnimation(0f, 1f); - alphaAnimation.setDuration(2000); - alphaAnimation.setInterpolator(new AccelerateDecelerateInterpolator()); - - break; - case 3: - //平移 - Point point = tencentMap.getProjection().toScreenLocation(latLng); - point.y -= dip2px(this, 250); - LatLng target = tencentMap.getProjection().fromScreenLocation(point); - translateAnimation = tencentMap.getMapContext().createTranslateAnimation(target); - translateAnimation.setInterpolator(new Interpolator() { - @Override - public float getInterpolation(float v) { - if (v <= 0.5f) { - return (float) (0.5f - 2 * (0.5 - v) * (0.5 - v)); - } else { - return (float) (0.5f - Math.sqrt((v - 0.5f) * (1.5f - v))); - } - } - }); - translateAnimation.setDuration(2000); - break; - case 4: - //组合动画 - animationSet = tencentMap.getMapContext().createAnimationSet(true); - if (rotateAnimation != null || scaleAnimation != null || alphaAnimation != null) { - animationSet.addAnimation(rotateAnimation); - animationSet.addAnimation(scaleAnimation); - animationSet.addAnimation(alphaAnimation); - } - - break; - - default: - throw new IllegalStateException("Unexpected value: " + type); - } - return position; - } - - private static int dip2px(Context context, float dpValue) { - final float scale = context.getResources().getDisplayMetrics().density; - return (int) (dpValue * scale + 1.5f); - } - - private Bitmap getBitMap(int resourceId) { - Bitmap bitmap = BitmapFactory.decodeResource(getResources(), resourceId); - int width = bitmap.getWidth(); - int height = bitmap.getHeight(); - int newWidth = 100; - int newHeight = 100; - float widthScale = ((float) newWidth) / width; - float heightScale = ((float) newHeight) / height; - Matrix matrix = new Matrix(); - matrix.postScale(widthScale, heightScale); - bitmap = Bitmap.createBitmap(bitmap, 0, 0, width, height, matrix, true); - return bitmap; - } +// private int rotate = 0; +// private int scale = 1; +// private int alpha = 2; +// private int translate = 3; +// private int set = 4; +// private boolean mHasAdded; +// private Marker marker; +// private IRotateAnimation rotateAnimation; +// private IScaleAnimation scaleAnimation; +// private IAlphaAnimation alphaAnimation; +// private ITranslateAnimation translateAnimation; +// private TencentMap tencentMap; +// private IAnimationSet animationSet; +// private LatLng latLng; +// +// @Override +// protected void onCreate(@Nullable Bundle savedInstanceState, TencentMap mTencentMap) { +// super.onCreate(savedInstanceState, mTencentMap); +// tencentMap = mTencentMap; +// tencentMap.moveCamera(CameraUpdateFactory.zoomTo(15)); +// } +// +// @Override +// public boolean onCreateOptionsMenu(Menu menu) { +// getMenuInflater().inflate(R.menu.marker_animation, menu); +// return true; +// } +// +// @Override +// public boolean onPrepareOptionsMenu(Menu menu) { +// menu.findItem(R.id.menu_add_marker).setVisible(!mHasAdded); +// menu.findItem(R.id.menu_delete_marker).setVisible(mHasAdded); +// return super.onPrepareOptionsMenu(menu); +// } +// +// @Override +// public boolean onOptionsItemSelected(MenuItem item) { +// switch (item.getItemId()) { +// case R.id.menu_add_marker_rotate: +// tencentMap.clear(); +// marker = tencentMap.addMarker(setMarkerAnimation(rotate)); +// mHasAdded = true; +// marker.setAnimation(rotateAnimation); +// marker.startAnimation(); +// break; +// +// case R.id.menu_add_marker_scale: +// tencentMap.clear(); +// marker = tencentMap.addMarker(setMarkerAnimation(scale)); +// mHasAdded = true; +// marker.setAnimation(scaleAnimation); +// marker.startAnimation(); +// scaleAnimation.setAnimationListener(new AnimationListener() { +// @Override +// public void onAnimationStart() { +// +// } +// +// @Override +// public void onAnimationEnd() { +// marker.startAnimation(); +// } +// }); +// +// +// break; +// case R.id.menu_add_marker_alpha: +// tencentMap.clear(); +// marker = tencentMap.addMarker(setMarkerAnimation(alpha)); +// mHasAdded = true; +// marker.setAnimation(alphaAnimation); +// marker.startAnimation(); +// break; +// case R.id.menu_add_marker_translate: +// tencentMap.clear(); +// marker = tencentMap.addMarker(setMarkerAnimation(translate)); +// mHasAdded = true; +// Point screenLocation = tencentMap.getProjection().toScreenLocation(latLng); +// +// marker.setFixingPoint(screenLocation.x, screenLocation.y); +// +// marker.setAnimation(translateAnimation); +// marker.startAnimation(); +// +// translateAnimation.setAnimationListener(new AnimationListener() { +// @Override +// public void onAnimationStart() { +// +// } +// +// @Override +// public void onAnimationEnd() { +// marker.setFixingPointEnable(false); +// +// } +// }); +// break; +// case R.id.menu_add_marker_set: +// tencentMap.clear(); +// marker = tencentMap.addMarker(setMarkerAnimation(set)); +// mHasAdded = true; +// marker.setAnimation(animationSet); +// marker.startAnimation(); +// break; +// +// case R.id.menu_delete_marker: +// if (marker != null) { +// marker.remove(); +// marker = null; +// mHasAdded = false; +// } +// break; +// } +// return super.onOptionsItemSelected(item); +// } +// +// private MarkerOptions setMarkerAnimation(int type) { +// latLng = new LatLng(39.984108, 116.307557); +// BitmapDescriptor bitmapDescriptor = BitmapDescriptorFactory.fromBitmap(getBitMap(R.drawable.marker)); +// MarkerOptions position = new MarkerOptions().position(latLng).icon(bitmapDescriptor); +// switch (type) { +// case 0: +// //旋转动画 +// rotateAnimation = tencentMap.getMapContext().createRotateAnimation(0, 360, 0, 0, 0); +// rotateAnimation.setDuration(2000); +// break; +// case 1: +// //缩放动画 +// scaleAnimation = tencentMap.getMapContext().createScaleAnimation(0.0f, 1f, 0.0f, 1f); +// scaleAnimation.setDuration(2000); +// scaleAnimation.setInterpolator(new AccelerateDecelerateInterpolator()); +// +// case 2: +// //渐变 +// alphaAnimation = tencentMap.getMapContext().createAlphaAnimation(0f, 1f); +// alphaAnimation.setDuration(2000); +// alphaAnimation.setInterpolator(new AccelerateDecelerateInterpolator()); +// +// break; +// case 3: +// //平移 +// Point point = tencentMap.getProjection().toScreenLocation(latLng); +// point.y -= dip2px(this, 250); +// LatLng target = tencentMap.getProjection().fromScreenLocation(point); +// translateAnimation = tencentMap.getMapContext().createTranslateAnimation(target); +// translateAnimation.setInterpolator(new Interpolator() { +// @Override +// public float getInterpolation(float v) { +// if (v <= 0.5f) { +// return (float) (0.5f - 2 * (0.5 - v) * (0.5 - v)); +// } else { +// return (float) (0.5f - Math.sqrt((v - 0.5f) * (1.5f - v))); +// } +// } +// }); +// translateAnimation.setDuration(2000); +// break; +// case 4: +// //组合动画 +// animationSet = tencentMap.getMapContext().createAnimationSet(true); +// if (rotateAnimation != null || scaleAnimation != null || alphaAnimation != null) { +// animationSet.addAnimation(rotateAnimation); +// animationSet.addAnimation(scaleAnimation); +// animationSet.addAnimation(alphaAnimation); +// } +// +// break; +// +// default: +// throw new IllegalStateException("Unexpected value: " + type); +// } +// return position; +// } +// +// private static int dip2px(Context context, float dpValue) { +// final float scale = context.getResources().getDisplayMetrics().density; +// return (int) (dpValue * scale + 1.5f); +// } +// +// private Bitmap getBitMap(int resourceId) { +// Bitmap bitmap = BitmapFactory.decodeResource(getResources(), resourceId); +// int width = bitmap.getWidth(); +// int height = bitmap.getHeight(); +// int newWidth = 100; +// int newHeight = 100; +// float widthScale = ((float) newWidth) / width; +// float heightScale = ((float) newHeight) / height; +// Matrix matrix = new Matrix(); +// matrix.postScale(widthScale, heightScale); +// bitmap = Bitmap.createBitmap(bitmap, 0, 0, width, height, matrix, true); +// return bitmap; +// } } diff --git a/positions/src/main/java/cc/winboll/studio/positions/demo/marker/MarkerClickActivity.java b/positions/src/main/java/cc/winboll/studio/positions/demo/marker/MarkerClickActivity.java index f70acda..ddc8eaa 100644 --- a/positions/src/main/java/cc/winboll/studio/positions/demo/marker/MarkerClickActivity.java +++ b/positions/src/main/java/cc/winboll/studio/positions/demo/marker/MarkerClickActivity.java @@ -1,25 +1,25 @@ package cc.winboll.studio.positions.demo.marker; -import android.os.Bundle; -import android.view.View; -import android.widget.Toast; - -import com.tencent.tencentmap.mapsdk.maps.TencentMap; -import com.tencent.tencentmap.mapsdk.maps.model.Marker; - -public class MarkerClickActivity extends MarkerActivity implements TencentMap.OnMarkerClickListener{ - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - marker.setInfoWindowEnable(false); - aSwitch.setVisibility(View.GONE); - tencentMap.setOnMarkerClickListener(this); - } - - @Override - public boolean onMarkerClick(Marker marker) { - Toast.makeText(getApplicationContext(),"您点击了标注", Toast.LENGTH_SHORT).show(); - return false; - } -} +//import android.os.Bundle; +//import android.view.View; +//import android.widget.Toast; +// +//import com.tencent.tencentmap.mapsdk.maps.TencentMap; +//import com.tencent.tencentmap.mapsdk.maps.model.Marker; +// +//public class MarkerClickActivity extends MarkerActivity implements TencentMap.OnMarkerClickListener{ +// +// @Override +// protected void onCreate(Bundle savedInstanceState) { +// super.onCreate(savedInstanceState); +// marker.setInfoWindowEnable(false); +// aSwitch.setVisibility(View.GONE); +// tencentMap.setOnMarkerClickListener(this); +// } +// +// @Override +// public boolean onMarkerClick(Marker marker) { +// Toast.makeText(getApplicationContext(),"您点击了标注", Toast.LENGTH_SHORT).show(); +// return false; +// } +//} diff --git a/positions/src/main/java/cc/winboll/studio/positions/demo/marker/MarkerClusterActivity.java b/positions/src/main/java/cc/winboll/studio/positions/demo/marker/MarkerClusterActivity.java index 82c4bd8..9afa055 100644 --- a/positions/src/main/java/cc/winboll/studio/positions/demo/marker/MarkerClusterActivity.java +++ b/positions/src/main/java/cc/winboll/studio/positions/demo/marker/MarkerClusterActivity.java @@ -20,7 +20,7 @@ import androidx.annotation.Nullable; import cc.winboll.studio.positions.demo.AbsMapActivity; import cc.winboll.studio.positions.R; -import cc.winboll.studio.positions.demo.utils.CoordinateActivity; +//import cc.winboll.studio.positions.demo.utils.CoordinateActivity; import com.tencent.tencentmap.mapsdk.maps.CameraUpdate; import com.tencent.tencentmap.mapsdk.maps.CameraUpdateFactory; import com.tencent.tencentmap.mapsdk.maps.TencentMap; @@ -54,334 +54,334 @@ import java.util.Set; import java.util.Timer; import java.util.TimerTask; -public class MarkerClusterActivity extends AbsMapActivity { - private TencentMap tencentMap; - private boolean mHasAdded; - //点聚合坐标数据集合 - private List generalItemList = new ArrayList<>(); - private ClusterManager markerClusterItemClusterManager; - private int i = 8; - //自定义聚合 - private ClusterManager petaItemClusterManager; - private ArrayList petaItems; - private ArrayList latLngs; - private NonHierarchicalDistanceBasedAlgorithm ndba; - private DefaultClusterRenderer markerClusterItemDefaultClusterRenderer; - private String TAG="MarkerClusterActivity"; - - @Override - - protected void onCreate(@Nullable Bundle savedInstanceState, TencentMap mTencentMap) { - super.onCreate(savedInstanceState, mTencentMap); - tencentMap = mTencentMap; - //tencentMap.enableMultipleInfowindow(true); - tencentMap.moveCamera(CameraUpdateFactory.zoomTo(15)); - //默认聚合管理 - configDefaultCluterManger(); - configCustomCluterManger(); - petaItemClusterManager.setOnClusterClickListener(new ClusterManager.OnClusterClickListener() { - @Override - public boolean onClusterClick(Cluster cluster) { - Collection items = cluster.getItems(); - - return false; - } - }); - tencentMap.setOnCameraChangeListener(new TencentMap.OnCameraChangeListener() { - @Override - public void onCameraChange(CameraPosition cameraPosition) { - - } - - @Override - public void onCameraChangeFinished(CameraPosition cameraPosition) { - float zoom = cameraPosition.zoom; - if (zoom < 6) { - tencentMap.setOnCameraChangeListener(markerClusterItemClusterManager); - markerClusterItemClusterManager.addItems(getMassiveCoords()); - // tencentMap.animateCamera(CameraUpdateFactory.newLatLngBounds(LatLngBounds.builder().include(latLngs).build(), 20)); - markerClusterItemClusterManager.cluster(); - - } else { - markerClusterItemClusterManager.cancel(); - } - Log.d(TAG, "onCameraChangeFinished: " + zoom); - } - }); - } - - public class PetaItem implements ClusterItem { - private final LatLng mLatLng; - private int mDrawableResourceId; - - public PetaItem(double lat, double lon, int resourceId) { - mLatLng = new LatLng(lat, lon); - mDrawableResourceId = resourceId; - } - - @Override - public LatLng getPosition() { - return mLatLng; - } - - public int getDrawableResourceId() { - return mDrawableResourceId; - } - } - - //聚合设置 - private void configDefaultCluterManger() { - //实例化点聚合管理者 - markerClusterItemClusterManager = new ClusterManager<>(this, tencentMap); - //默认聚合策略,调用时不用添加,如果需要其它聚合策略可以按以下修改 - ndba = new NonHierarchicalDistanceBasedAlgorithm<>(this); - //设置点聚合距离 - ndba.setMaxDistanceAtZoom(35); - //设置策略 - markerClusterItemClusterManager.setAlgorithm(ndba); - //设置聚合渲染器,按照需要设置 - markerClusterItemDefaultClusterRenderer = new DefaultClusterRenderer<>(this, tencentMap, markerClusterItemClusterManager); - //设置最小聚合数量,默认是4 - markerClusterItemDefaultClusterRenderer.setMinClusterSize(5); - //定义聚合的分段,例如:当超过5个不满足10个数据,显示5+ - markerClusterItemDefaultClusterRenderer.setBuckets(new int[]{5, 10, 20, 50}); - markerClusterItemClusterManager.setRenderer(markerClusterItemDefaultClusterRenderer); - - - } - - //自定义聚合样式设置 - private void configCustomCluterManger() { - petaItemClusterManager = new ClusterManager<>(this, tencentMap); - CustomIconClusterRenderer customIconClusterRender = new CustomIconClusterRenderer(this, tencentMap, petaItemClusterManager); - customIconClusterRender.setMinClusterSize(3); - petaItemClusterManager.setRenderer(customIconClusterRender); - - } - - - //普通聚合 - private Collection getGeneralCoords() { - if (generalItemList == null || generalItemList.size() == 0) { - generalItemList = getItemWithFileName("cluster_new"); - } - return generalItemList; - } - - //海量聚合 - private Collection getMassiveCoords() { - if (generalItemList == null || generalItemList.size() == 0) { - generalItemList = getItemWithFileName("datab"); - } - return generalItemList; - } - - private List getItemWithFileName(String cluster_new) { - ArrayList arrayList = new ArrayList<>(); - latLngs = new ArrayList<>(); - try { - InputStream inputStream = getAssets().open(cluster_new); - InputStreamReader inputStreamReader = new InputStreamReader(inputStream); - BufferedReader bufferedReader = new BufferedReader(inputStreamReader); - String line; - while ((line = bufferedReader.readLine()) != null) { - String[] data = line.split("\t"); - double longitue = Double.parseDouble(data[0]); - double latitue = Double.parseDouble(data[1]); - arrayList.add(new MarkerClusterItem(latitue, longitue)); - latLngs.add(new LatLng(latitue, longitue)); - } - inputStream.close(); - inputStreamReader.close(); - bufferedReader.close(); - return arrayList; - } catch (Exception e) { - e.printStackTrace(); - } - return null; - } - - @Override - public boolean onCreateOptionsMenu(Menu menu) { - getMenuInflater().inflate(R.menu.marker_cluster, menu); - return true; - } - - @Override - public boolean onPrepareOptionsMenu(Menu menu) { - menu.findItem(R.id.menu_add_marker).setVisible(!mHasAdded); - menu.findItem(R.id.menu_delete_marker).setVisible(mHasAdded); - return super.onPrepareOptionsMenu(menu); - } - - @Override - public boolean onOptionsItemSelected(MenuItem item) { - tencentMap.setInfoWindowAdapter(new TencentMap.InfoWindowAdapter() { - @Override - public View getInfoWindow(Marker marker) { - LinearLayout inflate = (LinearLayout) View.inflate(getApplicationContext(), R.layout.custom_infowindow, null); - TextView title = inflate.findViewById(R.id.tv_title); - Point point = tencentMap.getProjection().toScreenLocation(marker.getPosition()); - title.setText("\t\t\t\t\t\t\t\t自定义View弹窗:\n点在屏幕位置:" + point); - return inflate; - } - - @Override - public View getInfoContents(Marker marker) { - return null; - } - }); - final IAlphaAnimation alphaAnimation_custom = tencentMap.getMapContext().createAlphaAnimation(0f, 1f); - alphaAnimation_custom.setDuration(1000); - alphaAnimation_custom.setInterpolator(new AccelerateDecelerateInterpolator()); - tencentMap.setOnMarkerClickListener(new TencentMap.OnMarkerClickListener() { - @Override - public boolean onMarkerClick(Marker marker) { - Point point = tencentMap.getProjection().toScreenLocation(marker.getPosition()); - marker.setTitle(point.toString()); - marker.setAnimation(alphaAnimation_custom); - marker.startAnimation(); - return false; - } - }); - switch (item.getItemId()) { - case R.id.menu_add_marker_general: - mHasAdded = true; - //markerClusterItemClusterManager.cancel(); - tencentMap.setOnCameraChangeListener(markerClusterItemClusterManager); - markerClusterItemClusterManager.addItems(getGeneralCoords()); - LatLng position = generalItemList.get(6).getPosition(); - CameraUpdate cameraUpdate; - if (i < 16) { - i++; - cameraUpdate = CameraUpdateFactory.newLatLngZoom(position, i); - } else { - i = 6; - cameraUpdate = CameraUpdateFactory.newLatLngZoom(position, i); - } - tencentMap.animateCamera(cameraUpdate); - markerClusterItemClusterManager.cluster(); - - break; - case R.id.menu_add_marker_massive: - mHasAdded = true; - tencentMap.setOnCameraChangeListener(markerClusterItemClusterManager); - markerClusterItemClusterManager.addItems(getMassiveCoords()); - - LatLng position_massive = generalItemList.get(60).getPosition(); - CameraUpdate cameraUpdate_massive; - if (i < 16) { - i++; - cameraUpdate_massive = CameraUpdateFactory.newLatLngZoom(position_massive, i); - } else { - i = 6; - cameraUpdate_massive = CameraUpdateFactory.newLatLngZoom(position_massive, i); - } - tencentMap.animateCamera(cameraUpdate_massive); - markerClusterItemClusterManager.cluster(); - break; - case R.id.menu_add_marker_custom: - mHasAdded = true; - tencentMap.setOnCameraChangeListener(petaItemClusterManager); - addCustomClusterItem(); - tencentMap.animateCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(39.971595, 116.314316), 15)); - petaItemClusterManager.cluster(); - break; - case R.id.menu_delete_marker: - mHasAdded = false; - clusterReMove(); - break; - - } - return super.onOptionsItemSelected(item); - } - - private void addCustomClusterItem() { - - petaItemClusterManager.addItem(new PetaItem(39.971595, 116.294747, R.mipmap.petal_blue)); - - petaItemClusterManager.addItem(new PetaItem(39.971595, 116.314316, R.mipmap.petal_red)); - - petaItemClusterManager.addItem(new PetaItem(39.967385, 116.317063, R.mipmap.petal_green)); - - petaItemClusterManager.addItem(new PetaItem(39.951596, 116.302300, R.mipmap.petal_yellow)); - - petaItemClusterManager.addItem(new PetaItem(39.970543, 116.290627, R.mipmap.petal_orange)); - - petaItemClusterManager.addItem(new PetaItem(39.966333, 116.311569, R.mipmap.petal_purple)); - } - - //移除聚合数据 - private void clusterReMove() { - markerClusterItemClusterManager.cancel(); - markerClusterItemClusterManager.cluster(); - generalItemList.clear(); - petaItemClusterManager.cancel(); - petaItemClusterManager.cluster(); - tencentMap.clearAllOverlays(); - - } - - class CustomIconClusterRenderer extends DefaultClusterRenderer { - - private IconGenerator mIconGenerator = new IconGenerator(getApplicationContext()); - private IconGenerator mClusterIconGenerator = new IconGenerator(getApplicationContext()); - private ImageView mItemImageView = new ImageView(getApplicationContext()); - private ImageView mClusterImageView = new ImageView(getApplicationContext()); - - public CustomIconClusterRenderer( - Context context, TencentMap map, ClusterManager clusterManager) { - super(context, map, clusterManager); - mItemImageView.setLayoutParams( - new ViewGroup.LayoutParams( - ViewGroup.LayoutParams.WRAP_CONTENT, - ViewGroup.LayoutParams.WRAP_CONTENT)); - mIconGenerator.setContentView(mItemImageView); - - mClusterImageView.setLayoutParams( - new ViewGroup.LayoutParams( - ViewGroup.LayoutParams.WRAP_CONTENT, - ViewGroup.LayoutParams.WRAP_CONTENT)); - mClusterIconGenerator.setContentView(mClusterImageView); - - setMinClusterSize(1); - } - - @Override - public void onBeforeClusterRendered( - Cluster cluster, MarkerOptions markerOptions) { - int[] resources = new int[cluster.getItems().size()]; - int i = 0; - for (PetaItem item : cluster.getItems()) { - resources[i++] = item.getDrawableResourceId(); - } - - PetalDrawable drawable = new PetalDrawable(getApplicationContext(), resources); - mClusterImageView.setImageDrawable(drawable); - Bitmap icon = mClusterIconGenerator.makeIcon(); - markerOptions.icon(BitmapDescriptorFactory.fromBitmap(icon)); - } - - @Override - public void onBeforeClusterItemRendered(PetaItem item, MarkerOptions markerOptions) { - mItemImageView.setImageResource(item.getDrawableResourceId()); - Bitmap icon = mIconGenerator.makeIcon(); - markerOptions.icon(BitmapDescriptorFactory.fromBitmap(icon)); - } - } - - class MarkerClusterItem implements ClusterItem { - private final LatLng mLatLng; - - public MarkerClusterItem(double lat, double lon) { - mLatLng = new LatLng(lat, lon); - } - - @Override - public LatLng getPosition() { - return mLatLng; - } - } -} +//public class MarkerClusterActivity extends AbsMapActivity { +// private TencentMap tencentMap; +// private boolean mHasAdded; +// //点聚合坐标数据集合 +// private List generalItemList = new ArrayList<>(); +// private ClusterManager markerClusterItemClusterManager; +// private int i = 8; +// //自定义聚合 +// private ClusterManager petaItemClusterManager; +// private ArrayList petaItems; +// private ArrayList latLngs; +// private NonHierarchicalDistanceBasedAlgorithm ndba; +// private DefaultClusterRenderer markerClusterItemDefaultClusterRenderer; +// private String TAG="MarkerClusterActivity"; +// +// @Override +// +// protected void onCreate(@Nullable Bundle savedInstanceState, TencentMap mTencentMap) { +// super.onCreate(savedInstanceState, mTencentMap); +// tencentMap = mTencentMap; +// //tencentMap.enableMultipleInfowindow(true); +// tencentMap.moveCamera(CameraUpdateFactory.zoomTo(15)); +// //默认聚合管理 +// configDefaultCluterManger(); +// configCustomCluterManger(); +// petaItemClusterManager.setOnClusterClickListener(new ClusterManager.OnClusterClickListener() { +// @Override +// public boolean onClusterClick(Cluster cluster) { +// Collection items = cluster.getItems(); +// +// return false; +// } +// }); +// tencentMap.setOnCameraChangeListener(new TencentMap.OnCameraChangeListener() { +// @Override +// public void onCameraChange(CameraPosition cameraPosition) { +// +// } +// +// @Override +// public void onCameraChangeFinished(CameraPosition cameraPosition) { +// float zoom = cameraPosition.zoom; +// if (zoom < 6) { +// tencentMap.setOnCameraChangeListener(markerClusterItemClusterManager); +// markerClusterItemClusterManager.addItems(getMassiveCoords()); +// // tencentMap.animateCamera(CameraUpdateFactory.newLatLngBounds(LatLngBounds.builder().include(latLngs).build(), 20)); +// markerClusterItemClusterManager.cluster(); +// +// } else { +// markerClusterItemClusterManager.cancel(); +// } +// Log.d(TAG, "onCameraChangeFinished: " + zoom); +// } +// }); +// } +// +// public class PetaItem implements ClusterItem { +// private final LatLng mLatLng; +// private int mDrawableResourceId; +// +// public PetaItem(double lat, double lon, int resourceId) { +// mLatLng = new LatLng(lat, lon); +// mDrawableResourceId = resourceId; +// } +// +// @Override +// public LatLng getPosition() { +// return mLatLng; +// } +// +// public int getDrawableResourceId() { +// return mDrawableResourceId; +// } +// } +// +// //聚合设置 +// private void configDefaultCluterManger() { +// //实例化点聚合管理者 +// markerClusterItemClusterManager = new ClusterManager<>(this, tencentMap); +// //默认聚合策略,调用时不用添加,如果需要其它聚合策略可以按以下修改 +// ndba = new NonHierarchicalDistanceBasedAlgorithm<>(this); +// //设置点聚合距离 +// ndba.setMaxDistanceAtZoom(35); +// //设置策略 +// markerClusterItemClusterManager.setAlgorithm(ndba); +// //设置聚合渲染器,按照需要设置 +// markerClusterItemDefaultClusterRenderer = new DefaultClusterRenderer<>(this, tencentMap, markerClusterItemClusterManager); +// //设置最小聚合数量,默认是4 +// markerClusterItemDefaultClusterRenderer.setMinClusterSize(5); +// //定义聚合的分段,例如:当超过5个不满足10个数据,显示5+ +// markerClusterItemDefaultClusterRenderer.setBuckets(new int[]{5, 10, 20, 50}); +// markerClusterItemClusterManager.setRenderer(markerClusterItemDefaultClusterRenderer); +// +// +// } +// +// //自定义聚合样式设置 +// private void configCustomCluterManger() { +// petaItemClusterManager = new ClusterManager<>(this, tencentMap); +// CustomIconClusterRenderer customIconClusterRender = new CustomIconClusterRenderer(this, tencentMap, petaItemClusterManager); +// customIconClusterRender.setMinClusterSize(3); +// petaItemClusterManager.setRenderer(customIconClusterRender); +// +// } +// +// +// //普通聚合 +// private Collection getGeneralCoords() { +// if (generalItemList == null || generalItemList.size() == 0) { +// generalItemList = getItemWithFileName("cluster_new"); +// } +// return generalItemList; +// } +// +// //海量聚合 +// private Collection getMassiveCoords() { +// if (generalItemList == null || generalItemList.size() == 0) { +// generalItemList = getItemWithFileName("datab"); +// } +// return generalItemList; +// } +// +// private List getItemWithFileName(String cluster_new) { +// ArrayList arrayList = new ArrayList<>(); +// latLngs = new ArrayList<>(); +// try { +// InputStream inputStream = getAssets().open(cluster_new); +// InputStreamReader inputStreamReader = new InputStreamReader(inputStream); +// BufferedReader bufferedReader = new BufferedReader(inputStreamReader); +// String line; +// while ((line = bufferedReader.readLine()) != null) { +// String[] data = line.split("\t"); +// double longitue = Double.parseDouble(data[0]); +// double latitue = Double.parseDouble(data[1]); +// arrayList.add(new MarkerClusterItem(latitue, longitue)); +// latLngs.add(new LatLng(latitue, longitue)); +// } +// inputStream.close(); +// inputStreamReader.close(); +// bufferedReader.close(); +// return arrayList; +// } catch (Exception e) { +// e.printStackTrace(); +// } +// return null; +// } +// +// @Override +// public boolean onCreateOptionsMenu(Menu menu) { +// getMenuInflater().inflate(R.menu.marker_cluster, menu); +// return true; +// } +// +// @Override +// public boolean onPrepareOptionsMenu(Menu menu) { +// menu.findItem(R.id.menu_add_marker).setVisible(!mHasAdded); +// menu.findItem(R.id.menu_delete_marker).setVisible(mHasAdded); +// return super.onPrepareOptionsMenu(menu); +// } +// +// @Override +// public boolean onOptionsItemSelected(MenuItem item) { +// tencentMap.setInfoWindowAdapter(new TencentMap.InfoWindowAdapter() { +// @Override +// public View getInfoWindow(Marker marker) { +// LinearLayout inflate = (LinearLayout) View.inflate(getApplicationContext(), R.layout.custom_infowindow, null); +// TextView title = inflate.findViewById(R.id.tv_title); +// Point point = tencentMap.getProjection().toScreenLocation(marker.getPosition()); +// title.setText("\t\t\t\t\t\t\t\t自定义View弹窗:\n点在屏幕位置:" + point); +// return inflate; +// } +// +// @Override +// public View getInfoContents(Marker marker) { +// return null; +// } +// }); +// final IAlphaAnimation alphaAnimation_custom = tencentMap.getMapContext().createAlphaAnimation(0f, 1f); +// alphaAnimation_custom.setDuration(1000); +// alphaAnimation_custom.setInterpolator(new AccelerateDecelerateInterpolator()); +// tencentMap.setOnMarkerClickListener(new TencentMap.OnMarkerClickListener() { +// @Override +// public boolean onMarkerClick(Marker marker) { +// Point point = tencentMap.getProjection().toScreenLocation(marker.getPosition()); +// marker.setTitle(point.toString()); +// marker.setAnimation(alphaAnimation_custom); +// marker.startAnimation(); +// return false; +// } +// }); +// switch (item.getItemId()) { +// case R.id.menu_add_marker_general: +// mHasAdded = true; +// //markerClusterItemClusterManager.cancel(); +// tencentMap.setOnCameraChangeListener(markerClusterItemClusterManager); +// markerClusterItemClusterManager.addItems(getGeneralCoords()); +// LatLng position = generalItemList.get(6).getPosition(); +// CameraUpdate cameraUpdate; +// if (i < 16) { +// i++; +// cameraUpdate = CameraUpdateFactory.newLatLngZoom(position, i); +// } else { +// i = 6; +// cameraUpdate = CameraUpdateFactory.newLatLngZoom(position, i); +// } +// tencentMap.animateCamera(cameraUpdate); +// markerClusterItemClusterManager.cluster(); +// +// break; +// case R.id.menu_add_marker_massive: +// mHasAdded = true; +// tencentMap.setOnCameraChangeListener(markerClusterItemClusterManager); +// markerClusterItemClusterManager.addItems(getMassiveCoords()); +// +// LatLng position_massive = generalItemList.get(60).getPosition(); +// CameraUpdate cameraUpdate_massive; +// if (i < 16) { +// i++; +// cameraUpdate_massive = CameraUpdateFactory.newLatLngZoom(position_massive, i); +// } else { +// i = 6; +// cameraUpdate_massive = CameraUpdateFactory.newLatLngZoom(position_massive, i); +// } +// tencentMap.animateCamera(cameraUpdate_massive); +// markerClusterItemClusterManager.cluster(); +// break; +// case R.id.menu_add_marker_custom: +// mHasAdded = true; +// tencentMap.setOnCameraChangeListener(petaItemClusterManager); +// addCustomClusterItem(); +// tencentMap.animateCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(39.971595, 116.314316), 15)); +// petaItemClusterManager.cluster(); +// break; +// case R.id.menu_delete_marker: +// mHasAdded = false; +// clusterReMove(); +// break; +// +// } +// return super.onOptionsItemSelected(item); +// } +// +// private void addCustomClusterItem() { +// +// petaItemClusterManager.addItem(new PetaItem(39.971595, 116.294747, R.mipmap.petal_blue)); +// +// petaItemClusterManager.addItem(new PetaItem(39.971595, 116.314316, R.mipmap.petal_red)); +// +// petaItemClusterManager.addItem(new PetaItem(39.967385, 116.317063, R.mipmap.petal_green)); +// +// petaItemClusterManager.addItem(new PetaItem(39.951596, 116.302300, R.mipmap.petal_yellow)); +// +// petaItemClusterManager.addItem(new PetaItem(39.970543, 116.290627, R.mipmap.petal_orange)); +// +// petaItemClusterManager.addItem(new PetaItem(39.966333, 116.311569, R.mipmap.petal_purple)); +// } +// +// //移除聚合数据 +// private void clusterReMove() { +// markerClusterItemClusterManager.cancel(); +// markerClusterItemClusterManager.cluster(); +// generalItemList.clear(); +// petaItemClusterManager.cancel(); +// petaItemClusterManager.cluster(); +// tencentMap.clearAllOverlays(); +// +// } +// +// class CustomIconClusterRenderer extends DefaultClusterRenderer { +// +// private IconGenerator mIconGenerator = new IconGenerator(getApplicationContext()); +// private IconGenerator mClusterIconGenerator = new IconGenerator(getApplicationContext()); +// private ImageView mItemImageView = new ImageView(getApplicationContext()); +// private ImageView mClusterImageView = new ImageView(getApplicationContext()); +// +// public CustomIconClusterRenderer( +// Context context, TencentMap map, ClusterManager clusterManager) { +// super(context, map, clusterManager); +// mItemImageView.setLayoutParams( +// new ViewGroup.LayoutParams( +// ViewGroup.LayoutParams.WRAP_CONTENT, +// ViewGroup.LayoutParams.WRAP_CONTENT)); +// mIconGenerator.setContentView(mItemImageView); +// +// mClusterImageView.setLayoutParams( +// new ViewGroup.LayoutParams( +// ViewGroup.LayoutParams.WRAP_CONTENT, +// ViewGroup.LayoutParams.WRAP_CONTENT)); +// mClusterIconGenerator.setContentView(mClusterImageView); +// +// setMinClusterSize(1); +// } +// +// @Override +// public void onBeforeClusterRendered( +// Cluster cluster, MarkerOptions markerOptions) { +// int[] resources = new int[cluster.getItems().size()]; +// int i = 0; +// for (PetaItem item : cluster.getItems()) { +// resources[i++] = item.getDrawableResourceId(); +// } +// +// PetalDrawable drawable = new PetalDrawable(getApplicationContext(), resources); +// mClusterImageView.setImageDrawable(drawable); +// Bitmap icon = mClusterIconGenerator.makeIcon(); +// markerOptions.icon(BitmapDescriptorFactory.fromBitmap(icon)); +// } +// +// @Override +// public void onBeforeClusterItemRendered(PetaItem item, MarkerOptions markerOptions) { +// mItemImageView.setImageResource(item.getDrawableResourceId()); +// Bitmap icon = mIconGenerator.makeIcon(); +// markerOptions.icon(BitmapDescriptorFactory.fromBitmap(icon)); +// } +// } +// +// class MarkerClusterItem implements ClusterItem { +// private final LatLng mLatLng; +// +// public MarkerClusterItem(double lat, double lon) { +// mLatLng = new LatLng(lat, lon); +// } +// +// @Override +// public LatLng getPosition() { +// return mLatLng; +// } +// } +//} diff --git a/positions/src/main/java/cc/winboll/studio/positions/demo/marker/MarkerCollisions.java b/positions/src/main/java/cc/winboll/studio/positions/demo/marker/MarkerCollisions.java index 3c01046..e27d58a 100644 --- a/positions/src/main/java/cc/winboll/studio/positions/demo/marker/MarkerCollisions.java +++ b/positions/src/main/java/cc/winboll/studio/positions/demo/marker/MarkerCollisions.java @@ -1,116 +1,116 @@ -package cc.winboll.studio.positions.demo.marker; - -import androidx.annotation.NonNull; -import androidx.appcompat.app.AppCompatActivity; - -import android.os.Bundle; -import android.view.Menu; -import android.view.MenuItem; -import android.view.View; - -import cc.winboll.studio.positions.R; -import com.tencent.tencentmap.mapsdk.maps.CameraUpdate; -import com.tencent.tencentmap.mapsdk.maps.CameraUpdateFactory; -import com.tencent.tencentmap.mapsdk.maps.MapView; -import com.tencent.tencentmap.mapsdk.maps.TencentMap; -import com.tencent.tencentmap.mapsdk.maps.model.BitmapDescriptor; -import com.tencent.tencentmap.mapsdk.maps.model.BitmapDescriptorFactory; -import com.tencent.tencentmap.mapsdk.maps.model.CameraPosition; -import com.tencent.tencentmap.mapsdk.maps.model.LatLng; -import com.tencent.tencentmap.mapsdk.maps.model.MapPoi; -import com.tencent.tencentmap.mapsdk.maps.model.Marker; -import com.tencent.tencentmap.mapsdk.maps.model.MarkerCollisionItem; -import com.tencent.tencentmap.mapsdk.maps.model.MarkerOptions; - -public class MarkerCollisions extends AppCompatActivity { - - private MapView mapView; - private TencentMap tencentMap; - private boolean mMarkerAdded; - private Marker mMarker; - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.activity_marker_collisions); - intit(); - } - - private void intit() { - mapView = findViewById(R.id.mapView); - tencentMap = mapView.getMap(); - CameraUpdate cameraSigma = - CameraUpdateFactory.newCameraPosition(new CameraPosition( - new LatLng(39.984066, 116.307548), - 15, - 0f, - 0f)); - //移动地图 - tencentMap.moveCamera(cameraSigma); - } - - @Override - public boolean onCreateOptionsMenu(Menu menu) { - getMenuInflater().inflate(R.menu.markercol, menu); - return super.onCreateOptionsMenu(menu); - } - - @Override - public boolean onPrepareOptionsMenu(Menu menu) { - menu.findItem(R.id.menu_open_collisionsmap).setVisible(!mMarkerAdded); - menu.findItem(R.id.menu_close_collisionsmap).setVisible(mMarkerAdded); - return super.onPrepareOptionsMenu(menu); - } - - @Override - public boolean onOptionsItemSelected(@NonNull MenuItem item) { - switch (item.getItemId()) { - case R.id.menu_open_collisionsmap: - mMarkerAdded = true; - BitmapDescriptor custom = BitmapDescriptorFactory.fromResource(R.drawable.marker); - MarkerOptions options = new MarkerOptions().position(new LatLng(39.984066, 116.307548)); - options.icon(custom); - mMarker = tencentMap.addMarker(options); - mMarker.setCollisions(MarkerCollisionItem.POI); - break; - case R.id.menu_close_collisionsmap: - mMarkerAdded = false; - mMarker.remove(); - break; - } - - supportInvalidateOptionsMenu(); - return super.onOptionsItemSelected(item); - } - - @Override - protected void onResume() { - super.onResume(); - mapView.onResume(); - } - - @Override - protected void onPause() { - super.onPause(); - mapView.onPause(); - } - - @Override - protected void onDestroy() { - super.onDestroy(); - mapView.onDestroy(); - } - - - @Override - protected void onStart() { - super.onStart(); - mapView.onStart(); - } - - @Override - protected void onStop() { - super.onStop(); - mapView.onStop(); - } -} \ No newline at end of file +package cc.winboll.studio.positions.demo.marker; + +//import androidx.annotation.NonNull; +//import androidx.appcompat.app.AppCompatActivity; +// +//import android.os.Bundle; +//import android.view.Menu; +//import android.view.MenuItem; +//import android.view.View; +// +//import cc.winboll.studio.positions.R; +//import com.tencent.tencentmap.mapsdk.maps.CameraUpdate; +//import com.tencent.tencentmap.mapsdk.maps.CameraUpdateFactory; +//import com.tencent.tencentmap.mapsdk.maps.MapView; +//import com.tencent.tencentmap.mapsdk.maps.TencentMap; +//import com.tencent.tencentmap.mapsdk.maps.model.BitmapDescriptor; +//import com.tencent.tencentmap.mapsdk.maps.model.BitmapDescriptorFactory; +//import com.tencent.tencentmap.mapsdk.maps.model.CameraPosition; +//import com.tencent.tencentmap.mapsdk.maps.model.LatLng; +//import com.tencent.tencentmap.mapsdk.maps.model.MapPoi; +//import com.tencent.tencentmap.mapsdk.maps.model.Marker; +//import com.tencent.tencentmap.mapsdk.maps.model.MarkerCollisionItem; +//import com.tencent.tencentmap.mapsdk.maps.model.MarkerOptions; +// +//public class MarkerCollisions extends AppCompatActivity { +// +// private MapView mapView; +// private TencentMap tencentMap; +// private boolean mMarkerAdded; +// private Marker mMarker; +// +// @Override +// protected void onCreate(Bundle savedInstanceState) { +// super.onCreate(savedInstanceState); +// setContentView(R.layout.activity_marker_collisions); +// intit(); +// } +// +// private void intit() { +// mapView = findViewById(R.id.mapView); +// tencentMap = mapView.getMap(); +// CameraUpdate cameraSigma = +// CameraUpdateFactory.newCameraPosition(new CameraPosition( +// new LatLng(39.984066, 116.307548), +// 15, +// 0f, +// 0f)); +// //移动地图 +// tencentMap.moveCamera(cameraSigma); +// } +// +// @Override +// public boolean onCreateOptionsMenu(Menu menu) { +// getMenuInflater().inflate(R.menu.markercol, menu); +// return super.onCreateOptionsMenu(menu); +// } +// +// @Override +// public boolean onPrepareOptionsMenu(Menu menu) { +// menu.findItem(R.id.menu_open_collisionsmap).setVisible(!mMarkerAdded); +// menu.findItem(R.id.menu_close_collisionsmap).setVisible(mMarkerAdded); +// return super.onPrepareOptionsMenu(menu); +// } +// +// @Override +// public boolean onOptionsItemSelected(@NonNull MenuItem item) { +// switch (item.getItemId()) { +// case R.id.menu_open_collisionsmap: +// mMarkerAdded = true; +// BitmapDescriptor custom = BitmapDescriptorFactory.fromResource(R.drawable.marker); +// MarkerOptions options = new MarkerOptions().position(new LatLng(39.984066, 116.307548)); +// options.icon(custom); +// mMarker = tencentMap.addMarker(options); +// mMarker.setCollisions(MarkerCollisionItem.POI); +// break; +// case R.id.menu_close_collisionsmap: +// mMarkerAdded = false; +// mMarker.remove(); +// break; +// } +// +// supportInvalidateOptionsMenu(); +// return super.onOptionsItemSelected(item); +// } +// +// @Override +// protected void onResume() { +// super.onResume(); +// mapView.onResume(); +// } +// +// @Override +// protected void onPause() { +// super.onPause(); +// mapView.onPause(); +// } +// +// @Override +// protected void onDestroy() { +// super.onDestroy(); +// mapView.onDestroy(); +// } +// +// +// @Override +// protected void onStart() { +// super.onStart(); +// mapView.onStart(); +// } +// +// @Override +// protected void onStop() { +// super.onStop(); +// mapView.onStop(); +// } +//} diff --git a/positions/src/main/java/cc/winboll/studio/positions/demo/marker/MarkerDragActivity.java b/positions/src/main/java/cc/winboll/studio/positions/demo/marker/MarkerDragActivity.java index 2aed5b2..9d82547 100644 --- a/positions/src/main/java/cc/winboll/studio/positions/demo/marker/MarkerDragActivity.java +++ b/positions/src/main/java/cc/winboll/studio/positions/demo/marker/MarkerDragActivity.java @@ -10,36 +10,49 @@ import cc.winboll.studio.positions.R; import com.tencent.tencentmap.mapsdk.maps.TencentMap; import com.tencent.tencentmap.mapsdk.maps.model.Marker; -public class MarkerDragActivity extends MarkerActivity implements TencentMap.OnMarkerDragListener{ - private TextView textView; +public class MarkerDragActivity extends MarkerActivity implements TencentMap.OnMarkerDragListener { @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - marker.setInfoWindowEnable(false); - aSwitch.setVisibility(View.GONE); - - textView = findViewById(R.id.tv_info); - textView.setText("长按标记开始拖动"); - textView.setVisibility(View.VISIBLE); - - marker.setDraggable(true); - tencentMap.setOnMarkerDragListener(this); + public void onMarkerDragStart(Marker p1) { } @Override - public void onMarkerDragStart(Marker marker) { - Log.e("marker:","drag"); - Toast.makeText(this, "拖拽开始", Toast.LENGTH_SHORT).show(); + public void onMarkerDrag(Marker p1) { } @Override - public void onMarkerDrag(Marker marker) { - - } - - @Override - public void onMarkerDragEnd(Marker marker) { - Toast.makeText(this, "拖拽结束", Toast.LENGTH_SHORT).show(); + public void onMarkerDragEnd(Marker p1) { } + +// private TextView textView; +// +// @Override +// protected void onCreate(Bundle savedInstanceState) { +// super.onCreate(savedInstanceState); +// marker.setInfoWindowEnable(false); +// aSwitch.setVisibility(View.GONE); +// +// textView = findViewById(R.id.tv_info); +// textView.setText("长按标记开始拖动"); +// textView.setVisibility(View.VISIBLE); +// +// marker.setDraggable(true); +// tencentMap.setOnMarkerDragListener(this); +// } +// +// @Override +// public void onMarkerDragStart(Marker marker) { +// Log.e("marker:","drag"); +// Toast.makeText(this, "拖拽开始", Toast.LENGTH_SHORT).show(); +// } +// +// @Override +// public void onMarkerDrag(Marker marker) { +// +// } +// +// @Override +// public void onMarkerDragEnd(Marker marker) { +// Toast.makeText(this, "拖拽结束", Toast.LENGTH_SHORT).show(); +// } } diff --git a/positions/src/main/java/cc/winboll/studio/positions/demo/marker/MarkerInfoWindowActivity.java b/positions/src/main/java/cc/winboll/studio/positions/demo/marker/MarkerInfoWindowActivity.java index b3b4996..8ec544d 100644 --- a/positions/src/main/java/cc/winboll/studio/positions/demo/marker/MarkerInfoWindowActivity.java +++ b/positions/src/main/java/cc/winboll/studio/positions/demo/marker/MarkerInfoWindowActivity.java @@ -22,233 +22,233 @@ import com.tencent.tencentmap.mapsdk.maps.model.MarkerOptions; public class MarkerInfoWindowActivity extends AbsMapActivity { - private static final int TYPE_BITMAP = 0; - private static final int TYPE_VIEW = 1; - - private static final int STYLE_NO_FRAME = 1; - private static final int STYLE_FRAME = 2; - - private Marker mMarker; - private Marker mAnotherMarker; - private TencentMap mTencentMap; - private int mInfoWindowAdapterStyle; - private int mInfoWindowType = TYPE_BITMAP; - private LinearLayout mCustomInfoWindowView; - - /** - * 自定义信息窗 - */ - private TencentMap.InfoWindowAdapter mInfoWindowAdapter = new TencentMap.InfoWindowAdapter() { - - TextView tvTitle; - - //返回View为信息窗自定义样式,返回null时为默认信息窗样式 - @Override - public View getInfoWindow(final Marker marker) { - if (mInfoWindowAdapterStyle == 1 && marker.equals(mMarker)) { - return createCustomInfoView(marker); - } - return null; - } - - //返回View为信息窗内容自定义样式,返回null时为默认信息窗样式 - @Override - public View getInfoContents(Marker marker) { - if (mInfoWindowAdapterStyle == 2 && marker.equals(mMarker)) { - return createCustomInfoView(marker); - } - return null; - } - - private View createCustomInfoView(Marker marker) { - mCustomInfoWindowView = (LinearLayout) View.inflate( - getApplicationContext(), R.layout.custom_infowindow, null); - tvTitle = mCustomInfoWindowView.findViewById(R.id.tv_title); - //设置自定义信息窗的内容 - tvTitle.setText("我是自定义信息窗口:"); - tvTitle.append("\n" + marker.getTitle()); - tvTitle.append("\n" + marker.getSnippet()); - return mCustomInfoWindowView; - } - }; - private boolean mMultEnable; - - - @Override - protected void onCreate(@Nullable Bundle savedInstanceState, TencentMap pTencentMap) { - super.onCreate(savedInstanceState, pTencentMap); - mTencentMap = pTencentMap; - mMarker = createMarker(); - pTencentMap.setOnMarkerClickListener(new TencentMap.OnMarkerClickListener() { - @Override - public boolean onMarkerClick(Marker marker) { - invalidateOptionsMenu(); - return false; - } - }); - pTencentMap.setOnInfoWindowClickListener(new TencentMap.OnInfoWindowClickListener() { - @Override - public void onInfoWindowClick(Marker marker) { - Toast.makeText(getApplicationContext(), "信息窗被点击", Toast.LENGTH_SHORT).show(); - } - - @Override - public void onInfoWindowClickLocation(int i, int i1, int i2, int i3) { - Toast.makeText(getApplicationContext(), - "尺寸:" + i + "x" + i1 + " 位置:" + i2 + "," + i3, Toast.LENGTH_SHORT).show(); - } - }); - } - - private Marker createMarker() { - if (mTencentMap == null) { - return null; - } - if (mMarker != null) { - mMarker.remove(); - mMarker = null; - } - LatLng position = new LatLng(39.908710, 116.397499); - MarkerOptions options = new MarkerOptions(position); - options.infoWindowEnable(true);//默认为true - options.title("天安门")//标注的InfoWindow的标题 - .snippet("地址: 北京市东城区东长安街")//标注的InfoWindow的内容 - .anchor(0.5f, 1) - .viewInfoWindow(mInfoWindowType == TYPE_VIEW) - .icon(BitmapDescriptorFactory.fromResource(R.drawable.marker));//设置自定义Marker图标 - mTencentMap.moveCamera(CameraUpdateFactory.newLatLngZoom(position, 15)); - return mTencentMap.addMarker(options); - } - - private Marker createMultMarker() { - if (mTencentMap == null) { - return null; - } - if (mAnotherMarker != null) { - mAnotherMarker.remove(); - mAnotherMarker = null; - } - LatLng position = new LatLng(39.902500,116.397750); - MarkerOptions options = new MarkerOptions(position); - options.infoWindowEnable(true);//默认为true - options.title("毛主席纪念堂")//标注的InfoWindow的标题 - .snippet("地址: 北京市东城区前门东大街11号")//标注的InfoWindow的内容 - .anchor(0.5f, 1) - .viewInfoWindow(mInfoWindowType == TYPE_VIEW) - .icon(BitmapDescriptorFactory.fromResource(R.drawable.marker));//设置自定义Marker图标 - return mTencentMap.addMarker(options); - } - - @Override - public boolean onCreateOptionsMenu(Menu menu) { - getMenuInflater().inflate(R.menu.infowindow, menu); - return super.onCreateOptionsMenu(menu); - } - - @Override - public boolean onPrepareOptionsMenu(Menu menu) { - String typeName = null; - if (mInfoWindowType == TYPE_VIEW) { - typeName = "View类型"; - } else if (mInfoWindowType == TYPE_BITMAP) { - typeName = "Bitmap类型"; - } - if (typeName != null) { - menu.findItem(R.id.menu_type).setTitle(typeName) - .setVisible(!mMarker.isInfoWindowShown()); - } - menu.findItem(R.id.menu_mult).setTitle(mMultEnable ? "开启多窗口" : "关闭多窗口") - .setVisible(!mMarker.isInfoWindowShown()); - menu.findItem(R.id.menu_add).setVisible(!mMarker.isInfoWindowShown()); - menu.findItem(R.id.menu_play).setVisible(mMarker.isInfoWindowShown()); - menu.findItem(R.id.menu_delete).setVisible(mMarker.isInfoWindowShown()); - return super.onPrepareOptionsMenu(menu); - } - - @Override - public boolean onOptionsItemSelected(MenuItem item) { - switch (item.getItemId()) { - case R.id.menu_mult_enable: - mMultEnable = true; - initMarkers(); - hideInfoWindow(); - break; - case R.id.menu_mult_close: - mMultEnable = false; - if (mAnotherMarker != null) { - mAnotherMarker.remove(); - mAnotherMarker = null; - } - - hideInfoWindow(); - break; - case R.id.menu_type_bitmap: - mInfoWindowType = TYPE_BITMAP; - initMarkers(); - hideInfoWindow(); - break; - case R.id.menu_type_view: - mInfoWindowType = TYPE_VIEW; - initMarkers(); - hideInfoWindow(); - break; - case R.id.menu_add_infowindow_default: - showInfoWindow(); - break; - case R.id.menu_add_infowindow_custom_1: - mInfoWindowAdapterStyle = STYLE_NO_FRAME; - mTencentMap.setInfoWindowAdapter(mInfoWindowAdapter); - showInfoWindow(); - break; - case R.id.menu_add_infowindow_custom_2: - mInfoWindowAdapterStyle = STYLE_FRAME; - mTencentMap.setInfoWindowAdapter(mInfoWindowAdapter); - showInfoWindow(); - break; - case R.id.menu_play: - animationPlay(); - break; - case R.id.menu_delete: - hideInfoWindow(); - break; - } - - mTencentMap.enableMultipleInfowindow(mMultEnable); - return super.onOptionsItemSelected(item); - } - - private void initMarkers() { - mMarker = createMarker(); - if (mMultEnable) { - mAnotherMarker = createMultMarker(); - } - } - - private void showInfoWindow() { - if (mMarker != null) { - mMarker.showInfoWindow(); - } - - if (mAnotherMarker != null && mMultEnable) { - mAnotherMarker.showInfoWindow(); - } - } - - private void hideInfoWindow() { - if (mMarker != null) { - mMarker.hideInfoWindow(); - } - - if (mAnotherMarker != null && mMultEnable) { - mAnotherMarker.hideInfoWindow(); - } - mTencentMap.setInfoWindowAdapter(null); - } - - private void animationPlay() { - - if (mInfoWindowType == TYPE_VIEW) { - //TODO :动画 - } - } +// private static final int TYPE_BITMAP = 0; +// private static final int TYPE_VIEW = 1; +// +// private static final int STYLE_NO_FRAME = 1; +// private static final int STYLE_FRAME = 2; +// +// private Marker mMarker; +// private Marker mAnotherMarker; +// private TencentMap mTencentMap; +// private int mInfoWindowAdapterStyle; +// private int mInfoWindowType = TYPE_BITMAP; +// private LinearLayout mCustomInfoWindowView; +// +// /** +// * 自定义信息窗 +// */ +// private TencentMap.InfoWindowAdapter mInfoWindowAdapter = new TencentMap.InfoWindowAdapter() { +// +// TextView tvTitle; +// +// //返回View为信息窗自定义样式,返回null时为默认信息窗样式 +// @Override +// public View getInfoWindow(final Marker marker) { +// if (mInfoWindowAdapterStyle == 1 && marker.equals(mMarker)) { +// return createCustomInfoView(marker); +// } +// return null; +// } +// +// //返回View为信息窗内容自定义样式,返回null时为默认信息窗样式 +// @Override +// public View getInfoContents(Marker marker) { +// if (mInfoWindowAdapterStyle == 2 && marker.equals(mMarker)) { +// return createCustomInfoView(marker); +// } +// return null; +// } +// +// private View createCustomInfoView(Marker marker) { +// mCustomInfoWindowView = (LinearLayout) View.inflate( +// getApplicationContext(), R.layout.custom_infowindow, null); +// tvTitle = mCustomInfoWindowView.findViewById(R.id.tv_title); +// //设置自定义信息窗的内容 +// tvTitle.setText("我是自定义信息窗口:"); +// tvTitle.append("\n" + marker.getTitle()); +// tvTitle.append("\n" + marker.getSnippet()); +// return mCustomInfoWindowView; +// } +// }; +// private boolean mMultEnable; +// +// +// @Override +// protected void onCreate(@Nullable Bundle savedInstanceState, TencentMap pTencentMap) { +// super.onCreate(savedInstanceState, pTencentMap); +// mTencentMap = pTencentMap; +// mMarker = createMarker(); +// pTencentMap.setOnMarkerClickListener(new TencentMap.OnMarkerClickListener() { +// @Override +// public boolean onMarkerClick(Marker marker) { +// invalidateOptionsMenu(); +// return false; +// } +// }); +// pTencentMap.setOnInfoWindowClickListener(new TencentMap.OnInfoWindowClickListener() { +// @Override +// public void onInfoWindowClick(Marker marker) { +// Toast.makeText(getApplicationContext(), "信息窗被点击", Toast.LENGTH_SHORT).show(); +// } +// +// @Override +// public void onInfoWindowClickLocation(int i, int i1, int i2, int i3) { +// Toast.makeText(getApplicationContext(), +// "尺寸:" + i + "x" + i1 + " 位置:" + i2 + "," + i3, Toast.LENGTH_SHORT).show(); +// } +// }); +// } +// +// private Marker createMarker() { +// if (mTencentMap == null) { +// return null; +// } +// if (mMarker != null) { +// mMarker.remove(); +// mMarker = null; +// } +// LatLng position = new LatLng(39.908710, 116.397499); +// MarkerOptions options = new MarkerOptions(position); +// options.infoWindowEnable(true);//默认为true +// options.title("天安门")//标注的InfoWindow的标题 +// .snippet("地址: 北京市东城区东长安街")//标注的InfoWindow的内容 +// .anchor(0.5f, 1) +// .viewInfoWindow(mInfoWindowType == TYPE_VIEW) +// .icon(BitmapDescriptorFactory.fromResource(R.drawable.marker));//设置自定义Marker图标 +// mTencentMap.moveCamera(CameraUpdateFactory.newLatLngZoom(position, 15)); +// return mTencentMap.addMarker(options); +// } +// +// private Marker createMultMarker() { +// if (mTencentMap == null) { +// return null; +// } +// if (mAnotherMarker != null) { +// mAnotherMarker.remove(); +// mAnotherMarker = null; +// } +// LatLng position = new LatLng(39.902500,116.397750); +// MarkerOptions options = new MarkerOptions(position); +// options.infoWindowEnable(true);//默认为true +// options.title("毛主席纪念堂")//标注的InfoWindow的标题 +// .snippet("地址: 北京市东城区前门东大街11号")//标注的InfoWindow的内容 +// .anchor(0.5f, 1) +// .viewInfoWindow(mInfoWindowType == TYPE_VIEW) +// .icon(BitmapDescriptorFactory.fromResource(R.drawable.marker));//设置自定义Marker图标 +// return mTencentMap.addMarker(options); +// } +// +// @Override +// public boolean onCreateOptionsMenu(Menu menu) { +// getMenuInflater().inflate(R.menu.infowindow, menu); +// return super.onCreateOptionsMenu(menu); +// } +// +// @Override +// public boolean onPrepareOptionsMenu(Menu menu) { +// String typeName = null; +// if (mInfoWindowType == TYPE_VIEW) { +// typeName = "View类型"; +// } else if (mInfoWindowType == TYPE_BITMAP) { +// typeName = "Bitmap类型"; +// } +// if (typeName != null) { +// menu.findItem(R.id.menu_type).setTitle(typeName) +// .setVisible(!mMarker.isInfoWindowShown()); +// } +// menu.findItem(R.id.menu_mult).setTitle(mMultEnable ? "开启多窗口" : "关闭多窗口") +// .setVisible(!mMarker.isInfoWindowShown()); +// menu.findItem(R.id.menu_add).setVisible(!mMarker.isInfoWindowShown()); +// menu.findItem(R.id.menu_play).setVisible(mMarker.isInfoWindowShown()); +// menu.findItem(R.id.menu_delete).setVisible(mMarker.isInfoWindowShown()); +// return super.onPrepareOptionsMenu(menu); +// } +// +// @Override +// public boolean onOptionsItemSelected(MenuItem item) { +// switch (item.getItemId()) { +// case R.id.menu_mult_enable: +// mMultEnable = true; +// initMarkers(); +// hideInfoWindow(); +// break; +// case R.id.menu_mult_close: +// mMultEnable = false; +// if (mAnotherMarker != null) { +// mAnotherMarker.remove(); +// mAnotherMarker = null; +// } +// +// hideInfoWindow(); +// break; +// case R.id.menu_type_bitmap: +// mInfoWindowType = TYPE_BITMAP; +// initMarkers(); +// hideInfoWindow(); +// break; +// case R.id.menu_type_view: +// mInfoWindowType = TYPE_VIEW; +// initMarkers(); +// hideInfoWindow(); +// break; +// case R.id.menu_add_infowindow_default: +// showInfoWindow(); +// break; +// case R.id.menu_add_infowindow_custom_1: +// mInfoWindowAdapterStyle = STYLE_NO_FRAME; +// mTencentMap.setInfoWindowAdapter(mInfoWindowAdapter); +// showInfoWindow(); +// break; +// case R.id.menu_add_infowindow_custom_2: +// mInfoWindowAdapterStyle = STYLE_FRAME; +// mTencentMap.setInfoWindowAdapter(mInfoWindowAdapter); +// showInfoWindow(); +// break; +// case R.id.menu_play: +// animationPlay(); +// break; +// case R.id.menu_delete: +// hideInfoWindow(); +// break; +// } +// +// mTencentMap.enableMultipleInfowindow(mMultEnable); +// return super.onOptionsItemSelected(item); +// } +// +// private void initMarkers() { +// mMarker = createMarker(); +// if (mMultEnable) { +// mAnotherMarker = createMultMarker(); +// } +// } +// +// private void showInfoWindow() { +// if (mMarker != null) { +// mMarker.showInfoWindow(); +// } +// +// if (mAnotherMarker != null && mMultEnable) { +// mAnotherMarker.showInfoWindow(); +// } +// } +// +// private void hideInfoWindow() { +// if (mMarker != null) { +// mMarker.hideInfoWindow(); +// } +// +// if (mAnotherMarker != null && mMultEnable) { +// mAnotherMarker.hideInfoWindow(); +// } +// mTencentMap.setInfoWindowAdapter(null); +// } +// +// private void animationPlay() { +// +// if (mInfoWindowType == TYPE_VIEW) { +// //TODO :动画 +// } +// } } diff --git a/positions/src/main/java/cc/winboll/studio/positions/demo/marker/MarkerOptionsActivity.java b/positions/src/main/java/cc/winboll/studio/positions/demo/marker/MarkerOptionsActivity.java index c38bfa9..1fff6c5 100644 --- a/positions/src/main/java/cc/winboll/studio/positions/demo/marker/MarkerOptionsActivity.java +++ b/positions/src/main/java/cc/winboll/studio/positions/demo/marker/MarkerOptionsActivity.java @@ -1,54 +1,54 @@ package cc.winboll.studio.positions.demo.marker; -import android.graphics.Bitmap; -import android.graphics.BitmapFactory; -import android.graphics.Matrix; -import android.os.Bundle; - -import cc.winboll.studio.positions.R; -import cc.winboll.studio.positions.demo.basic.SupportMapFragmentActivity; -import com.tencent.tencentmap.mapsdk.maps.model.BitmapDescriptorFactory; -import com.tencent.tencentmap.mapsdk.maps.model.CircleOptions; -import com.tencent.tencentmap.mapsdk.maps.model.LatLng; -import com.tencent.tencentmap.mapsdk.maps.model.MarkerOptions; - -public class MarkerOptionsActivity extends SupportMapFragmentActivity { - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - options.fastLoad(true); //设置是否快速加载 - options.icon(BitmapDescriptorFactory.fromBitmap(getBitMap(R.drawable.marker))); //加载图标 - options.tag(tencentMap.addCircle(new CircleOptions().center(new LatLng(39.984059, 116.305756)))); //设置标签对象 - tencentMap.addMarker(options); - } - - private LatLng latLng = new LatLng(39.984864, 116.305756); - - private Bitmap getBitMap(int resourceId){ - Bitmap bitmap = BitmapFactory.decodeResource(getResources(), resourceId); - int width = bitmap.getWidth(); - int height = bitmap.getHeight(); - int newWidth = 100; - int newHeight = 100; - float widthScale = ((float)newWidth)/width; - float heightScale = ((float)newHeight)/height; - Matrix matrix = new Matrix(); - matrix.postScale(widthScale, heightScale); - bitmap = Bitmap.createBitmap(bitmap,0,0,width,height,matrix,true); - return bitmap; - } - - - private MarkerOptions options = new MarkerOptions(latLng). //坐标设置 - anchor(0.5f, 0.5f). //标注的锚点 - clockwise(true). //旋转角度顺时针 - draggable(true). //标注可被拖动 - flat(true). //设置3D标注 - infoWindowEnable(true). //弹出infowindow - infoWindowAnchor(0.5f, 0.5f). //标注信息infowindow锚点 - rotation(90f). //旋转角度 - snippet("气泡infowindow内容"). //设置infowindow内容 - title("标题内容"). //infowindow标题内容 - visible(true). //标注是否可见 - zIndex(0); //堆叠顺序,越大优先级越高 -} +//import android.graphics.Bitmap; +//import android.graphics.BitmapFactory; +//import android.graphics.Matrix; +//import android.os.Bundle; +// +//import cc.winboll.studio.positions.R; +//import cc.winboll.studio.positions.demo.basic.SupportMapFragmentActivity; +//import com.tencent.tencentmap.mapsdk.maps.model.BitmapDescriptorFactory; +//import com.tencent.tencentmap.mapsdk.maps.model.CircleOptions; +//import com.tencent.tencentmap.mapsdk.maps.model.LatLng; +//import com.tencent.tencentmap.mapsdk.maps.model.MarkerOptions; +// +//public class MarkerOptionsActivity extends SupportMapFragmentActivity { +// @Override +// protected void onCreate(Bundle savedInstanceState) { +// super.onCreate(savedInstanceState); +// options.fastLoad(true); //设置是否快速加载 +// options.icon(BitmapDescriptorFactory.fromBitmap(getBitMap(R.drawable.marker))); //加载图标 +// options.tag(tencentMap.addCircle(new CircleOptions().center(new LatLng(39.984059, 116.305756)))); //设置标签对象 +// tencentMap.addMarker(options); +// } +// +// private LatLng latLng = new LatLng(39.984864, 116.305756); +// +// private Bitmap getBitMap(int resourceId){ +// Bitmap bitmap = BitmapFactory.decodeResource(getResources(), resourceId); +// int width = bitmap.getWidth(); +// int height = bitmap.getHeight(); +// int newWidth = 100; +// int newHeight = 100; +// float widthScale = ((float)newWidth)/width; +// float heightScale = ((float)newHeight)/height; +// Matrix matrix = new Matrix(); +// matrix.postScale(widthScale, heightScale); +// bitmap = Bitmap.createBitmap(bitmap,0,0,width,height,matrix,true); +// return bitmap; +// } +// +// +// private MarkerOptions options = new MarkerOptions(latLng). //坐标设置 +// anchor(0.5f, 0.5f). //标注的锚点 +// clockwise(true). //旋转角度顺时针 +// draggable(true). //标注可被拖动 +// flat(true). //设置3D标注 +// infoWindowEnable(true). //弹出infowindow +// infoWindowAnchor(0.5f, 0.5f). //标注信息infowindow锚点 +// rotation(90f). //旋转角度 +// snippet("气泡infowindow内容"). //设置infowindow内容 +// title("标题内容"). //infowindow标题内容 +// visible(true). //标注是否可见 +// zIndex(0); //堆叠顺序,越大优先级越高 +//} diff --git a/positions/src/main/java/cc/winboll/studio/positions/demo/marker/SimpleMarkerActivity.java b/positions/src/main/java/cc/winboll/studio/positions/demo/marker/SimpleMarkerActivity.java index eb22deb..eac1f62 100644 --- a/positions/src/main/java/cc/winboll/studio/positions/demo/marker/SimpleMarkerActivity.java +++ b/positions/src/main/java/cc/winboll/studio/positions/demo/marker/SimpleMarkerActivity.java @@ -21,87 +21,87 @@ import com.tencent.tencentmap.mapsdk.maps.model.MarkerOptions; public class SimpleMarkerActivity extends AbsMapActivity { - private TencentMap mTencentMap; - private Marker mSimpleMarker; - private Marker mCustomMarker; - - private boolean mMarkerAdded; - @Override - protected void onCreate(@Nullable Bundle savedInstanceState, TencentMap pTencentMap) { - super.onCreate(savedInstanceState, pTencentMap); - mTencentMap = pTencentMap; - } - - @Override - public boolean onCreateOptionsMenu(Menu menu) { - getMenuInflater().inflate(R.menu.simple_marker, menu); - return super.onCreateOptionsMenu(menu); - } - - @Override - public boolean onPrepareOptionsMenu(Menu menu) { - menu.findItem(R.id.menu_add).setVisible(!mMarkerAdded); - menu.findItem(R.id.menu_delete).setVisible(mMarkerAdded); - return super.onPrepareOptionsMenu(menu); - } - - @Override - public boolean onOptionsItemSelected(MenuItem item) { - switch (item.getItemId()) { - case R.id.menu_add_marker_simple: - if (mSimpleMarker == null) { - LatLng position = new LatLng(40.011313,116.391907); - mSimpleMarker = mTencentMap.addMarker(new MarkerOptions(position)); - mTencentMap.moveCamera(CameraUpdateFactory.newLatLng(position)); - mMarkerAdded = true; - } - break; - case R.id.menu_add_marker_custom: - - if (mCustomMarker == null) { - LatLng position = new LatLng(40.011313,116.391907); - BitmapDescriptor custom = BitmapDescriptorFactory.fromResource(R.drawable.marker); - mCustomMarker = mTencentMap.addMarker(new MarkerOptions(position) - .icon(custom) - .alpha(0.7f) - .flat(true) - .clockwise(false) - .rotation(30) - ); - - Animation animation = new AlphaAnimation(0.7f, 0f); - animation.setDuration(2000); - animation.setAnimationListener(new AnimationListener() { - @Override - public void onAnimationStart() { - - } - - @Override - public void onAnimationEnd() { - mCustomMarker.setAlpha(1); - } - }); - mCustomMarker.setAnimation(animation); - mCustomMarker.startAnimation(); - mTencentMap.moveCamera(CameraUpdateFactory.newLatLng(position)); - mMarkerAdded = true; - } - break; - case R.id.menu_delete: - if (mSimpleMarker != null) { - mSimpleMarker.remove(); - mSimpleMarker = null; - } - - if (mCustomMarker != null) { - mCustomMarker.remove(); - mCustomMarker = null; - } - - mMarkerAdded = false; - break; - } - return super.onOptionsItemSelected(item); - } +// private TencentMap mTencentMap; +// private Marker mSimpleMarker; +// private Marker mCustomMarker; +// +// private boolean mMarkerAdded; +// @Override +// protected void onCreate(@Nullable Bundle savedInstanceState, TencentMap pTencentMap) { +// super.onCreate(savedInstanceState, pTencentMap); +// mTencentMap = pTencentMap; +// } +// +// @Override +// public boolean onCreateOptionsMenu(Menu menu) { +// getMenuInflater().inflate(R.menu.simple_marker, menu); +// return super.onCreateOptionsMenu(menu); +// } +// +// @Override +// public boolean onPrepareOptionsMenu(Menu menu) { +// menu.findItem(R.id.menu_add).setVisible(!mMarkerAdded); +// menu.findItem(R.id.menu_delete).setVisible(mMarkerAdded); +// return super.onPrepareOptionsMenu(menu); +// } +// +// @Override +// public boolean onOptionsItemSelected(MenuItem item) { +// switch (item.getItemId()) { +// case R.id.menu_add_marker_simple: +// if (mSimpleMarker == null) { +// LatLng position = new LatLng(40.011313,116.391907); +// mSimpleMarker = mTencentMap.addMarker(new MarkerOptions(position)); +// mTencentMap.moveCamera(CameraUpdateFactory.newLatLng(position)); +// mMarkerAdded = true; +// } +// break; +// case R.id.menu_add_marker_custom: +// +// if (mCustomMarker == null) { +// LatLng position = new LatLng(40.011313,116.391907); +// BitmapDescriptor custom = BitmapDescriptorFactory.fromResource(R.drawable.marker); +// mCustomMarker = mTencentMap.addMarker(new MarkerOptions(position) +// .icon(custom) +// .alpha(0.7f) +// .flat(true) +// .clockwise(false) +// .rotation(30) +// ); +// +// Animation animation = new AlphaAnimation(0.7f, 0f); +// animation.setDuration(2000); +// animation.setAnimationListener(new AnimationListener() { +// @Override +// public void onAnimationStart() { +// +// } +// +// @Override +// public void onAnimationEnd() { +// mCustomMarker.setAlpha(1); +// } +// }); +// mCustomMarker.setAnimation(animation); +// mCustomMarker.startAnimation(); +// mTencentMap.moveCamera(CameraUpdateFactory.newLatLng(position)); +// mMarkerAdded = true; +// } +// break; +// case R.id.menu_delete: +// if (mSimpleMarker != null) { +// mSimpleMarker.remove(); +// mSimpleMarker = null; +// } +// +// if (mCustomMarker != null) { +// mCustomMarker.remove(); +// mCustomMarker = null; +// } +// +// mMarkerAdded = false; +// break; +// } +// return super.onOptionsItemSelected(item); +// } } diff --git a/positions/src/main/java/cc/winboll/studio/positions/demo/poi/PoiClickActivity.java b/positions/src/main/java/cc/winboll/studio/positions/demo/poi/PoiClickActivity.java index eec66a3..aa7b88a 100644 --- a/positions/src/main/java/cc/winboll/studio/positions/demo/poi/PoiClickActivity.java +++ b/positions/src/main/java/cc/winboll/studio/positions/demo/poi/PoiClickActivity.java @@ -14,46 +14,51 @@ import com.tencent.tencentmap.mapsdk.maps.model.Marker; import com.tencent.tencentmap.mapsdk.maps.model.MarkerOptions; public class PoiClickActivity extends SupportMapFragmentActivity implements TencentMap.OnMapPoiClickListener { - private Switch poiSwitch; - private Marker marker; - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - poiSwitch = findViewById(R.id.switch_poi); - poiSwitch.setVisibility(View.VISIBLE); - poiSwitch.setText("Poi显示"); - tencentMap.setOnMapPoiClickListener(this); - poiSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { - @Override - public void onCheckedChanged(CompoundButton compoundButton, boolean b) { - if (b){ - tencentMap.setPoisEnabled(true); - }else{ - tencentMap.setPoisEnabled(false); - if (marker != null) - marker.remove(); - } - } - }); - } @Override - public void onClicked(MapPoi mapPoi) { - setMarker(mapPoi.getPosition(), mapPoi.getName()); - } - - /** - * 设置标注 - */ - private void setMarker(LatLng latLng, String name){ - - if(marker != null) - marker.remove(); - MarkerOptions options = new MarkerOptions().position(latLng); - //设置infowindow - options.title("地址:"); - options.snippet(name); - marker = tencentMap.addMarker(options); - marker.showInfoWindow(); + public void onClicked(MapPoi p1) { } + +// private Switch poiSwitch; +// private Marker marker; +// @Override +// protected void onCreate(Bundle savedInstanceState) { +// super.onCreate(savedInstanceState); +// poiSwitch = findViewById(R.id.switch_poi); +// poiSwitch.setVisibility(View.VISIBLE); +// poiSwitch.setText("Poi显示"); +// tencentMap.setOnMapPoiClickListener(this); +// poiSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { +// @Override +// public void onCheckedChanged(CompoundButton compoundButton, boolean b) { +// if (b){ +// tencentMap.setPoisEnabled(true); +// }else{ +// tencentMap.setPoisEnabled(false); +// if (marker != null) +// marker.remove(); +// } +// } +// }); +// } +// +// @Override +// public void onClicked(MapPoi mapPoi) { +// setMarker(mapPoi.getPosition(), mapPoi.getName()); +// } +// +// /** +// * 设置标注 +// */ +// private void setMarker(LatLng latLng, String name){ +// +// if(marker != null) +// marker.remove(); +// MarkerOptions options = new MarkerOptions().position(latLng); +// //设置infowindow +// options.title("地址:"); +// options.snippet(name); +// marker = tencentMap.addMarker(options); +// marker.showInfoWindow(); +// } } diff --git a/positions/src/main/java/cc/winboll/studio/positions/demo/polygon/DrawPolygonActivity.java b/positions/src/main/java/cc/winboll/studio/positions/demo/polygon/DrawPolygonActivity.java index b48bba9..2630176 100644 --- a/positions/src/main/java/cc/winboll/studio/positions/demo/polygon/DrawPolygonActivity.java +++ b/positions/src/main/java/cc/winboll/studio/positions/demo/polygon/DrawPolygonActivity.java @@ -1,38 +1,38 @@ package cc.winboll.studio.positions.demo.polygon; -import android.os.Bundle; - -import cc.winboll.studio.positions.R; -import cc.winboll.studio.positions.demo.basic.SupportMapFragmentActivity; -import com.tencent.tencentmap.mapsdk.maps.TencentMap; -import com.tencent.tencentmap.mapsdk.maps.model.LatLng; -import com.tencent.tencentmap.mapsdk.maps.model.Polygon; -import com.tencent.tencentmap.mapsdk.maps.model.PolygonOptions; - -public class DrawPolygonActivity extends SupportMapFragmentActivity { - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - LatLng[] latLngs = { - new LatLng(39.984864, 116.305756), - new LatLng(39.983618, 116.305848), - new LatLng(39.982347, 116.305966), - new LatLng(39.982412, 116.308111), - new LatLng(39.984122, 116.308224), - new LatLng(39.984955, 116.308099), - new LatLng(39.984864, 116.305756) - }; - Polygon polygon = tencentMap.addPolygon(new PolygonOptions(). - add(latLngs). - fillColor(getResources().getColor(R.color.style)). - strokeColor(getResources().getColor(R.color.colorPrimary)). - strokeWidth(1)); - tencentMap.setOnPolygonClickListener(new TencentMap.OnPolygonClickListener() { - @Override - public void onPolygonClick(Polygon polygon, LatLng latLng) { - - } - }); - } -} +//import android.os.Bundle; +// +//import cc.winboll.studio.positions.R; +//import cc.winboll.studio.positions.demo.basic.SupportMapFragmentActivity; +//import com.tencent.tencentmap.mapsdk.maps.TencentMap; +//import com.tencent.tencentmap.mapsdk.maps.model.LatLng; +//import com.tencent.tencentmap.mapsdk.maps.model.Polygon; +//import com.tencent.tencentmap.mapsdk.maps.model.PolygonOptions; +// +//public class DrawPolygonActivity extends SupportMapFragmentActivity { +// +// @Override +// protected void onCreate(Bundle savedInstanceState) { +// super.onCreate(savedInstanceState); +// LatLng[] latLngs = { +// new LatLng(39.984864, 116.305756), +// new LatLng(39.983618, 116.305848), +// new LatLng(39.982347, 116.305966), +// new LatLng(39.982412, 116.308111), +// new LatLng(39.984122, 116.308224), +// new LatLng(39.984955, 116.308099), +// new LatLng(39.984864, 116.305756) +// }; +// Polygon polygon = tencentMap.addPolygon(new PolygonOptions(). +// add(latLngs). +// fillColor(getResources().getColor(R.color.style)). +// strokeColor(getResources().getColor(R.color.colorPrimary)). +// strokeWidth(1)); +// tencentMap.setOnPolygonClickListener(new TencentMap.OnPolygonClickListener() { +// @Override +// public void onPolygonClick(Polygon polygon, LatLng latLng) { +// +// } +// }); +// } +//} diff --git a/positions/src/main/java/cc/winboll/studio/positions/demo/polygon/PolylonOptionsActivity.java b/positions/src/main/java/cc/winboll/studio/positions/demo/polygon/PolylonOptionsActivity.java index b0a0adb..738ce9d 100644 --- a/positions/src/main/java/cc/winboll/studio/positions/demo/polygon/PolylonOptionsActivity.java +++ b/positions/src/main/java/cc/winboll/studio/positions/demo/polygon/PolylonOptionsActivity.java @@ -1,73 +1,73 @@ package cc.winboll.studio.positions.demo.polygon; -import android.os.Bundle; - -import cc.winboll.studio.positions.demo.basic.SupportMapFragmentActivity; -import com.tencent.tencentmap.mapsdk.maps.model.LatLng; -import com.tencent.tencentmap.mapsdk.maps.model.MarkerOptions; -import com.tencent.tencentmap.mapsdk.maps.model.Polygon; -import com.tencent.tencentmap.mapsdk.maps.model.PolygonOptions; - -import java.util.ArrayList; -import java.util.List; - -public class PolylonOptionsActivity extends SupportMapFragmentActivity { - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - Polygon polygon = tencentMap.addPolygon(polygonOptions); - polygon.setPoints(transferArrayToList(latLngs)); //Options中设置顶点 - Polygon newPolygon = tencentMap.addPolygon(newPolygonOptions); - newPolygon.setOptions(newPolygonOptions); //重新设置Options - newPolygon.setClickable(true); //设置可点击 - newPolygon.setFillColor(0xaa324354); - newPolygon.setPoints(transferArrayToList(newLatLngs)); //设置坐标 - newPolygon.setTag(tencentMap.addMarker(new MarkerOptions().position(new LatLng(39.984866, 116.305759)).title("设置标注").draggable(true))); - - - } - - private List transferArrayToList(LatLng[] latLngs){ //坐标数组与List转换 - List list = new ArrayList<>(); - if (latLngs == null) - return list; - for (int i = 0; i < latLngs.length; i++) - list.add(latLngs[i]); - - return list; - - } - private LatLng[] latLngs = { - new LatLng(39.984864, 116.305756), - new LatLng(39.983618, 116.305848), - new LatLng(39.982347, 116.305966), - new LatLng(39.982412, 116.308111), - new LatLng(39.984122, 116.308224), - new LatLng(39.984955, 116.308099), - new LatLng(39.984864, 116.305756) - }; - - private LatLng[] newLatLngs = { - new LatLng(39.984864, 116.305756), - new LatLng(39.983618, 116.305848), - new LatLng(39.982347, 116.305966), - new LatLng(39.982412, 116.308111), - new LatLng(39.984122, 116.308224), - new LatLng(39.984955, 116.308099), - new LatLng(39.984864, 116.305756) - }; - - - private PolygonOptions polygonOptions = new PolygonOptions(). - add(latLngs). // 添加图形坐标点 - fillColor(0x56643313). //填充颜色 - strokeColor(0xfa349012). //描边颜色 - strokeWidth(1). //描边宽度 - visible(true). //是否可见 - zIndex(0). //堆叠顺序,越大优先级越高 - clickable(true); // 是否可点击 - - private PolygonOptions newPolygonOptions = new PolygonOptions(). - addAll(transferArrayToList(newLatLngs)); //设置批量添加顶点 -} +//import android.os.Bundle; +// +//import cc.winboll.studio.positions.demo.basic.SupportMapFragmentActivity; +//import com.tencent.tencentmap.mapsdk.maps.model.LatLng; +//import com.tencent.tencentmap.mapsdk.maps.model.MarkerOptions; +//import com.tencent.tencentmap.mapsdk.maps.model.Polygon; +//import com.tencent.tencentmap.mapsdk.maps.model.PolygonOptions; +// +//import java.util.ArrayList; +//import java.util.List; +// +//public class PolylonOptionsActivity extends SupportMapFragmentActivity { +// +// @Override +// protected void onCreate(Bundle savedInstanceState) { +// super.onCreate(savedInstanceState); +// Polygon polygon = tencentMap.addPolygon(polygonOptions); +// polygon.setPoints(transferArrayToList(latLngs)); //Options中设置顶点 +// Polygon newPolygon = tencentMap.addPolygon(newPolygonOptions); +// newPolygon.setOptions(newPolygonOptions); //重新设置Options +// newPolygon.setClickable(true); //设置可点击 +// newPolygon.setFillColor(0xaa324354); +// newPolygon.setPoints(transferArrayToList(newLatLngs)); //设置坐标 +// newPolygon.setTag(tencentMap.addMarker(new MarkerOptions().position(new LatLng(39.984866, 116.305759)).title("设置标注").draggable(true))); +// +// +// } +// +// private List transferArrayToList(LatLng[] latLngs){ //坐标数组与List转换 +// List list = new ArrayList<>(); +// if (latLngs == null) +// return list; +// for (int i = 0; i < latLngs.length; i++) +// list.add(latLngs[i]); +// +// return list; +// +// } +// private LatLng[] latLngs = { +// new LatLng(39.984864, 116.305756), +// new LatLng(39.983618, 116.305848), +// new LatLng(39.982347, 116.305966), +// new LatLng(39.982412, 116.308111), +// new LatLng(39.984122, 116.308224), +// new LatLng(39.984955, 116.308099), +// new LatLng(39.984864, 116.305756) +// }; +// +// private LatLng[] newLatLngs = { +// new LatLng(39.984864, 116.305756), +// new LatLng(39.983618, 116.305848), +// new LatLng(39.982347, 116.305966), +// new LatLng(39.982412, 116.308111), +// new LatLng(39.984122, 116.308224), +// new LatLng(39.984955, 116.308099), +// new LatLng(39.984864, 116.305756) +// }; +// +// +// private PolygonOptions polygonOptions = new PolygonOptions(). +// add(latLngs). // 添加图形坐标点 +// fillColor(0x56643313). //填充颜色 +// strokeColor(0xfa349012). //描边颜色 +// strokeWidth(1). //描边宽度 +// visible(true). //是否可见 +// zIndex(0). //堆叠顺序,越大优先级越高 +// clickable(true); // 是否可点击 +// +// private PolygonOptions newPolygonOptions = new PolygonOptions(). +// addAll(transferArrayToList(newLatLngs)); //设置批量添加顶点 +//} diff --git a/positions/src/main/java/cc/winboll/studio/positions/demo/polygon/TileOverlayActivity.java b/positions/src/main/java/cc/winboll/studio/positions/demo/polygon/TileOverlayActivity.java index a5b12d8..a7c8125 100644 --- a/positions/src/main/java/cc/winboll/studio/positions/demo/polygon/TileOverlayActivity.java +++ b/positions/src/main/java/cc/winboll/studio/positions/demo/polygon/TileOverlayActivity.java @@ -1,178 +1,178 @@ -package cc.winboll.studio.positions.demo.polygon; - -import androidx.annotation.NonNull; -import androidx.appcompat.app.AppCompatActivity; - -import android.os.Bundle; -import android.util.Log; -import android.view.Menu; -import android.view.MenuItem; -import android.view.View; - -import cc.winboll.studio.positions.R; -import com.tencent.tencentmap.mapsdk.maps.CameraUpdate; -import com.tencent.tencentmap.mapsdk.maps.CameraUpdateFactory; -import com.tencent.tencentmap.mapsdk.maps.MapView; -import com.tencent.tencentmap.mapsdk.maps.TencentMap; -import com.tencent.tencentmap.mapsdk.maps.model.BitmapDescriptor; -import com.tencent.tencentmap.mapsdk.maps.model.BitmapDescriptorFactory; -import com.tencent.tencentmap.mapsdk.maps.model.CameraPosition; -import com.tencent.tencentmap.mapsdk.maps.model.LatLng; -import com.tencent.tencentmap.mapsdk.maps.model.MarkerCollisionItem; -import com.tencent.tencentmap.mapsdk.maps.model.MarkerOptions; -import com.tencent.tencentmap.mapsdk.maps.model.Tile; -import com.tencent.tencentmap.mapsdk.maps.model.TileOverlay; -import com.tencent.tencentmap.mapsdk.maps.model.TileOverlayOptions; -import com.tencent.tencentmap.mapsdk.maps.model.TileProvider; - -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.InputStream; - -public class TileOverlayActivity extends AppCompatActivity { - private MapView mapView; - private TencentMap tencentMap; - private boolean mMarkerAdded; - private TileOverlay mTileOverlay; - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.activity_tile_overlay); - initView(); - } - - private void initView() { - mapView = findViewById(R.id.mapView); - tencentMap = mapView.getMap(); - CameraUpdate cameraSigma = - CameraUpdateFactory.newCameraPosition(new CameraPosition( - new LatLng(39.917505, 116.397657), - 15, - 0f, - 0f)); - //移动地图 - tencentMap.moveCamera(cameraSigma); - } - - @Override - public boolean onCreateOptionsMenu(Menu menu) { - getMenuInflater().inflate(R.menu.markercol, menu); - return super.onCreateOptionsMenu(menu); - } - - @Override - public boolean onPrepareOptionsMenu(Menu menu) { - menu.findItem(R.id.menu_open_collisionsmap).setVisible(!mMarkerAdded); - menu.findItem(R.id.menu_close_collisionsmap).setVisible(mMarkerAdded); - return super.onPrepareOptionsMenu(menu); - } - - @Override - public boolean onOptionsItemSelected(@NonNull MenuItem item) { - switch (item.getItemId()) { - case R.id.menu_open_collisionsmap: - mMarkerAdded = true; - if (mTileOverlay == null) { - mTileOverlay = tencentMap.addTileOverlay( - new TileOverlayOptions(). - tileProvider(new LocalTileProvider())); - } - - break; - case R.id.menu_close_collisionsmap: - mMarkerAdded = false; - if (mTileOverlay != null) { - mTileOverlay.clearTileCache(); - mTileOverlay.remove(); - mTileOverlay = null; - } - break; - } - - supportInvalidateOptionsMenu(); - return super.onOptionsItemSelected(item); - } - - class LocalTileProvider implements TileProvider { - - @Override - public Tile getTile(int x, int y, int zoom) { - LatLng latLng = new LatLng(39.917505, 116.397657); - int iZ = 16; - double n = Math.pow(2, iZ); - int iX = (int) (((latLng.getLongitude() + 180) / 360) * n); - int iY = (int) ((1 - (Math.log(Math.tan(Math.toRadians(latLng.getLatitude())) + - (1 / Math.cos(Math.toRadians(latLng.getLatitude())))) / Math.PI)) / 2 * n); - if (iX == x && iY == y && iZ == zoom) { - Log.e("tile", "zoom:" + zoom + " x:" + x + " y:" + y); - return new Tile(256, 256, tileData()); - } - return TileProvider.NO_TILE; - } - - byte[] tileData() { - InputStream is = null; - ByteArrayOutputStream baos = null; - try { - is = getApplicationContext().getAssets().open("gugong.jpg"); - baos = new ByteArrayOutputStream(); - byte[] byteBuffer = new byte[1024]; - int count = 0; - while ((count = is.read(byteBuffer)) != -1) { - baos.write(byteBuffer, 0, count); - } - return baos.toByteArray(); - } catch (IOException e) { - e.printStackTrace(); - return null; - } finally { - if (is != null) { - try { - is.close(); - } catch (IOException e) { - e.printStackTrace(); - } - } - if (baos != null) { - try { - baos.close(); - } catch (IOException e) { - e.printStackTrace(); - } - } - } - } - } - - @Override - protected void onResume() { - super.onResume(); - mapView.onResume(); - } - - @Override - protected void onPause() { - super.onPause(); - mapView.onPause(); - } - - @Override - protected void onDestroy() { - super.onDestroy(); - mapView.onDestroy(); - } - - - @Override - protected void onStart() { - super.onStart(); - mapView.onStart(); - } - - @Override - protected void onStop() { - super.onStop(); - mapView.onStop(); - } -} \ No newline at end of file +package cc.winboll.studio.positions.demo.polygon; + +//import androidx.annotation.NonNull; +//import androidx.appcompat.app.AppCompatActivity; +// +//import android.os.Bundle; +//import android.util.Log; +//import android.view.Menu; +//import android.view.MenuItem; +//import android.view.View; +// +//import cc.winboll.studio.positions.R; +//import com.tencent.tencentmap.mapsdk.maps.CameraUpdate; +//import com.tencent.tencentmap.mapsdk.maps.CameraUpdateFactory; +//import com.tencent.tencentmap.mapsdk.maps.MapView; +//import com.tencent.tencentmap.mapsdk.maps.TencentMap; +//import com.tencent.tencentmap.mapsdk.maps.model.BitmapDescriptor; +//import com.tencent.tencentmap.mapsdk.maps.model.BitmapDescriptorFactory; +//import com.tencent.tencentmap.mapsdk.maps.model.CameraPosition; +//import com.tencent.tencentmap.mapsdk.maps.model.LatLng; +//import com.tencent.tencentmap.mapsdk.maps.model.MarkerCollisionItem; +//import com.tencent.tencentmap.mapsdk.maps.model.MarkerOptions; +//import com.tencent.tencentmap.mapsdk.maps.model.Tile; +//import com.tencent.tencentmap.mapsdk.maps.model.TileOverlay; +//import com.tencent.tencentmap.mapsdk.maps.model.TileOverlayOptions; +//import com.tencent.tencentmap.mapsdk.maps.model.TileProvider; +// +//import java.io.ByteArrayOutputStream; +//import java.io.IOException; +//import java.io.InputStream; +// +//public class TileOverlayActivity extends AppCompatActivity { +// private MapView mapView; +// private TencentMap tencentMap; +// private boolean mMarkerAdded; +// private TileOverlay mTileOverlay; +// +// @Override +// protected void onCreate(Bundle savedInstanceState) { +// super.onCreate(savedInstanceState); +// setContentView(R.layout.activity_tile_overlay); +// initView(); +// } +// +// private void initView() { +// mapView = findViewById(R.id.mapView); +// tencentMap = mapView.getMap(); +// CameraUpdate cameraSigma = +// CameraUpdateFactory.newCameraPosition(new CameraPosition( +// new LatLng(39.917505, 116.397657), +// 15, +// 0f, +// 0f)); +// //移动地图 +// tencentMap.moveCamera(cameraSigma); +// } +// +// @Override +// public boolean onCreateOptionsMenu(Menu menu) { +// getMenuInflater().inflate(R.menu.markercol, menu); +// return super.onCreateOptionsMenu(menu); +// } +// +// @Override +// public boolean onPrepareOptionsMenu(Menu menu) { +// menu.findItem(R.id.menu_open_collisionsmap).setVisible(!mMarkerAdded); +// menu.findItem(R.id.menu_close_collisionsmap).setVisible(mMarkerAdded); +// return super.onPrepareOptionsMenu(menu); +// } +// +// @Override +// public boolean onOptionsItemSelected(@NonNull MenuItem item) { +// switch (item.getItemId()) { +// case R.id.menu_open_collisionsmap: +// mMarkerAdded = true; +// if (mTileOverlay == null) { +// mTileOverlay = tencentMap.addTileOverlay( +// new TileOverlayOptions(). +// tileProvider(new LocalTileProvider())); +// } +// +// break; +// case R.id.menu_close_collisionsmap: +// mMarkerAdded = false; +// if (mTileOverlay != null) { +// mTileOverlay.clearTileCache(); +// mTileOverlay.remove(); +// mTileOverlay = null; +// } +// break; +// } +// +// supportInvalidateOptionsMenu(); +// return super.onOptionsItemSelected(item); +// } +// +// class LocalTileProvider implements TileProvider { +// +// @Override +// public Tile getTile(int x, int y, int zoom) { +// LatLng latLng = new LatLng(39.917505, 116.397657); +// int iZ = 16; +// double n = Math.pow(2, iZ); +// int iX = (int) (((latLng.getLongitude() + 180) / 360) * n); +// int iY = (int) ((1 - (Math.log(Math.tan(Math.toRadians(latLng.getLatitude())) + +// (1 / Math.cos(Math.toRadians(latLng.getLatitude())))) / Math.PI)) / 2 * n); +// if (iX == x && iY == y && iZ == zoom) { +// Log.e("tile", "zoom:" + zoom + " x:" + x + " y:" + y); +// return new Tile(256, 256, tileData()); +// } +// return TileProvider.NO_TILE; +// } +// +// byte[] tileData() { +// InputStream is = null; +// ByteArrayOutputStream baos = null; +// try { +// is = getApplicationContext().getAssets().open("gugong.jpg"); +// baos = new ByteArrayOutputStream(); +// byte[] byteBuffer = new byte[1024]; +// int count = 0; +// while ((count = is.read(byteBuffer)) != -1) { +// baos.write(byteBuffer, 0, count); +// } +// return baos.toByteArray(); +// } catch (IOException e) { +// e.printStackTrace(); +// return null; +// } finally { +// if (is != null) { +// try { +// is.close(); +// } catch (IOException e) { +// e.printStackTrace(); +// } +// } +// if (baos != null) { +// try { +// baos.close(); +// } catch (IOException e) { +// e.printStackTrace(); +// } +// } +// } +// } +// } +// +// @Override +// protected void onResume() { +// super.onResume(); +// mapView.onResume(); +// } +// +// @Override +// protected void onPause() { +// super.onPause(); +// mapView.onPause(); +// } +// +// @Override +// protected void onDestroy() { +// super.onDestroy(); +// mapView.onDestroy(); +// } +// +// +// @Override +// protected void onStart() { +// super.onStart(); +// mapView.onStart(); +// } +// +// @Override +// protected void onStop() { +// super.onStop(); +// mapView.onStop(); +// } +//} diff --git a/positions/src/main/java/cc/winboll/studio/positions/demo/polyline/DrawLineActivity.java b/positions/src/main/java/cc/winboll/studio/positions/demo/polyline/DrawLineActivity.java index 5e0fa9c..27405cf 100644 --- a/positions/src/main/java/cc/winboll/studio/positions/demo/polyline/DrawLineActivity.java +++ b/positions/src/main/java/cc/winboll/studio/positions/demo/polyline/DrawLineActivity.java @@ -1,194 +1,194 @@ package cc.winboll.studio.positions.demo.polyline; -import android.graphics.Color; -import android.os.Bundle; -import android.view.Menu; -import android.view.MenuItem; - -import androidx.annotation.Nullable; - -import cc.winboll.studio.positions.demo.AbsMapActivity; -import cc.winboll.studio.positions.R; -import com.tencent.tencentmap.mapsdk.maps.CameraUpdateFactory; -import com.tencent.tencentmap.mapsdk.maps.TencentMap; -import com.tencent.tencentmap.mapsdk.maps.model.BitmapDescriptorFactory; -import com.tencent.tencentmap.mapsdk.maps.model.LatLng; -import com.tencent.tencentmap.mapsdk.maps.model.Polyline; -import com.tencent.tencentmap.mapsdk.maps.model.PolylineOptions; - -import java.util.ArrayList; -import java.util.List; - -public class DrawLineActivity extends AbsMapActivity { - private int typeSimple = 0; - private int typeImage = 1; - private int typeColor = 2; - private int typeArrow = 3; - private int typeGradient = 4; - - private TencentMap mTencentMap; - private boolean mHasAdded; - private boolean mHasEnableText; - private Polyline polyline; - private PolylineOptions.Text mPolylineText; - - @Override - protected void onCreate(@Nullable Bundle savedInstanceState, TencentMap tencentMap) { - super.onCreate(savedInstanceState, tencentMap); - mTencentMap = tencentMap; - tencentMap.moveCamera(CameraUpdateFactory.zoomTo(15)); - } - - @Override - public boolean onCreateOptionsMenu(Menu menu) { - getMenuInflater().inflate(R.menu.polyline, menu); - return true; - } - - @Override - public boolean onPrepareOptionsMenu(Menu menu) { - menu.findItem(R.id.menu_add).setVisible(!mHasAdded); - menu.findItem(R.id.menu_text).setTitle(mHasEnableText ? "关闭路名" : "开启路名").setVisible(mHasAdded); - menu.findItem(R.id.menu_delete).setVisible(mHasAdded); - return super.onPrepareOptionsMenu(menu); - } - - @Override - public boolean onOptionsItemSelected(MenuItem item) { - switch (item.getItemId()) { - case R.id.menu_add_line_simple: - mTencentMap.clear(); - polyline = mTencentMap.addPolyline(setLineStyle(typeSimple)); - mHasAdded = true; - break; - - case R.id.menu_add_line_dash: - mTencentMap.clear(); - polyline = mTencentMap.addPolyline(setLineStyle(typeImage)); - mHasAdded = true; - break; - case R.id.menu_add_line_segment: - mTencentMap.clear(); - polyline = mTencentMap.addPolyline(setLineStyle(typeColor)); - int[] color = {0, 1, 2, 3, 4}; - int[] index = {0, 1, 2, 3, 4, 5}; - polyline.setColors(color, index); - mHasAdded = true; - break; - case R.id.menu_add_line_texture: - mTencentMap.clear(); - polyline = mTencentMap.addPolyline(setLineStyle((typeArrow))); - mHasAdded = true; - break; - case R.id.menu_add_line_gradient: - mTencentMap.clear(); - polyline = mTencentMap.addPolyline(setLineStyle((typeGradient))); - int[] indexes = {0, 1, 2, 3, 4}; -// 设置每段索引之间的颜色,这个颜色同样支持纹理颜色,即 PolylineOptions.Colors 中定义的 [0, 10] 值 - int[] colors = { - 0xff00ff00, // 线上点 [0, 1] 之间为绿色 - 0xffffff00, // 线上点 [1, 2] 之间为黄色 - 0xffff0000, // 线上点 [2, 3] 之间为红色 - 0xff131313, // 线上点 [3, 4] 之间为黄色 - 0xff1033f6 // 线上点 [4, 最后一个点] 之间为绿色 - }; - polyline.setColors(colors, indexes); - mHasAdded = true; - break; - case R.id.menu_text: - mHasEnableText = !mHasEnableText; - if (mHasEnableText) { - if (mPolylineText == null) { - mPolylineText = generateText(); - //设置显示优先级,可选项有HIGH或NORMAL - mPolylineText.setPriority(PolylineOptions.TextPriority.HIGH); - //设置字体大小 - mPolylineText.setTextSize(10); - //设置填充颜色 - mPolylineText.setStrokeColor(Color.WHITE); - //设置文字颜色 - mPolylineText.setTextColor(Color.BLACK); - } - - polyline.setText(mPolylineText); - } else { - polyline.setText(null); - } - - break; - - case R.id.menu_delete: - if (polyline != null) { - polyline.remove(); - polyline = null; - mHasAdded = false; - mHasEnableText = false; - - } - break; - } - return super.onOptionsItemSelected(item); - } - - private PolylineOptions setLineStyle(int type) { - PolylineOptions polylineOptions = new PolylineOptions().addAll(getLatlons()).lineCap(true); - switch (type) { - case 0: - //设置折线颜色、宽度 - polylineOptions - .color(0xff00ff00) - .width(5f); - break; - case 1: - List list = new ArrayList<>(); - list.add(35); - list.add(20); - polylineOptions - .lineType(PolylineOptions.LineType.LINE_TYPE_IMAGEINARYLINE) - .width(10) - .pattern(list); - break; - case 2: - //线路颜色值纹理图片里的颜色索引 - polylineOptions - .colorType(PolylineOptions.ColorType.LINE_COLOR_TEXTURE) - .color(PolylineOptions.Colors.GREEN) - .colorTexture(BitmapDescriptorFactory.fromAsset("color_texture.png")); - break; - case 3: - polylineOptions - .arrow(true) - .arrowSpacing(30) - .arrowTexture(BitmapDescriptorFactory.fromAsset("color_arrow_texture.png")); - break; - case 4: - polylineOptions - .gradient(true) - .lineType(PolylineOptions.LineType.LINE_TYPE_MULTICOLORLINE) - .width(20); - break; - - } - return polylineOptions; - } - - private PolylineOptions.Text generateText() { - List segmentTexts = new ArrayList<>(); - //参数分别表示坐标路径数组起点index,终点index,动态路名文字 - segmentTexts.add(new PolylineOptions.SegmentText(0, 1, "苏州街")); - segmentTexts.add(new PolylineOptions.SegmentText(1, 2, "北四环西路辅路")); - segmentTexts.add(new PolylineOptions.SegmentText(2, 4, "彩和坊路")); - return new PolylineOptions.Text.Builder(segmentTexts).build(); - } - - private List getLatlons() { - List latLngs = new ArrayList(); - latLngs.add(new LatLng(39.984864, 116.305756)); - latLngs.add(new LatLng(39.983618, 116.305848)); - latLngs.add(new LatLng(39.982347, 116.305966)); - latLngs.add(new LatLng(39.982412, 116.308111)); - latLngs.add(new LatLng(39.984122, 116.308224)); - latLngs.add(new LatLng(39.984955, 116.308099)); - return latLngs; - } -} +//import android.graphics.Color; +//import android.os.Bundle; +//import android.view.Menu; +//import android.view.MenuItem; +// +//import androidx.annotation.Nullable; +// +//import cc.winboll.studio.positions.demo.AbsMapActivity; +//import cc.winboll.studio.positions.R; +//import com.tencent.tencentmap.mapsdk.maps.CameraUpdateFactory; +//import com.tencent.tencentmap.mapsdk.maps.TencentMap; +//import com.tencent.tencentmap.mapsdk.maps.model.BitmapDescriptorFactory; +//import com.tencent.tencentmap.mapsdk.maps.model.LatLng; +//import com.tencent.tencentmap.mapsdk.maps.model.Polyline; +//import com.tencent.tencentmap.mapsdk.maps.model.PolylineOptions; +// +//import java.util.ArrayList; +//import java.util.List; +// +//public class DrawLineActivity extends AbsMapActivity { +// private int typeSimple = 0; +// private int typeImage = 1; +// private int typeColor = 2; +// private int typeArrow = 3; +// private int typeGradient = 4; +// +// private TencentMap mTencentMap; +// private boolean mHasAdded; +// private boolean mHasEnableText; +// private Polyline polyline; +// private PolylineOptions.Text mPolylineText; +// +// @Override +// protected void onCreate(@Nullable Bundle savedInstanceState, TencentMap tencentMap) { +// super.onCreate(savedInstanceState, tencentMap); +// mTencentMap = tencentMap; +// tencentMap.moveCamera(CameraUpdateFactory.zoomTo(15)); +// } +// +// @Override +// public boolean onCreateOptionsMenu(Menu menu) { +// getMenuInflater().inflate(R.menu.polyline, menu); +// return true; +// } +// +// @Override +// public boolean onPrepareOptionsMenu(Menu menu) { +// menu.findItem(R.id.menu_add).setVisible(!mHasAdded); +// menu.findItem(R.id.menu_text).setTitle(mHasEnableText ? "关闭路名" : "开启路名").setVisible(mHasAdded); +// menu.findItem(R.id.menu_delete).setVisible(mHasAdded); +// return super.onPrepareOptionsMenu(menu); +// } +// +// @Override +// public boolean onOptionsItemSelected(MenuItem item) { +// switch (item.getItemId()) { +// case R.id.menu_add_line_simple: +// mTencentMap.clear(); +// polyline = mTencentMap.addPolyline(setLineStyle(typeSimple)); +// mHasAdded = true; +// break; +// +// case R.id.menu_add_line_dash: +// mTencentMap.clear(); +// polyline = mTencentMap.addPolyline(setLineStyle(typeImage)); +// mHasAdded = true; +// break; +// case R.id.menu_add_line_segment: +// mTencentMap.clear(); +// polyline = mTencentMap.addPolyline(setLineStyle(typeColor)); +// int[] color = {0, 1, 2, 3, 4}; +// int[] index = {0, 1, 2, 3, 4, 5}; +// polyline.setColors(color, index); +// mHasAdded = true; +// break; +// case R.id.menu_add_line_texture: +// mTencentMap.clear(); +// polyline = mTencentMap.addPolyline(setLineStyle((typeArrow))); +// mHasAdded = true; +// break; +// case R.id.menu_add_line_gradient: +// mTencentMap.clear(); +// polyline = mTencentMap.addPolyline(setLineStyle((typeGradient))); +// int[] indexes = {0, 1, 2, 3, 4}; +//// 设置每段索引之间的颜色,这个颜色同样支持纹理颜色,即 PolylineOptions.Colors 中定义的 [0, 10] 值 +// int[] colors = { +// 0xff00ff00, // 线上点 [0, 1] 之间为绿色 +// 0xffffff00, // 线上点 [1, 2] 之间为黄色 +// 0xffff0000, // 线上点 [2, 3] 之间为红色 +// 0xff131313, // 线上点 [3, 4] 之间为黄色 +// 0xff1033f6 // 线上点 [4, 最后一个点] 之间为绿色 +// }; +// polyline.setColors(colors, indexes); +// mHasAdded = true; +// break; +// case R.id.menu_text: +// mHasEnableText = !mHasEnableText; +// if (mHasEnableText) { +// if (mPolylineText == null) { +// mPolylineText = generateText(); +// //设置显示优先级,可选项有HIGH或NORMAL +// mPolylineText.setPriority(PolylineOptions.TextPriority.HIGH); +// //设置字体大小 +// mPolylineText.setTextSize(10); +// //设置填充颜色 +// mPolylineText.setStrokeColor(Color.WHITE); +// //设置文字颜色 +// mPolylineText.setTextColor(Color.BLACK); +// } +// +// polyline.setText(mPolylineText); +// } else { +// polyline.setText(null); +// } +// +// break; +// +// case R.id.menu_delete: +// if (polyline != null) { +// polyline.remove(); +// polyline = null; +// mHasAdded = false; +// mHasEnableText = false; +// +// } +// break; +// } +// return super.onOptionsItemSelected(item); +// } +// +// private PolylineOptions setLineStyle(int type) { +// PolylineOptions polylineOptions = new PolylineOptions().addAll(getLatlons()).lineCap(true); +// switch (type) { +// case 0: +// //设置折线颜色、宽度 +// polylineOptions +// .color(0xff00ff00) +// .width(5f); +// break; +// case 1: +// List list = new ArrayList<>(); +// list.add(35); +// list.add(20); +// polylineOptions +// .lineType(PolylineOptions.LineType.LINE_TYPE_IMAGEINARYLINE) +// .width(10) +// .pattern(list); +// break; +// case 2: +// //线路颜色值纹理图片里的颜色索引 +// polylineOptions +// .colorType(PolylineOptions.ColorType.LINE_COLOR_TEXTURE) +// .color(PolylineOptions.Colors.GREEN) +// .colorTexture(BitmapDescriptorFactory.fromAsset("color_texture.png")); +// break; +// case 3: +// polylineOptions +// .arrow(true) +// .arrowSpacing(30) +// .arrowTexture(BitmapDescriptorFactory.fromAsset("color_arrow_texture.png")); +// break; +// case 4: +// polylineOptions +// .gradient(true) +// .lineType(PolylineOptions.LineType.LINE_TYPE_MULTICOLORLINE) +// .width(20); +// break; +// +// } +// return polylineOptions; +// } +// +// private PolylineOptions.Text generateText() { +// List segmentTexts = new ArrayList<>(); +// //参数分别表示坐标路径数组起点index,终点index,动态路名文字 +// segmentTexts.add(new PolylineOptions.SegmentText(0, 1, "苏州街")); +// segmentTexts.add(new PolylineOptions.SegmentText(1, 2, "北四环西路辅路")); +// segmentTexts.add(new PolylineOptions.SegmentText(2, 4, "彩和坊路")); +// return new PolylineOptions.Text.Builder(segmentTexts).build(); +// } +// +// private List getLatlons() { +// List latLngs = new ArrayList(); +// latLngs.add(new LatLng(39.984864, 116.305756)); +// latLngs.add(new LatLng(39.983618, 116.305848)); +// latLngs.add(new LatLng(39.982347, 116.305966)); +// latLngs.add(new LatLng(39.982412, 116.308111)); +// latLngs.add(new LatLng(39.984122, 116.308224)); +// latLngs.add(new LatLng(39.984955, 116.308099)); +// return latLngs; +// } +//} diff --git a/positions/src/main/java/cc/winboll/studio/positions/demo/polyline/LineTextActivity.java b/positions/src/main/java/cc/winboll/studio/positions/demo/polyline/LineTextActivity.java index 9c90a4d..d9fa753 100644 --- a/positions/src/main/java/cc/winboll/studio/positions/demo/polyline/LineTextActivity.java +++ b/positions/src/main/java/cc/winboll/studio/positions/demo/polyline/LineTextActivity.java @@ -17,116 +17,116 @@ import java.util.ArrayList; import java.util.List; public class LineTextActivity extends SupportMapFragmentActivity { - private Polyline polyline; - private static List mPoints = new ArrayList<>(); - private Switch switch_style; - private Switch switch_off; - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - initView(); - tencentMap.moveCamera(CameraUpdateFactory.zoomTo(16)); - switch_style.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { - - @Override - public void onCheckedChanged(CompoundButton compoundButton, boolean checked) { - if (polyline == null) { - return; - } - - PolylineOptions.Text text = polyline.getText(); - removeText(); - if (checked) { - //设置显示优先级,可选项有HIGH或NORMAL - text.setPriority(PolylineOptions.TextPriority.HIGH); - //设置字体大小 - text.setTextSize(10); - //设置填充颜色 - text.setStrokeColor(Color.WHITE); - //设置文字颜色 - text.setTextColor(Color.BLACK); - } else { - //设置显示优先级,可选项有HIGH或NORMAL - text.setPriority(PolylineOptions.TextPriority.NORMAL); - //设置字体大小 - text.setTextSize(8); - //设置填充颜色 - text.setStrokeColor(Color.WHITE); - //设置文字颜色 - text.setTextColor(Color.GRAY); - - } - - polyline.setText(text); - } - }); - - switch_off.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { - @Override - public void onCheckedChanged(CompoundButton compoundButton, boolean checked) { - if (checked) { - polyline = createLineWithText(); - } else { - removeText(); - polyline.remove(); - polyline = null; - } - } - }); - } - - - private void initView() { - //文字 - switch_style = (Switch) findViewById(R.id.switch_style); - switch_style.setVisibility(View.VISIBLE); - switch_off = (Switch) findViewById(R.id.switch_off); - switch_off.setVisibility(View.VISIBLE); - } - - public Polyline addLine() { - Polyline polyline = tencentMap.addPolyline(new PolylineOptions().addAll(mPoints).color(0x22ff0000)); - - return polyline; - } - - - //生成坐标点路径 - private List generateLatLngs() { - if (mPoints.size() != 0) - mPoints = new ArrayList<>(); - //苏州街 - mPoints.add(new LatLng(39.982382, 116.305883)); - //北四环西路辅路 - mPoints.add(new LatLng(39.984914, 116.305690)); - //彩和坊路 - mPoints.add(new LatLng(39.985045, 116.308136)); - mPoints.add(new LatLng(39.983570, 116.308088)); - mPoints.add(new LatLng(39.980063, 116.308297)); - return mPoints; - } - - private PolylineOptions.Text generateText() { - List segmentTexts = new ArrayList<>(); - //参数分别表示坐标路径数组起点index,终点index,动态路名文字 - segmentTexts.add(new PolylineOptions.SegmentText(0, 1, "苏州街")); - segmentTexts.add(new PolylineOptions.SegmentText(1, 2, "北四环西路辅路")); - segmentTexts.add(new PolylineOptions.SegmentText(2, 4, "彩和坊路")); - - return new PolylineOptions.Text.Builder(segmentTexts).build(); - } - - - private Polyline createLineWithText() { - Polyline polyline = tencentMap.addPolyline(new PolylineOptions().addAll(generateLatLngs()).text(generateText())); - PolylineOptions.Text text = polyline.getText(); - return polyline; - } - - - private void removeText() { - polyline.setText(null); - } - +// private Polyline polyline; +// private static List mPoints = new ArrayList<>(); +// private Switch switch_style; +// private Switch switch_off; +// +// @Override +// protected void onCreate(Bundle savedInstanceState) { +// super.onCreate(savedInstanceState); +// initView(); +// tencentMap.moveCamera(CameraUpdateFactory.zoomTo(16)); +// switch_style.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { +// +// @Override +// public void onCheckedChanged(CompoundButton compoundButton, boolean checked) { +// if (polyline == null) { +// return; +// } +// +// PolylineOptions.Text text = polyline.getText(); +// removeText(); +// if (checked) { +// //设置显示优先级,可选项有HIGH或NORMAL +// text.setPriority(PolylineOptions.TextPriority.HIGH); +// //设置字体大小 +// text.setTextSize(10); +// //设置填充颜色 +// text.setStrokeColor(Color.WHITE); +// //设置文字颜色 +// text.setTextColor(Color.BLACK); +// } else { +// //设置显示优先级,可选项有HIGH或NORMAL +// text.setPriority(PolylineOptions.TextPriority.NORMAL); +// //设置字体大小 +// text.setTextSize(8); +// //设置填充颜色 +// text.setStrokeColor(Color.WHITE); +// //设置文字颜色 +// text.setTextColor(Color.GRAY); +// +// } +// +// polyline.setText(text); +// } +// }); +// +// switch_off.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { +// @Override +// public void onCheckedChanged(CompoundButton compoundButton, boolean checked) { +// if (checked) { +// polyline = createLineWithText(); +// } else { +// removeText(); +// polyline.remove(); +// polyline = null; +// } +// } +// }); +// } +// +// +// private void initView() { +// //文字 +// switch_style = (Switch) findViewById(R.id.switch_style); +// switch_style.setVisibility(View.VISIBLE); +// switch_off = (Switch) findViewById(R.id.switch_off); +// switch_off.setVisibility(View.VISIBLE); +// } +// +// public Polyline addLine() { +// Polyline polyline = tencentMap.addPolyline(new PolylineOptions().addAll(mPoints).color(0x22ff0000)); +// +// return polyline; +// } +// +// +// //生成坐标点路径 +// private List generateLatLngs() { +// if (mPoints.size() != 0) +// mPoints = new ArrayList<>(); +// //苏州街 +// mPoints.add(new LatLng(39.982382, 116.305883)); +// //北四环西路辅路 +// mPoints.add(new LatLng(39.984914, 116.305690)); +// //彩和坊路 +// mPoints.add(new LatLng(39.985045, 116.308136)); +// mPoints.add(new LatLng(39.983570, 116.308088)); +// mPoints.add(new LatLng(39.980063, 116.308297)); +// return mPoints; +// } +// +// private PolylineOptions.Text generateText() { +// List segmentTexts = new ArrayList<>(); +// //参数分别表示坐标路径数组起点index,终点index,动态路名文字 +// segmentTexts.add(new PolylineOptions.SegmentText(0, 1, "苏州街")); +// segmentTexts.add(new PolylineOptions.SegmentText(1, 2, "北四环西路辅路")); +// segmentTexts.add(new PolylineOptions.SegmentText(2, 4, "彩和坊路")); +// +// return new PolylineOptions.Text.Builder(segmentTexts).build(); +// } +// +// +// private Polyline createLineWithText() { +// Polyline polyline = tencentMap.addPolyline(new PolylineOptions().addAll(generateLatLngs()).text(generateText())); +// PolylineOptions.Text text = polyline.getText(); +// return polyline; +// } +// +// +// private void removeText() { +// polyline.setText(null); +// } +// } diff --git a/positions/src/main/java/cc/winboll/studio/positions/demo/polyline/MutablePolylineActivity.java b/positions/src/main/java/cc/winboll/studio/positions/demo/polyline/MutablePolylineActivity.java index 63e0db7..0553f73 100644 --- a/positions/src/main/java/cc/winboll/studio/positions/demo/polyline/MutablePolylineActivity.java +++ b/positions/src/main/java/cc/winboll/studio/positions/demo/polyline/MutablePolylineActivity.java @@ -23,269 +23,269 @@ import androidx.annotation.NonNull; * @since 2020/6/11 */ public class MutablePolylineActivity extends SupportMapFragmentActivity { - private boolean mIsAdd; - private Polyline mPolyline; - - private final static Object[][] sData = { - {"更新1"}, - {"更新2"}, - {"重置"}, - {"删除"}, - }; - - private List mAppendPoints = new ArrayList<>(); - private int mAppendIndex; - - private Handler sHandler = new Handler(Looper.getMainLooper()) { - @Override - public void handleMessage(@NonNull Message msg) { - super.handleMessage(msg); - - if (msg.what == 1 && mPolyline != null && mAppendIndex < mAppendPoints.size()) { - mPolyline.appendPoint(mAppendPoints.get(mAppendIndex)); - mAppendIndex++; - - sendEmptyMessageDelayed(1, 300); - } - } - }; - - @Override - public boolean onCreateOptionsMenu(Menu menu) { - getMenuInflater().inflate(R.menu.menu_polyline_items, menu); - - MenuItem actionMenu = menu.findItem(R.id.menu_actions); - SubMenu actionSubMenu = actionMenu.getSubMenu(); - - for (int i = 0; i < sData.length; i++) { - Object[] indoor = sData[i]; - actionSubMenu.add(0, i, 0, String.valueOf(indoor[0])); - } - return true; - } - - @Override - public boolean onPrepareOptionsMenu(Menu menu) { - menu.findItem(R.id.menu_actions).setVisible(mIsAdd); - return super.onPrepareOptionsMenu(menu); - } - - @Override - public boolean onOptionsItemSelected(@NonNull MenuItem item) { - - int itemId = item.getItemId(); - - if (mPolyline != null && itemId >= 0 && itemId < sData.length) { - if (itemId == 3) { - mPolyline.remove(); - mIsAdd = false; - mAppendIndex = 0; - invalidateOptionsMenu(); - } else if (itemId == 2) { - mPolyline.setPoints(getPoints(itemId)); - } else { - mPolyline.appendPoints(getPoints(itemId)); - } - return true; - } - - List pattern = new ArrayList<>(); - pattern.add(35); - pattern.add(20); - - PolylineOptions options = new PolylineOptions() - .addAll(getCreatePoints()) - .width(15); - - switch (item.getItemId()) { - case R.id.menu_add: - if (mIsAdd) { - break; - } - mIsAdd = true; - mPolyline = tencentMap.addPolyline(options); - break; - case R.id.menu_add_anim: - if (mIsAdd) { - break; - } - mIsAdd = true; - - mPolyline = tencentMap.addPolyline(options); - - sHandler.sendEmptyMessage(1); - break; - - } - invalidateOptionsMenu(); - return super.onOptionsItemSelected(item); - } - - private static List getCreatePoints() { - List listPoints = new ArrayList<>(); - addLine(listPoints); - return listPoints; - } - - private static List getPoints(int itemId) { - List listPoints = new ArrayList(); - if (itemId == 0) { - addLine1(listPoints); - } else if (itemId == 1) { - addLine2(listPoints); - } else if (itemId == 2) { - addLine(listPoints); - } - - return listPoints; - } - - private static void addLine(List listPoints) { - listPoints.add(new LatLng(39.981787, 116.306649)); - listPoints.add(new LatLng(39.982021, 116.306739)); - listPoints.add(new LatLng(39.982351, 116.306883)); - listPoints.add(new LatLng(39.98233, 116.306047)); - listPoints.add(new LatLng(39.982324, 116.305867)); - listPoints.add(new LatLng(39.981918, 116.305885)); - listPoints.add(new LatLng(39.981298, 116.305921)); - listPoints.add(new LatLng(39.981091, 116.305939)); - listPoints.add(new LatLng(39.980506, 116.305975)); - listPoints.add(new LatLng(39.980148, 116.306002)); - listPoints.add(new LatLng(39.980121, 116.306002)); - listPoints.add(new LatLng(39.979708, 116.306038)); - listPoints.add(new LatLng(39.979205, 116.306074)); - listPoints.add(new LatLng(39.979205, 116.306074)); - listPoints.add(new LatLng(39.978813, 116.306101)); - listPoints.add(new LatLng(39.978015, 116.306182)); - listPoints.add(new LatLng(39.977299, 116.306227)); - listPoints.add(new LatLng(39.976996, 116.306245)); - listPoints.add(new LatLng(39.976913, 116.306245)); - listPoints.add(new LatLng(39.97597, 116.306308)); - listPoints.add(new LatLng(39.97575, 116.306326)); - listPoints.add(new LatLng(39.97564, 116.306335)); - listPoints.add(new LatLng(39.975178, 116.306371)); - listPoints.add(new LatLng(39.975185, 116.306514)); - listPoints.add(new LatLng(39.97564, 116.306272)); - listPoints.add(new LatLng(39.975633, 116.306272)); - listPoints.add(new LatLng(39.975715, 116.307997)); - listPoints.add(new LatLng(39.975819, 116.311545)); - listPoints.add(new LatLng(39.975936, 116.314878)); - listPoints.add(new LatLng(39.975998, 116.317528)); - listPoints.add(new LatLng(39.976025, 116.318785)); - listPoints.add(new LatLng(39.976108, 116.321714)); - listPoints.add(new LatLng(39.976259, 116.326843)); - listPoints.add(new LatLng(39.976328, 116.328622)); - listPoints.add(new LatLng(39.976397, 116.330356)); - listPoints.add(new LatLng(39.9765, 116.333967)); - listPoints.add(new LatLng(39.976459, 116.341019)); - listPoints.add(new LatLng(39.976473, 116.341674)); - listPoints.add(new LatLng(39.976473, 116.341944)); - listPoints.add(new LatLng(39.976473, 116.342546)); - listPoints.add(new LatLng(39.976479, 116.345295)); - listPoints.add(new LatLng(39.976197, 116.353829)); - listPoints.add(new LatLng(39.976459, 116.369926)); - listPoints.add(new LatLng(39.97672, 116.381353)); - } - - private static void addLine2(List listPoints) { - listPoints.add(new LatLng(39.91254, 116.41786)); - listPoints.add(new LatLng(39.911258, 116.417905)); - listPoints.add(new LatLng(39.910459, 116.417923)); - listPoints.add(new LatLng(39.908557, 116.418049)); - listPoints.add(new LatLng(39.908337, 116.418058)); - listPoints.add(new LatLng(39.90824, 116.418067)); - listPoints.add(new LatLng(39.90669, 116.418148)); - listPoints.add(new LatLng(39.904795, 116.418283)); - listPoints.add(new LatLng(39.903416, 116.418265)); - listPoints.add(new LatLng(39.901218, 116.418408)); - listPoints.add(new LatLng(39.900805, 116.418417)); - listPoints.add(new LatLng(39.900805, 116.418426)); - listPoints.add(new LatLng(39.901335, 116.417968)); - listPoints.add(new LatLng(39.901342, 116.417968)); - listPoints.add(new LatLng(39.901342, 116.418004)); - listPoints.add(new LatLng(39.901197, 116.418193)); - listPoints.add(new LatLng(39.901204, 116.418426)); - listPoints.add(new LatLng(39.901218, 116.418552)); - listPoints.add(new LatLng(39.901087, 116.418624)); - listPoints.add(new LatLng(39.901053, 116.41884)); - listPoints.add(new LatLng(39.901004, 116.419028)); - listPoints.add(new LatLng(39.900922, 116.419388)); - listPoints.add(new LatLng(39.900839, 116.419774)); - listPoints.add(new LatLng(39.900749, 116.420043)); - listPoints.add(new LatLng(39.900722, 116.420178)); - listPoints.add(new LatLng(39.900667, 116.42034)); - listPoints.add(new LatLng(39.900619, 116.420519)); - listPoints.add(new LatLng(39.900557, 116.420744)); - listPoints.add(new LatLng(39.900515, 116.420915)); - listPoints.add(new LatLng(39.900488, 116.421067)); - listPoints.add(new LatLng(39.900467, 116.421274)); - listPoints.add(new LatLng(39.900467, 116.421301)); - listPoints.add(new LatLng(39.900467, 116.421301)); - listPoints.add(new LatLng(39.900674, 116.428856)); - listPoints.add(new LatLng(39.900681, 116.429287)); - listPoints.add(new LatLng(39.900674, 116.429287)); - listPoints.add(new LatLng(39.900694, 116.429745)); - listPoints.add(new LatLng(39.900736, 116.43173)); - listPoints.add(new LatLng(39.900729, 116.433132)); - listPoints.add(new LatLng(39.900729, 116.433267)); - listPoints.add(new LatLng(39.900743, 116.433545)); - } - - private static void addLine1(List listPoints) { - listPoints.add(new LatLng(39.976748, 116.382314)); - listPoints.add(new LatLng(39.976851, 116.388045)); - listPoints.add(new LatLng(39.976892, 116.393597)); - listPoints.add(new LatLng(39.976906, 116.394199)); - listPoints.add(new LatLng(39.976906, 116.394298)); - listPoints.add(new LatLng(39.976996, 116.405949)); - listPoints.add(new LatLng(39.977016, 116.407692)); - listPoints.add(new LatLng(39.97701, 116.417564)); - listPoints.add(new LatLng(39.97701, 116.417564)); - listPoints.add(new LatLng(39.977127, 116.417591)); - listPoints.add(new LatLng(39.977127, 116.417582)); - listPoints.add(new LatLng(39.969017, 116.417932)); - listPoints.add(new LatLng(39.968549, 116.417977)); - listPoints.add(new LatLng(39.9666, 116.418094)); - listPoints.add(new LatLng(39.965099, 116.418193)); - listPoints.add(new LatLng(39.963957, 116.418256)); - listPoints.add(new LatLng(39.961533, 116.418301)); - listPoints.add(new LatLng(39.959343, 116.418301)); - listPoints.add(new LatLng(39.95422, 116.418732)); - listPoints.add(new LatLng(39.952375, 116.418858)); - listPoints.add(new LatLng(39.952106, 116.418876)); - listPoints.add(new LatLng(39.95192, 116.418849)); - listPoints.add(new LatLng(39.951693, 116.418696)); - listPoints.add(new LatLng(39.951528, 116.418525)); - listPoints.add(new LatLng(39.951383, 116.41822)); - listPoints.add(new LatLng(39.95128, 116.417941)); - listPoints.add(new LatLng(39.951239, 116.417609)); - listPoints.add(new LatLng(39.951218, 116.417312)); - listPoints.add(new LatLng(39.951218, 116.417088)); - listPoints.add(new LatLng(39.951197, 116.416899)); - listPoints.add(new LatLng(39.951115, 116.416675)); - listPoints.add(new LatLng(39.950984, 116.416513)); - listPoints.add(new LatLng(39.950839, 116.416378)); - listPoints.add(new LatLng(39.950639, 116.41627)); - listPoints.add(new LatLng(39.950426, 116.416217)); - listPoints.add(new LatLng(39.950095, 116.416243)); - listPoints.add(new LatLng(39.948835, 116.416486)); - listPoints.add(new LatLng(39.948697, 116.416486)); - listPoints.add(new LatLng(39.945557, 116.416648)); - listPoints.add(new LatLng(39.941686, 116.416791)); - listPoints.add(new LatLng(39.941005, 116.4168)); - listPoints.add(new LatLng(39.938442, 116.416944)); - listPoints.add(new LatLng(39.936045, 116.417016)); - listPoints.add(new LatLng(39.933662, 116.417142)); - listPoints.add(new LatLng(39.929247, 116.417295)); - listPoints.add(new LatLng(39.927683, 116.417393)); - listPoints.add(new LatLng(39.926553, 116.417438)); - listPoints.add(new LatLng(39.924583, 116.417492)); - listPoints.add(new LatLng(39.924369, 116.417492)); - listPoints.add(new LatLng(39.921779, 116.417573)); - listPoints.add(new LatLng(39.919044, 116.417654)); - listPoints.add(new LatLng(39.917404, 116.417708)); - listPoints.add(new LatLng(39.917287, 116.417717)); - listPoints.add(new LatLng(39.916233, 116.417825)); - listPoints.add(new LatLng(39.913904, 116.417807)); - } +// private boolean mIsAdd; +// private Polyline mPolyline; +// +// private final static Object[][] sData = { +// {"更新1"}, +// {"更新2"}, +// {"重置"}, +// {"删除"}, +// }; +// +// private List mAppendPoints = new ArrayList<>(); +// private int mAppendIndex; +// +// private Handler sHandler = new Handler(Looper.getMainLooper()) { +// @Override +// public void handleMessage(@NonNull Message msg) { +// super.handleMessage(msg); +// +// if (msg.what == 1 && mPolyline != null && mAppendIndex < mAppendPoints.size()) { +// mPolyline.appendPoint(mAppendPoints.get(mAppendIndex)); +// mAppendIndex++; +// +// sendEmptyMessageDelayed(1, 300); +// } +// } +// }; +// +// @Override +// public boolean onCreateOptionsMenu(Menu menu) { +// getMenuInflater().inflate(R.menu.menu_polyline_items, menu); +// +// MenuItem actionMenu = menu.findItem(R.id.menu_actions); +// SubMenu actionSubMenu = actionMenu.getSubMenu(); +// +// for (int i = 0; i < sData.length; i++) { +// Object[] indoor = sData[i]; +// actionSubMenu.add(0, i, 0, String.valueOf(indoor[0])); +// } +// return true; +// } +// +// @Override +// public boolean onPrepareOptionsMenu(Menu menu) { +// menu.findItem(R.id.menu_actions).setVisible(mIsAdd); +// return super.onPrepareOptionsMenu(menu); +// } +// +// @Override +// public boolean onOptionsItemSelected(@NonNull MenuItem item) { +// +// int itemId = item.getItemId(); +// +// if (mPolyline != null && itemId >= 0 && itemId < sData.length) { +// if (itemId == 3) { +// mPolyline.remove(); +// mIsAdd = false; +// mAppendIndex = 0; +// invalidateOptionsMenu(); +// } else if (itemId == 2) { +// mPolyline.setPoints(getPoints(itemId)); +// } else { +// mPolyline.appendPoints(getPoints(itemId)); +// } +// return true; +// } +// +// List pattern = new ArrayList<>(); +// pattern.add(35); +// pattern.add(20); +// +// PolylineOptions options = new PolylineOptions() +// .addAll(getCreatePoints()) +// .width(15); +// +// switch (item.getItemId()) { +// case R.id.menu_add: +// if (mIsAdd) { +// break; +// } +// mIsAdd = true; +// mPolyline = tencentMap.addPolyline(options); +// break; +// case R.id.menu_add_anim: +// if (mIsAdd) { +// break; +// } +// mIsAdd = true; +// +// mPolyline = tencentMap.addPolyline(options); +// +// sHandler.sendEmptyMessage(1); +// break; +// +// } +// invalidateOptionsMenu(); +// return super.onOptionsItemSelected(item); +// } +// +// private static List getCreatePoints() { +// List listPoints = new ArrayList<>(); +// addLine(listPoints); +// return listPoints; +// } +// +// private static List getPoints(int itemId) { +// List listPoints = new ArrayList(); +// if (itemId == 0) { +// addLine1(listPoints); +// } else if (itemId == 1) { +// addLine2(listPoints); +// } else if (itemId == 2) { +// addLine(listPoints); +// } +// +// return listPoints; +// } +// +// private static void addLine(List listPoints) { +// listPoints.add(new LatLng(39.981787, 116.306649)); +// listPoints.add(new LatLng(39.982021, 116.306739)); +// listPoints.add(new LatLng(39.982351, 116.306883)); +// listPoints.add(new LatLng(39.98233, 116.306047)); +// listPoints.add(new LatLng(39.982324, 116.305867)); +// listPoints.add(new LatLng(39.981918, 116.305885)); +// listPoints.add(new LatLng(39.981298, 116.305921)); +// listPoints.add(new LatLng(39.981091, 116.305939)); +// listPoints.add(new LatLng(39.980506, 116.305975)); +// listPoints.add(new LatLng(39.980148, 116.306002)); +// listPoints.add(new LatLng(39.980121, 116.306002)); +// listPoints.add(new LatLng(39.979708, 116.306038)); +// listPoints.add(new LatLng(39.979205, 116.306074)); +// listPoints.add(new LatLng(39.979205, 116.306074)); +// listPoints.add(new LatLng(39.978813, 116.306101)); +// listPoints.add(new LatLng(39.978015, 116.306182)); +// listPoints.add(new LatLng(39.977299, 116.306227)); +// listPoints.add(new LatLng(39.976996, 116.306245)); +// listPoints.add(new LatLng(39.976913, 116.306245)); +// listPoints.add(new LatLng(39.97597, 116.306308)); +// listPoints.add(new LatLng(39.97575, 116.306326)); +// listPoints.add(new LatLng(39.97564, 116.306335)); +// listPoints.add(new LatLng(39.975178, 116.306371)); +// listPoints.add(new LatLng(39.975185, 116.306514)); +// listPoints.add(new LatLng(39.97564, 116.306272)); +// listPoints.add(new LatLng(39.975633, 116.306272)); +// listPoints.add(new LatLng(39.975715, 116.307997)); +// listPoints.add(new LatLng(39.975819, 116.311545)); +// listPoints.add(new LatLng(39.975936, 116.314878)); +// listPoints.add(new LatLng(39.975998, 116.317528)); +// listPoints.add(new LatLng(39.976025, 116.318785)); +// listPoints.add(new LatLng(39.976108, 116.321714)); +// listPoints.add(new LatLng(39.976259, 116.326843)); +// listPoints.add(new LatLng(39.976328, 116.328622)); +// listPoints.add(new LatLng(39.976397, 116.330356)); +// listPoints.add(new LatLng(39.9765, 116.333967)); +// listPoints.add(new LatLng(39.976459, 116.341019)); +// listPoints.add(new LatLng(39.976473, 116.341674)); +// listPoints.add(new LatLng(39.976473, 116.341944)); +// listPoints.add(new LatLng(39.976473, 116.342546)); +// listPoints.add(new LatLng(39.976479, 116.345295)); +// listPoints.add(new LatLng(39.976197, 116.353829)); +// listPoints.add(new LatLng(39.976459, 116.369926)); +// listPoints.add(new LatLng(39.97672, 116.381353)); +// } +// +// private static void addLine2(List listPoints) { +// listPoints.add(new LatLng(39.91254, 116.41786)); +// listPoints.add(new LatLng(39.911258, 116.417905)); +// listPoints.add(new LatLng(39.910459, 116.417923)); +// listPoints.add(new LatLng(39.908557, 116.418049)); +// listPoints.add(new LatLng(39.908337, 116.418058)); +// listPoints.add(new LatLng(39.90824, 116.418067)); +// listPoints.add(new LatLng(39.90669, 116.418148)); +// listPoints.add(new LatLng(39.904795, 116.418283)); +// listPoints.add(new LatLng(39.903416, 116.418265)); +// listPoints.add(new LatLng(39.901218, 116.418408)); +// listPoints.add(new LatLng(39.900805, 116.418417)); +// listPoints.add(new LatLng(39.900805, 116.418426)); +// listPoints.add(new LatLng(39.901335, 116.417968)); +// listPoints.add(new LatLng(39.901342, 116.417968)); +// listPoints.add(new LatLng(39.901342, 116.418004)); +// listPoints.add(new LatLng(39.901197, 116.418193)); +// listPoints.add(new LatLng(39.901204, 116.418426)); +// listPoints.add(new LatLng(39.901218, 116.418552)); +// listPoints.add(new LatLng(39.901087, 116.418624)); +// listPoints.add(new LatLng(39.901053, 116.41884)); +// listPoints.add(new LatLng(39.901004, 116.419028)); +// listPoints.add(new LatLng(39.900922, 116.419388)); +// listPoints.add(new LatLng(39.900839, 116.419774)); +// listPoints.add(new LatLng(39.900749, 116.420043)); +// listPoints.add(new LatLng(39.900722, 116.420178)); +// listPoints.add(new LatLng(39.900667, 116.42034)); +// listPoints.add(new LatLng(39.900619, 116.420519)); +// listPoints.add(new LatLng(39.900557, 116.420744)); +// listPoints.add(new LatLng(39.900515, 116.420915)); +// listPoints.add(new LatLng(39.900488, 116.421067)); +// listPoints.add(new LatLng(39.900467, 116.421274)); +// listPoints.add(new LatLng(39.900467, 116.421301)); +// listPoints.add(new LatLng(39.900467, 116.421301)); +// listPoints.add(new LatLng(39.900674, 116.428856)); +// listPoints.add(new LatLng(39.900681, 116.429287)); +// listPoints.add(new LatLng(39.900674, 116.429287)); +// listPoints.add(new LatLng(39.900694, 116.429745)); +// listPoints.add(new LatLng(39.900736, 116.43173)); +// listPoints.add(new LatLng(39.900729, 116.433132)); +// listPoints.add(new LatLng(39.900729, 116.433267)); +// listPoints.add(new LatLng(39.900743, 116.433545)); +// } +// +// private static void addLine1(List listPoints) { +// listPoints.add(new LatLng(39.976748, 116.382314)); +// listPoints.add(new LatLng(39.976851, 116.388045)); +// listPoints.add(new LatLng(39.976892, 116.393597)); +// listPoints.add(new LatLng(39.976906, 116.394199)); +// listPoints.add(new LatLng(39.976906, 116.394298)); +// listPoints.add(new LatLng(39.976996, 116.405949)); +// listPoints.add(new LatLng(39.977016, 116.407692)); +// listPoints.add(new LatLng(39.97701, 116.417564)); +// listPoints.add(new LatLng(39.97701, 116.417564)); +// listPoints.add(new LatLng(39.977127, 116.417591)); +// listPoints.add(new LatLng(39.977127, 116.417582)); +// listPoints.add(new LatLng(39.969017, 116.417932)); +// listPoints.add(new LatLng(39.968549, 116.417977)); +// listPoints.add(new LatLng(39.9666, 116.418094)); +// listPoints.add(new LatLng(39.965099, 116.418193)); +// listPoints.add(new LatLng(39.963957, 116.418256)); +// listPoints.add(new LatLng(39.961533, 116.418301)); +// listPoints.add(new LatLng(39.959343, 116.418301)); +// listPoints.add(new LatLng(39.95422, 116.418732)); +// listPoints.add(new LatLng(39.952375, 116.418858)); +// listPoints.add(new LatLng(39.952106, 116.418876)); +// listPoints.add(new LatLng(39.95192, 116.418849)); +// listPoints.add(new LatLng(39.951693, 116.418696)); +// listPoints.add(new LatLng(39.951528, 116.418525)); +// listPoints.add(new LatLng(39.951383, 116.41822)); +// listPoints.add(new LatLng(39.95128, 116.417941)); +// listPoints.add(new LatLng(39.951239, 116.417609)); +// listPoints.add(new LatLng(39.951218, 116.417312)); +// listPoints.add(new LatLng(39.951218, 116.417088)); +// listPoints.add(new LatLng(39.951197, 116.416899)); +// listPoints.add(new LatLng(39.951115, 116.416675)); +// listPoints.add(new LatLng(39.950984, 116.416513)); +// listPoints.add(new LatLng(39.950839, 116.416378)); +// listPoints.add(new LatLng(39.950639, 116.41627)); +// listPoints.add(new LatLng(39.950426, 116.416217)); +// listPoints.add(new LatLng(39.950095, 116.416243)); +// listPoints.add(new LatLng(39.948835, 116.416486)); +// listPoints.add(new LatLng(39.948697, 116.416486)); +// listPoints.add(new LatLng(39.945557, 116.416648)); +// listPoints.add(new LatLng(39.941686, 116.416791)); +// listPoints.add(new LatLng(39.941005, 116.4168)); +// listPoints.add(new LatLng(39.938442, 116.416944)); +// listPoints.add(new LatLng(39.936045, 116.417016)); +// listPoints.add(new LatLng(39.933662, 116.417142)); +// listPoints.add(new LatLng(39.929247, 116.417295)); +// listPoints.add(new LatLng(39.927683, 116.417393)); +// listPoints.add(new LatLng(39.926553, 116.417438)); +// listPoints.add(new LatLng(39.924583, 116.417492)); +// listPoints.add(new LatLng(39.924369, 116.417492)); +// listPoints.add(new LatLng(39.921779, 116.417573)); +// listPoints.add(new LatLng(39.919044, 116.417654)); +// listPoints.add(new LatLng(39.917404, 116.417708)); +// listPoints.add(new LatLng(39.917287, 116.417717)); +// listPoints.add(new LatLng(39.916233, 116.417825)); +// listPoints.add(new LatLng(39.913904, 116.417807)); +// } } diff --git a/positions/src/main/java/cc/winboll/studio/positions/demo/polyline/PolylineOptionsActivity.java b/positions/src/main/java/cc/winboll/studio/positions/demo/polyline/PolylineOptionsActivity.java index e8e9194..e99c380 100644 --- a/positions/src/main/java/cc/winboll/studio/positions/demo/polyline/PolylineOptionsActivity.java +++ b/positions/src/main/java/cc/winboll/studio/positions/demo/polyline/PolylineOptionsActivity.java @@ -1,87 +1,87 @@ package cc.winboll.studio.positions.demo.polyline; -import android.os.Bundle; - -import cc.winboll.studio.positions.demo.basic.SupportMapFragmentActivity; -import com.tencent.tencentmap.mapsdk.maps.model.BitmapDescriptorFactory; -import com.tencent.tencentmap.mapsdk.maps.model.LatLng; -import com.tencent.tencentmap.mapsdk.maps.model.Polyline; -import com.tencent.tencentmap.mapsdk.maps.model.PolylineOptions; - -import java.util.ArrayList; -import java.util.List; - -public class PolylineOptionsActivity extends SupportMapFragmentActivity { - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - Polyline polyline = tencentMap.addPolyline(polylineOptions); - Polyline newPolyline = tencentMap.addPolyline(newPolylineOptions); - polyline.pattern(patternLine(patterns)); //设置虚线样式 - } - - private int[] patterns = {10, 15, 20}; - private List patternLine(int [] patterns){ - List patternLine = new ArrayList<>(); - if (patterns == null) - return patternLine; - for (int i = 0; i < patterns.length; i++) - patternLine.add(patterns[i]); - return patternLine; - } - - - private List transferArrayToList(LatLng[] latLngs){ //坐标数组与List转换 - List list = new ArrayList<>(); - if (latLngs == null) - return list; - for (int i = 0; i < latLngs.length; i++) - list.add(latLngs[i]); - - return list; - - } - - private LatLng[] latLngs = { - new LatLng(39.984864, 116.305756), - new LatLng(39.983618, 116.305848), - new LatLng(39.982347, 116.305966), - new LatLng(39.982412, 116.308111), - new LatLng(39.984122, 116.308224), - new LatLng(39.984955, 116.308099), - new LatLng(39.984864, 116.305756) - }; - - private LatLng[] newLatLngs = { - new LatLng(39.984864, 116.305756), - new LatLng(39.983618, 116.305848), - new LatLng(39.982347, 116.305966), - new LatLng(39.982412, 116.308111), - new LatLng(39.984122, 116.308224), - new LatLng(39.984955, 116.308099), - new LatLng(39.984864, 116.305756) - }; - private PolylineOptions polylineOptions = new PolylineOptions(). - addAll(transferArrayToList(latLngs)). //添加顶点 - alpha(0.5f). //设置透明度 - arrow(true). //导航用 接口 - arrowSpacing(110). // 设置方向箭头间距 - arrowTexture(BitmapDescriptorFactory.fromAsset("color_arrow_texture.png")). // 设置箭头纹理 - borderColor(0xaa323456). //设置描边颜色 - borderWidth(1f). //设置描边宽度 - clickable(true). //可点击 - color(PolylineOptions.Colors.LIGHT_BLUE). //线的颜色 - colorTexture(BitmapDescriptorFactory.fromAsset("color_texture.png")). //颜色纹理 - lineCap(true). //路线是否显示半圆端点 - lineType(PolylineOptions.LineType.LINE_TYPE_MULTICOLORLINE). //设置线的类型 - visible(true). //设置折线可见性 - width(10f). //设置线的宽度 - zIndex(0); //堆叠顺序,越大优先级越高 - - - private PolylineOptions newPolylineOptions = new PolylineOptions().add(newLatLngs). - lineType(PolylineOptions.LineType.LINE_TYPE_DOTTEDLINE). - visible(true). - pattern(patternLine(patterns)). - zIndex(1); -} +//import android.os.Bundle; +// +//import cc.winboll.studio.positions.demo.basic.SupportMapFragmentActivity; +//import com.tencent.tencentmap.mapsdk.maps.model.BitmapDescriptorFactory; +//import com.tencent.tencentmap.mapsdk.maps.model.LatLng; +//import com.tencent.tencentmap.mapsdk.maps.model.Polyline; +//import com.tencent.tencentmap.mapsdk.maps.model.PolylineOptions; +// +//import java.util.ArrayList; +//import java.util.List; +// +//public class PolylineOptionsActivity extends SupportMapFragmentActivity { +// @Override +// protected void onCreate(Bundle savedInstanceState) { +// super.onCreate(savedInstanceState); +// Polyline polyline = tencentMap.addPolyline(polylineOptions); +// Polyline newPolyline = tencentMap.addPolyline(newPolylineOptions); +// polyline.pattern(patternLine(patterns)); //设置虚线样式 +// } +// +// private int[] patterns = {10, 15, 20}; +// private List patternLine(int [] patterns){ +// List patternLine = new ArrayList<>(); +// if (patterns == null) +// return patternLine; +// for (int i = 0; i < patterns.length; i++) +// patternLine.add(patterns[i]); +// return patternLine; +// } +// +// +// private List transferArrayToList(LatLng[] latLngs){ //坐标数组与List转换 +// List list = new ArrayList<>(); +// if (latLngs == null) +// return list; +// for (int i = 0; i < latLngs.length; i++) +// list.add(latLngs[i]); +// +// return list; +// +// } +// +// private LatLng[] latLngs = { +// new LatLng(39.984864, 116.305756), +// new LatLng(39.983618, 116.305848), +// new LatLng(39.982347, 116.305966), +// new LatLng(39.982412, 116.308111), +// new LatLng(39.984122, 116.308224), +// new LatLng(39.984955, 116.308099), +// new LatLng(39.984864, 116.305756) +// }; +// +// private LatLng[] newLatLngs = { +// new LatLng(39.984864, 116.305756), +// new LatLng(39.983618, 116.305848), +// new LatLng(39.982347, 116.305966), +// new LatLng(39.982412, 116.308111), +// new LatLng(39.984122, 116.308224), +// new LatLng(39.984955, 116.308099), +// new LatLng(39.984864, 116.305756) +// }; +// private PolylineOptions polylineOptions = new PolylineOptions(). +// addAll(transferArrayToList(latLngs)). //添加顶点 +// alpha(0.5f). //设置透明度 +// arrow(true). //导航用 接口 +// arrowSpacing(110). // 设置方向箭头间距 +// arrowTexture(BitmapDescriptorFactory.fromAsset("color_arrow_texture.png")). // 设置箭头纹理 +// borderColor(0xaa323456). //设置描边颜色 +// borderWidth(1f). //设置描边宽度 +// clickable(true). //可点击 +// color(PolylineOptions.Colors.LIGHT_BLUE). //线的颜色 +// colorTexture(BitmapDescriptorFactory.fromAsset("color_texture.png")). //颜色纹理 +// lineCap(true). //路线是否显示半圆端点 +// lineType(PolylineOptions.LineType.LINE_TYPE_MULTICOLORLINE). //设置线的类型 +// visible(true). //设置折线可见性 +// width(10f). //设置线的宽度 +// zIndex(0); //堆叠顺序,越大优先级越高 +// +// +// private PolylineOptions newPolylineOptions = new PolylineOptions().add(newLatLngs). +// lineType(PolylineOptions.LineType.LINE_TYPE_DOTTEDLINE). +// visible(true). +// pattern(patternLine(patterns)). +// zIndex(1); +//} diff --git a/positions/src/main/java/cc/winboll/studio/positions/demo/search/DistrictActivity.java b/positions/src/main/java/cc/winboll/studio/positions/demo/search/DistrictActivity.java index 2581f3c..d8658dd 100644 --- a/positions/src/main/java/cc/winboll/studio/positions/demo/search/DistrictActivity.java +++ b/positions/src/main/java/cc/winboll/studio/positions/demo/search/DistrictActivity.java @@ -21,154 +21,154 @@ import java.util.ArrayList; import java.util.List; public class DistrictActivity extends SupportMapFragmentActivity { - private Spinner spProvince; - private Spinner spCity; - private Spinner spDistrict; - private TextView tvResult; - private List latLngs = new ArrayList<>(); - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - initView(); - initSpinner(); - } - - protected void initView() { - spProvince = (Spinner) findViewById(R.id.sp_province); - spCity = (Spinner) findViewById(R.id.sp_city); - spDistrict = (Spinner) findViewById(R.id.sp_district); - tvResult = (TextView) findViewById(R.id.tv_result); - spProvince.setVisibility(View.VISIBLE); - spCity.setVisibility(View.VISIBLE); - spDistrict.setVisibility(View.VISIBLE); - tvResult.setVisibility(View.VISIBLE); - } - - protected void initSpinner() { - - //初始化行政区划,像北京市等只有市和区两级的数据,可能会输出错误id - getDistrict(0, R.id.sp_province); - AdapterView.OnItemSelectedListener onItemSelectedListener = new AdapterView.OnItemSelectedListener() { - - @Override - public void onItemSelected(AdapterView parent, View view, - int position, long id) { - // TODO Auto-generated method stub - switch (parent.getId()) { - case R.id.sp_province: - getDistrict(((List) parent.getTag()). - get(position).intValue(), R.id.sp_city); - break; - case R.id.sp_city: - getDistrict(((List) parent.getTag()). - get(position).intValue(), R.id.sp_district); - break; - case R.id.sp_district: - getDistrict(((List) parent.getTag()). - get(position).intValue(), R.id.sp_district); - tencentMap.moveCamera(CameraUpdateFactory.newCameraPosition(new CameraPosition(latLngs.get(position), 15f, 0, 0))); - default: - break; - } - } - - @Override - public void onNothingSelected(AdapterView parent) { - // TODO Auto-generated method stub - - } - }; - spProvince.setOnItemSelectedListener(onItemSelectedListener); - spCity.setOnItemSelectedListener(onItemSelectedListener); - spDistrict.setOnItemSelectedListener(onItemSelectedListener); - } - - /** - * 获取行政区划 - */ - protected void getDistrict(int pDistrict, final int spId) { - TencentSearch tencentSearch = new TencentSearch(this); - DistrictChildrenParam districtChildrenParam = new DistrictChildrenParam(); - Log.d("eqrwqeqewr", "getDistrict: " + spId); - //如果不设置id,则获取全部数据 - if (spId != R.id.sp_province && spId == R.id.sp_city) { - districtChildrenParam.id(pDistrict); - } - if (spId != R.id.sp_province && spId != R.id.sp_city) { - districtChildrenParam.id(pDistrict); - } - - tencentSearch.getDistrictChildren(districtChildrenParam, new HttpResponseListener() { - - @Override - public void onSuccess(int arg0, BaseObject arg1) { - // TODO Auto-generated method stub - if (arg1 == null) { - return; - } - DistrictResultObject obj = (DistrictResultObject) arg1; - switch (spId) { - case R.id.sp_province: - setDistrictAdapter(spProvince, obj); - break; - case R.id.sp_city: - setDistrictAdapter(spCity, obj); - break; - case R.id.sp_district: - setDistrictAdapter(spDistrict, obj); - break; - - default: - break; - } - } - - @Override - public void onFailure(int arg0, String arg1, Throwable arg2) { - // TODO Auto-generated method stub - // printResult(arg1); - } - }); - } - - /** - * 设置行政区划的adapter - * - * @param spinner 要设置adapter的spinner - * @param obj 用于填充adapter的数据源 - */ - protected void setDistrictAdapter(Spinner spinner, final DistrictResultObject obj) { - List names = new ArrayList(); - List ids = new ArrayList(); - latLngs.clear(); - final List districtResults = obj.result.get(0); - for (final DistrictResultObject.DistrictResult result : districtResults) { - names.add(result.fullname); - ids.add(result.id); - latLngs.add(result.latLng); - Log.d("位置", "setDistrictAdapter: " + result.fullname); - - } - ArrayAdapter adapter = new ArrayAdapter(this, - android.R.layout.simple_spinner_item, names); - spinner.setAdapter(adapter); - //将行政区划编码附到spinner方便后续查询 - spinner.setTag(ids); - - } - - - protected void printResult(final String result) { - runOnUiThread(new Runnable() { - - @Override - public void run() { - // TODO Auto-generated method stub - tvResult.setText(result); - } - }); - } - +// private Spinner spProvince; +// private Spinner spCity; +// private Spinner spDistrict; +// private TextView tvResult; +// private List latLngs = new ArrayList<>(); +// +// @Override +// protected void onCreate(Bundle savedInstanceState) { +// super.onCreate(savedInstanceState); +// initView(); +// initSpinner(); +// } +// +// protected void initView() { +// spProvince = (Spinner) findViewById(R.id.sp_province); +// spCity = (Spinner) findViewById(R.id.sp_city); +// spDistrict = (Spinner) findViewById(R.id.sp_district); +// tvResult = (TextView) findViewById(R.id.tv_result); +// spProvince.setVisibility(View.VISIBLE); +// spCity.setVisibility(View.VISIBLE); +// spDistrict.setVisibility(View.VISIBLE); +// tvResult.setVisibility(View.VISIBLE); +// } +// +// protected void initSpinner() { +// +// //初始化行政区划,像北京市等只有市和区两级的数据,可能会输出错误id +// getDistrict(0, R.id.sp_province); +// AdapterView.OnItemSelectedListener onItemSelectedListener = new AdapterView.OnItemSelectedListener() { +// +// @Override +// public void onItemSelected(AdapterView parent, View view, +// int position, long id) { +// // TODO Auto-generated method stub +// switch (parent.getId()) { +// case R.id.sp_province: +// getDistrict(((List) parent.getTag()). +// get(position).intValue(), R.id.sp_city); +// break; +// case R.id.sp_city: +// getDistrict(((List) parent.getTag()). +// get(position).intValue(), R.id.sp_district); +// break; +// case R.id.sp_district: +// getDistrict(((List) parent.getTag()). +// get(position).intValue(), R.id.sp_district); +// tencentMap.moveCamera(CameraUpdateFactory.newCameraPosition(new CameraPosition(latLngs.get(position), 15f, 0, 0))); +// default: +// break; +// } +// } +// +// @Override +// public void onNothingSelected(AdapterView parent) { +// // TODO Auto-generated method stub +// +// } +// }; +// spProvince.setOnItemSelectedListener(onItemSelectedListener); +// spCity.setOnItemSelectedListener(onItemSelectedListener); +// spDistrict.setOnItemSelectedListener(onItemSelectedListener); +// } +// +// /** +// * 获取行政区划 +// */ +// protected void getDistrict(int pDistrict, final int spId) { +// TencentSearch tencentSearch = new TencentSearch(this); +// DistrictChildrenParam districtChildrenParam = new DistrictChildrenParam(); +// Log.d("eqrwqeqewr", "getDistrict: " + spId); +// //如果不设置id,则获取全部数据 +// if (spId != R.id.sp_province && spId == R.id.sp_city) { +// districtChildrenParam.id(pDistrict); +// } +// if (spId != R.id.sp_province && spId != R.id.sp_city) { +// districtChildrenParam.id(pDistrict); +// } +// +// tencentSearch.getDistrictChildren(districtChildrenParam, new HttpResponseListener() { +// +// @Override +// public void onSuccess(int arg0, BaseObject arg1) { +// // TODO Auto-generated method stub +// if (arg1 == null) { +// return; +// } +// DistrictResultObject obj = (DistrictResultObject) arg1; +// switch (spId) { +// case R.id.sp_province: +// setDistrictAdapter(spProvince, obj); +// break; +// case R.id.sp_city: +// setDistrictAdapter(spCity, obj); +// break; +// case R.id.sp_district: +// setDistrictAdapter(spDistrict, obj); +// break; +// +// default: +// break; +// } +// } +// +// @Override +// public void onFailure(int arg0, String arg1, Throwable arg2) { +// // TODO Auto-generated method stub +// // printResult(arg1); +// } +// }); +// } +// +// /** +// * 设置行政区划的adapter +// * +// * @param spinner 要设置adapter的spinner +// * @param obj 用于填充adapter的数据源 +// */ +// protected void setDistrictAdapter(Spinner spinner, final DistrictResultObject obj) { +// List names = new ArrayList(); +// List ids = new ArrayList(); +// latLngs.clear(); +// final List districtResults = obj.result.get(0); +// for (final DistrictResultObject.DistrictResult result : districtResults) { +// names.add(result.fullname); +// ids.add(result.id); +// latLngs.add(result.latLng); +// Log.d("位置", "setDistrictAdapter: " + result.fullname); +// +// } +// ArrayAdapter adapter = new ArrayAdapter(this, +// android.R.layout.simple_spinner_item, names); +// spinner.setAdapter(adapter); +// //将行政区划编码附到spinner方便后续查询 +// spinner.setTag(ids); +// +// } +// +// +// protected void printResult(final String result) { +// runOnUiThread(new Runnable() { +// +// @Override +// public void run() { +// // TODO Auto-generated method stub +// tvResult.setText(result); +// } +// }); +// } +// } diff --git a/positions/src/main/java/cc/winboll/studio/positions/demo/search/DrivingRouteActivity.java b/positions/src/main/java/cc/winboll/studio/positions/demo/search/DrivingRouteActivity.java index 63e64fc..b0972bd 100644 --- a/positions/src/main/java/cc/winboll/studio/positions/demo/search/DrivingRouteActivity.java +++ b/positions/src/main/java/cc/winboll/studio/positions/demo/search/DrivingRouteActivity.java @@ -18,58 +18,58 @@ import com.tencent.tencentmap.mapsdk.maps.model.PolylineOptions; import java.util.List; public class DrivingRouteActivity extends SupportMapFragmentActivity { - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - CameraUpdate cameraSigma = - CameraUpdateFactory.newCameraPosition(new CameraPosition( - new LatLng(24.66493, 117.09568), - 15, - 0f, - 0f)); - //移动地图 - tencentMap.moveCamera(cameraSigma); - getDrivingRoute(); - } - - private LatLng fromPoint = new LatLng(24.66493, 117.09568); // 起点坐标 - private LatLng toPoint = new LatLng(26.8857, 120.00514); //终点坐标 - - /** - * 获取驾车路线规划 - */ - private void getDrivingRoute() { - long l = (System.currentTimeMillis() / 1000)+1000; - Log.d("时间戳", "getDrivingRoute: " + l); - DrivingParam drivingParam = new DrivingParam(fromPoint, toPoint); //创建导航参数 - drivingParam.roadType(DrivingParam.RoadType.ON_MAIN_ROAD_BELOW_BRIDGE); - drivingParam.heading(90); - drivingParam.accuracy(30); - //drivingParam.departureTime(l) - TencentSearch tencentSearch = new TencentSearch(this); - tencentSearch.getRoutePlan(drivingParam, new HttpResponseListener() { - - @Override - public void onSuccess(int i, DrivingResultObject drivingResultObject) { - if (drivingResultObject == null) { - return; - } - for (DrivingResultObject.Route route : drivingResultObject.result.routes) { - List lines = route.polyline; - tencentMap.addPolyline(new PolylineOptions().addAll(lines).color(0x22ff0000)); - tencentMap.moveCamera(CameraUpdateFactory.newLatLngBounds(LatLngBounds.builder() - .include(route.polyline).build(), 100)); - tencentMap.moveCamera(CameraUpdateFactory.newLatLngBounds(LatLngBounds.builder() - .include(lines).build(), 100)); - } - } - - @Override - public void onFailure(int i, String s, Throwable throwable) { - - } - }); - } +// @Override +// protected void onCreate(Bundle savedInstanceState) { +// super.onCreate(savedInstanceState); +// CameraUpdate cameraSigma = +// CameraUpdateFactory.newCameraPosition(new CameraPosition( +// new LatLng(24.66493, 117.09568), +// 15, +// 0f, +// 0f)); +// //移动地图 +// tencentMap.moveCamera(cameraSigma); +// getDrivingRoute(); +// } +// +// private LatLng fromPoint = new LatLng(24.66493, 117.09568); // 起点坐标 +// private LatLng toPoint = new LatLng(26.8857, 120.00514); //终点坐标 +// +// /** +// * 获取驾车路线规划 +// */ +// private void getDrivingRoute() { +// long l = (System.currentTimeMillis() / 1000)+1000; +// Log.d("时间戳", "getDrivingRoute: " + l); +// DrivingParam drivingParam = new DrivingParam(fromPoint, toPoint); //创建导航参数 +// drivingParam.roadType(DrivingParam.RoadType.ON_MAIN_ROAD_BELOW_BRIDGE); +// drivingParam.heading(90); +// drivingParam.accuracy(30); +// //drivingParam.departureTime(l) +// TencentSearch tencentSearch = new TencentSearch(this); +// tencentSearch.getRoutePlan(drivingParam, new HttpResponseListener() { +// +// @Override +// public void onSuccess(int i, DrivingResultObject drivingResultObject) { +// if (drivingResultObject == null) { +// return; +// } +// for (DrivingResultObject.Route route : drivingResultObject.result.routes) { +// List lines = route.polyline; +// tencentMap.addPolyline(new PolylineOptions().addAll(lines).color(0x22ff0000)); +// tencentMap.moveCamera(CameraUpdateFactory.newLatLngBounds(LatLngBounds.builder() +// .include(route.polyline).build(), 100)); +// tencentMap.moveCamera(CameraUpdateFactory.newLatLngBounds(LatLngBounds.builder() +// .include(lines).build(), 100)); +// } +// } +// +// @Override +// public void onFailure(int i, String s, Throwable throwable) { +// +// } +// }); +// } } diff --git a/positions/src/main/java/cc/winboll/studio/positions/demo/search/GeoCoderActivity.java b/positions/src/main/java/cc/winboll/studio/positions/demo/search/GeoCoderActivity.java index b06c3c2..2530362 100644 --- a/positions/src/main/java/cc/winboll/studio/positions/demo/search/GeoCoderActivity.java +++ b/positions/src/main/java/cc/winboll/studio/positions/demo/search/GeoCoderActivity.java @@ -25,162 +25,162 @@ import com.tencent.tencentmap.mapsdk.maps.model.MarkerOptions; public class GeoCoderActivity extends SupportMapFragmentActivity { - private EditText etGeocoder; - private Button btnGeocoder; - private EditText etRegeocoder; - private Button btnRegeocoder; - private TextView tvResult; - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - initView(); - } - - - private void initView(){ - etGeocoder = (EditText) findViewById(R.id.et_geocoder); - btnGeocoder = (Button) findViewById(R.id.btn_geocoder); - etRegeocoder = (EditText) findViewById(R.id.et_regeocoder); - btnRegeocoder = (Button) findViewById(R.id.btn_regeocoder); - etGeocoder.setVisibility(View.VISIBLE); - btnGeocoder.setVisibility(View.VISIBLE); - etRegeocoder.setVisibility(View.VISIBLE); - btnRegeocoder.setVisibility(View.VISIBLE); - tvResult = (TextView) findViewById(R.id.tv_result); - tvResult.setVisibility(View.VISIBLE); - btnGeocoder.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - geocoder(); - } - }); - - btnRegeocoder.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - reGeocoder(); - } - }); - } - /** - *地理编码 - */ - protected void geocoder() { - TencentSearch tencentSearch = new TencentSearch(this); - String address = etGeocoder.getText().toString(); - Address2GeoParam address2GeoParam = - new Address2GeoParam(address).region("北京"); - tencentSearch.address2geo(address2GeoParam, new HttpResponseListener() { - - @Override - public void onSuccess(int arg0, BaseObject arg1) { - // TODO Auto-generated method stub - if (arg1 == null) { - return; - } - Address2GeoResultObject obj = (Address2GeoResultObject)arg1; - StringBuilder sb = new StringBuilder(); - sb.append("地址解析"); - if (obj.result.latLng != null) { - sb.append("\n坐标:" + obj.result.latLng.toString()); - } else { - sb.append("\n无坐标"); - } - printResult(sb.toString()); - tencentMap.moveCamera(CameraUpdateFactory.newCameraPosition(new CameraPosition(obj.result.latLng,15f, 0, 0))); - tencentMap.addMarker(new MarkerOptions() - .position(obj.result.latLng)); - } - - @Override - public void onFailure(int arg0, String arg1, Throwable arg2) { - // TODO Auto-generated method stub - printResult(arg1); - } - }); - } - - /** - * 逆地理编码 - */ - protected void reGeocoder() { - String str = etRegeocoder.getText().toString().trim(); - LatLng latLng = str2Coordinate(this, str); - if (latLng == null) { - return; - } - TencentSearch tencentSearch = new TencentSearch(this); - //还可以传入其他坐标系的坐标,不过需要用coord_type()指明所用类型 - //这里设置返回周边poi列表,可以在一定程度上满足用户获取指定坐标周边poi的需求 - Geo2AddressParam geo2AddressParam = new Geo2AddressParam(latLng).getPoi(true) - .setPoiOptions(new Geo2AddressParam.PoiOptions() - .setRadius(1000).setCategorys("面包") - .setPolicy(Geo2AddressParam.PoiOptions.POLICY_O2O)); - tencentSearch.geo2address(geo2AddressParam, new HttpResponseListener() { - - @Override - public void onSuccess(int arg0, BaseObject arg1) { - // TODO Auto-generated method stub - if (arg1 == null) { - return; - } - Geo2AddressResultObject obj = (Geo2AddressResultObject)arg1; - StringBuilder sb = new StringBuilder(); - sb.append("逆地址解析"); - sb.append("\n地址:" + obj.result.address); - sb.append("\npois:"); - for (Poi poi : obj.result.pois) { - sb.append("\n\t" + poi.title); - tencentMap.addMarker(new MarkerOptions() - .position(poi.latLng) //标注的位置 - .title(poi.title) //标注的InfoWindow的标题 - .snippet(poi.address) //标注的InfoWindow的内容 - ); - } - //printResult(sb.toString()); - } - - @Override - public void onFailure(int arg0, String arg1, Throwable arg2) { - // TODO Auto-generated method stub - printResult(arg1); - } - }); - } - - - /** - * 由字符串获取坐标 - * @param context - * @param str - * @return - */ - public static LatLng str2Coordinate(Context context, String str) { - if (!str.contains(",")) { - Toast.makeText(context, "经纬度用\",\"分割", Toast.LENGTH_SHORT).show(); - return null; - } - String[] strs = str.split(","); - double lat = 0; - double lng = 0; - try { - lat = Double.parseDouble(strs[0]); - lng = Double.parseDouble(strs[1]); - } catch (NumberFormatException e) { - Toast.makeText(context, e.toString(), Toast.LENGTH_SHORT).show(); - return null; - } - return new LatLng(lat, lng); - } - protected void printResult(final String result) { - runOnUiThread(new Runnable() { - - @Override - public void run() { - // TODO Auto-generated method stub - tvResult.setText(result); - } - }); - } +// private EditText etGeocoder; +// private Button btnGeocoder; +// private EditText etRegeocoder; +// private Button btnRegeocoder; +// private TextView tvResult; +// +// @Override +// protected void onCreate(Bundle savedInstanceState) { +// super.onCreate(savedInstanceState); +// initView(); +// } +// +// +// private void initView(){ +// etGeocoder = (EditText) findViewById(R.id.et_geocoder); +// btnGeocoder = (Button) findViewById(R.id.btn_geocoder); +// etRegeocoder = (EditText) findViewById(R.id.et_regeocoder); +// btnRegeocoder = (Button) findViewById(R.id.btn_regeocoder); +// etGeocoder.setVisibility(View.VISIBLE); +// btnGeocoder.setVisibility(View.VISIBLE); +// etRegeocoder.setVisibility(View.VISIBLE); +// btnRegeocoder.setVisibility(View.VISIBLE); +// tvResult = (TextView) findViewById(R.id.tv_result); +// tvResult.setVisibility(View.VISIBLE); +// btnGeocoder.setOnClickListener(new View.OnClickListener() { +// @Override +// public void onClick(View view) { +// geocoder(); +// } +// }); +// +// btnRegeocoder.setOnClickListener(new View.OnClickListener() { +// @Override +// public void onClick(View view) { +// reGeocoder(); +// } +// }); +// } +// /** +// *地理编码 +// */ +// protected void geocoder() { +// TencentSearch tencentSearch = new TencentSearch(this); +// String address = etGeocoder.getText().toString(); +// Address2GeoParam address2GeoParam = +// new Address2GeoParam(address).region("北京"); +// tencentSearch.address2geo(address2GeoParam, new HttpResponseListener() { +// +// @Override +// public void onSuccess(int arg0, BaseObject arg1) { +// // TODO Auto-generated method stub +// if (arg1 == null) { +// return; +// } +// Address2GeoResultObject obj = (Address2GeoResultObject)arg1; +// StringBuilder sb = new StringBuilder(); +// sb.append("地址解析"); +// if (obj.result.latLng != null) { +// sb.append("\n坐标:" + obj.result.latLng.toString()); +// } else { +// sb.append("\n无坐标"); +// } +// printResult(sb.toString()); +// tencentMap.moveCamera(CameraUpdateFactory.newCameraPosition(new CameraPosition(obj.result.latLng,15f, 0, 0))); +// tencentMap.addMarker(new MarkerOptions() +// .position(obj.result.latLng)); +// } +// +// @Override +// public void onFailure(int arg0, String arg1, Throwable arg2) { +// // TODO Auto-generated method stub +// printResult(arg1); +// } +// }); +// } +// +// /** +// * 逆地理编码 +// */ +// protected void reGeocoder() { +// String str = etRegeocoder.getText().toString().trim(); +// LatLng latLng = str2Coordinate(this, str); +// if (latLng == null) { +// return; +// } +// TencentSearch tencentSearch = new TencentSearch(this); +// //还可以传入其他坐标系的坐标,不过需要用coord_type()指明所用类型 +// //这里设置返回周边poi列表,可以在一定程度上满足用户获取指定坐标周边poi的需求 +// Geo2AddressParam geo2AddressParam = new Geo2AddressParam(latLng).getPoi(true) +// .setPoiOptions(new Geo2AddressParam.PoiOptions() +// .setRadius(1000).setCategorys("面包") +// .setPolicy(Geo2AddressParam.PoiOptions.POLICY_O2O)); +// tencentSearch.geo2address(geo2AddressParam, new HttpResponseListener() { +// +// @Override +// public void onSuccess(int arg0, BaseObject arg1) { +// // TODO Auto-generated method stub +// if (arg1 == null) { +// return; +// } +// Geo2AddressResultObject obj = (Geo2AddressResultObject)arg1; +// StringBuilder sb = new StringBuilder(); +// sb.append("逆地址解析"); +// sb.append("\n地址:" + obj.result.address); +// sb.append("\npois:"); +// for (Poi poi : obj.result.pois) { +// sb.append("\n\t" + poi.title); +// tencentMap.addMarker(new MarkerOptions() +// .position(poi.latLng) //标注的位置 +// .title(poi.title) //标注的InfoWindow的标题 +// .snippet(poi.address) //标注的InfoWindow的内容 +// ); +// } +// //printResult(sb.toString()); +// } +// +// @Override +// public void onFailure(int arg0, String arg1, Throwable arg2) { +// // TODO Auto-generated method stub +// printResult(arg1); +// } +// }); +// } +// +// +// /** +// * 由字符串获取坐标 +// * @param context +// * @param str +// * @return +// */ +// public static LatLng str2Coordinate(Context context, String str) { +// if (!str.contains(",")) { +// Toast.makeText(context, "经纬度用\",\"分割", Toast.LENGTH_SHORT).show(); +// return null; +// } +// String[] strs = str.split(","); +// double lat = 0; +// double lng = 0; +// try { +// lat = Double.parseDouble(strs[0]); +// lng = Double.parseDouble(strs[1]); +// } catch (NumberFormatException e) { +// Toast.makeText(context, e.toString(), Toast.LENGTH_SHORT).show(); +// return null; +// } +// return new LatLng(lat, lng); +// } +// protected void printResult(final String result) { +// runOnUiThread(new Runnable() { +// +// @Override +// public void run() { +// // TODO Auto-generated method stub +// tvResult.setText(result); +// } +// }); +// } } diff --git a/positions/src/main/java/cc/winboll/studio/positions/demo/search/SearchBasicActivity.java b/positions/src/main/java/cc/winboll/studio/positions/demo/search/SearchBasicActivity.java index 9a40c05..f97239a 100644 --- a/positions/src/main/java/cc/winboll/studio/positions/demo/search/SearchBasicActivity.java +++ b/positions/src/main/java/cc/winboll/studio/positions/demo/search/SearchBasicActivity.java @@ -34,272 +34,272 @@ import java.lang.ref.WeakReference; import java.util.List; public class SearchBasicActivity extends SupportMapFragmentActivity { - private EditText etSearch; - private Button btnSearch; - private ListView lvSuggesion; - private SuggestionAdapter suggestionAdapter; - private final int MSG_SUGGESTION = 10000; - private final MyHandler handler = new MyHandler(this); - - private static class MyHandler extends Handler { - private final WeakReference mActivity; - - public MyHandler(SearchBasicActivity activity) { - // TODO Auto-generated constructor stub - mActivity = new WeakReference<>(activity); - } - - @Override - public void handleMessage(Message msg) { - // TODO Auto-generated method stub - SearchBasicActivity activity = mActivity.get(); - if (activity != null) { - activity.handleMessage(msg); - } - } - } - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - initView(); - } - - protected void initView(){ - etSearch = (EditText) findViewById(R.id.et_search_poi); - btnSearch = (Button) findViewById(R.id.btn_search_poi); - etSearch.setVisibility(View.VISIBLE); - btnSearch.setVisibility(View.VISIBLE); - lvSuggesion = (ListView) findViewById(R.id.lv_suggestions); - - etSearch.addTextChangedListener(textWatcher); - etSearch.setOnFocusChangeListener(new View.OnFocusChangeListener() { - - @Override - public void onFocusChange(View v, boolean hasFocus) { - // TODO Auto-generated method stub - if (!etSearch.hasFocus()) { - lvSuggesion.setVisibility(View.GONE); - } - } - }); - - lvSuggesion.setOnItemClickListener(new AdapterView.OnItemClickListener() { - - @Override - public void onItemClick(AdapterView parent, View view, - int position, long id) { - // TODO Auto-generated method stub - etSearch.removeTextChangedListener(textWatcher); - CharSequence cs = - ((TextView)view.findViewById(R.id.label)).getText(); - etSearch.setText(cs); - lvSuggesion.setVisibility(View.GONE); - etSearch.addTextChangedListener(textWatcher); - } - }); - - btnSearch.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - searchPoi(); - } - }); - } - - final TextWatcher textWatcher = new TextWatcher() { - - @Override - public void onTextChanged(CharSequence s, int start, int before, int count) { - // TODO Auto-generated method stub - suggestion(s.toString()); - } - - @Override - public void beforeTextChanged(CharSequence s, int start, int count, - int after) { - // TODO Auto-generated method stub - - } - - @Override - public void afterTextChanged(Editable s) { - // TODO Auto-generated method stub - - } - }; - - - - /** - * poi检索 - */ - protected void searchPoi() { - TencentSearch tencentSearch = new TencentSearch(this); - String keyWord = etSearch.getText().toString().trim(); - //城市搜索 - SearchParam.Region region = new SearchParam.Region("北京").//设置搜索城市 - autoExtend(false);//设置搜索范围不扩大 - //圆形范围搜索 - LatLng latLng1 = new LatLng(39.984154, 116.307490); - SearchParam.Nearby nearBy = new SearchParam.Nearby(latLng1, 1000); - //矩形搜索,这里的范围是故宫 - LatLng latLng2 = new LatLng(39.913127, 116.392164); - LatLng latLng3 = new LatLng(39.923034, 116.402078); - SearchParam.Rectangle rectangle = new SearchParam.Rectangle(latLng2, latLng3); - - //filter()方法可以设置过滤类别, - //search接口还提供了排序方式、返回条目数、返回页码具体用法见文档, - //同时也可以参考官网的webservice对应接口的说明 - SearchParam searchParam = new SearchParam(keyWord, region);//.pageIndex(0).pageSize(20).filter("大学,中学"); - tencentSearch.search(searchParam, new HttpResponseListener() { - - @Override - public void onFailure(int arg0, String arg2, - Throwable arg3) { - Toast.makeText(getApplicationContext(), arg2, Toast.LENGTH_LONG).show(); - } - - @Override - public void onSuccess(int arg0, BaseObject arg1) { - if (arg1 == null) { - return; - } - SearchResultObject obj = (SearchResultObject) arg1; - if(obj.data == null){ - return; - } - tencentMap.moveCamera(CameraUpdateFactory.newCameraPosition(new CameraPosition(obj.data.get(0).latLng,15f, 0, 0))); - for(SearchResultObject.SearchResultData data : obj.data){ - Log.v("SearchDemo","title:"+data.title + ";" + data.address); - tencentMap.addMarker(new MarkerOptions() - .position(data.latLng) //标注的位置 - .title(data.title) //标注的InfoWindow的标题 - .snippet(data.address) //标注的InfoWindow的内容 - ); - - } - } - }); - } - - public void handleMessage(Message msg) { - switch (msg.what) { - case MSG_SUGGESTION: - showAutoComplete((SuggestionResultObject)msg.obj); - break; - - default: - break; - } - } - - /** - * 显示完整ListView - * @param obj - */ - protected void showAutoComplete(SuggestionResultObject obj) { - if (obj.data.size() == 0) { - lvSuggesion.setVisibility(View.GONE); - return; - } - if (suggestionAdapter == null) { - suggestionAdapter = new SuggestionAdapter(obj.data); - lvSuggesion.setAdapter(suggestionAdapter); - } else { - suggestionAdapter.setDatas(obj.data); - suggestionAdapter.notifyDataSetChanged(); - } - lvSuggesion.setVisibility(View.VISIBLE); - } - /** - * 关键字提示 - * @param keyword - */ - protected void suggestion(String keyword) { - if (keyword.trim().length() == 0) { - lvSuggesion.setVisibility(View.GONE); - return; - } - TencentSearch tencentSearch = new TencentSearch(this); - SuggestionParam suggestionParam = new SuggestionParam(keyword, "北京"); - //suggestion也提供了filter()方法和region方法 - //具体说明见文档,或者官网的webservice对应接口 - tencentSearch.suggestion(suggestionParam, new HttpResponseListener() { - - @Override - public void onSuccess(int arg0, BaseObject arg1) { - if (arg1 == null || - etSearch.getText().toString().trim().length() == 0) { - lvSuggesion.setVisibility(View.GONE); - return; - } - - Message msg = new Message(); - msg.what = MSG_SUGGESTION; - msg.obj = arg1; - handler.sendMessage(msg); - } - - @Override - public void onFailure(int arg0, String arg1, Throwable arg2) { - //printResult(arg1); - } - }); - } - - class SuggestionAdapter extends BaseAdapter { - - List mSuggestionDatas; - - public SuggestionAdapter(List suggestionDatas) { - // TODO Auto-generated constructor stub - setDatas(suggestionDatas); - } - - public void setDatas(List suggestionDatas) { - mSuggestionDatas = suggestionDatas; - } - - @Override - public int getCount() { - // TODO Auto-generated method stub - return mSuggestionDatas.size(); - } - - @Override - public Object getItem(int position) { - // TODO Auto-generated method stub - return mSuggestionDatas.get(position); - } - - @Override - public long getItemId(int position) { - // TODO Auto-generated method stub - return position; - } - - @Override - public View getView(int position, View convertView, ViewGroup parent) { - // TODO Auto-generated method stub - ViewHolder viewHolder; - if (convertView == null) { - convertView = View.inflate(SearchBasicActivity.this, - R.layout.suggestion_list_item, null); - viewHolder = new ViewHolder(); - viewHolder.tvTitle = (TextView) convertView.findViewById(R.id.label); - viewHolder.tvAddress = (TextView) convertView.findViewById(R.id.desc); - convertView.setTag(viewHolder); - } else { - viewHolder = (ViewHolder) convertView.getTag(); - } - viewHolder.tvTitle.setText(mSuggestionDatas.get(position).title); - viewHolder.tvAddress.setText(mSuggestionDatas.get(position).address); - return convertView; - } - - private class ViewHolder{ - TextView tvTitle; - TextView tvAddress; - } - } +// private EditText etSearch; +// private Button btnSearch; +// private ListView lvSuggesion; +// private SuggestionAdapter suggestionAdapter; +// private final int MSG_SUGGESTION = 10000; +// private final MyHandler handler = new MyHandler(this); +// +// private static class MyHandler extends Handler { +// private final WeakReference mActivity; +// +// public MyHandler(SearchBasicActivity activity) { +// // TODO Auto-generated constructor stub +// mActivity = new WeakReference<>(activity); +// } +// +// @Override +// public void handleMessage(Message msg) { +// // TODO Auto-generated method stub +// SearchBasicActivity activity = mActivity.get(); +// if (activity != null) { +// activity.handleMessage(msg); +// } +// } +// } +// @Override +// protected void onCreate(Bundle savedInstanceState) { +// super.onCreate(savedInstanceState); +// initView(); +// } +// +// protected void initView(){ +// etSearch = (EditText) findViewById(R.id.et_search_poi); +// btnSearch = (Button) findViewById(R.id.btn_search_poi); +// etSearch.setVisibility(View.VISIBLE); +// btnSearch.setVisibility(View.VISIBLE); +// lvSuggesion = (ListView) findViewById(R.id.lv_suggestions); +// +// etSearch.addTextChangedListener(textWatcher); +// etSearch.setOnFocusChangeListener(new View.OnFocusChangeListener() { +// +// @Override +// public void onFocusChange(View v, boolean hasFocus) { +// // TODO Auto-generated method stub +// if (!etSearch.hasFocus()) { +// lvSuggesion.setVisibility(View.GONE); +// } +// } +// }); +// +// lvSuggesion.setOnItemClickListener(new AdapterView.OnItemClickListener() { +// +// @Override +// public void onItemClick(AdapterView parent, View view, +// int position, long id) { +// // TODO Auto-generated method stub +// etSearch.removeTextChangedListener(textWatcher); +// CharSequence cs = +// ((TextView)view.findViewById(R.id.label)).getText(); +// etSearch.setText(cs); +// lvSuggesion.setVisibility(View.GONE); +// etSearch.addTextChangedListener(textWatcher); +// } +// }); +// +// btnSearch.setOnClickListener(new View.OnClickListener() { +// @Override +// public void onClick(View view) { +// searchPoi(); +// } +// }); +// } +// +// final TextWatcher textWatcher = new TextWatcher() { +// +// @Override +// public void onTextChanged(CharSequence s, int start, int before, int count) { +// // TODO Auto-generated method stub +// suggestion(s.toString()); +// } +// +// @Override +// public void beforeTextChanged(CharSequence s, int start, int count, +// int after) { +// // TODO Auto-generated method stub +// +// } +// +// @Override +// public void afterTextChanged(Editable s) { +// // TODO Auto-generated method stub +// +// } +// }; +// +// +// +// /** +// * poi检索 +// */ +// protected void searchPoi() { +// TencentSearch tencentSearch = new TencentSearch(this); +// String keyWord = etSearch.getText().toString().trim(); +// //城市搜索 +// SearchParam.Region region = new SearchParam.Region("北京").//设置搜索城市 +// autoExtend(false);//设置搜索范围不扩大 +// //圆形范围搜索 +// LatLng latLng1 = new LatLng(39.984154, 116.307490); +// SearchParam.Nearby nearBy = new SearchParam.Nearby(latLng1, 1000); +// //矩形搜索,这里的范围是故宫 +// LatLng latLng2 = new LatLng(39.913127, 116.392164); +// LatLng latLng3 = new LatLng(39.923034, 116.402078); +// SearchParam.Rectangle rectangle = new SearchParam.Rectangle(latLng2, latLng3); +// +// //filter()方法可以设置过滤类别, +// //search接口还提供了排序方式、返回条目数、返回页码具体用法见文档, +// //同时也可以参考官网的webservice对应接口的说明 +// SearchParam searchParam = new SearchParam(keyWord, region);//.pageIndex(0).pageSize(20).filter("大学,中学"); +// tencentSearch.search(searchParam, new HttpResponseListener() { +// +// @Override +// public void onFailure(int arg0, String arg2, +// Throwable arg3) { +// Toast.makeText(getApplicationContext(), arg2, Toast.LENGTH_LONG).show(); +// } +// +// @Override +// public void onSuccess(int arg0, BaseObject arg1) { +// if (arg1 == null) { +// return; +// } +// SearchResultObject obj = (SearchResultObject) arg1; +// if(obj.data == null){ +// return; +// } +// tencentMap.moveCamera(CameraUpdateFactory.newCameraPosition(new CameraPosition(obj.data.get(0).latLng,15f, 0, 0))); +// for(SearchResultObject.SearchResultData data : obj.data){ +// Log.v("SearchDemo","title:"+data.title + ";" + data.address); +// tencentMap.addMarker(new MarkerOptions() +// .position(data.latLng) //标注的位置 +// .title(data.title) //标注的InfoWindow的标题 +// .snippet(data.address) //标注的InfoWindow的内容 +// ); +// +// } +// } +// }); +// } +// +// public void handleMessage(Message msg) { +// switch (msg.what) { +// case MSG_SUGGESTION: +// showAutoComplete((SuggestionResultObject)msg.obj); +// break; +// +// default: +// break; +// } +// } +// +// /** +// * 显示完整ListView +// * @param obj +// */ +// protected void showAutoComplete(SuggestionResultObject obj) { +// if (obj.data.size() == 0) { +// lvSuggesion.setVisibility(View.GONE); +// return; +// } +// if (suggestionAdapter == null) { +// suggestionAdapter = new SuggestionAdapter(obj.data); +// lvSuggesion.setAdapter(suggestionAdapter); +// } else { +// suggestionAdapter.setDatas(obj.data); +// suggestionAdapter.notifyDataSetChanged(); +// } +// lvSuggesion.setVisibility(View.VISIBLE); +// } +// /** +// * 关键字提示 +// * @param keyword +// */ +// protected void suggestion(String keyword) { +// if (keyword.trim().length() == 0) { +// lvSuggesion.setVisibility(View.GONE); +// return; +// } +// TencentSearch tencentSearch = new TencentSearch(this); +// SuggestionParam suggestionParam = new SuggestionParam(keyword, "北京"); +// //suggestion也提供了filter()方法和region方法 +// //具体说明见文档,或者官网的webservice对应接口 +// tencentSearch.suggestion(suggestionParam, new HttpResponseListener() { +// +// @Override +// public void onSuccess(int arg0, BaseObject arg1) { +// if (arg1 == null || +// etSearch.getText().toString().trim().length() == 0) { +// lvSuggesion.setVisibility(View.GONE); +// return; +// } +// +// Message msg = new Message(); +// msg.what = MSG_SUGGESTION; +// msg.obj = arg1; +// handler.sendMessage(msg); +// } +// +// @Override +// public void onFailure(int arg0, String arg1, Throwable arg2) { +// //printResult(arg1); +// } +// }); +// } +// +// class SuggestionAdapter extends BaseAdapter { +// +// List mSuggestionDatas; +// +// public SuggestionAdapter(List suggestionDatas) { +// // TODO Auto-generated constructor stub +// setDatas(suggestionDatas); +// } +// +// public void setDatas(List suggestionDatas) { +// mSuggestionDatas = suggestionDatas; +// } +// +// @Override +// public int getCount() { +// // TODO Auto-generated method stub +// return mSuggestionDatas.size(); +// } +// +// @Override +// public Object getItem(int position) { +// // TODO Auto-generated method stub +// return mSuggestionDatas.get(position); +// } +// +// @Override +// public long getItemId(int position) { +// // TODO Auto-generated method stub +// return position; +// } +// +// @Override +// public View getView(int position, View convertView, ViewGroup parent) { +// // TODO Auto-generated method stub +// ViewHolder viewHolder; +// if (convertView == null) { +// convertView = View.inflate(SearchBasicActivity.this, +// R.layout.suggestion_list_item, null); +// viewHolder = new ViewHolder(); +// viewHolder.tvTitle = (TextView) convertView.findViewById(R.id.label); +// viewHolder.tvAddress = (TextView) convertView.findViewById(R.id.desc); +// convertView.setTag(viewHolder); +// } else { +// viewHolder = (ViewHolder) convertView.getTag(); +// } +// viewHolder.tvTitle.setText(mSuggestionDatas.get(position).title); +// viewHolder.tvAddress.setText(mSuggestionDatas.get(position).address); +// return convertView; +// } +// +// private class ViewHolder{ +// TextView tvTitle; +// TextView tvAddress; +// } +// } } diff --git a/positions/src/main/java/cc/winboll/studio/positions/demo/search/TransitRouteActivity.java b/positions/src/main/java/cc/winboll/studio/positions/demo/search/TransitRouteActivity.java index cdd488e..10c7c31 100644 --- a/positions/src/main/java/cc/winboll/studio/positions/demo/search/TransitRouteActivity.java +++ b/positions/src/main/java/cc/winboll/studio/positions/demo/search/TransitRouteActivity.java @@ -1,93 +1,93 @@ -package cc.winboll.studio.positions.demo.search; - -import android.os.Bundle; -import android.util.Log; - -import com.tencent.lbssearch.TencentSearch; -import com.tencent.lbssearch.httpresponse.HttpResponseListener; -import com.tencent.lbssearch.object.param.TransitParam; -import com.tencent.lbssearch.object.result.TransitResultObject; -import cc.winboll.studio.positions.demo.basic.SupportMapFragmentActivity; -import com.tencent.tencentmap.mapsdk.maps.CameraUpdateFactory; -import com.tencent.tencentmap.mapsdk.maps.TencentMap; -import com.tencent.tencentmap.mapsdk.maps.model.CameraPosition; -import com.tencent.tencentmap.mapsdk.maps.model.LatLng; -import com.tencent.tencentmap.mapsdk.maps.model.PolylineOptions; - -import java.util.List; - -public class TransitRouteActivity extends SupportMapFragmentActivity { - private LatLng fromPoint = new LatLng(40.127265, 116.208051); // 起点坐标 - private LatLng toPoint = new LatLng(40.040219, 116.273348); //终点坐标 - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - //移动地图 - tencentMap.moveCamera(CameraUpdateFactory.newCameraPosition(new CameraPosition( - new LatLng(40.080287, 116.244949), - 12, - 0f, - 0f))); - getTransitRoute(); - tencentMap.setOnMapClickListener(new TencentMap.OnMapClickListener() { - @Override - public void onMapClick(LatLng latLng) { - Log.d("TAG", "onMapClick: "+latLng); - } - }); - } - - /** - * 获取公交路径规划 - * TransitResultObject中的Segment是抽象类,要转换成具体的子类才能获取数据 - */ - private void getTransitRoute() { - TransitParam transitParam = new TransitParam(fromPoint, toPoint); - TencentSearch tencentSearch = new TencentSearch(this); - transitParam.policy(TransitParam.Policy.LEAST_WALKING, TransitParam.Preference.NO_SUBWAY); - tencentSearch.getRoutePlan(transitParam, new HttpResponseListener() { - - @Override - public void onSuccess(int i, TransitResultObject transitResultObject) { - if (transitResultObject == null) { - Log.i("TAG", "baseObject为空"); - return; - } - showTransitRoute(transitResultObject); - - } - - @Override - public void onFailure(int i, String s, Throwable throwable) { - Log.d("TransitRouteActivity", "onFailure: " + s); - } - }); - } - - private void showTransitRoute(TransitResultObject transitResultObject) { - tencentMap.clearAllOverlays(); - if (transitResultObject.result != null && transitResultObject.result.routes != null && transitResultObject.result.routes.size() > 0) { - for (int i = 0; i < transitResultObject.result.routes.size(); i++) { - TransitResultObject.Route route = transitResultObject.result.routes.get(i); - - List steps = route.steps; - for (int j = 0; j < steps.size(); j++) { - TransitResultObject.Segment segment = steps.get(j); - if (segment instanceof TransitResultObject.Transit) { - TransitResultObject.Transit transit = (TransitResultObject.Transit) segment; - tencentMap.addPolyline(new PolylineOptions().addAll(transit.lines.get(0).polyline).color(i + 1).width(20)); - - } else if (segment instanceof TransitResultObject.Walking) { - TransitResultObject.Walking walking = (TransitResultObject.Walking) segment; - tencentMap.addPolyline(new PolylineOptions().addAll(walking.polyline).color(j + 1).lineType(PolylineOptions.LineType.LINE_TYPE_IMAGEINARYLINE).width(20)); - } - - } - } - - } else { - Log.i("TAG", "路线结果为空"); - } - } -} \ No newline at end of file +package cc.winboll.studio.positions.demo.search; + +//import android.os.Bundle; +//import android.util.Log; +// +//import com.tencent.lbssearch.TencentSearch; +//import com.tencent.lbssearch.httpresponse.HttpResponseListener; +//import com.tencent.lbssearch.object.param.TransitParam; +//import com.tencent.lbssearch.object.result.TransitResultObject; +//import cc.winboll.studio.positions.demo.basic.SupportMapFragmentActivity; +//import com.tencent.tencentmap.mapsdk.maps.CameraUpdateFactory; +//import com.tencent.tencentmap.mapsdk.maps.TencentMap; +//import com.tencent.tencentmap.mapsdk.maps.model.CameraPosition; +//import com.tencent.tencentmap.mapsdk.maps.model.LatLng; +//import com.tencent.tencentmap.mapsdk.maps.model.PolylineOptions; +// +//import java.util.List; +// +//public class TransitRouteActivity extends SupportMapFragmentActivity { +// private LatLng fromPoint = new LatLng(40.127265, 116.208051); // 起点坐标 +// private LatLng toPoint = new LatLng(40.040219, 116.273348); //终点坐标 +// +// @Override +// protected void onCreate(Bundle savedInstanceState) { +// super.onCreate(savedInstanceState); +// //移动地图 +// tencentMap.moveCamera(CameraUpdateFactory.newCameraPosition(new CameraPosition( +// new LatLng(40.080287, 116.244949), +// 12, +// 0f, +// 0f))); +// getTransitRoute(); +// tencentMap.setOnMapClickListener(new TencentMap.OnMapClickListener() { +// @Override +// public void onMapClick(LatLng latLng) { +// Log.d("TAG", "onMapClick: "+latLng); +// } +// }); +// } +// +// /** +// * 获取公交路径规划 +// * TransitResultObject中的Segment是抽象类,要转换成具体的子类才能获取数据 +// */ +// private void getTransitRoute() { +// TransitParam transitParam = new TransitParam(fromPoint, toPoint); +// TencentSearch tencentSearch = new TencentSearch(this); +// transitParam.policy(TransitParam.Policy.LEAST_WALKING, TransitParam.Preference.NO_SUBWAY); +// tencentSearch.getRoutePlan(transitParam, new HttpResponseListener() { +// +// @Override +// public void onSuccess(int i, TransitResultObject transitResultObject) { +// if (transitResultObject == null) { +// Log.i("TAG", "baseObject为空"); +// return; +// } +// showTransitRoute(transitResultObject); +// +// } +// +// @Override +// public void onFailure(int i, String s, Throwable throwable) { +// Log.d("TransitRouteActivity", "onFailure: " + s); +// } +// }); +// } +// +// private void showTransitRoute(TransitResultObject transitResultObject) { +// tencentMap.clearAllOverlays(); +// if (transitResultObject.result != null && transitResultObject.result.routes != null && transitResultObject.result.routes.size() > 0) { +// for (int i = 0; i < transitResultObject.result.routes.size(); i++) { +// TransitResultObject.Route route = transitResultObject.result.routes.get(i); +// +// List steps = route.steps; +// for (int j = 0; j < steps.size(); j++) { +// TransitResultObject.Segment segment = steps.get(j); +// if (segment instanceof TransitResultObject.Transit) { +// TransitResultObject.Transit transit = (TransitResultObject.Transit) segment; +// tencentMap.addPolyline(new PolylineOptions().addAll(transit.lines.get(0).polyline).color(i + 1).width(20)); +// +// } else if (segment instanceof TransitResultObject.Walking) { +// TransitResultObject.Walking walking = (TransitResultObject.Walking) segment; +// tencentMap.addPolyline(new PolylineOptions().addAll(walking.polyline).color(j + 1).lineType(PolylineOptions.LineType.LINE_TYPE_IMAGEINARYLINE).width(20)); +// } +// +// } +// } +// +// } else { +// Log.i("TAG", "路线结果为空"); +// } +// } +//} diff --git a/positions/src/main/java/cc/winboll/studio/positions/demo/search/TruckingRouteActivity.java b/positions/src/main/java/cc/winboll/studio/positions/demo/search/TruckingRouteActivity.java index 5924561..ecd40e8 100644 --- a/positions/src/main/java/cc/winboll/studio/positions/demo/search/TruckingRouteActivity.java +++ b/positions/src/main/java/cc/winboll/studio/positions/demo/search/TruckingRouteActivity.java @@ -1,77 +1,77 @@ -package cc.winboll.studio.positions.demo.search; - -import androidx.appcompat.app.AppCompatActivity; - -import android.os.Bundle; -import android.util.Log; - -import com.tencent.lbssearch.TencentSearch; -import com.tencent.lbssearch.httpresponse.HttpResponseListener; -import com.tencent.lbssearch.object.param.TransitParam; -import com.tencent.lbssearch.object.param.TruckingParam; -import com.tencent.lbssearch.object.result.RoutePlanningObject; -import com.tencent.lbssearch.object.result.TransitResultObject; -import com.tencent.lbssearch.object.result.TruckingResultObject; -import cc.winboll.studio.positions.R; -import cc.winboll.studio.positions.demo.basic.SupportMapFragmentActivity; -import com.tencent.tencentmap.mapsdk.maps.CameraUpdate; -import com.tencent.tencentmap.mapsdk.maps.CameraUpdateFactory; -import com.tencent.tencentmap.mapsdk.maps.model.CameraPosition; -import com.tencent.tencentmap.mapsdk.maps.model.LatLng; -import com.tencent.tencentmap.mapsdk.maps.model.LatLngBounds; -import com.tencent.tencentmap.mapsdk.maps.model.PolylineOptions; - -import java.util.List; - -public class TruckingRouteActivity extends SupportMapFragmentActivity { - private LatLng fromPoint = new LatLng(40.127265, 116.208051); // 起点坐标 - private LatLng toPoint = new LatLng(40.040219, 116.273348); //终点坐标 - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - CameraUpdate cameraSigma = - CameraUpdateFactory.newCameraPosition(new CameraPosition( - new LatLng(40.040219, 116.273348), - 15, - 0f, - 0f)); - //移动地图 - tencentMap.moveCamera(cameraSigma); - geTruckingRoute(); - } - - private void geTruckingRoute() { - TruckingParam truckingParam = new TruckingParam(); - truckingParam.from(fromPoint); - truckingParam.to(toPoint); - truckingParam.setMultRoute(1); - // truckingParam.setNoPolyline(1); - truckingParam.trafficSpeed(true); - TencentSearch tencentSearch = new TencentSearch(this); - tencentSearch.getRoutePlan(truckingParam, new HttpResponseListener() { - - @Override - public void onSuccess(int i, TruckingResultObject truckingResultObject) { - if (null != truckingResultObject.result && null != truckingResultObject.result.routes && truckingResultObject.result.routes.size() > 0) { - for (int j = 0; j < truckingResultObject.result.routes.size(); j++) { - TruckingResultObject.Result result = truckingResultObject.result; - TruckingResultObject.Route route = result.routes.get(j); - // List steps = route.steps; - tencentMap.addPolyline(new PolylineOptions().addAll(route.polyline).color(i + 1).width(20)); - tencentMap.moveCamera(CameraUpdateFactory.newLatLngBounds(LatLngBounds.builder() - .include(route.polyline).build(), 100)); - - } - } - } - - @Override - public void onFailure(int i, String s, Throwable throwable) { - Log.d("TruckingRouteActivity", "onFailure: " + s); - - } - }); - - } -} \ No newline at end of file +package cc.winboll.studio.positions.demo.search; + +import androidx.appcompat.app.AppCompatActivity; + +import android.os.Bundle; +import android.util.Log; + +import com.tencent.lbssearch.TencentSearch; +import com.tencent.lbssearch.httpresponse.HttpResponseListener; +import com.tencent.lbssearch.object.param.TransitParam; +import com.tencent.lbssearch.object.param.TruckingParam; +import com.tencent.lbssearch.object.result.RoutePlanningObject; +import com.tencent.lbssearch.object.result.TransitResultObject; +import com.tencent.lbssearch.object.result.TruckingResultObject; +import cc.winboll.studio.positions.R; +import cc.winboll.studio.positions.demo.basic.SupportMapFragmentActivity; +import com.tencent.tencentmap.mapsdk.maps.CameraUpdate; +import com.tencent.tencentmap.mapsdk.maps.CameraUpdateFactory; +import com.tencent.tencentmap.mapsdk.maps.model.CameraPosition; +import com.tencent.tencentmap.mapsdk.maps.model.LatLng; +import com.tencent.tencentmap.mapsdk.maps.model.LatLngBounds; +import com.tencent.tencentmap.mapsdk.maps.model.PolylineOptions; + +import java.util.List; + +public class TruckingRouteActivity extends SupportMapFragmentActivity { +// private LatLng fromPoint = new LatLng(40.127265, 116.208051); // 起点坐标 +// private LatLng toPoint = new LatLng(40.040219, 116.273348); //终点坐标 +// +// @Override +// protected void onCreate(Bundle savedInstanceState) { +// super.onCreate(savedInstanceState); +// CameraUpdate cameraSigma = +// CameraUpdateFactory.newCameraPosition(new CameraPosition( +// new LatLng(40.040219, 116.273348), +// 15, +// 0f, +// 0f)); +// //移动地图 +// tencentMap.moveCamera(cameraSigma); +// geTruckingRoute(); +// } +// +// private void geTruckingRoute() { +// TruckingParam truckingParam = new TruckingParam(); +// truckingParam.from(fromPoint); +// truckingParam.to(toPoint); +// truckingParam.setMultRoute(1); +// // truckingParam.setNoPolyline(1); +// truckingParam.trafficSpeed(true); +// TencentSearch tencentSearch = new TencentSearch(this); +// tencentSearch.getRoutePlan(truckingParam, new HttpResponseListener() { +// +// @Override +// public void onSuccess(int i, TruckingResultObject truckingResultObject) { +// if (null != truckingResultObject.result && null != truckingResultObject.result.routes && truckingResultObject.result.routes.size() > 0) { +// for (int j = 0; j < truckingResultObject.result.routes.size(); j++) { +// TruckingResultObject.Result result = truckingResultObject.result; +// TruckingResultObject.Route route = result.routes.get(j); +// // List steps = route.steps; +// tencentMap.addPolyline(new PolylineOptions().addAll(route.polyline).color(i + 1).width(20)); +// tencentMap.moveCamera(CameraUpdateFactory.newLatLngBounds(LatLngBounds.builder() +// .include(route.polyline).build(), 100)); +// +// } +// } +// } +// +// @Override +// public void onFailure(int i, String s, Throwable throwable) { +// Log.d("TruckingRouteActivity", "onFailure: " + s); +// +// } +// }); +// +// } +} diff --git a/positions/src/main/java/cc/winboll/studio/positions/demo/search/WalkingRouteActivity.java b/positions/src/main/java/cc/winboll/studio/positions/demo/search/WalkingRouteActivity.java index 674134d..642265b 100644 --- a/positions/src/main/java/cc/winboll/studio/positions/demo/search/WalkingRouteActivity.java +++ b/positions/src/main/java/cc/winboll/studio/positions/demo/search/WalkingRouteActivity.java @@ -17,60 +17,60 @@ import com.tencent.tencentmap.mapsdk.maps.model.PolylineOptions; public class WalkingRouteActivity extends SupportMapFragmentActivity { - private LatLng fromPoint = new LatLng(40.040219, 116.273348); // 起点坐标 - private LatLng toPoint = new LatLng(40.048055, 116.281166); //终点坐标 - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - getWalkingRoute(); - } - - /** - * 获取步行路线规划 - */ - private void getWalkingRoute() { - WalkingParam walkingParam = new WalkingParam(); - walkingParam.from(fromPoint); - walkingParam.to(toPoint); - TencentSearch tencentSearch = new TencentSearch(getApplicationContext()); - Log.i("TAG", "checkParams:" + walkingParam.checkParams()); - tencentSearch.getRoutePlan(walkingParam, new HttpResponseListener() { - @Override - public void onSuccess(int statusCode, WalkingResultObject object) { - if (object == null) { - Log.i("TAG", "baseObject为空"); - return; - } - showWalkingRoute(object); - Log.i("TAG", "message:" + object.message); - } - - @Override - public void onFailure(int statusCode, String responseString, Throwable throwable) { - Log.i("TAG:", statusCode + " " + responseString); - } - }); - } - - private void showWalkingRoute(WalkingResultObject object) { - tencentMap.clearAllOverlays(); - if (object.result != null && object.result.routes != null && object.result.routes.size() > 0) { - for (int i = 0; i < object.result.routes.size(); i++) { - WalkingResultObject.Route result = object.result.routes.get(i); - tencentMap.addPolyline(new PolylineOptions().addAll(result.polyline).color(i + 1).width(20)); - Log.i("TAG", "distance:" + result.distance + " duration:" + result.duration - + " mode:" + result.mode + " direction:" + result.direction); - for (RoutePlanningObject.Step step : result.steps) { - Log.i("TAG", "step:" + step.road_name + " " + step.distance + " " - + step.instruction + " " + step.act_desc + " " + step.dir_desc); - } - tencentMap.moveCamera(CameraUpdateFactory.newLatLngBounds(LatLngBounds.builder() - .include(result.polyline).build(), 100)); - } - - } else { - Log.i("TAG", "路线结果为空"); - } - } +// private LatLng fromPoint = new LatLng(40.040219, 116.273348); // 起点坐标 +// private LatLng toPoint = new LatLng(40.048055, 116.281166); //终点坐标 +// +// @Override +// protected void onCreate(Bundle savedInstanceState) { +// super.onCreate(savedInstanceState); +// getWalkingRoute(); +// } +// +// /** +// * 获取步行路线规划 +// */ +// private void getWalkingRoute() { +// WalkingParam walkingParam = new WalkingParam(); +// walkingParam.from(fromPoint); +// walkingParam.to(toPoint); +// TencentSearch tencentSearch = new TencentSearch(getApplicationContext()); +// Log.i("TAG", "checkParams:" + walkingParam.checkParams()); +// tencentSearch.getRoutePlan(walkingParam, new HttpResponseListener() { +// @Override +// public void onSuccess(int statusCode, WalkingResultObject object) { +// if (object == null) { +// Log.i("TAG", "baseObject为空"); +// return; +// } +// showWalkingRoute(object); +// Log.i("TAG", "message:" + object.message); +// } +// +// @Override +// public void onFailure(int statusCode, String responseString, Throwable throwable) { +// Log.i("TAG:", statusCode + " " + responseString); +// } +// }); +// } +// +// private void showWalkingRoute(WalkingResultObject object) { +// tencentMap.clearAllOverlays(); +// if (object.result != null && object.result.routes != null && object.result.routes.size() > 0) { +// for (int i = 0; i < object.result.routes.size(); i++) { +// WalkingResultObject.Route result = object.result.routes.get(i); +// tencentMap.addPolyline(new PolylineOptions().addAll(result.polyline).color(i + 1).width(20)); +// Log.i("TAG", "distance:" + result.distance + " duration:" + result.duration +// + " mode:" + result.mode + " direction:" + result.direction); +// for (RoutePlanningObject.Step step : result.steps) { +// Log.i("TAG", "step:" + step.road_name + " " + step.distance + " " +// + step.instruction + " " + step.act_desc + " " + step.dir_desc); +// } +// tencentMap.moveCamera(CameraUpdateFactory.newLatLngBounds(LatLngBounds.builder() +// .include(result.polyline).build(), 100)); +// } +// +// } else { +// Log.i("TAG", "路线结果为空"); +// } +// } } diff --git a/positions/src/main/java/cc/winboll/studio/positions/demo/smooth/SmoothMoveActivity.java b/positions/src/main/java/cc/winboll/studio/positions/demo/smooth/SmoothMoveActivity.java index c6dc8ac..d578020 100644 --- a/positions/src/main/java/cc/winboll/studio/positions/demo/smooth/SmoothMoveActivity.java +++ b/positions/src/main/java/cc/winboll/studio/positions/demo/smooth/SmoothMoveActivity.java @@ -1,251 +1,257 @@ -package cc.winboll.studio.positions.demo.smooth; - -import androidx.appcompat.app.AppCompatActivity; -import androidx.core.graphics.drawable.RoundedBitmapDrawable; -import androidx.core.graphics.drawable.RoundedBitmapDrawableFactory; - -import android.graphics.Bitmap; -import android.graphics.BitmapFactory; -import android.graphics.Matrix; -import android.os.Bundle; -import android.util.Log; -import android.view.View; -import android.widget.Button; -import android.widget.ImageView; - -import cc.winboll.studio.positions.R; -import com.tencent.tencentmap.mapsdk.maps.CameraUpdate; -import com.tencent.tencentmap.mapsdk.maps.CameraUpdateFactory; -import com.tencent.tencentmap.mapsdk.maps.MapView; -import com.tencent.tencentmap.mapsdk.maps.TencentMap; -import com.tencent.tencentmap.mapsdk.maps.model.BitmapDescriptorFactory; -import com.tencent.tencentmap.mapsdk.maps.model.CameraPosition; -import com.tencent.tencentmap.mapsdk.maps.model.LatLng; -import com.tencent.tencentmap.mapsdk.maps.model.LatLngBounds; -import com.tencent.tencentmap.mapsdk.maps.model.Marker; -import com.tencent.tencentmap.mapsdk.maps.model.MarkerOptions; -import com.tencent.tencentmap.mapsdk.maps.model.Polyline; -import com.tencent.tencentmap.mapsdk.maps.model.PolylineOptions; -import com.tencent.tencentmap.mapsdk.vector.utils.animation.MarkerTranslateAnimator; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Timer; -import java.util.TimerTask; - -import static com.tencent.tencentmap.mapsdk.vector.utils.animation.MarkerTranslateAnimator.MarkerTranslateStatusListener.AnimationStatus.AnimationComplete; - -public class SmoothMoveActivity extends AppCompatActivity implements View.OnClickListener { - private MapView mapView; - private final String mLine = "39.98409,116.30804,39.98409,116.3081,39.98409,116.3081,39.98397,116.30809,39.9823,116.30809,39.9811,116.30817,39.9811,116.30817,39.97918,116.308266,39.97918,116.308266,39.9791,116.30827,39.9791,116.30827,39.979008,116.3083,39.978756,116.3084,39.978386,116.3086,39.977867,116.30884,39.977547,116.308914,39.976845,116.308914,39.975826,116.308945,39.975826,116.308945,39.975666,116.30901,39.975716,116.310486,39.975716,116.310486,39.975754,116.31129,39.975754,116.31129,39.975784,116.31241,39.975822,116.31327,39.97581,116.31352,39.97588,116.31591,39.97588,116.31591,39.97591,116.31735,39.97591,116.31735,39.97593,116.31815,39.975967,116.31879,39.975986,116.32034,39.976055,116.32211,39.976086,116.323395,39.976105,116.32514,39.976173,116.32631,39.976254,116.32811,39.976265,116.3288,39.976345,116.33123,39.976357,116.33198,39.976418,116.33346,39.976418,116.33346,39.97653,116.333755,39.97653,116.333755,39.978157,116.333664,39.978157,116.333664,39.978195,116.33509,39.978195,116.33509,39.978226,116.33625,39.978226,116.33625,39.97823,116.33656,39.97823,116.33656,39.978256,116.33791,39.978256,116.33791,39.978016,116.33789,39.977047,116.33791,39.977047,116.33791,39.97706,116.33768,39.97706,116.33768,39.976967,116.33706,39.976967,116.33697"; - private TencentMap map; - private Polyline mPolyline; - private Marker mCarMarker; - private LatLng[] mCarLatLngArray; - private MarkerTranslateAnimator mAnimator; - private Polyline polyline; - private ArrayList skews; - private ArrayList roates; - private String parentPath; - private ImageView imageView; - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.activity_smooth_move); - mapView = findViewById(R.id.map); - map = mapView.getMap(); - //解析路线 - init(); - Button btLin = findViewById(R.id.button_set); - Button btStart = findViewById(R.id.satrt); - Button btStop = findViewById(R.id.stop); - btLin.setOnClickListener(this); - btStart.setOnClickListener(this); - btStop.setOnClickListener(this); - } - - private void init() { - String[] linePointsStr = mLine.split(","); - mCarLatLngArray = new LatLng[linePointsStr.length / 4]; - skews = new ArrayList<>(); - roates = new ArrayList<>(); - - for (int i = 0; i < mCarLatLngArray.length; i++) { - double latitude = Double.parseDouble(linePointsStr[i * 4]); - double longitude = Double.parseDouble(linePointsStr[i * 4 + 1]); - // float skew = Float.parseFloat(linePointsStr[i * 4 + 2]); - // float roate = Float.parseFloat(linePointsStr[i * 4 + 3]); - mCarLatLngArray[i] = new LatLng(latitude, longitude); - // skews.add(skew); - // roates.add(roate); - } - } - - @Override - protected void onStart() { - super.onStart(); - mapView.onStart(); - } - - @Override - protected void onResume() { - super.onResume(); - mapView.onResume(); - } - - @Override - protected void onPause() { - super.onPause(); - mapView.onPause(); - } - - @Override - protected void onStop() { - super.onStop(); - mapView.onStop(); - } - - @Override - protected void onDestroy() { - super.onDestroy(); - mapView.onDestroy(); - } - - @Override - protected void onRestart() { - super.onRestart(); - mapView.onRestart(); - } - - @Override - public void onClick(View v) { - switch (v.getId()) { - case R.id.button_set: - if (polyline == null && mCarMarker == null) { - //添加小车路线 - polyline = map.addPolyline(new PolylineOptions().add(mCarLatLngArray).color(R.color.colorPrimaryDark)); - LatLng carLatLng = mCarLatLngArray[0]; - mCarMarker = map.addMarker( - new MarkerOptions(carLatLng) - .anchor(0.5f, 0.5f) - .title("即将到达终点") - .icon(BitmapDescriptorFactory.fromBitmap(getBitMap(R.drawable.taxi))) - .flat(true) - .clockwise(false)); - //调整最佳视界 - map.animateCamera(CameraUpdateFactory.newLatLngBounds(LatLngBounds.builder().include(Arrays.asList(mCarLatLngArray)).build(), 50)); - TimerTask timerTask = new TimerTask() { - @Override - public void run() { - if (polyline != null) { - snapshot(); - } - - } - }; - Timer timer = new Timer(); - timer.schedule(timerTask, 800); - } - break; - case R.id.satrt: - if (mAnimator == null) { - //创建移动动画 - mAnimator = new MarkerTranslateAnimator(mCarMarker, 100 * 1000, mCarLatLngArray, true, new MarkerTranslateAnimator.MarkerTranslateStatusListener() { - private CameraUpdate cameraSigma; - - @Override - public void onInterpolatePoint(LatLng latLng, int i, AnimationStatus animationStatus) { - //路线擦出 - polyline.setEraseable(true); - polyline.eraseTo(i, latLng); - - /* CameraUpdate cameraUpdate = CameraUpdateFactory.newLatLngBoundsWithMapCenter(LatLngBounds.builder().include(Arrays.asList(mCarLatLngArray)).build(), latLng, 10); - map.animateCamera(cameraUpdate);*/ - if (mCarMarker.getRotation() < 90 && mCarMarker.getRotation() > 0) { - cameraSigma = - CameraUpdateFactory.newCameraPosition(new CameraPosition( - latLng, - 18, - 60, - mCarMarker.getRotation() + 180)); - } else if (mCarMarker.getRotation() >= 90 && mCarMarker.getRotation() <= 180) { - cameraSigma = - CameraUpdateFactory.newCameraPosition(new CameraPosition( - latLng, - 18, - 60, - -mCarMarker.getRotation())); - } else { - cameraSigma = - CameraUpdateFactory.newCameraPosition(new CameraPosition( - latLng, - 18, - 60, - -mCarMarker.getRotation())); - } - - //移动地图 - map.moveCamera(cameraSigma); - map.enableMultipleInfowindow(true); - if (i == 41) { - mCarMarker.startAnimation(); - mCarMarker.showInfoWindow(); - } - if (animationStatus == AnimationComplete) { - mCarMarker.setTitle("到达目的地"); - } - } - }); - - - //开启动画 - mAnimator.startAnimation(); - } - break; - case R.id.stop: - if (mAnimator != null && polyline != null && mCarMarker != null) { - mAnimator.endAnimation(); - //mAnimator.cancelAnimation(); - polyline.remove(); - polyline = null; - mCarMarker.remove(); - mCarMarker = null; - mAnimator = null; - } - - - break; - default: - throw new IllegalStateException("Unexpected value: " + v.getId()); - } - } - - private void snapshot() { - imageView = findViewById(R.id.iv); - - map.snapshot(new TencentMap.SnapshotReadyCallback() { - @Override - public void onSnapshotReady(Bitmap bitmap) { - RoundedBitmapDrawable roundedBitmapDrawable = RoundedBitmapDrawableFactory.create(getResources(), bitmap); - roundedBitmapDrawable.setCircular(true); - imageView.setImageDrawable(roundedBitmapDrawable); - } - }, Bitmap.Config.ARGB_8888); - } - - //设置图片 - private Bitmap getBitMap(int resourceId) { - Bitmap bitmap = BitmapFactory.decodeResource(getResources(), resourceId); - int width = bitmap.getWidth(); - int height = bitmap.getHeight(); - int newWidth = 100; - int newHeight = 150; - float widthScale = ((float) newWidth) / width; - float heightScale = ((float) newHeight) / height; - Matrix matrix = new Matrix(); - matrix.postScale(widthScale, heightScale); - bitmap = Bitmap.createBitmap(bitmap, 0, 0, width, height, matrix, true); - return bitmap; - } -} \ No newline at end of file +package cc.winboll.studio.positions.demo.smooth; + +import androidx.appcompat.app.AppCompatActivity; +import androidx.core.graphics.drawable.RoundedBitmapDrawable; +import androidx.core.graphics.drawable.RoundedBitmapDrawableFactory; + +import android.graphics.Bitmap; +import android.graphics.BitmapFactory; +import android.graphics.Matrix; +import android.os.Bundle; +import android.util.Log; +import android.view.View; +import android.widget.Button; +import android.widget.ImageView; + +import cc.winboll.studio.positions.R; +import com.tencent.tencentmap.mapsdk.maps.CameraUpdate; +import com.tencent.tencentmap.mapsdk.maps.CameraUpdateFactory; +import com.tencent.tencentmap.mapsdk.maps.MapView; +import com.tencent.tencentmap.mapsdk.maps.TencentMap; +import com.tencent.tencentmap.mapsdk.maps.model.BitmapDescriptorFactory; +import com.tencent.tencentmap.mapsdk.maps.model.CameraPosition; +import com.tencent.tencentmap.mapsdk.maps.model.LatLng; +import com.tencent.tencentmap.mapsdk.maps.model.LatLngBounds; +import com.tencent.tencentmap.mapsdk.maps.model.Marker; +import com.tencent.tencentmap.mapsdk.maps.model.MarkerOptions; +import com.tencent.tencentmap.mapsdk.maps.model.Polyline; +import com.tencent.tencentmap.mapsdk.maps.model.PolylineOptions; +import com.tencent.tencentmap.mapsdk.vector.utils.animation.MarkerTranslateAnimator; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Timer; +import java.util.TimerTask; + +import static com.tencent.tencentmap.mapsdk.vector.utils.animation.MarkerTranslateAnimator.MarkerTranslateStatusListener.AnimationStatus.AnimationComplete; + +public class SmoothMoveActivity extends AppCompatActivity implements View.OnClickListener { + +@Override +public void onClick(View p1) +{ +} + +// private MapView mapView; +// private final String mLine = "39.98409,116.30804,39.98409,116.3081,39.98409,116.3081,39.98397,116.30809,39.9823,116.30809,39.9811,116.30817,39.9811,116.30817,39.97918,116.308266,39.97918,116.308266,39.9791,116.30827,39.9791,116.30827,39.979008,116.3083,39.978756,116.3084,39.978386,116.3086,39.977867,116.30884,39.977547,116.308914,39.976845,116.308914,39.975826,116.308945,39.975826,116.308945,39.975666,116.30901,39.975716,116.310486,39.975716,116.310486,39.975754,116.31129,39.975754,116.31129,39.975784,116.31241,39.975822,116.31327,39.97581,116.31352,39.97588,116.31591,39.97588,116.31591,39.97591,116.31735,39.97591,116.31735,39.97593,116.31815,39.975967,116.31879,39.975986,116.32034,39.976055,116.32211,39.976086,116.323395,39.976105,116.32514,39.976173,116.32631,39.976254,116.32811,39.976265,116.3288,39.976345,116.33123,39.976357,116.33198,39.976418,116.33346,39.976418,116.33346,39.97653,116.333755,39.97653,116.333755,39.978157,116.333664,39.978157,116.333664,39.978195,116.33509,39.978195,116.33509,39.978226,116.33625,39.978226,116.33625,39.97823,116.33656,39.97823,116.33656,39.978256,116.33791,39.978256,116.33791,39.978016,116.33789,39.977047,116.33791,39.977047,116.33791,39.97706,116.33768,39.97706,116.33768,39.976967,116.33706,39.976967,116.33697"; +// private TencentMap map; +// private Polyline mPolyline; +// private Marker mCarMarker; +// private LatLng[] mCarLatLngArray; +// private MarkerTranslateAnimator mAnimator; +// private Polyline polyline; +// private ArrayList skews; +// private ArrayList roates; +// private String parentPath; +// private ImageView imageView; +// +// @Override +// protected void onCreate(Bundle savedInstanceState) { +// super.onCreate(savedInstanceState); +// setContentView(R.layout.activity_smooth_move); +// mapView = findViewById(R.id.map); +// map = mapView.getMap(); +// //解析路线 +// init(); +// Button btLin = findViewById(R.id.button_set); +// Button btStart = findViewById(R.id.satrt); +// Button btStop = findViewById(R.id.stop); +// btLin.setOnClickListener(this); +// btStart.setOnClickListener(this); +// btStop.setOnClickListener(this); +// } +// +// private void init() { +// String[] linePointsStr = mLine.split(","); +// mCarLatLngArray = new LatLng[linePointsStr.length / 4]; +// skews = new ArrayList<>(); +// roates = new ArrayList<>(); +// +// for (int i = 0; i < mCarLatLngArray.length; i++) { +// double latitude = Double.parseDouble(linePointsStr[i * 4]); +// double longitude = Double.parseDouble(linePointsStr[i * 4 + 1]); +// // float skew = Float.parseFloat(linePointsStr[i * 4 + 2]); +// // float roate = Float.parseFloat(linePointsStr[i * 4 + 3]); +// mCarLatLngArray[i] = new LatLng(latitude, longitude); +// // skews.add(skew); +// // roates.add(roate); +// } +// } +// +// @Override +// protected void onStart() { +// super.onStart(); +// mapView.onStart(); +// } +// +// @Override +// protected void onResume() { +// super.onResume(); +// mapView.onResume(); +// } +// +// @Override +// protected void onPause() { +// super.onPause(); +// mapView.onPause(); +// } +// +// @Override +// protected void onStop() { +// super.onStop(); +// mapView.onStop(); +// } +// +// @Override +// protected void onDestroy() { +// super.onDestroy(); +// mapView.onDestroy(); +// } +// +// @Override +// protected void onRestart() { +// super.onRestart(); +// mapView.onRestart(); +// } +// +// @Override +// public void onClick(View v) { +// switch (v.getId()) { +// case R.id.button_set: +// if (polyline == null && mCarMarker == null) { +// //添加小车路线 +// polyline = map.addPolyline(new PolylineOptions().add(mCarLatLngArray).color(R.color.colorPrimaryDark)); +// LatLng carLatLng = mCarLatLngArray[0]; +// mCarMarker = map.addMarker( +// new MarkerOptions(carLatLng) +// .anchor(0.5f, 0.5f) +// .title("即将到达终点") +// .icon(BitmapDescriptorFactory.fromBitmap(getBitMap(R.drawable.taxi))) +// .flat(true) +// .clockwise(false)); +// //调整最佳视界 +// map.animateCamera(CameraUpdateFactory.newLatLngBounds(LatLngBounds.builder().include(Arrays.asList(mCarLatLngArray)).build(), 50)); +// TimerTask timerTask = new TimerTask() { +// @Override +// public void run() { +// if (polyline != null) { +// snapshot(); +// } +// +// } +// }; +// Timer timer = new Timer(); +// timer.schedule(timerTask, 800); +// } +// break; +// case R.id.satrt: +// if (mAnimator == null) { +// //创建移动动画 +// mAnimator = new MarkerTranslateAnimator(mCarMarker, 100 * 1000, mCarLatLngArray, true, new MarkerTranslateAnimator.MarkerTranslateStatusListener() { +// private CameraUpdate cameraSigma; +// +// @Override +// public void onInterpolatePoint(LatLng latLng, int i, AnimationStatus animationStatus) { +// //路线擦出 +// polyline.setEraseable(true); +// polyline.eraseTo(i, latLng); +// +// /* CameraUpdate cameraUpdate = CameraUpdateFactory.newLatLngBoundsWithMapCenter(LatLngBounds.builder().include(Arrays.asList(mCarLatLngArray)).build(), latLng, 10); +// map.animateCamera(cameraUpdate);*/ +// if (mCarMarker.getRotation() < 90 && mCarMarker.getRotation() > 0) { +// cameraSigma = +// CameraUpdateFactory.newCameraPosition(new CameraPosition( +// latLng, +// 18, +// 60, +// mCarMarker.getRotation() + 180)); +// } else if (mCarMarker.getRotation() >= 90 && mCarMarker.getRotation() <= 180) { +// cameraSigma = +// CameraUpdateFactory.newCameraPosition(new CameraPosition( +// latLng, +// 18, +// 60, +// -mCarMarker.getRotation())); +// } else { +// cameraSigma = +// CameraUpdateFactory.newCameraPosition(new CameraPosition( +// latLng, +// 18, +// 60, +// -mCarMarker.getRotation())); +// } +// +// //移动地图 +// map.moveCamera(cameraSigma); +// map.enableMultipleInfowindow(true); +// if (i == 41) { +// mCarMarker.startAnimation(); +// mCarMarker.showInfoWindow(); +// } +// if (animationStatus == AnimationComplete) { +// mCarMarker.setTitle("到达目的地"); +// } +// } +// }); +// +// +// //开启动画 +// mAnimator.startAnimation(); +// } +// break; +// case R.id.stop: +// if (mAnimator != null && polyline != null && mCarMarker != null) { +// mAnimator.endAnimation(); +// //mAnimator.cancelAnimation(); +// polyline.remove(); +// polyline = null; +// mCarMarker.remove(); +// mCarMarker = null; +// mAnimator = null; +// } +// +// +// break; +// default: +// throw new IllegalStateException("Unexpected value: " + v.getId()); +// } +// } +// +// private void snapshot() { +// imageView = findViewById(R.id.iv); +// +// map.snapshot(new TencentMap.SnapshotReadyCallback() { +// @Override +// public void onSnapshotReady(Bitmap bitmap) { +// RoundedBitmapDrawable roundedBitmapDrawable = RoundedBitmapDrawableFactory.create(getResources(), bitmap); +// roundedBitmapDrawable.setCircular(true); +// imageView.setImageDrawable(roundedBitmapDrawable); +// } +// }, Bitmap.Config.ARGB_8888); +// } +// +// //设置图片 +// private Bitmap getBitMap(int resourceId) { +// Bitmap bitmap = BitmapFactory.decodeResource(getResources(), resourceId); +// int width = bitmap.getWidth(); +// int height = bitmap.getHeight(); +// int newWidth = 100; +// int newHeight = 150; +// float widthScale = ((float) newWidth) / width; +// float heightScale = ((float) newHeight) / height; +// Matrix matrix = new Matrix(); +// matrix.postScale(widthScale, heightScale); +// bitmap = Bitmap.createBitmap(bitmap, 0, 0, width, height, matrix, true); +// return bitmap; +// } +} diff --git a/positions/src/main/java/cc/winboll/studio/positions/demo/transaction/AnimateCameraActivity.java b/positions/src/main/java/cc/winboll/studio/positions/demo/transaction/AnimateCameraActivity.java index 90a7e17..3348940 100644 --- a/positions/src/main/java/cc/winboll/studio/positions/demo/transaction/AnimateCameraActivity.java +++ b/positions/src/main/java/cc/winboll/studio/positions/demo/transaction/AnimateCameraActivity.java @@ -13,49 +13,54 @@ import com.tencent.tencentmap.mapsdk.maps.model.LatLng; public class AnimateCameraActivity extends SupportMapFragmentActivity implements View.OnClickListener { - private Button btn; - private boolean flag; - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - - btn = findViewById(R.id.btn_bottom); - btn.setVisibility(View.VISIBLE); - btn.setText("以动画的方式改变地图视图"); - btn.setOnClickListener(this); - - flag = true; - } - - /** - * 改变地图视图 - * @param v - */ - @Override - public void onClick(View v) { - if(flag){ - CameraUpdate cameraSigma = - CameraUpdateFactory.newCameraPosition(new CameraPosition( - new LatLng(39.977290,116.337000), //新的中心点坐标 - 19, //新的缩放级别 - 40f, //俯仰角 0~45° (垂直地图时为0) - 45f)); //偏航角 0~360° (正北方为0) - //移动地图 - tencentMap.animateCamera(cameraSigma); - flag = !flag; - }else { - CameraUpdate cameraSigma = - CameraUpdateFactory.newCameraPosition(new CameraPosition( - new LatLng(39.877290,116.437000), //新的中心点坐标 - 18, //新的缩放级别 - 0f, //俯仰角 0~45° (垂直地图时为0) - 0f)); //偏航角 0~360° (正北方为0) - //移动地图 - tencentMap.animateCamera(cameraSigma); - flag = !flag; - } - + public void onClick(View p1) { } + +// private Button btn; +// private boolean flag; +// +// @Override +// protected void onCreate(Bundle savedInstanceState) { +// super.onCreate(savedInstanceState); +// +// btn = findViewById(R.id.btn_bottom); +// btn.setVisibility(View.VISIBLE); +// btn.setText("以动画的方式改变地图视图"); +// btn.setOnClickListener(this); +// +// flag = true; +// } +// +// /** +// * 改变地图视图 +// * @param v +// */ +// @Override +// public void onClick(View v) { +// if(flag){ +// CameraUpdate cameraSigma = +// CameraUpdateFactory.newCameraPosition(new CameraPosition( +// new LatLng(39.977290,116.337000), //新的中心点坐标 +// 19, //新的缩放级别 +// 40f, //俯仰角 0~45° (垂直地图时为0) +// 45f)); //偏航角 0~360° (正北方为0) +// //移动地图 +// tencentMap.animateCamera(cameraSigma); +// flag = !flag; +// }else { +// CameraUpdate cameraSigma = +// CameraUpdateFactory.newCameraPosition(new CameraPosition( +// new LatLng(39.877290,116.437000), //新的中心点坐标 +// 18, //新的缩放级别 +// 0f, //俯仰角 0~45° (垂直地图时为0) +// 0f)); //偏航角 0~360° (正北方为0) +// //移动地图 +// tencentMap.animateCamera(cameraSigma); +// flag = !flag; +// } +// +// } +// } diff --git a/positions/src/main/java/cc/winboll/studio/positions/demo/transaction/MoveCameraActivity.java b/positions/src/main/java/cc/winboll/studio/positions/demo/transaction/MoveCameraActivity.java index a288b33..3570e8f 100644 --- a/positions/src/main/java/cc/winboll/studio/positions/demo/transaction/MoveCameraActivity.java +++ b/positions/src/main/java/cc/winboll/studio/positions/demo/transaction/MoveCameraActivity.java @@ -13,49 +13,54 @@ import com.tencent.tencentmap.mapsdk.maps.model.LatLng; public class MoveCameraActivity extends SupportMapFragmentActivity implements View.OnClickListener { - - private Button btn; - private boolean flag; - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - - btn = findViewById(R.id.btn_bottom); - btn.setVisibility(View.VISIBLE); - btn.setText("以移动的方式改变地图视图"); - btn.setOnClickListener(this); - - flag = true; + public void onClick(View p1) { } + - /** - * 改变地图视图 - * @param v - */ - @Override - public void onClick(View v) { - if(flag){ - CameraUpdate cameraSigma = - CameraUpdateFactory.newCameraPosition(new CameraPosition( - new LatLng(39.977290,116.337000), //新的中心点坐标 - 19, //新的缩放级别 - 40f, //俯仰角 0~45° (垂直地图时为0) - 45f)); //偏航角 0~360° (正北方为0) - //移动地图 - tencentMap.moveCamera(cameraSigma); - flag = !flag; - }else { - CameraUpdate cameraSigma = - CameraUpdateFactory.newCameraPosition(new CameraPosition( - new LatLng(39.877290,116.437000), //新的中心点坐标 - 18, //新的缩放级别 - 0f, //俯仰角 0~45° (垂直地图时为0) - 0f)); //偏航角 0~360° (正北方为0) - //移动地图 - tencentMap.moveCamera(cameraSigma); - flag = !flag; - } - } +// private Button btn; +// private boolean flag; +// +// @Override +// protected void onCreate(Bundle savedInstanceState) { +// super.onCreate(savedInstanceState); +// +// btn = findViewById(R.id.btn_bottom); +// btn.setVisibility(View.VISIBLE); +// btn.setText("以移动的方式改变地图视图"); +// btn.setOnClickListener(this); +// +// flag = true; +// } +// +// /** +// * 改变地图视图 +// * @param v +// */ +// @Override +// public void onClick(View v) { +// if(flag){ +// CameraUpdate cameraSigma = +// CameraUpdateFactory.newCameraPosition(new CameraPosition( +// new LatLng(39.977290,116.337000), //新的中心点坐标 +// 19, //新的缩放级别 +// 40f, //俯仰角 0~45° (垂直地图时为0) +// 45f)); //偏航角 0~360° (正北方为0) +// //移动地图 +// tencentMap.moveCamera(cameraSigma); +// flag = !flag; +// }else { +// CameraUpdate cameraSigma = +// CameraUpdateFactory.newCameraPosition(new CameraPosition( +// new LatLng(39.877290,116.437000), //新的中心点坐标 +// 18, //新的缩放级别 +// 0f, //俯仰角 0~45° (垂直地图时为0) +// 0f)); //偏航角 0~360° (正北方为0) +// //移动地图 +// tencentMap.moveCamera(cameraSigma); +// flag = !flag; +// } +// +// } } diff --git a/positions/src/main/java/cc/winboll/studio/positions/demo/transaction/RotateMapActivity.java b/positions/src/main/java/cc/winboll/studio/positions/demo/transaction/RotateMapActivity.java index 968df8c..2cf410c 100644 --- a/positions/src/main/java/cc/winboll/studio/positions/demo/transaction/RotateMapActivity.java +++ b/positions/src/main/java/cc/winboll/studio/positions/demo/transaction/RotateMapActivity.java @@ -1,28 +1,28 @@ package cc.winboll.studio.positions.demo.transaction; -import android.os.Bundle; -import android.view.View; -import android.widget.Button; - -import cc.winboll.studio.positions.R; -import cc.winboll.studio.positions.demo.basic.SupportMapFragmentActivity; -import com.tencent.tencentmap.mapsdk.maps.CameraUpdate; -import com.tencent.tencentmap.mapsdk.maps.CameraUpdateFactory; - -public class RotateMapActivity extends SupportMapFragmentActivity { - private Button btn; - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - btn = findViewById(R.id.btn_bottom); - btn.setVisibility(View.VISIBLE); - btn.setText("旋转地图"); - btn.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - CameraUpdate cameraUpdate = CameraUpdateFactory.rotateTo(90f,1.5f); - tencentMap.animateCamera(cameraUpdate); - } - }); - } -} +//import android.os.Bundle; +//import android.view.View; +//import android.widget.Button; +// +//import cc.winboll.studio.positions.R; +//import cc.winboll.studio.positions.demo.basic.SupportMapFragmentActivity; +//import com.tencent.tencentmap.mapsdk.maps.CameraUpdate; +//import com.tencent.tencentmap.mapsdk.maps.CameraUpdateFactory; +// +//public class RotateMapActivity extends SupportMapFragmentActivity { +// private Button btn; +// @Override +// protected void onCreate(Bundle savedInstanceState) { +// super.onCreate(savedInstanceState); +// btn = findViewById(R.id.btn_bottom); +// btn.setVisibility(View.VISIBLE); +// btn.setText("旋转地图"); +// btn.setOnClickListener(new View.OnClickListener() { +// @Override +// public void onClick(View v) { +// CameraUpdate cameraUpdate = CameraUpdateFactory.rotateTo(90f,1.5f); +// tencentMap.animateCamera(cameraUpdate); +// } +// }); +// } +//} diff --git a/positions/src/main/java/cc/winboll/studio/positions/demo/transaction/ScollMapActivity.java b/positions/src/main/java/cc/winboll/studio/positions/demo/transaction/ScollMapActivity.java index 8732f34..1752224 100644 --- a/positions/src/main/java/cc/winboll/studio/positions/demo/transaction/ScollMapActivity.java +++ b/positions/src/main/java/cc/winboll/studio/positions/demo/transaction/ScollMapActivity.java @@ -13,70 +13,75 @@ import com.tencent.tencentmap.mapsdk.maps.CameraUpdateFactory; import com.tencent.tencentmap.mapsdk.maps.TencentMap; public class ScollMapActivity extends SupportMapFragmentActivity implements View.OnClickListener { - private static final int SCROLL_BY_PX = 100; @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - LinearLayout linearLayout = findViewById(R.id.ll); - linearLayout.setVisibility(View.VISIBLE); - Button scrollLeft = (Button) findViewById(R.id.scroll_left); - scrollLeft.setOnClickListener(this); - - Button scrollRight = (Button) findViewById(R.id.scroll_right); - scrollRight.setOnClickListener(this); - - Button scrollUp = (Button) findViewById(R.id.scroll_up); - scrollUp.setOnClickListener(this); - - Button scrollDown = (Button) findViewById(R.id.scroll_down); - scrollDown.setOnClickListener(this); - - /* btn.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - CameraUpdate cameraUpdate = CameraUpdateFactory.scrollBy(50f,50f); - tencentMap.animateCamera(cameraUpdate); - } - });*/ - } - - - // 根据动画按钮状态,调用函数animateCamera或moveCamera来改变可视区域 - - private void changeCamera(CameraUpdate update, TencentMap.CancelableCallback callback) { - boolean animated = ((CompoundButton) findViewById(R.id.animate)) - .isChecked(); - if (animated) { - tencentMap.animateCamera(update, 1000, callback); - } else { - tencentMap.moveCamera(update); - } - } - - @Override - public void onClick(View v) { - switch (v.getId()) { - //点击向左移动按钮响应事件,camera将向左边移动 - - case R.id.scroll_left: - changeCamera(CameraUpdateFactory.scrollBy(-SCROLL_BY_PX, 0), null); - break; - // 点击向右移动按钮响应事件,camera将向右边移动 - case R.id.scroll_right: - changeCamera(CameraUpdateFactory.scrollBy(SCROLL_BY_PX, 0), null); - break; - // 点击向上移动按钮响应事件,camera将向上边移动 - case R.id.scroll_up: - changeCamera(CameraUpdateFactory.scrollBy(0, -SCROLL_BY_PX), null); - break; - // 点击向下移动按钮响应事件,camera将向下边移动 - case R.id.scroll_down: - changeCamera(CameraUpdateFactory.scrollBy(0, SCROLL_BY_PX), null); - break; - - default: - break; - } + public void onClick(View p1) { } + +// private static final int SCROLL_BY_PX = 100; +// +// @Override +// protected void onCreate(Bundle savedInstanceState) { +// super.onCreate(savedInstanceState); +// LinearLayout linearLayout = findViewById(R.id.ll); +// linearLayout.setVisibility(View.VISIBLE); +// Button scrollLeft = (Button) findViewById(R.id.scroll_left); +// scrollLeft.setOnClickListener(this); +// +// Button scrollRight = (Button) findViewById(R.id.scroll_right); +// scrollRight.setOnClickListener(this); +// +// Button scrollUp = (Button) findViewById(R.id.scroll_up); +// scrollUp.setOnClickListener(this); +// +// Button scrollDown = (Button) findViewById(R.id.scroll_down); +// scrollDown.setOnClickListener(this); +// +// /* btn.setOnClickListener(new View.OnClickListener() { +// @Override +// public void onClick(View v) { +// CameraUpdate cameraUpdate = CameraUpdateFactory.scrollBy(50f,50f); +// tencentMap.animateCamera(cameraUpdate); +// } +// });*/ +// } +// +// +// // 根据动画按钮状态,调用函数animateCamera或moveCamera来改变可视区域 +// +// private void changeCamera(CameraUpdate update, TencentMap.CancelableCallback callback) { +// boolean animated = ((CompoundButton) findViewById(R.id.animate)) +// .isChecked(); +// if (animated) { +// tencentMap.animateCamera(update, 1000, callback); +// } else { +// tencentMap.moveCamera(update); +// } +// } +// +// @Override +// public void onClick(View v) { +// switch (v.getId()) { +// //点击向左移动按钮响应事件,camera将向左边移动 +// +// case R.id.scroll_left: +// changeCamera(CameraUpdateFactory.scrollBy(-SCROLL_BY_PX, 0), null); +// break; +// // 点击向右移动按钮响应事件,camera将向右边移动 +// case R.id.scroll_right: +// changeCamera(CameraUpdateFactory.scrollBy(SCROLL_BY_PX, 0), null); +// break; +// // 点击向上移动按钮响应事件,camera将向上边移动 +// case R.id.scroll_up: +// changeCamera(CameraUpdateFactory.scrollBy(0, -SCROLL_BY_PX), null); +// break; +// // 点击向下移动按钮响应事件,camera将向下边移动 +// case R.id.scroll_down: +// changeCamera(CameraUpdateFactory.scrollBy(0, SCROLL_BY_PX), null); +// break; +// +// default: +// break; +// } +// } } diff --git a/positions/src/main/java/cc/winboll/studio/positions/demo/transaction/ZoomCalulateActivity.java b/positions/src/main/java/cc/winboll/studio/positions/demo/transaction/ZoomCalulateActivity.java index 375ca3e..296cbbe 100644 --- a/positions/src/main/java/cc/winboll/studio/positions/demo/transaction/ZoomCalulateActivity.java +++ b/positions/src/main/java/cc/winboll/studio/positions/demo/transaction/ZoomCalulateActivity.java @@ -20,54 +20,54 @@ import java.util.ArrayList; public class ZoomCalulateActivity extends SupportMapFragmentActivity { - private Button btn; - private int leftpadding = 50,rightpadding =50, toppadding = 50, bottompadding=50; - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - btn = findViewById(R.id.btn_bottom); - btn.setVisibility(View.VISIBLE); - btn.setText("根据点集缩放地图"); - btn.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - CameraUpdate cameraUpdate = CameraUpdateFactory.newCameraPosition(addMarker()); - tencentMap.moveCamera(cameraUpdate); - } - }); - } - - - private CameraPosition addMarker(){ - ArrayList points = new ArrayList<>(); - points.add(new LatLng(39.984059,116.307621)); - points.add(new LatLng(39.984049,116.307631)); -// points.add(new LatLng(39.981527,116.308994)); -// points.add(new LatLng(39.984026,116.316419)); -// points.add(new LatLng(39.978501,116.311827)); - //根据markers计算缩放级别 - for(int i=0; i points = new ArrayList<>(); +// points.add(new LatLng(39.984059,116.307621)); +// points.add(new LatLng(39.984049,116.307631)); +//// points.add(new LatLng(39.981527,116.308994)); +//// points.add(new LatLng(39.984026,116.316419)); +//// points.add(new LatLng(39.978501,116.311827)); +// //根据markers计算缩放级别 +// for(int i=0; i