注释问题代码

This commit is contained in:
ZhanGSKen 2025-02-24 04:30:26 +08:00
parent e06b642b70
commit 0c00ace869
64 changed files with 6902 additions and 6757 deletions

View File

@ -1,8 +1,8 @@
#Created by .winboll/winboll_app_build.gradle #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 stageCount=0
libraryProject= libraryProject=
baseVersion=1.0 baseVersion=1.0
publishVersion=1.0.0 publishVersion=1.0.0
buildCount=60 buildCount=61
baseBetaVersion=1.0.1 baseBetaVersion=1.0.1

View File

@ -1,5 +1,6 @@
package cc.winboll.studio.positions.demo; package cc.winboll.studio.positions.demo;
import cc.winboll.studio.positions.R;
import android.content.Intent; import android.content.Intent;
import android.net.Uri; import android.net.Uri;
import android.os.Bundle; import android.os.Bundle;

View File

@ -1,5 +1,6 @@
package cc.winboll.studio.positions.demo; package cc.winboll.studio.positions.demo;
import cc.winboll.studio.positions.R;
import android.os.Bundle; import android.os.Bundle;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.fragment.app.FragmentManager; import androidx.fragment.app.FragmentManager;
@ -11,43 +12,43 @@ import com.tencent.tencentmap.mapsdk.maps.TencentMap;
public abstract class AbsMapActivity extends AbsActivity { public abstract class AbsMapActivity extends AbsActivity {
private TencentMap mTencentMap; // private TencentMap mTencentMap;
//
protected int getLayoutId() { // protected int getLayoutId() {
return R.layout.activity_map_container; // return R.layout.activity_map_container;
} // }
//
@Override // @Override
protected final void onCreate(@Nullable Bundle savedInstanceState) { // protected final void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState); // super.onCreate(savedInstanceState);
setContentView(getLayoutId()); // setContentView(getLayoutId());
//
FragmentManager manager = getSupportFragmentManager(); // FragmentManager manager = getSupportFragmentManager();
SupportMapFragment fragment = (SupportMapFragment) manager.findFragmentById(R.id.fragment_map); // SupportMapFragment fragment = (SupportMapFragment) manager.findFragmentById(R.id.fragment_map);
if (fragment != null) { // if (fragment != null) {
mTencentMap = fragment.getMap(); // mTencentMap = fragment.getMap();
} // }
//
onCreate(savedInstanceState, mTencentMap); // onCreate(savedInstanceState, mTencentMap);
} // }
//
protected boolean checkMapInvalid() { // protected boolean checkMapInvalid() {
return mTencentMap == null || mTencentMap.isDestroyed(); // return mTencentMap == null || mTencentMap.isDestroyed();
} // }
//
protected void onCreate(@Nullable Bundle savedInstanceState, TencentMap tencentMap) { // protected void onCreate(@Nullable Bundle savedInstanceState, TencentMap tencentMap) {
//
} // }
//
@Override // @Override
public boolean onPrepareOptionsMenu(Menu menu) { // public boolean onPrepareOptionsMenu(Menu menu) {
supportInvalidateOptionsMenu(); // supportInvalidateOptionsMenu();
return super.onPrepareOptionsMenu(menu); // return super.onPrepareOptionsMenu(menu);
} // }
//
@Override // @Override
public boolean onOptionsItemSelected(MenuItem item) { // public boolean onOptionsItemSelected(MenuItem item) {
supportInvalidateOptionsMenu(); // supportInvalidateOptionsMenu();
return super.onOptionsItemSelected(item); // return super.onOptionsItemSelected(item);
} // }
} }

View File

@ -31,168 +31,184 @@ import java.util.List;
public class IndoorMapActivity extends AppCompatActivity implements TencentMap.OnIndoorStateChangeListener { 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<MarkerCluster> 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<MarkerCluster> markerClusterClusterManager = new ClusterManager<MarkerCluster>(this, tencentMap);
NonHierarchicalDistanceBasedAlgorithm<MarkerCluster> nba = new NonHierarchicalDistanceBasedAlgorithm<>(this);
nba.setMaxDistanceAtZoom(15);
markerClusterClusterManager.setAlgorithm(nba);
DefaultClusterRenderer<MarkerCluster> 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 @Override
public boolean onIndoorBuildingFocused() { public boolean onIndoorBuildingFocused() {
Log.d(TAG, "onIndoorBuildingFocused: 室内图场景激活回调");
return false; return false;
} }
@Override @Override
public boolean onIndoorLevelActivated(final IndoorBuilding indoorBuilding) { public boolean onIndoorLevelActivated(IndoorBuilding p1) {
if (indoorBuilding != null) {
handler.post(new Runnable() {
@Override
public void run() {
indoorFloorView.setVisible(true);
if (mIndoorBuilding == null || !mIndoorBuilding.getBuidlingId().equals(indoorBuilding.getBuidlingId())) {
List<IndoorLevel> 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; return false;
} }
@Override @Override
public boolean onIndoorBuildingDeactivated() { public boolean onIndoorBuildingDeactivated() {
Log.d(TAG, "onIndoorBuildingDeactivated: 当前室内图处于无效状态");
return false; return false;
} }
IndoorBuilding mIndoorBuilding = null;
private class MyIndoorViewAdapter implements IndoorFloorView.OnIndoorFloorListener { // private static final String TAG = "IndoorMapActivity";
// private MapView mapView;
@Override // private TencentMap tencentMap;
public void onSelected(int selectedIndex) { // private IndoorFloorView indoorFloorView;
if (mIndoorBuilding != null) { // private UiSettings uiSettings;
// private Handler handler = new Handler();
List<IndoorLevel> levels = mIndoorBuilding.getLevels(); // private String floorName;
String activedIndoorFloorName = tencentMap.getActivedIndoorFloorNames()[selectedIndex]; //
String name = levels.get(selectedIndex).getName(); // @Override
name = activedIndoorFloorName; // protected void onCreate(Bundle savedInstanceState) {
String buidlingId = mIndoorBuilding.getBuidlingId(); // super.onCreate(savedInstanceState);
tencentMap.setIndoorFloor(buidlingId, name); // setContentView(R.layout.activity_indoor);
} // mapView = findViewById(R.id.mapView);
} // indoorFloorView = findViewById(R.id.indoor_floor);
} // if (tencentMap == null) {
} // tencentMap = mapView.getMap();
// }
class MarkerCluster implements ClusterItem { // //欧美汇室内地图需Key开通室内地图权限
// CameraUpdate camera =
private final LatLng latLng; // CameraUpdateFactory.newCameraPosition(new CameraPosition(
// new LatLng(39.979382, 116.314106),
public MarkerCluster(double lat, double longitude) { // 18,
latLng = new LatLng(lat, longitude); // 0f,
} // 0f));
// tencentMap.moveCamera(camera);
@Override // final ArrayList<MarkerCluster> markerClusters = new ArrayList<>();
public LatLng getPosition() { //
// uiSettings = tencentMap.getUiSettings();
return latLng; // 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<MarkerCluster> markerClusterClusterManager = new ClusterManager<MarkerCluster>(this, tencentMap);
// NonHierarchicalDistanceBasedAlgorithm<MarkerCluster> nba = new NonHierarchicalDistanceBasedAlgorithm<>(this);
// nba.setMaxDistanceAtZoom(15);
// markerClusterClusterManager.setAlgorithm(nba);
// DefaultClusterRenderer<MarkerCluster> 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<IndoorLevel> 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<IndoorLevel> 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;
// }
} }

View File

@ -16,180 +16,180 @@
package cc.winboll.studio.positions.demo.basic; package cc.winboll.studio.positions.demo.basic;
import android.annotation.SuppressLint; //import android.annotation.SuppressLint;
import android.graphics.PorterDuff; //import android.graphics.PorterDuff;
import android.os.Bundle; //import android.os.Bundle;
import android.util.Log; //import android.util.Log;
import android.view.View; //import android.view.View;
import android.widget.AdapterView; //import android.widget.AdapterView;
import android.widget.ArrayAdapter; //import android.widget.ArrayAdapter;
import android.widget.CompoundButton; //import android.widget.CompoundButton;
import android.widget.RadioGroup; //import android.widget.RadioGroup;
import android.widget.Spinner; //import android.widget.Spinner;
import android.widget.Switch; //import android.widget.Switch;
import android.widget.TextView; //import android.widget.TextView;
//
//
import androidx.fragment.app.FragmentActivity; //import androidx.fragment.app.FragmentActivity;
//
import cc.winboll.studio.positions.R; //import cc.winboll.studio.positions.R;
import com.tencent.tencentmap.mapsdk.maps.CameraUpdate; //import com.tencent.tencentmap.mapsdk.maps.CameraUpdate;
import com.tencent.tencentmap.mapsdk.maps.CameraUpdateFactory; //import com.tencent.tencentmap.mapsdk.maps.CameraUpdateFactory;
import com.tencent.tencentmap.mapsdk.maps.MapView; //import com.tencent.tencentmap.mapsdk.maps.MapView;
import com.tencent.tencentmap.mapsdk.maps.TencentMap; //import com.tencent.tencentmap.mapsdk.maps.TencentMap;
import com.tencent.tencentmap.mapsdk.maps.model.CameraPosition; //import com.tencent.tencentmap.mapsdk.maps.model.CameraPosition;
import com.tencent.tencentmap.mapsdk.maps.model.LatLng; //import com.tencent.tencentmap.mapsdk.maps.model.LatLng;
//
/** ///**
* Demonstrates the different base layers of a map. // * Demonstrates the different base layers of a map.
*/ // */
@SuppressLint("NewApi") //@SuppressLint("NewApi")
public class MapStyleDemoActivity extends FragmentActivity implements TencentMap.OnCameraChangeListener { //public class MapStyleDemoActivity extends FragmentActivity implements TencentMap.OnCameraChangeListener {
private MapView mMapView; // private MapView mMapView;
private TextView mTextView; // private TextView mTextView;
private TencentMap mTencentMap; // private TencentMap mTencentMap;
private Switch mSwitch; // private Switch mSwitch;
private Spinner mSpinner; // private Spinner mSpinner;
//
private String[] styles = new String[]{"style1", "style2", "style3", "style4", "style5", // private String[] styles = new String[]{"style1", "style2", "style3", "style4", "style5",
"normal", "traffic_navi", "traffic_navi_night", "satellite", "night", "navi", "night", "eagle_day", "eagle_night"}; // "normal", "traffic_navi", "traffic_navi_night", "satellite", "night", "navi", "night", "eagle_day", "eagle_night"};
//
@Override // @Override
protected void onCreate(Bundle savedInstanceState) { // protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); // super.onCreate(savedInstanceState);
setContentView(R.layout.activity_map_style); // setContentView(R.layout.activity_map_style);
mMapView = findViewById(R.id.map_view); // mMapView = findViewById(R.id.map_view);
mTextView = findViewById(R.id.tv_level); // mTextView = findViewById(R.id.tv_level);
mSwitch=findViewById(R.id.switch_open); // mSwitch=findViewById(R.id.switch_open);
mTencentMap = mMapView.getMap(); // mTencentMap = mMapView.getMap();
CameraUpdate cameraUpdate = CameraUpdateFactory.newCameraPosition(new CameraPosition(new LatLng(39.901268, 116.403854), 11f, 0f, 0f)); // CameraUpdate cameraUpdate = CameraUpdateFactory.newCameraPosition(new CameraPosition(new LatLng(39.901268, 116.403854), 11f, 0f, 0f));
mTencentMap.moveCamera(cameraUpdate); // mTencentMap.moveCamera(cameraUpdate);
//mTencentMap.moveCamera(CameraUpdateFactory.newLatLng(new LatLng(39.901268, 116.403854))); //移动地图 // //mTencentMap.moveCamera(CameraUpdateFactory.newLatLng(new LatLng(39.901268, 116.403854))); //移动地图
mTencentMap.setOnCameraChangeListener(this); // mTencentMap.setOnCameraChangeListener(this);
mSpinner = findViewById(R.id.sp_style); // mSpinner = findViewById(R.id.sp_style);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(getApplicationContext(), android.R.layout.simple_spinner_dropdown_item, styles); // ArrayAdapter<String> adapter = new ArrayAdapter<String>(getApplicationContext(), android.R.layout.simple_spinner_dropdown_item, styles);
mSpinner.setAdapter(adapter); // mSpinner.setAdapter(adapter);
mSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { // mSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override // @Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { // public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
if (position < 5) { // if (position < 5) {
mTencentMap.setMapStyle(position + 1); // mTencentMap.setMapStyle(position + 1);
} // }
switch (position) { // switch (position) {
case 5: // case 5:
mTencentMap.setMapStyle(TencentMap.MAP_TYPE_NORMAL); // mTencentMap.setMapStyle(TencentMap.MAP_TYPE_NORMAL);
break; // break;
case 6: // case 6:
mTencentMap.setMapStyle(TencentMap.MAP_TYPE_TRAFFIC_NAVI); // mTencentMap.setMapStyle(TencentMap.MAP_TYPE_TRAFFIC_NAVI);
break; // break;
case 7: // case 7:
mTencentMap.setMapStyle(TencentMap.MAP_TYPE_TRAFFIC_NIGHT); // mTencentMap.setMapStyle(TencentMap.MAP_TYPE_TRAFFIC_NIGHT);
break; // break;
case 8: // case 8:
mTencentMap.setMapStyle(TencentMap.MAP_TYPE_SATELLITE); // mTencentMap.setMapStyle(TencentMap.MAP_TYPE_SATELLITE);
break; // break;
case 9: // case 9:
mTencentMap.setMapStyle(TencentMap.MAP_TYPE_NIGHT); // mTencentMap.setMapStyle(TencentMap.MAP_TYPE_NIGHT);
break; // break;
case 10: // case 10:
mTencentMap.setMapStyle(TencentMap.MAP_TYPE_NAVI); // mTencentMap.setMapStyle(TencentMap.MAP_TYPE_NAVI);
break; // break;
case 11: // case 11:
mTencentMap.setMapStyle(13 + 1000); // mTencentMap.setMapStyle(13 + 1000);
break; // break;
case 12: // case 12:
mTencentMap.setMapStyle(14 + 1000); // mTencentMap.setMapStyle(14 + 1000);
break; // break;
case 13: // case 13:
mTencentMap.setMapStyle(15 + 1000); // mTencentMap.setMapStyle(15 + 1000);
break; // break;
} // }
} // }
//
@Override // @Override
public void onNothingSelected(AdapterView<?> parent) { // public void onNothingSelected(AdapterView<?> parent) {
//
} // }
}); // });
//
RadioGroup rg = findViewById(R.id.rg_map_type); // RadioGroup rg = findViewById(R.id.rg_map_type);
rg.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() { // rg.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
@Override // @Override
public void onCheckedChanged(RadioGroup group, int checkedId) { // public void onCheckedChanged(RadioGroup group, int checkedId) {
switch (checkedId) { // switch (checkedId) {
case R.id.rb_normal_type: // case R.id.rb_normal_type:
if (mTencentMap != null) { // if (mTencentMap != null) {
mTencentMap.setMapType(TencentMap.MAP_TYPE_NORMAL); // mTencentMap.setMapType(TencentMap.MAP_TYPE_NORMAL);
} // }
break; // break;
case R.id.rb_dark_type: // case R.id.rb_dark_type:
if (mTencentMap != null) { // if (mTencentMap != null) {
mTencentMap.setMapType(TencentMap.MAP_TYPE_DARK); // mTencentMap.setMapType(TencentMap.MAP_TYPE_DARK);
} // }
break; // break;
case R.id.rb_sagellite_type: // case R.id.rb_sagellite_type:
if (mTencentMap != null) { // if (mTencentMap != null) {
mTencentMap.setMapType(TencentMap.MAP_TYPE_SATELLITE); // mTencentMap.setMapType(TencentMap.MAP_TYPE_SATELLITE);
} // }
break; // break;
} // }
} // }
}); // });
mTencentMap.getUiSettings().setCompassEnabled(true); // mTencentMap.getUiSettings().setCompassEnabled(true);
mTencentMap.getUiSettings().setMyLocationButtonEnabled(true); // mTencentMap.getUiSettings().setMyLocationButtonEnabled(true);
mSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { // mSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override // @Override
public void onCheckedChanged(CompoundButton compoundButton, boolean b) { // public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
PorterDuff.Mode buttonTintMode = compoundButton.getButtonTintMode(); // PorterDuff.Mode buttonTintMode = compoundButton.getButtonTintMode();
if(b){ // if(b){
mTencentMap.setBuildingEnable(true); // mTencentMap.setBuildingEnable(true);
}else{ // }else{
mTencentMap.setBuildingEnable(false); // mTencentMap.setBuildingEnable(false);
} // }
} // }
}); // });
} // }
//
@Override // @Override
protected void onResume() { // protected void onResume() {
super.onResume(); // super.onResume();
mMapView.onResume(); // mMapView.onResume();
} // }
//
@Override // @Override
protected void onPause() { // protected void onPause() {
super.onPause(); // super.onPause();
mMapView.onPause(); // mMapView.onPause();
} // }
//
@Override // @Override
protected void onDestroy() { // protected void onDestroy() {
super.onDestroy(); // super.onDestroy();
mMapView.onDestroy(); // mMapView.onDestroy();
} // }
//
//
@Override // @Override
protected void onStart() { // protected void onStart() {
super.onStart(); // super.onStart();
mMapView.onStart(); // mMapView.onStart();
} // }
//
@Override // @Override
protected void onStop() { // protected void onStop() {
super.onStop(); // super.onStop();
mMapView.onStop(); // mMapView.onStop();
} // }
//
@Override // @Override
public void onCameraChange(CameraPosition cameraPosition) { // public void onCameraChange(CameraPosition cameraPosition) {
Log.i("TAG","地图滑动了"); // Log.i("TAG","地图滑动了");
mTextView.setText("当前缩放级别为:" + cameraPosition.zoom); // mTextView.setText("当前缩放级别为:" + cameraPosition.zoom);
} // }
//
@Override // @Override
public void onCameraChangeFinished(CameraPosition cameraPosition) { // public void onCameraChangeFinished(CameraPosition cameraPosition) {
Log.i("TAG","地图滑动了"); // Log.i("TAG","地图滑动了");
mTextView.setText("当前缩放级别为:" + cameraPosition.zoom); // mTextView.setText("当前缩放级别为:" + cameraPosition.zoom);
} // }
} //}

View File

@ -1,91 +1,91 @@
package cc.winboll.studio.positions.demo.basic; package cc.winboll.studio.positions.demo.basic;
import android.content.res.AssetManager; //import android.content.res.AssetManager;
import android.graphics.Bitmap; //import android.graphics.Bitmap;
import android.graphics.BitmapFactory; //import android.graphics.BitmapFactory;
import android.os.Bundle; //import android.os.Bundle;
//
import com.tencent.tencentmap.mapsdk.maps.CameraUpdate; //import com.tencent.tencentmap.mapsdk.maps.CameraUpdate;
import com.tencent.tencentmap.mapsdk.maps.CameraUpdateFactory; //import com.tencent.tencentmap.mapsdk.maps.CameraUpdateFactory;
import com.tencent.tencentmap.mapsdk.maps.TencentMapContext; //import com.tencent.tencentmap.mapsdk.maps.TencentMapContext;
import com.tencent.tencentmap.mapsdk.maps.model.CameraPosition; //import com.tencent.tencentmap.mapsdk.maps.model.CameraPosition;
import com.tencent.tencentmap.mapsdk.maps.model.Language; //import com.tencent.tencentmap.mapsdk.maps.model.Language;
import com.tencent.tencentmap.mapsdk.maps.model.LatLng; //import com.tencent.tencentmap.mapsdk.maps.model.LatLng;
import com.tencent.tencentmap.mapsdk.maps.model.OverSeaTileProvider; //import com.tencent.tencentmap.mapsdk.maps.model.OverSeaTileProvider;
//
import java.io.InputStream; //import java.io.InputStream;
import java.net.MalformedURLException; //import java.net.MalformedURLException;
import java.net.URL; //import java.net.URL;
import java.util.Locale; //import java.util.Locale;
//
public class OverseaMapActivity extends SupportMapFragmentActivity { //public class OverseaMapActivity extends SupportMapFragmentActivity {
@Override // @Override
protected void onCreate(Bundle savedInstanceState) { // protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); // super.onCreate(savedInstanceState);
//纽约时代广场海外地图需Key开通海外位置服务权限 // //纽约时代广场海外地图需Key开通海外位置服务权限
CameraUpdate cameraSigma = // CameraUpdate cameraSigma =
CameraUpdateFactory.newCameraPosition(new CameraPosition( // CameraUpdateFactory.newCameraPosition(new CameraPosition(
new LatLng(40.75797, -73.985542), // new LatLng(40.75797, -73.985542),
11, // 11,
0f, // 0f,
0f)); // 0f));
//移动地图 // //移动地图
tencentMap.moveCamera(cameraSigma); // tencentMap.moveCamera(cameraSigma);
//设置自定义海外图源 // //设置自定义海外图源
tencentMap.setOverSeaTileProvider(new CustomOverSeaTileProvider(tencentMap.getMapContext())); // tencentMap.setOverSeaTileProvider(new CustomOverSeaTileProvider(tencentMap.getMapContext()));
} // }
//
class CustomOverSeaTileProvider extends OverSeaTileProvider { // class CustomOverSeaTileProvider extends OverSeaTileProvider {
boolean mIsZhLanguage; // boolean mIsZhLanguage;
boolean mIsNight; // boolean mIsNight;
//
/** // /**
* 创建海外图源供应 // * 创建海外图源供应
*/ // */
public CustomOverSeaTileProvider(TencentMapContext context){ // public CustomOverSeaTileProvider(TencentMapContext context){
//设置名称和版本号 // //设置名称和版本号
super("custom", 1, context); // super("custom", 1, context);
} // }
//
@Override // @Override
public URL getTileUrl(int x, int y, int zoom) { // 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 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"); // String formatUrl = String.format(Locale.ENGLISH, url, x, y, zoom, mIsNight ? "dark" : "day", mIsZhLanguage ? "zh" : "en");
try { // try {
return new URL(formatUrl); // return new URL(formatUrl);
} catch (MalformedURLException e) { // } catch (MalformedURLException e) {
e.printStackTrace(); // e.printStackTrace();
} // }
return null; // return null;
} // }
//
@Override // @Override
public boolean onDayNightChange(boolean dayNight) { // public boolean onDayNightChange(boolean dayNight) {
mIsNight = dayNight; // mIsNight = dayNight;
return true; // return true;
} // }
//
public boolean onLanguageChange(Language language) { // public boolean onLanguageChange(Language language) {
mIsZhLanguage = (language == Language.zh); // mIsZhLanguage = (language == Language.zh);
return true; // return true;
} // }
//
@Override // @Override
public Bitmap getLogo(boolean isNight) { // public Bitmap getLogo(boolean isNight) {
AssetManager assetManager = getAssets(); // AssetManager assetManager = getAssets();
Bitmap iBitmap = null; // Bitmap iBitmap = null;
InputStream is = null; // InputStream is = null;
try { // try {
is = assetManager.open("logo.png"); // is = assetManager.open("logo.png");
iBitmap = BitmapFactory.decodeStream(is); // iBitmap = BitmapFactory.decodeStream(is);
} catch (Exception e) { // } catch (Exception e) {
return null; // return null;
} catch (OutOfMemoryError ignored) { // } catch (OutOfMemoryError ignored) {
} finally { // } finally {
// IO.safeClose(is); // // IO.safeClose(is);
} // }
return iBitmap; // return iBitmap;
} // }
} // }
} //}
//

View File

@ -9,43 +9,48 @@ import com.tencent.tencentmap.mapsdk.maps.TencentMap;
public class SetMapTypeActivity extends SupportMapFragmentActivity implements RadioGroup.OnCheckedChangeListener { public class SetMapTypeActivity extends SupportMapFragmentActivity implements RadioGroup.OnCheckedChangeListener {
private RadioGroup radioGroup;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { public void onCheckedChanged(RadioGroup p1, int p2) {
super.onCreate(savedInstanceState);
initView();
} }
private void initView() { // private RadioGroup radioGroup;
radioGroup = findViewById(R.id.lay_map_type); //
radioGroup.setVisibility(View.VISIBLE); // @Override
radioGroup.setOnCheckedChangeListener(this); // protected void onCreate(Bundle savedInstanceState) {
} // super.onCreate(savedInstanceState);
// initView();
@Override // }
public void onCheckedChanged(RadioGroup radioGroup, int i) { //
switch (i) { // private void initView() {
case R.id.btn_normal: //普通地图-默认地图类型 // radioGroup = findViewById(R.id.lay_map_type);
tencentMap.setMapType(TencentMap.MAP_TYPE_NORMAL); // radioGroup.setVisibility(View.VISIBLE);
break; // radioGroup.setOnCheckedChangeListener(this);
case R.id.btn_satellite: //卫星地图 // }
tencentMap.setMapType(TencentMap.MAP_TYPE_SATELLITE); //
break; // @Override
case R.id.btn_dark: //暗色地图 // public void onCheckedChanged(RadioGroup radioGroup, int i) {
tencentMap.setMapType(TencentMap.MAP_TYPE_DARK); // switch (i) {
break; // case R.id.btn_normal: //普通地图-默认地图类型
case R.id.btn_traffic: // tencentMap.setMapType(TencentMap.MAP_TYPE_NORMAL);
tencentMap.setTrafficEnabled(true); // break;
break; // case R.id.btn_satellite: //卫星地图
case R.id.style_map: // tencentMap.setMapType(TencentMap.MAP_TYPE_SATELLITE);
/*TencentMapOptions mapOptions = new TencentMapOptions(); // break;
//将本地资源打包到apk的asset目录中 // case R.id.btn_dark: //暗色地图
mapOptions.setCustomAssetsPath("myMapStyle"); // tencentMap.setMapType(TencentMap.MAP_TYPE_DARK);
//参数1对应的是我的样式中的序号 // break;
tencentMap.setMapStyle(1); // case R.id.btn_traffic:
MapView mMapView = new MapView(SetMapTypeActivity.this, mapOptions);*/ // tencentMap.setTrafficEnabled(true);
break; // 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;
// }
// }
} }

View File

@ -16,35 +16,35 @@ import com.tencent.tencentmap.mapsdk.maps.model.CameraPosition;
import com.tencent.tencentmap.mapsdk.maps.model.LatLng; import com.tencent.tencentmap.mapsdk.maps.model.LatLng;
public class SupportMapFragmentActivity extends AppCompatActivity { public class SupportMapFragmentActivity extends AppCompatActivity {
//
/** // /**
* SDK提供了SupportMapFragment这个类来加载地图这个类的方便之处就在于不用手动管理内存 // * SDK提供了SupportMapFragment这个类来加载地图这个类的方便之处就在于不用手动管理内存
*/ // */
//
private FragmentManager fm; // private FragmentManager fm;
protected TencentMap tencentMap; // protected TencentMap tencentMap;
private SupportMapFragment supportMapFragment; // private SupportMapFragment supportMapFragment;
protected UiSettings mapUiSettings; // protected UiSettings mapUiSettings;
//
@Override // @Override
protected void onCreate(Bundle savedInstanceState) { // protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); // super.onCreate(savedInstanceState);
setContentView(R.layout.activity_support_map_fragment); // setContentView(R.layout.activity_support_map_fragment);
//
//创建tencentMap地图对象可以完成对地图的几乎所有操作 // //创建tencentMap地图对象可以完成对地图的几乎所有操作
fm = getSupportFragmentManager(); // fm = getSupportFragmentManager();
supportMapFragment = (SupportMapFragment) fm.findFragmentById(R.id.map_frag); // supportMapFragment = (SupportMapFragment) fm.findFragmentById(R.id.map_frag);
tencentMap = supportMapFragment.getMap(); // tencentMap = supportMapFragment.getMap();
mapUiSettings = tencentMap.getUiSettings(); // mapUiSettings = tencentMap.getUiSettings();
//对地图操作类进行操作 // //对地图操作类进行操作
CameraUpdate cameraSigma = // CameraUpdate cameraSigma =
CameraUpdateFactory.newCameraPosition(new CameraPosition( // CameraUpdateFactory.newCameraPosition(new CameraPosition(
new LatLng(39.984066, 116.307548), // new LatLng(39.984066, 116.307548),
15, // 15,
0f, // 0f,
0f)); // 0f));
//移动地图 // //移动地图
tencentMap.moveCamera(cameraSigma); // tencentMap.moveCamera(cameraSigma);
//
} // }
} }

View File

@ -11,76 +11,76 @@ import com.tencent.tencentmap.mapsdk.maps.TencentMapOptions;
public class UiSettingsActivity extends SupportMapFragmentActivity { public class UiSettingsActivity extends SupportMapFragmentActivity {
private Switch logoControl; // private Switch logoControl;
private Switch compassControl; // private Switch compassControl;
private Switch scaleViewControl; // private Switch scaleViewControl;
//
@Override // @Override
protected void onCreate(Bundle savedInstanceState) { // protected void onCreate(Bundle savedInstanceState) {
//
super.onCreate(savedInstanceState); // super.onCreate(savedInstanceState);
initView(); // initView();
} // }
private void initView(){ // private void initView(){
//
logoControl = findViewById(R.id.switch_logo); // logoControl = findViewById(R.id.switch_logo);
compassControl = findViewById(R.id.switch_compass); // compassControl = findViewById(R.id.switch_compass);
scaleViewControl = findViewById(R.id.switch_scale_view); // scaleViewControl = findViewById(R.id.switch_scale_view);
logoControl.setVisibility(View.VISIBLE); // logoControl.setVisibility(View.VISIBLE);
logoControl.setText("logo位置"); // logoControl.setText("logo位置");
compassControl.setVisibility(View.VISIBLE); // compassControl.setVisibility(View.VISIBLE);
compassControl.setText("指南针"); // compassControl.setText("指南针");
scaleViewControl.setVisibility(View.VISIBLE); // scaleViewControl.setVisibility(View.VISIBLE);
scaleViewControl.setText("比例尺"); // scaleViewControl.setText("比例尺");
//
//打开缩放 // //打开缩放
mapUiSettings.setZoomControlsEnabled(true); // mapUiSettings.setZoomControlsEnabled(true);
//打开位置标志 // //打开位置标志
mapUiSettings.setMyLocationButtonEnabled(true); // mapUiSettings.setMyLocationButtonEnabled(true);
//
//
logoControl.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { // logoControl.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override // @Override
public void onCheckedChanged(CompoundButton compoundButton, boolean b) { // public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
if (b){ // if (b){
//logo左下角 // //logo左下角
mapUiSettings.setLogoPosition(TencentMapOptions.LOGO_POSITION_BOTTOM_LEFT); // mapUiSettings.setLogoPosition(TencentMapOptions.LOGO_POSITION_BOTTOM_LEFT);
}else{ // }else{
//logo右上角 // //logo右上角
mapUiSettings.setLogoPosition(TencentMapOptions.LOGO_POSITION_TOP_RIGHT); // mapUiSettings.setLogoPosition(TencentMapOptions.LOGO_POSITION_TOP_RIGHT);
} // }
//
} // }
}); // });
//
compassControl.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { // compassControl.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override // @Override
public void onCheckedChanged(CompoundButton compoundButton, boolean b) { // public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
if (b){ // if (b){
//显示指南针 // //显示指南针
mapUiSettings.setCompassEnabled(true); // mapUiSettings.setCompassEnabled(true);
}else{ // }else{
//隐藏指南针 // //隐藏指南针
mapUiSettings.setCompassEnabled(false); // mapUiSettings.setCompassEnabled(false);
} // }
} // }
}); // });
//
scaleViewControl.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { // scaleViewControl.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override // @Override
public void onCheckedChanged(CompoundButton compoundButton, boolean b) { // public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
if (b){ // if (b){
//打开比例尺 // //打开比例尺
mapUiSettings.setScaleViewEnabled(true); // mapUiSettings.setScaleViewEnabled(true);
}else{ // }else{
//关闭比例尺 // //关闭比例尺
mapUiSettings.setScaleViewEnabled(false); // mapUiSettings.setScaleViewEnabled(false);
} // }
} // }
}); // });
//
//
//
//
} // }
} }

View File

@ -15,40 +15,40 @@ import com.tencent.tencentmap.mapsdk.maps.model.RestrictBoundsFitMode;
import com.tencent.tencentmap.mapsdk.maps.model.VisibleRegion; import com.tencent.tencentmap.mapsdk.maps.model.VisibleRegion;
public class MapAnchorZoomActivity extends SupportMapFragmentActivity { public class MapAnchorZoomActivity extends SupportMapFragmentActivity {
private Marker marker; // private Marker marker;
//
@Override // @Override
protected void onCreate(Bundle savedInstanceState) { // protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); // super.onCreate(savedInstanceState);
//
LatLng latLng = new LatLng(39.984108,116.307557); // LatLng latLng = new LatLng(39.984108,116.307557);
//
CameraUpdate cameraSigma = // CameraUpdate cameraSigma =
CameraUpdateFactory.newCameraPosition(new CameraPosition( // CameraUpdateFactory.newCameraPosition(new CameraPosition(
latLng, // latLng,
15, // 15,
0f, // 0f,
0f)); // 0f));
//移动地图 // //移动地图
tencentMap.moveCamera(cameraSigma); // tencentMap.moveCamera(cameraSigma);
Projection projection = tencentMap.getProjection(); // Projection projection = tencentMap.getProjection();
//
VisibleRegion region = projection.getVisibleRegion(); // 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_HEIGHT);
tencentMap.setRestrictBounds(new LatLngBounds(region.farRight, region.nearLeft), RestrictBoundsFitMode.FIT_WIDTH); // tencentMap.setRestrictBounds(new LatLngBounds(region.farRight, region.nearLeft), RestrictBoundsFitMode.FIT_WIDTH);
setMarker(latLng); // setMarker(latLng);
} // }
/** // /**
* 设置标注 // * 设置标注
*/ // */
private void setMarker(LatLng latLng){ // private void setMarker(LatLng latLng){
//
MarkerOptions options = new MarkerOptions().position(latLng); // MarkerOptions options = new MarkerOptions().position(latLng);
//
//设置infowindow // //设置infowindow
options.title("锚点"); // options.title("锚点");
marker = tencentMap.addMarker(options); // marker = tencentMap.addMarker(options);
marker.setInfoWindowEnable(true); // marker.setInfoWindowEnable(true);
} // }
} }

View File

@ -1,54 +1,54 @@
package cc.winboll.studio.positions.demo.camera; package cc.winboll.studio.positions.demo.camera;
import android.os.Bundle; //import android.os.Bundle;
import android.view.View; //import android.view.View;
import android.widget.CheckBox; //import android.widget.CheckBox;
import android.widget.CompoundButton; //import android.widget.CompoundButton;
import android.widget.RadioGroup; //import android.widget.RadioGroup;
//
import cc.winboll.studio.positions.R; //import cc.winboll.studio.positions.R;
import cc.winboll.studio.positions.demo.basic.SupportMapFragmentActivity; //import cc.winboll.studio.positions.demo.basic.SupportMapFragmentActivity;
import com.tencent.tencentmap.mapsdk.maps.model.LatLng; //import com.tencent.tencentmap.mapsdk.maps.model.LatLng;
import com.tencent.tencentmap.mapsdk.maps.model.LatLngBounds; //import com.tencent.tencentmap.mapsdk.maps.model.LatLngBounds;
import com.tencent.tencentmap.mapsdk.maps.model.RestrictBoundsFitMode; //import com.tencent.tencentmap.mapsdk.maps.model.RestrictBoundsFitMode;
//
public class MapBoundActivity extends SupportMapFragmentActivity { //public class MapBoundActivity extends SupportMapFragmentActivity {
private RadioGroup radioGroup; // private RadioGroup radioGroup;
private CheckBox fitHeight; // private CheckBox fitHeight;
private CheckBox fitWidth; // private CheckBox fitWidth;
@Override // @Override
protected void onCreate(Bundle savedInstanceState) { // protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); // super.onCreate(savedInstanceState);
final LatLng northeastLatLng = new LatLng(39.984066, 116.307548); // final LatLng northeastLatLng = new LatLng(39.984066, 116.307548);
final LatLng southwestLatLng = new LatLng(39.974066, 116.297548); // final LatLng southwestLatLng = new LatLng(39.974066, 116.297548);
radioGroup = findViewById(R.id.lay_map_bound); // radioGroup = findViewById(R.id.lay_map_bound);
radioGroup.setVisibility(View.VISIBLE); // radioGroup.setVisibility(View.VISIBLE);
fitWidth = findViewById(R.id.btn_fit_width); // fitWidth = findViewById(R.id.btn_fit_width);
fitWidth.setText("适应宽度"); // fitWidth.setText("适应宽度");
fitHeight = findViewById(R.id.btn_fit_height); // fitHeight = findViewById(R.id.btn_fit_height);
fitHeight.setText("适应高度"); // fitHeight.setText("适应高度");
fitHeight.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { // fitHeight.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override // @Override
public void onCheckedChanged(CompoundButton compoundButton, boolean b) { // public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
if (b){ // if (b){
tencentMap.setRestrictBounds(new LatLngBounds(northeastLatLng, southwestLatLng), RestrictBoundsFitMode.FIT_HEIGHT); // tencentMap.setRestrictBounds(new LatLngBounds(northeastLatLng, southwestLatLng), RestrictBoundsFitMode.FIT_HEIGHT);
}else{ // }else{
//
} // }
} // }
}); // });
//
fitWidth.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { // fitWidth.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override // @Override
public void onCheckedChanged(CompoundButton compoundButton, boolean b) { // public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
if (b){ // if (b){
tencentMap.setRestrictBounds(new LatLngBounds(northeastLatLng, southwestLatLng), RestrictBoundsFitMode.FIT_WIDTH); // tencentMap.setRestrictBounds(new LatLngBounds(northeastLatLng, southwestLatLng), RestrictBoundsFitMode.FIT_WIDTH);
}else{ // }else{
//
} // }
} // }
}); // });
} // }
//
//
} //}

View File

@ -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.CameraPosition;
import com.tencent.tencentmap.mapsdk.maps.model.LatLng; import com.tencent.tencentmap.mapsdk.maps.model.LatLng;
public class MapCameraCenterActivity extends SupportMapFragmentActivity implements TencentMap.OnCameraChangeListener, TencentMap.OnMapClickListener { //public class MapCameraCenterActivity extends SupportMapFragmentActivity implements TencentMap.OnCameraChangeListener, TencentMap.OnMapClickListener {
private TextView textView; // private TextView textView;
private String info; // private String info;
//
@Override // @Override
protected void onCreate(Bundle savedInstanceState) { // protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); // super.onCreate(savedInstanceState);
//
textView = findViewById(R.id.tv_info); // textView = findViewById(R.id.tv_info);
textView.setVisibility(View.VISIBLE); // textView.setVisibility(View.VISIBLE);
tencentMap.setOnCameraChangeListener(this); // tencentMap.setOnCameraChangeListener(this);
tencentMap.setOnMapClickListener(this); // tencentMap.setOnMapClickListener(this);
} // }
//
//
/** // /**
* 地图视图改变回调 // * 地图视图改变回调
* @param cameraPosition // * @param cameraPosition
*/ // */
@Override // @Override
public void onCameraChange(CameraPosition cameraPosition) { // public void onCameraChange(CameraPosition cameraPosition) {
//获取当前地图视图信息 // //获取当前地图视图信息
info = "经纬度:"+cameraPosition.target.latitude+","+cameraPosition.target.longitude+";zoom"+cameraPosition.zoom; // info = "经纬度:"+cameraPosition.target.latitude+","+cameraPosition.target.longitude+";zoom"+cameraPosition.zoom;
textView.setText(info); // textView.setText(info);
} // }
//
@Override // @Override
public void onCameraChangeFinished(CameraPosition cameraPosition) { // public void onCameraChangeFinished(CameraPosition cameraPosition) {
//获取当前地图视图信息 // //获取当前地图视图信息
info = "经纬度:"+cameraPosition.target.latitude+","+cameraPosition.target.longitude+";zoom"+cameraPosition.zoom; // info = "经纬度:"+cameraPosition.target.latitude+","+cameraPosition.target.longitude+";zoom"+cameraPosition.zoom;
Toast.makeText(MapCameraCenterActivity.this,info,Toast.LENGTH_SHORT).show(); // Toast.makeText(MapCameraCenterActivity.this,info,Toast.LENGTH_SHORT).show();
textView.setText(info); // textView.setText(info);
//
} // }
//
@Override // @Override
public void onMapClick(LatLng latLng) { // public void onMapClick(LatLng latLng) {
tencentMap.moveCamera(CameraUpdateFactory.newCameraPosition(new CameraPosition(latLng,15f, 0, 0))); // tencentMap.moveCamera(CameraUpdateFactory.newCameraPosition(new CameraPosition(latLng,15f, 0, 0)));
} // }
} //}

View File

@ -1,126 +1,126 @@
package cc.winboll.studio.positions.demo.circle; package cc.winboll.studio.positions.demo.circle;
import androidx.annotation.NonNull; //import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity; //import androidx.appcompat.app.AppCompatActivity;
//
import android.graphics.Color; //import android.graphics.Color;
import android.os.Bundle; //import android.os.Bundle;
import android.view.Menu; //import android.view.Menu;
import android.view.MenuItem; //import android.view.MenuItem;
import android.view.View; //import android.view.View;
//
import cc.winboll.studio.positions.R; //import cc.winboll.studio.positions.R;
import com.tencent.tencentmap.mapsdk.maps.CameraUpdate; //import com.tencent.tencentmap.mapsdk.maps.CameraUpdate;
import com.tencent.tencentmap.mapsdk.maps.CameraUpdateFactory; //import com.tencent.tencentmap.mapsdk.maps.CameraUpdateFactory;
import com.tencent.tencentmap.mapsdk.maps.MapView; //import com.tencent.tencentmap.mapsdk.maps.MapView;
import com.tencent.tencentmap.mapsdk.maps.TencentMap; //import com.tencent.tencentmap.mapsdk.maps.TencentMap;
import com.tencent.tencentmap.mapsdk.maps.model.Arc; //import com.tencent.tencentmap.mapsdk.maps.model.Arc;
import com.tencent.tencentmap.mapsdk.maps.model.ArcOptions; //import com.tencent.tencentmap.mapsdk.maps.model.ArcOptions;
import com.tencent.tencentmap.mapsdk.maps.model.BitmapDescriptor; //import com.tencent.tencentmap.mapsdk.maps.model.BitmapDescriptor;
import com.tencent.tencentmap.mapsdk.maps.model.BitmapDescriptorFactory; //import com.tencent.tencentmap.mapsdk.maps.model.BitmapDescriptorFactory;
import com.tencent.tencentmap.mapsdk.maps.model.CameraPosition; //import com.tencent.tencentmap.mapsdk.maps.model.CameraPosition;
import com.tencent.tencentmap.mapsdk.maps.model.LatLng; //import com.tencent.tencentmap.mapsdk.maps.model.LatLng;
import com.tencent.tencentmap.mapsdk.maps.model.Marker; //import com.tencent.tencentmap.mapsdk.maps.model.Marker;
import com.tencent.tencentmap.mapsdk.maps.model.MarkerCollisionItem; //import com.tencent.tencentmap.mapsdk.maps.model.MarkerCollisionItem;
import com.tencent.tencentmap.mapsdk.maps.model.MarkerOptions; //import com.tencent.tencentmap.mapsdk.maps.model.MarkerOptions;
//
public class ArcActivity extends AppCompatActivity { //public class ArcActivity extends AppCompatActivity {
//
private MapView mapView; // private MapView mapView;
private TencentMap tencentMap; // private TencentMap tencentMap;
private boolean mMarkerAdded; // private boolean mMarkerAdded;
private Arc arc; // private Arc arc;
//
@Override // @Override
protected void onCreate(Bundle savedInstanceState) { // protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); // super.onCreate(savedInstanceState);
setContentView(R.layout.activity_arc); // setContentView(R.layout.activity_arc);
init(); // init();
} // }
//
private void init() { // private void init() {
mapView = findViewById(R.id.mapView); // mapView = findViewById(R.id.mapView);
tencentMap = mapView.getMap(); // tencentMap = mapView.getMap();
CameraUpdate cameraSigma = // CameraUpdate cameraSigma =
CameraUpdateFactory.newCameraPosition(new CameraPosition( // CameraUpdateFactory.newCameraPosition(new CameraPosition(
new LatLng(32.059352, 118.796623), // new LatLng(32.059352, 118.796623),
5, // 5,
0f, // 0f,
0f)); // 0f));
//移动地图 // //移动地图
tencentMap.moveCamera(cameraSigma); // tencentMap.moveCamera(cameraSigma);
} // }
//
@Override // @Override
public boolean onCreateOptionsMenu(Menu menu) { // public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.markercol, menu); // getMenuInflater().inflate(R.menu.markercol, menu);
return super.onCreateOptionsMenu(menu); // return super.onCreateOptionsMenu(menu);
} // }
//
@Override // @Override
public boolean onPrepareOptionsMenu(Menu menu) { // public boolean onPrepareOptionsMenu(Menu menu) {
menu.findItem(R.id.menu_open_collisionsmap).setVisible(!mMarkerAdded); // menu.findItem(R.id.menu_open_collisionsmap).setVisible(!mMarkerAdded);
menu.findItem(R.id.menu_close_collisionsmap).setVisible(mMarkerAdded); // menu.findItem(R.id.menu_close_collisionsmap).setVisible(mMarkerAdded);
return super.onPrepareOptionsMenu(menu); // return super.onPrepareOptionsMenu(menu);
} // }
//
@Override // @Override
public boolean onOptionsItemSelected(@NonNull MenuItem item) { // public boolean onOptionsItemSelected(@NonNull MenuItem item) {
switch (item.getItemId()) { // switch (item.getItemId()) {
case R.id.menu_open_collisionsmap: // case R.id.menu_open_collisionsmap:
mMarkerAdded = true; // mMarkerAdded = true;
LatLng startLat = new LatLng(39.89491, 116.322056); // LatLng startLat = new LatLng(39.89491, 116.322056);
LatLng endtLat = new LatLng(22.547, 114.085947); // LatLng endtLat = new LatLng(22.547, 114.085947);
LatLng passLat = new LatLng(32.059352, 118.796623); // LatLng passLat = new LatLng(32.059352, 118.796623);
ArcOptions arcOptions = new ArcOptions(); // ArcOptions arcOptions = new ArcOptions();
arcOptions.points(startLat, endtLat); // arcOptions.points(startLat, endtLat);
arcOptions.pass(passLat); // arcOptions.pass(passLat);
//设置起点到终点与起点外切线逆时针旋转的夹角角度 // //设置起点到终点与起点外切线逆时针旋转的夹角角度
arcOptions.angle(30); // arcOptions.angle(30);
//设置线宽默认5 // //设置线宽默认5
arcOptions.width(2); // arcOptions.width(2);
//设置线颜色默认黑色 // //设置线颜色默认黑色
arcOptions.color(Color.BLUE); // arcOptions.color(Color.BLUE);
arc = tencentMap.addArc(arcOptions); // arc = tencentMap.addArc(arcOptions);
break; // break;
case R.id.menu_close_collisionsmap: // case R.id.menu_close_collisionsmap:
mMarkerAdded = false; // mMarkerAdded = false;
arc.remove(); // arc.remove();
break; // break;
} // }
//
supportInvalidateOptionsMenu(); // supportInvalidateOptionsMenu();
return super.onOptionsItemSelected(item); // return super.onOptionsItemSelected(item);
} // }
//
@Override // @Override
protected void onResume() { // protected void onResume() {
super.onResume(); // super.onResume();
mapView.onResume(); // mapView.onResume();
} // }
//
@Override // @Override
protected void onPause() { // protected void onPause() {
super.onPause(); // super.onPause();
mapView.onPause(); // mapView.onPause();
} // }
//
@Override // @Override
protected void onDestroy() { // protected void onDestroy() {
super.onDestroy(); // super.onDestroy();
mapView.onDestroy(); // mapView.onDestroy();
} // }
//
//
@Override // @Override
protected void onStart() { // protected void onStart() {
super.onStart(); // super.onStart();
mapView.onStart(); // mapView.onStart();
} // }
//
@Override // @Override
protected void onStop() { // protected void onStop() {
super.onStop(); // super.onStop();
mapView.onStop(); // mapView.onStop();
} // }
} //}

View File

@ -8,28 +8,28 @@ import com.tencent.tencentmap.mapsdk.maps.model.CircleOptions;
import com.tencent.tencentmap.mapsdk.maps.model.LatLng; import com.tencent.tencentmap.mapsdk.maps.model.LatLng;
public class CircleOptionsActivity extends SupportMapFragmentActivity { public class CircleOptionsActivity extends SupportMapFragmentActivity {
@Override // @Override
protected void onCreate(Bundle savedInstanceState) { // protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); // super.onCreate(savedInstanceState);
Circle circle = tencentMap.addCircle(circleOptions); // Circle circle = tencentMap.addCircle(circleOptions);
Circle newCircle = tencentMap.addCircle(newCircleOptions); // Circle newCircle = tencentMap.addCircle(newCircleOptions);
newCircle.setCenter(new LatLng(39.98408, 116.30701)); //重新设置圆心 // newCircle.setCenter(new LatLng(39.98408, 116.30701)); //重新设置圆心
newCircle.setOptions(newCircleOptions); //重新设置圆形属性 // newCircle.setOptions(newCircleOptions); //重新设置圆形属性
} // }
//
/** // /**
* 圆形选项 // * 圆形选项
*/ // */
private CircleOptions circleOptions = new CircleOptions() //圆形选项 // private CircleOptions circleOptions = new CircleOptions() //圆形选项
.center(new LatLng(39.9849, 116.3977)) //圆心位置 // .center(new LatLng(39.9849, 116.3977)) //圆心位置
.clickable(true) //支持点击 // .clickable(true) //支持点击
.fillColor((128 << 24) + (100 << 16) + (50 << 8) + 120) //设置填充颜色RGBA // .fillColor((128 << 24) + (100 << 16) + (50 << 8) + 120) //设置填充颜色RGBA
.radius(110d) //设置半径 // .radius(110d) //设置半径
.visible(true) //设置是否可见 // .visible(true) //设置是否可见
.zIndex(1) //设置堆叠顺序越大优先级越高 // .zIndex(1) //设置堆叠顺序越大优先级越高
.strokeWidth(1) //描边宽度 // .strokeWidth(1) //描边宽度
.strokeColor((128 << 24) + (128 << 16) + (128 << 8) + 128); //描边颜色 // .strokeColor((128 << 24) + (128 << 16) + (128 << 8) + 128); //描边颜色
//
//
private CircleOptions newCircleOptions = new CircleOptions().center(new LatLng(39.121, 116.454)).radius(90d).fillColor(0xff00ff00); // private CircleOptions newCircleOptions = new CircleOptions().center(new LatLng(39.121, 116.454)).radius(90d).fillColor(0xff00ff00);
} }

View File

@ -9,16 +9,16 @@ import com.tencent.tencentmap.mapsdk.maps.model.CircleOptions;
import com.tencent.tencentmap.mapsdk.maps.model.LatLng; import com.tencent.tencentmap.mapsdk.maps.model.LatLng;
public class DrawCircleActivity extends SupportMapFragmentActivity { public class DrawCircleActivity extends SupportMapFragmentActivity {
//
@Override // @Override
protected void onCreate(Bundle savedInstanceState) { // protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); // super.onCreate(savedInstanceState);
LatLng latLng = new LatLng(39.984059,116.307771); // LatLng latLng = new LatLng(39.984059,116.307771);
Circle circle = tencentMap.addCircle(new CircleOptions(). // Circle circle = tencentMap.addCircle(new CircleOptions().
center(latLng). // center(latLng).
radius(100d). // radius(100d).
fillColor(getResources().getColor(R.color.style)). // fillColor(getResources().getColor(R.color.style)).
strokeColor(getResources().getColor(R.color.colorPrimary)). // strokeColor(getResources().getColor(R.color.colorPrimary)).
strokeWidth(1)); // strokeWidth(1));
} // }
} }

View File

@ -1,80 +1,80 @@
package cc.winboll.studio.positions.demo.gesture; package cc.winboll.studio.positions.demo.gesture;
import android.os.Bundle; //import android.os.Bundle;
import android.view.View; //import android.view.View;
import android.widget.CheckBox; //import android.widget.CheckBox;
import android.widget.CompoundButton; //import android.widget.CompoundButton;
import android.widget.RadioGroup; //import android.widget.RadioGroup;
//
import cc.winboll.studio.positions.R; //import cc.winboll.studio.positions.R;
import cc.winboll.studio.positions.demo.basic.SupportMapFragmentActivity; //import cc.winboll.studio.positions.demo.basic.SupportMapFragmentActivity;
//
public class GestureSettingsActivity extends SupportMapFragmentActivity { //public class GestureSettingsActivity extends SupportMapFragmentActivity {
//
private CheckBox scrollBox; // private CheckBox scrollBox;
private CheckBox zoomBox; // private CheckBox zoomBox;
private CheckBox rotateBox; // private CheckBox rotateBox;
private CheckBox tiltBox; // private CheckBox tiltBox;
private RadioGroup radioGroup; // private RadioGroup radioGroup;
@Override // @Override
protected void onCreate(Bundle savedInstanceState) { // protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); // super.onCreate(savedInstanceState);
radioGroup = findViewById(R.id.lay_checkbox); // radioGroup = findViewById(R.id.lay_checkbox);
radioGroup.setVisibility(View.VISIBLE); // radioGroup.setVisibility(View.VISIBLE);
initView(); // initView();
} // }
//
private void initView(){ // private void initView(){
scrollBox = findViewById(R.id.btn_scroll); // scrollBox = findViewById(R.id.btn_scroll);
zoomBox = findViewById(R.id.btn_zoom); // zoomBox = findViewById(R.id.btn_zoom);
rotateBox = findViewById(R.id.btn_rotate); // rotateBox = findViewById(R.id.btn_rotate);
tiltBox = findViewById(R.id.btn_slope); // tiltBox = findViewById(R.id.btn_slope);
//
//
scrollBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { // scrollBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override // @Override
public void onCheckedChanged(CompoundButton compoundButton, boolean b) { // public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
if (b){ // if (b){
mapUiSettings.setScrollGesturesEnabled(true); // mapUiSettings.setScrollGesturesEnabled(true);
}else{ // }else{
mapUiSettings.setScrollGesturesEnabled(false); // mapUiSettings.setScrollGesturesEnabled(false);
} // }
} // }
}); // });
//
//
zoomBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { // zoomBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override // @Override
public void onCheckedChanged(CompoundButton compoundButton, boolean b) { // public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
if (b){ // if (b){
mapUiSettings.setZoomGesturesEnabled(true); // mapUiSettings.setZoomGesturesEnabled(true);
}else{ // }else{
mapUiSettings.setZoomGesturesEnabled(false); // mapUiSettings.setZoomGesturesEnabled(false);
} // }
} // }
}); // });
//
rotateBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { // rotateBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override // @Override
public void onCheckedChanged(CompoundButton compoundButton, boolean b) { // public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
if (b){ // if (b){
mapUiSettings.setRotateGesturesEnabled(true); // mapUiSettings.setRotateGesturesEnabled(true);
}else{ // }else{
mapUiSettings.setRotateGesturesEnabled(false); // mapUiSettings.setRotateGesturesEnabled(false);
} // }
} // }
}); // });
//
tiltBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { // tiltBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override // @Override
public void onCheckedChanged(CompoundButton compoundButton, boolean b) { // public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
if (b){ // if (b){
mapUiSettings.setTiltGesturesEnabled(true); // mapUiSettings.setTiltGesturesEnabled(true);
}else{ // }else{
mapUiSettings.setTiltGesturesEnabled(false); // mapUiSettings.setTiltGesturesEnabled(false);
} // }
} // }
}); // });
} // }
//
} //}

View File

@ -8,75 +8,126 @@ import cc.winboll.studio.positions.R;
import cc.winboll.studio.positions.demo.basic.SupportMapFragmentActivity; import cc.winboll.studio.positions.demo.basic.SupportMapFragmentActivity;
import com.tencent.tencentmap.mapsdk.maps.model.CameraPosition; import com.tencent.tencentmap.mapsdk.maps.model.CameraPosition;
import com.tencent.tencentmap.mapsdk.maps.model.TencentMapGestureListener; 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 { public class MapGestureListenActivity extends SupportMapFragmentActivity implements TencentMapGestureListener {
private TextView textView;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { public boolean onDoubleTap(float p1, float p2) {
super.onCreate(savedInstanceState); return false;
textView = findViewById(R.id.tv_info);
textView.setVisibility(View.VISIBLE);
tencentMap.setTencentMapGestureListener(this);
} }
@Override @Override
public boolean onDoubleTap(float v, float v1) { public boolean onSingleTap(float p1, float p2) {
textView.setText("单指双击"); return false;
return true;
} }
@Override @Override
public boolean onSingleTap(float v, float v1) { public boolean onFling(float p1, float p2) {
textView.setText("单指单击"); return false;
return true;
} }
@Override @Override
public boolean onFling(float v, float v1) { public boolean onScroll(float p1, float p2) {
textView.setText("单指惯性滑动"); return false;
return true;
} }
@Override @Override
public boolean onScroll(float v, float v1) { public boolean onLongPress(float p1, float p2) {
textView.setText("单指滑动"); return false;
return true;
} }
@Override @Override
public boolean onLongPress(float v, float v1) { public boolean onDown(float p1, float p2) {
textView.setText("长按"); return false;
return true;
} }
@Override @Override
public boolean onDown(float v, float v1) { public boolean onUp(float p1, float p2) {
textView.setText("单指按下"); return false;
return true;
} }
@Override @Override
public boolean onUp(float v, float v1) { public boolean onTwoFingerMoveAgainst(TencentMapGestureListener.TwoFingerMoveAgainstStatus p1, CameraPosition p2) {
textView.setText("单指抬起");
return true;
}
@Override
public boolean onTwoFingerMoveAgainst(TwoFingerMoveAgainstStatus twoFingerMoveAgainstStatus, CameraPosition cameraPosition) {
textView.setText("双指捏合");
return false; return false;
} }
@Override @Override
public void onMapStable() { public void onMapStable() {
textView.setText("地图稳定");
return;
} }
@Override @Override
public void onMapStableBy(CameraPosition.Trigger trigger) { public void onMapStableBy(CameraPosition.Trigger p1) {
textView.setText("地图稳定 by " + trigger.name());
return;
} }
// 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;
// }
} }

View File

@ -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.TencentMap;
import com.tencent.tencentmap.mapsdk.maps.model.LatLng; import com.tencent.tencentmap.mapsdk.maps.model.LatLng;
public class MapListenActivity extends SupportMapFragmentActivity implements TencentMap.OnMapClickListener { //public class MapListenActivity extends SupportMapFragmentActivity implements TencentMap.OnMapClickListener {
private TextView textView; // private TextView textView;
//
@Override // @Override
protected void onCreate(Bundle savedInstanceState) { // protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); // super.onCreate(savedInstanceState);
textView = findViewById(R.id.tv_info); // textView = findViewById(R.id.tv_info);
textView.setVisibility(View.VISIBLE); // textView.setVisibility(View.VISIBLE);
tencentMap.setOnMapClickListener(this); // tencentMap.setOnMapClickListener(this);
} // }
//
@Override // @Override
public void onMapClick(LatLng latLng) { // public void onMapClick(LatLng latLng) {
String info = "经纬度:" + latLng.latitude + "," + latLng.longitude; // String info = "经纬度:" + latLng.latitude + "," + latLng.longitude;
Toast.makeText(MapListenActivity.this, info, Toast.LENGTH_SHORT).show(); // Toast.makeText(MapListenActivity.this, info, Toast.LENGTH_SHORT).show();
textView.setText(info); // textView.setText(info);
} // }
} //}

View File

@ -1,63 +1,63 @@
package cc.winboll.studio.positions.demo.gesture; package cc.winboll.studio.positions.demo.gesture;
import android.graphics.Bitmap; //import android.graphics.Bitmap;
import android.graphics.BitmapFactory; //import android.graphics.BitmapFactory;
import android.graphics.Matrix; //import android.graphics.Matrix;
import android.os.Bundle; //import android.os.Bundle;
import android.view.View; //import android.view.View;
import android.widget.TextView; //import android.widget.TextView;
//
import cc.winboll.studio.positions.R; //import cc.winboll.studio.positions.R;
import cc.winboll.studio.positions.demo.basic.SupportMapFragmentActivity; //import cc.winboll.studio.positions.demo.basic.SupportMapFragmentActivity;
import com.tencent.tencentmap.mapsdk.maps.TencentMap; //import com.tencent.tencentmap.mapsdk.maps.TencentMap;
import com.tencent.tencentmap.mapsdk.maps.model.BitmapDescriptor; //import com.tencent.tencentmap.mapsdk.maps.model.BitmapDescriptor;
import com.tencent.tencentmap.mapsdk.maps.model.BitmapDescriptorFactory; //import com.tencent.tencentmap.mapsdk.maps.model.BitmapDescriptorFactory;
import com.tencent.tencentmap.mapsdk.maps.model.LatLng; //import com.tencent.tencentmap.mapsdk.maps.model.LatLng;
import com.tencent.tencentmap.mapsdk.maps.model.MarkerOptions; //import com.tencent.tencentmap.mapsdk.maps.model.MarkerOptions;
//
public class MapLongClickActivity extends SupportMapFragmentActivity implements TencentMap.OnMapLongClickListener { //public class MapLongClickActivity extends SupportMapFragmentActivity implements TencentMap.OnMapLongClickListener {
private TextView textView; // private TextView textView;
@Override // @Override
protected void onCreate(Bundle savedInstanceState) { // protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); // super.onCreate(savedInstanceState);
textView = findViewById(R.id.tv_info); // textView = findViewById(R.id.tv_info);
textView.setVisibility(View.VISIBLE); // textView.setVisibility(View.VISIBLE);
tencentMap.setOnMapLongClickListener(this); // tencentMap.setOnMapLongClickListener(this);
} // }
//
@Override // @Override
public void onMapLongClick(LatLng latLng) { // public void onMapLongClick(LatLng latLng) {
String info = "经纬度:"+latLng.latitude+","+latLng.longitude; // String info = "经纬度:"+latLng.latitude+","+latLng.longitude;
textView.setText(info); // textView.setText(info);
setMarker(latLng); // setMarker(latLng);
} // }
//
/** // /**
* 长按添加标注 // * 长按添加标注
*/ // */
private void setMarker(LatLng latLng){ // private void setMarker(LatLng latLng){
//
BitmapDescriptor bitmapDescriptor = BitmapDescriptorFactory.fromBitmap(getBitMap(R.drawable.marker)); // BitmapDescriptor bitmapDescriptor = BitmapDescriptorFactory.fromBitmap(getBitMap(R.drawable.marker));
MarkerOptions options = new MarkerOptions().position(latLng).icon(bitmapDescriptor); // MarkerOptions options = new MarkerOptions().position(latLng).icon(bitmapDescriptor);
tencentMap.clear(); // tencentMap.clear();
tencentMap.addMarker(options); // tencentMap.addMarker(options);
//
} // }
//
//
private Bitmap getBitMap(int resourceId){ // private Bitmap getBitMap(int resourceId){
Bitmap bitmap = BitmapFactory.decodeResource(getResources(), resourceId); // Bitmap bitmap = BitmapFactory.decodeResource(getResources(), resourceId);
int width = bitmap.getWidth(); // int width = bitmap.getWidth();
int height = bitmap.getHeight(); // int height = bitmap.getHeight();
int newWidth = 100; // int newWidth = 100;
int newHeight = 100; // int newHeight = 100;
float widthScale = ((float)newWidth)/width; // float widthScale = ((float)newWidth)/width;
float heightScale = ((float)newHeight)/height; // float heightScale = ((float)newHeight)/height;
Matrix matrix = new Matrix(); // Matrix matrix = new Matrix();
matrix.postScale(widthScale, heightScale); // matrix.postScale(widthScale, heightScale);
bitmap = Bitmap.createBitmap(bitmap,0,0,width,height,matrix,true); // bitmap = Bitmap.createBitmap(bitmap,0,0,width,height,matrix,true);
return bitmap; // return bitmap;
} // }
//
//
} //}

View File

@ -26,172 +26,172 @@ import java.io.InputStreamReader;
import java.util.ArrayList; import java.util.ArrayList;
public class AggregationOverlayActivity extends AppCompatActivity { public class AggregationOverlayActivity extends AppCompatActivity {
private MapView mMapView; // private MapView mMapView;
private TencentMap mTencentMap; // private TencentMap mTencentMap;
private AggregationOverlay aggregationOverlay; // private AggregationOverlay aggregationOverlay;
private AggregationOverlayProvider aggregationOverlayProvider; // private AggregationOverlayProvider aggregationOverlayProvider;
private Switch btnSwitch3D; // private Switch btnSwitch3D;
//
boolean mIsSelected; // boolean mIsSelected;
//
@Override // @Override
protected void onCreate(Bundle savedInstanceState) { // protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); // super.onCreate(savedInstanceState);
setContentView(R.layout.activity_aggregation_overlay_design); // setContentView(R.layout.activity_aggregation_overlay_design);
init(); // init();
} // }
//
@Override // @Override
public boolean onCreateOptionsMenu(Menu menu) { // public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.vectorheatmap, menu); // getMenuInflater().inflate(R.menu.vectorheatmap, menu);
return true; // return true;
} // }
//
@Override // @Override
public boolean onPrepareOptionsMenu(Menu menu) { // public boolean onPrepareOptionsMenu(Menu menu) {
menu.findItem(R.id.menu_open_vectorheatmap).setVisible(!mIsSelected); // menu.findItem(R.id.menu_open_vectorheatmap).setVisible(!mIsSelected);
menu.findItem(R.id.menu_close_vectorheatmap).setVisible(mIsSelected); // menu.findItem(R.id.menu_close_vectorheatmap).setVisible(mIsSelected);
return super.onPrepareOptionsMenu(menu); // return super.onPrepareOptionsMenu(menu);
} // }
//
@Override // @Override
public boolean onOptionsItemSelected(@NonNull MenuItem item) { // public boolean onOptionsItemSelected(@NonNull MenuItem item) {
switch (item.getItemId()) { // switch (item.getItemId()) {
case R.id.menu_open_vectorheatmap: // case R.id.menu_open_vectorheatmap:
addAggregation(); // addAggregation();
break; // break;
case R.id.menu_close_vectorheatmap: // case R.id.menu_close_vectorheatmap:
mIsSelected = false; // mIsSelected = false;
if (aggregationOverlay != null) { // if (aggregationOverlay != null) {
aggregationOverlay.remove(); // aggregationOverlay.remove();
aggregationOverlay = null; // aggregationOverlay = null;
} // }
break; // break;
} // }
//
supportInvalidateOptionsMenu(); // supportInvalidateOptionsMenu();
return super.onOptionsItemSelected(item); // return super.onOptionsItemSelected(item);
} // }
//
@Override // @Override
protected void onResume() { // protected void onResume() {
super.onResume(); // super.onResume();
mMapView.onResume(); // mMapView.onResume();
} // }
//
@Override // @Override
protected void onPause() { // protected void onPause() {
super.onPause(); // super.onPause();
mMapView.onPause(); // mMapView.onPause();
} // }
//
@Override // @Override
protected void onDestroy() { // protected void onDestroy() {
super.onDestroy(); // super.onDestroy();
mMapView.onDestroy(); // mMapView.onDestroy();
} // }
//
//
@Override // @Override
protected void onStart() { // protected void onStart() {
super.onStart(); // super.onStart();
mMapView.onStart(); // mMapView.onStart();
} // }
//
@Override // @Override
protected void onStop() { // protected void onStop() {
super.onStop(); // super.onStop();
mMapView.onStop(); // mMapView.onStop();
} // }
//
private void init() { // private void init() {
mMapView = findViewById(R.id.mapView); // mMapView = findViewById(R.id.mapView);
mTencentMap = mMapView.getMap(); // mTencentMap = mMapView.getMap();
mTencentMap.setMapStyle(3); // mTencentMap.setMapStyle(3);
mTencentMap.moveCamera(CameraUpdateFactory.zoomTo(10f)); // mTencentMap.moveCamera(CameraUpdateFactory.zoomTo(10f));
btnSwitch3D = (Switch) findViewById(R.id.btn_switch_3D); // btnSwitch3D = (Switch) findViewById(R.id.btn_switch_3D);
bindListener(); // bindListener();
} // }
//
//
private void bindListener() { // private void bindListener() {
//
CompoundButton.OnCheckedChangeListener onCheckedChangeListener = new CompoundButton.OnCheckedChangeListener() { // CompoundButton.OnCheckedChangeListener onCheckedChangeListener = new CompoundButton.OnCheckedChangeListener() {
//
@Override // @Override
public void onCheckedChanged(CompoundButton compoundButton, boolean b) { // public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
switch (compoundButton.getId()) { // switch (compoundButton.getId()) {
case R.id.btn_switch_3D: // case R.id.btn_switch_3D:
if (aggregationOverlay != null) { // if (aggregationOverlay != null) {
if (compoundButton.isChecked()) { // if (compoundButton.isChecked()) {
aggregationOverlayProvider.enable3D(true); // aggregationOverlayProvider.enable3D(true);
aggregationOverlayProvider.enable3D(true).setAnimateDuration(3000); // aggregationOverlayProvider.enable3D(true).setAnimateDuration(3000);
} else { // } else {
aggregationOverlayProvider.enable3D(false); // aggregationOverlayProvider.enable3D(false);
} // }
mTencentMap.updateVectorOverlay(aggregationOverlay, aggregationOverlayProvider); // mTencentMap.updateVectorOverlay(aggregationOverlay, aggregationOverlayProvider);
} // }
break; // break;
default: // default:
break; // break;
} // }
} // }
}; // };
//
//
btnSwitch3D.setOnCheckedChangeListener(onCheckedChangeListener); // btnSwitch3D.setOnCheckedChangeListener(onCheckedChangeListener);
//
} // }
//
protected void addAggregation() { // protected void addAggregation() {
mIsSelected = true; // mIsSelected = true;
if (aggregationOverlay != null) { // if (aggregationOverlay != null) {
return; // return;
} // }
// mTencentMap.moveCamera(CameraUpdateFactory.newCameraPosition(new CameraPosition(new LatLng(39.961629, 116.355343), 12, 0, 0))); // // mTencentMap.moveCamera(CameraUpdateFactory.newCameraPosition(new CameraPosition(new LatLng(39.961629, 116.355343), 12, 0, 0)));
mTencentMap.setBuildingEnable(false); // mTencentMap.setBuildingEnable(false);
mTencentMap.setPoisEnabled(false); // mTencentMap.setPoisEnabled(false);
BufferedReader br = null; // BufferedReader br = null;
try { // try {
ArrayList<WeightedLatLng> nodes = new ArrayList<WeightedLatLng>(); // ArrayList<WeightedLatLng> nodes = new ArrayList<WeightedLatLng>();
br = new BufferedReader(new InputStreamReader(getResources().getAssets().open("data2k"))); // br = new BufferedReader(new InputStreamReader(getResources().getAssets().open("data2k")));
String line = null; // String line = null;
while ((line = br.readLine()) != null) { // while ((line = br.readLine()) != null) {
String[] lines = line.split("\t"); // String[] lines = line.split("\t");
if (lines.length == 3) { // if (lines.length == 3) {
double value = Double.parseDouble(lines[2]); // double value = Double.parseDouble(lines[2]);
LatLng latLng = new LatLng((Double.parseDouble(lines[1])), (Double.parseDouble(lines[0]))); // LatLng latLng = new LatLng((Double.parseDouble(lines[1])), (Double.parseDouble(lines[0])));
nodes.add(new WeightedLatLng(latLng, value)); // nodes.add(new WeightedLatLng(latLng, value));
} // }
} // }
//
int[] colors = { // int[] colors = {
Color.argb(255, 0x01, 0x2C, 0x4B), // Color.argb(255, 0x01, 0x2C, 0x4B),
Color.argb(255, 0x17, 0x3E, 0x59), // Color.argb(255, 0x17, 0x3E, 0x59),
Color.argb(255, 0x3A, 0x73, 0x78), // Color.argb(255, 0x3A, 0x73, 0x78),
Color.argb(255, 0x98, 0xCD, 0x9A), // Color.argb(255, 0x98, 0xCD, 0x9A),
Color.argb(255, 0xF6, 0xFB, 0xB6) // Color.argb(255, 0xF6, 0xFB, 0xB6)
}; // };
double[] startPoints = {0.f, 0.1f, 0.15f, 0.3f, 0.5f}; // double[] startPoints = {0.f, 0.1f, 0.15f, 0.3f, 0.5f};
//
//
aggregationOverlayProvider = new HoneyCombVectorOverlayProvider() // aggregationOverlayProvider = new HoneyCombVectorOverlayProvider()
.nodes(nodes.toArray(new WeightedLatLng[0])) // .nodes(nodes.toArray(new WeightedLatLng[0]))
.setHeightRange(0, 4000); // .setHeightRange(0, 4000);
aggregationOverlayProvider.colors(colors, startPoints); // aggregationOverlayProvider.colors(colors, startPoints);
aggregationOverlay = mTencentMap.addVectorOverlay(aggregationOverlayProvider); // aggregationOverlay = mTencentMap.addVectorOverlay(aggregationOverlayProvider);
//
//
} catch (Exception e) { // } catch (Exception e) {
e.printStackTrace(); // e.printStackTrace();
} finally { // } finally {
if (br != null) { // if (br != null) {
try { // try {
br.close(); // br.close();
} catch (IOException e) { // } catch (IOException e) {
e.printStackTrace(); // e.printStackTrace();
} // }
} // }
} // }
} // }
} }

View File

@ -1,182 +1,182 @@
package cc.winboll.studio.positions.demo.heatoverlay; package cc.winboll.studio.positions.demo.heatoverlay;
import androidx.annotation.NonNull; //import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity; //import androidx.appcompat.app.AppCompatActivity;
//
import android.graphics.Color; //import android.graphics.Color;
import android.os.Bundle; //import android.os.Bundle;
import android.view.Menu; //import android.view.Menu;
import android.view.MenuItem; //import android.view.MenuItem;
import android.view.View; //import android.view.View;
import android.widget.Button; //import android.widget.Button;
import android.widget.CompoundButton; //import android.widget.CompoundButton;
import android.widget.Switch; //import android.widget.Switch;
//
import com.tencent.map.sdk.utilities.visualization.datamodels.FromToLatLng; //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.ArcLineOverlay;
import com.tencent.map.sdk.utilities.visualization.od.ArcLineOverlayProvider; //import com.tencent.map.sdk.utilities.visualization.od.ArcLineOverlayProvider;
import cc.winboll.studio.positions.R; //import cc.winboll.studio.positions.R;
import com.tencent.tencentmap.mapsdk.maps.CameraUpdateFactory; //import com.tencent.tencentmap.mapsdk.maps.CameraUpdateFactory;
import com.tencent.tencentmap.mapsdk.maps.MapView; //import com.tencent.tencentmap.mapsdk.maps.MapView;
import com.tencent.tencentmap.mapsdk.maps.TencentMap; //import com.tencent.tencentmap.mapsdk.maps.TencentMap;
import com.tencent.tencentmap.mapsdk.maps.model.CameraPosition; //import com.tencent.tencentmap.mapsdk.maps.model.CameraPosition;
import com.tencent.tencentmap.mapsdk.maps.model.LatLng; //import com.tencent.tencentmap.mapsdk.maps.model.LatLng;
import com.tencent.tencentmap.mapsdk.maps.model.VectorOverlay; //import com.tencent.tencentmap.mapsdk.maps.model.VectorOverlay;
//
import java.io.BufferedReader; //import java.io.BufferedReader;
import java.io.InputStreamReader; //import java.io.InputStreamReader;
import java.util.ArrayList; //import java.util.ArrayList;
//
public class ArcLineLayerActivity extends AppCompatActivity { //public class ArcLineLayerActivity extends AppCompatActivity {
private MapView mMapView; // private MapView mMapView;
private TencentMap mTencentMap; // private TencentMap mTencentMap;
private VectorOverlay vectorOverlay; // private VectorOverlay vectorOverlay;
private ArcLineOverlayProvider options; // private ArcLineOverlayProvider options;
private Switch btnSwitch3D; // private Switch btnSwitch3D;
boolean mIsSelected; // boolean mIsSelected;
private Switch btnani3D; // private Switch btnani3D;
//
@Override // @Override
protected void onCreate(Bundle savedInstanceState) { // protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); // super.onCreate(savedInstanceState);
setContentView(R.layout.activity_arc_line_layer_design); // setContentView(R.layout.activity_arc_line_layer_design);
init(); // init();
} // }
//
@Override // @Override
public boolean onCreateOptionsMenu(Menu menu) { // public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.vectorheatmap, menu); // getMenuInflater().inflate(R.menu.vectorheatmap, menu);
return true; // return true;
} // }
//
@Override // @Override
public boolean onPrepareOptionsMenu(Menu menu) { // public boolean onPrepareOptionsMenu(Menu menu) {
menu.findItem(R.id.menu_open_vectorheatmap).setVisible(!mIsSelected); // menu.findItem(R.id.menu_open_vectorheatmap).setVisible(!mIsSelected);
menu.findItem(R.id.menu_close_vectorheatmap).setVisible(mIsSelected); // menu.findItem(R.id.menu_close_vectorheatmap).setVisible(mIsSelected);
return super.onPrepareOptionsMenu(menu); // return super.onPrepareOptionsMenu(menu);
} // }
//
@Override // @Override
public boolean onOptionsItemSelected(@NonNull MenuItem item) { // public boolean onOptionsItemSelected(@NonNull MenuItem item) {
switch (item.getItemId()) { // switch (item.getItemId()) {
case R.id.menu_open_vectorheatmap: // case R.id.menu_open_vectorheatmap:
btnSwitch3D.setVisibility(View.VISIBLE); // btnSwitch3D.setVisibility(View.VISIBLE);
addArcLineLayer(); // addArcLineLayer();
break; // break;
case R.id.menu_close_vectorheatmap: // case R.id.menu_close_vectorheatmap:
mIsSelected = false; // mIsSelected = false;
if (vectorOverlay != null) { // if (vectorOverlay != null) {
vectorOverlay.remove(); // vectorOverlay.remove();
vectorOverlay = null; // vectorOverlay = null;
} // }
break; // break;
} // }
//
supportInvalidateOptionsMenu(); // supportInvalidateOptionsMenu();
return super.onOptionsItemSelected(item); // return super.onOptionsItemSelected(item);
} // }
//
@Override // @Override
protected void onResume() { // protected void onResume() {
super.onResume(); // super.onResume();
mMapView.onResume(); // mMapView.onResume();
} // }
//
@Override // @Override
protected void onPause() { // protected void onPause() {
super.onPause(); // super.onPause();
mMapView.onPause(); // mMapView.onPause();
} // }
//
@Override // @Override
protected void onDestroy() { // protected void onDestroy() {
super.onDestroy(); // super.onDestroy();
mMapView.onDestroy(); // mMapView.onDestroy();
} // }
//
//
@Override // @Override
protected void onStart() { // protected void onStart() {
super.onStart(); // super.onStart();
mMapView.onStart(); // mMapView.onStart();
} // }
//
@Override // @Override
protected void onStop() { // protected void onStop() {
super.onStop(); // super.onStop();
mMapView.onStop(); // mMapView.onStop();
} // }
//
private void init() { // private void init() {
mMapView = findViewById(R.id.mapView); // mMapView = findViewById(R.id.mapView);
mTencentMap = mMapView.getMap(); // mTencentMap = mMapView.getMap();
mTencentMap.moveCamera(CameraUpdateFactory.zoomTo(5f)); // mTencentMap.moveCamera(CameraUpdateFactory.zoomTo(5f));
btnSwitch3D = (Switch) findViewById(R.id.btn_switch_3D); // btnSwitch3D = (Switch) findViewById(R.id.btn_switch_3D);
bindListener(); // bindListener();
//
} // }
//
private void bindListener() { // private void bindListener() {
CompoundButton.OnCheckedChangeListener onCheckedChangeListener = new CompoundButton.OnCheckedChangeListener() { // CompoundButton.OnCheckedChangeListener onCheckedChangeListener = new CompoundButton.OnCheckedChangeListener() {
//
@Override // @Override
public void onCheckedChanged(CompoundButton compoundButton, boolean b) { // public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
switch (compoundButton.getId()) { // switch (compoundButton.getId()) {
case R.id.btn_switch_3D: // case R.id.btn_switch_3D:
if (vectorOverlay != null) { // if (vectorOverlay != null) {
if (compoundButton.isChecked()) { // if (compoundButton.isChecked()) {
options.enable3D(true); // options.enable3D(true);
} else { // } else {
options.enable3D(false); // options.enable3D(false);
} // }
//
mTencentMap.updateVectorOverlay(vectorOverlay, options); // mTencentMap.updateVectorOverlay(vectorOverlay, options);
} // }
break; // break;
//
default: // default:
break; // break;
} // }
} // }
}; // };
//
btnSwitch3D.setOnCheckedChangeListener(onCheckedChangeListener); // btnSwitch3D.setOnCheckedChangeListener(onCheckedChangeListener);
} // }
//
private void addArcLineLayer() { // private void addArcLineLayer() {
mIsSelected = true; // mIsSelected = true;
if (vectorOverlay == null) { // if (vectorOverlay == null) {
// mTencentMap.moveCamera(CameraUpdateFactory.newCameraPosition(new CameraPosition(new LatLng(39.9229731, 116.422880668), 8, 0f, 0f))); // // mTencentMap.moveCamera(CameraUpdateFactory.newCameraPosition(new CameraPosition(new LatLng(39.9229731, 116.422880668), 8, 0f, 0f)));
mTencentMap.setMapStyle(3); // mTencentMap.setMapStyle(3);
//
int color = Color.argb(255, 0, 255, 170); // int color = Color.argb(255, 0, 255, 170);
BufferedReader br = null; // BufferedReader br = null;
final ArrayList<FromToLatLng> nodes = new ArrayList<FromToLatLng>(); // final ArrayList<FromToLatLng> nodes = new ArrayList<FromToLatLng>();
try { // try {
br = new BufferedReader(new InputStreamReader(getResources().getAssets().open("arc.dat"))); // br = new BufferedReader(new InputStreamReader(getResources().getAssets().open("arc.dat")));
String line = null; // String line = null;
while ((line = br.readLine()) != null) { // while ((line = br.readLine()) != null) {
String[] lines = line.split(" "); // String[] lines = line.split(" ");
if (lines.length == 5) { // if (lines.length == 5) {
double arc = Double.parseDouble(lines[4]); // double arc = Double.parseDouble(lines[4]);
LatLng startLatLng = new LatLng((Double.parseDouble(lines[0])), (Double.parseDouble(lines[1]))); // LatLng startLatLng = new LatLng((Double.parseDouble(lines[0])), (Double.parseDouble(lines[1])));
LatLng endLatLng = new LatLng((Double.parseDouble(lines[2])), (Double.parseDouble(lines[3]))); // LatLng endLatLng = new LatLng((Double.parseDouble(lines[2])), (Double.parseDouble(lines[3])));
nodes.add(new FromToLatLng(startLatLng, endLatLng)); // nodes.add(new FromToLatLng(startLatLng, endLatLng));
//nodes.add(new FromToLatLng(startLatLng, endLatLng, arc)); // //nodes.add(new FromToLatLng(startLatLng, endLatLng, arc));
} // }
} // }
} catch (Exception e) { // } catch (Exception e) {
e.printStackTrace(); // e.printStackTrace();
} // }
int[] colors = { // int[] colors = {
Color.argb(255, 0, 0xd4, 0xff), // Color.argb(255, 0, 0xd4, 0xff),
Color.argb((int) (255 * 0.3), 0, 0xd4, 0xff), // Color.argb((int) (255 * 0.3), 0, 0xd4, 0xff),
Color.argb(255, 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)); // 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); // vectorOverlay = mTencentMap.addVectorOverlay(options);
mTencentMap.setPoisEnabled(false); // mTencentMap.setPoisEnabled(false);
//
} // }
} // }
} //}

View File

@ -20,107 +20,112 @@ import java.io.IOException;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.util.ArrayList; import java.util.ArrayList;
public class DrawHeatOverlayActivity extends SupportMapFragmentActivity implements HeatMapTileProvider.OnHeatMapReadyListener{ 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<WeightedLatLng> 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 @Override
public void onHeatMapReady() { 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<WeightedLatLng> 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();
// }
} }

View File

@ -30,137 +30,137 @@ import static com.tencent.map.sdk.utilities.visualization.glmodel.GLModelOverlay
import static com.tencent.map.sdk.utilities.visualization.glmodel.GLModelOverlayProvider.CoordType.PixelType; import static com.tencent.map.sdk.utilities.visualization.glmodel.GLModelOverlayProvider.CoordType.PixelType;
public class GLModelActivity extends AppCompatActivity { public class GLModelActivity extends AppCompatActivity {
//
/** // /**
* 和其他覆盖物相同三维模型图也可控制图层的Level和zIndex // * 和其他覆盖物相同三维模型图也可控制图层的Level和zIndex
* 可通过 GLModelOverlayProvider的displayLevel和zIndex进行设置 // * 可通过 GLModelOverlayProvider的displayLevel和zIndex进行设置
* displayLevel - 默认层级为POI之下 OverlayLevel.OverlayLevelAboveBuildings // * displayLevel - 默认层级为POI之下 OverlayLevel.OverlayLevelAboveBuildings
* 相同Level内的显示层级关系通过zIndex(int)来控制zIndex越大越靠上显示 Level优先级高于zIndex displayLevel必须为如下值之一否则不生效 // * 相同Level内的显示层级关系通过zIndex(int)来控制zIndex越大越靠上显示 Level优先级高于zIndex displayLevel必须为如下值之一否则不生效
*/ // */
//
private MapView mapView; // private MapView mapView;
protected TencentMap tencentMap; // protected TencentMap tencentMap;
private String mResourcePath; // private String mResourcePath;
private GLModelOverlay vectorOverlay; // 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 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 LatLng[] mCarLatLngArray;
private GeneralTranslateAnimator animator; // private GeneralTranslateAnimator animator;
private Polyline polyline; // private Polyline polyline;
private Spinner mSpinner; // private Spinner mSpinner;
private String[] glmodelAnimator = new String[]{"开启平滑移动", "开启骨骼动画", "关闭骨骼动画"}; // private String[] glmodelAnimator = new String[]{"开启平滑移动", "开启骨骼动画", "关闭骨骼动画"};
private GLModelOverlayProvider provider; // private GLModelOverlayProvider provider;
//
@Override // @Override
protected void onCreate(Bundle savedInstanceState) { // protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); // super.onCreate(savedInstanceState);
setContentView(R.layout.activity_g_l_model); // setContentView(R.layout.activity_g_l_model);
mapView = findViewById(R.id.mapView); // mapView = findViewById(R.id.mapView);
tencentMap = this.mapView.getMap(); // tencentMap = this.mapView.getMap();
String[] linePointsStr = mLine.split(","); // String[] linePointsStr = mLine.split(",");
mCarLatLngArray = new LatLng[linePointsStr.length / 4]; // mCarLatLngArray = new LatLng[linePointsStr.length / 4];
//
for (int i = 0; i < mCarLatLngArray.length; i++) { // for (int i = 0; i < mCarLatLngArray.length; i++) {
double latitude = Double.parseDouble(linePointsStr[i * 4]); // double latitude = Double.parseDouble(linePointsStr[i * 4]);
double longitude = Double.parseDouble(linePointsStr[i * 4 + 1]); // double longitude = Double.parseDouble(linePointsStr[i * 4 + 1]);
mCarLatLngArray[i] = new LatLng(latitude, longitude); // mCarLatLngArray[i] = new LatLng(latitude, longitude);
} // }
polyline = tencentMap.addPolyline(new PolylineOptions().add(mCarLatLngArray).color(R.color.colorAccent).arrow(true)); // 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)); // tencentMap.animateCamera(CameraUpdateFactory.newLatLngBounds(LatLngBounds.builder().include(Arrays.asList(mCarLatLngArray)).build(), 50));
creatglmode(); // creatglmode();
init(); // init();
} // }
//
private void creatglmode() { // private void creatglmode() {
//gltf格式三维模型文件在assets内 // //gltf格式三维模型文件在assets内
String file = "BrainStem.gltf"; // String file = "BrainStem.gltf";
String SKELETON_PATH = "gltf-BrainStem"; // String SKELETON_PATH = "gltf-BrainStem";
//获取外部存储 // //获取外部存储
mResourcePath = getExternalFilesDir(null).getAbsolutePath() + File.separator + SKELETON_PATH; // mResourcePath = getExternalFilesDir(null).getAbsolutePath() + File.separator + SKELETON_PATH;
provider = new GLModelOverlayProvider( // provider = new GLModelOverlayProvider(
mResourcePath + File.separator + file, // mResourcePath + File.separator + file,
new LatLng(39.98409, 116.30804)).coordType(PixelType) // new LatLng(39.98409, 116.30804)).coordType(PixelType)
.pixelBounds(400, 1200).rotationX(90).rotationY(0).rotationZ(0).setClickEnable(true); // .pixelBounds(400, 1200).rotationX(90).rotationY(0).rotationZ(0).setClickEnable(true);
vectorOverlay = tencentMap.addVectorOverlay(provider); // vectorOverlay = tencentMap.addVectorOverlay(provider);
} // }
//
private void init() { // private void init() {
mSpinner = findViewById(R.id.sp_glmode); // mSpinner = findViewById(R.id.sp_glmode);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(getApplicationContext(), android.R.layout.simple_spinner_dropdown_item, glmodelAnimator); // ArrayAdapter<String> adapter = new ArrayAdapter<String>(getApplicationContext(), android.R.layout.simple_spinner_dropdown_item, glmodelAnimator);
mSpinner.setAdapter(adapter); // mSpinner.setAdapter(adapter);
mSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { // mSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override // @Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { // public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
switch (position) { // switch (position) {
//开启骨骼动画 // //开启骨骼动画
case 0: // case 0:
animator = new GeneralTranslateAnimator.Builder(vectorOverlay, 6000, // animator = new GeneralTranslateAnimator.Builder(vectorOverlay, 6000,
mCarLatLngArray).rotateEnabled(true).initRotate(180).modelType(GeneralTranslateAnimator.ModelType.MODEL_OVERLAY).build(); // mCarLatLngArray).rotateEnabled(true).initRotate(180).modelType(GeneralTranslateAnimator.ModelType.MODEL_OVERLAY).build();
animator.startAnimation(); // animator.startAnimation();
animator.addAnimatorEndListener(new IAnimatorModel.IAnimatorEndListener() { // animator.addAnimatorEndListener(new IAnimatorModel.IAnimatorEndListener() {
@Override // @Override
public void onAnimatorEnd() { // public void onAnimatorEnd() {
Log.i("TransformActivity", "onAnimatorEnd"); // Log.i("TransformActivity", "onAnimatorEnd");
} // }
}); // });
break; // break;
//停止骨骼动画 // //停止骨骼动画
case 1: // case 1:
vectorOverlay.playSkeletonAnimation(0, 1, true); // vectorOverlay.playSkeletonAnimation(0, 1, true);
break; // break;
//模型平移 // //模型平移
case 2: // case 2:
vectorOverlay.stopSkeletonAnimation(); // vectorOverlay.stopSkeletonAnimation();
break; // break;
} // }
} // }
//
@Override // @Override
public void onNothingSelected(AdapterView<?> parent) { // public void onNothingSelected(AdapterView<?> parent) {
//
} // }
}); // });
//
} // }
//
/** // /**
* mapview的生命周期管理 // * mapview的生命周期管理
*/ // */
@Override // @Override
protected void onStart() { // protected void onStart() {
super.onStart(); // super.onStart();
mapView.onStart(); // mapView.onStart();
} // }
//
@Override // @Override
protected void onResume() { // protected void onResume() {
super.onResume(); // super.onResume();
mapView.onResume(); // mapView.onResume();
} // }
//
//
@Override // @Override
protected void onPause() { // protected void onPause() {
super.onPause(); // super.onPause();
mapView.onPause(); // mapView.onPause();
} // }
//
@Override // @Override
protected void onStop() { // protected void onStop() {
super.onStop(); // super.onStop();
mapView.onStop(); // mapView.onStop();
} // }
//
@Override // @Override
protected void onDestroy() { // protected void onDestroy() {
super.onDestroy(); // super.onDestroy();
mapView.onDestroy(); // mapView.onDestroy();
vectorOverlay.remove(); // vectorOverlay.remove();
//
} // }
//
@Override // @Override
protected void onRestart() { // protected void onRestart() {
super.onRestart(); // super.onRestart();
mapView.onRestart(); // mapView.onRestart();
} // }
} }

View File

@ -27,145 +27,145 @@ import java.io.InputStreamReader;
import java.util.ArrayList; import java.util.ArrayList;
public class HeatMapVectorOverlayActivity extends AppCompatActivity { public class HeatMapVectorOverlayActivity extends AppCompatActivity {
private MapView mMapView; // private MapView mMapView;
private TencentMap mTencentMap; // private TencentMap mTencentMap;
private GradientVectorOverlay heatTileOverlay; // private GradientVectorOverlay heatTileOverlay;
private GradientVectorOverlayProvider heatMapTileProvider; // private GradientVectorOverlayProvider heatMapTileProvider;
boolean mIsSelected; // boolean mIsSelected;
//
@Override // @Override
protected void onCreate(Bundle savedInstanceState) { // protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); // super.onCreate(savedInstanceState);
setContentView(R.layout.activity_heat_map_vector_overlay_design); // setContentView(R.layout.activity_heat_map_vector_overlay_design);
init(); // init();
} // }
//
@Override // @Override
public boolean onCreateOptionsMenu(Menu menu) { // public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.vectorheatmap, menu); // getMenuInflater().inflate(R.menu.vectorheatmap, menu);
return true; // return true;
} // }
//
@Override // @Override
public boolean onPrepareOptionsMenu(Menu menu) { // public boolean onPrepareOptionsMenu(Menu menu) {
menu.findItem(R.id.menu_open_vectorheatmap).setVisible(!mIsSelected); // menu.findItem(R.id.menu_open_vectorheatmap).setVisible(!mIsSelected);
menu.findItem(R.id.menu_close_vectorheatmap).setVisible(mIsSelected); // menu.findItem(R.id.menu_close_vectorheatmap).setVisible(mIsSelected);
return super.onPrepareOptionsMenu(menu); // return super.onPrepareOptionsMenu(menu);
} // }
//
@Override // @Override
public boolean onOptionsItemSelected(@NonNull MenuItem item) { // public boolean onOptionsItemSelected(@NonNull MenuItem item) {
switch (item.getItemId()) { // switch (item.getItemId()) {
case R.id.menu_open_vectorheatmap: // case R.id.menu_open_vectorheatmap:
addHeatMap(); // addHeatMap();
break; // break;
case R.id.menu_close_vectorheatmap: // case R.id.menu_close_vectorheatmap:
mIsSelected = false; // mIsSelected = false;
if (heatTileOverlay != null) { // if (heatTileOverlay != null) {
heatTileOverlay.remove(); // heatTileOverlay.remove();
heatTileOverlay = null; // heatTileOverlay = null;
} // }
break; // break;
} // }
//
supportInvalidateOptionsMenu(); // supportInvalidateOptionsMenu();
return super.onOptionsItemSelected(item); // return super.onOptionsItemSelected(item);
} // }
//
@Override // @Override
protected void onResume() { // protected void onResume() {
super.onResume(); // super.onResume();
mMapView.onResume(); // mMapView.onResume();
} // }
//
@Override // @Override
protected void onPause() { // protected void onPause() {
super.onPause(); // super.onPause();
mMapView.onPause(); // mMapView.onPause();
} // }
//
@Override // @Override
protected void onDestroy() { // protected void onDestroy() {
super.onDestroy(); // super.onDestroy();
mMapView.onDestroy(); // mMapView.onDestroy();
} // }
//
//
@Override // @Override
protected void onStart() { // protected void onStart() {
super.onStart(); // super.onStart();
mMapView.onStart(); // mMapView.onStart();
} // }
//
@Override // @Override
protected void onStop() { // protected void onStop() {
super.onStop(); // super.onStop();
mMapView.onStop(); // mMapView.onStop();
} // }
//
private void init() { // private void init() {
mMapView = findViewById(R.id.mapView); // mMapView = findViewById(R.id.mapView);
mTencentMap = mMapView.getMap(); // mTencentMap = mMapView.getMap();
mTencentMap.setMapStyle(3); // mTencentMap.setMapStyle(3);
CameraUpdate cameraSigma = // CameraUpdate cameraSigma =
CameraUpdateFactory.newCameraPosition(new CameraPosition( // CameraUpdateFactory.newCameraPosition(new CameraPosition(
new LatLng(31.085414, 111.024319), // new LatLng(31.085414, 111.024319),
4, // 4,
20f, // 20f,
1f)); // 1f));
mTencentMap.moveCamera(cameraSigma); // mTencentMap.moveCamera(cameraSigma);
} // }
//
//
private void addHeatMap() { // private void addHeatMap() {
mIsSelected = true; // mIsSelected = true;
if (heatTileOverlay != null) { // if (heatTileOverlay != null) {
return; // return;
} // }
mTencentMap.setBuildingEnable(false); // mTencentMap.setBuildingEnable(false);
mTencentMap.setPoisEnabled(false); // mTencentMap.setPoisEnabled(false);
BufferedReader br = null; // BufferedReader br = null;
try { // try {
ArrayList<WeightedLatLng> nodes = new ArrayList<WeightedLatLng>(); // ArrayList<WeightedLatLng> nodes = new ArrayList<WeightedLatLng>();
br = new BufferedReader(new InputStreamReader(getResources().getAssets().open("data2k"))); // br = new BufferedReader(new InputStreamReader(getResources().getAssets().open("data2k")));
String line = null; // String line = null;
while ((line = br.readLine()) != null) { // while ((line = br.readLine()) != null) {
String[] lines = line.split("\t"); // String[] lines = line.split("\t");
if (lines.length == 3) { // if (lines.length == 3) {
double value = Double.parseDouble(lines[2]); // double value = Double.parseDouble(lines[2]);
LatLng latLng = new LatLng((Double.parseDouble(lines[1])), (Double.parseDouble(lines[0]))); // LatLng latLng = new LatLng((Double.parseDouble(lines[1])), (Double.parseDouble(lines[0])));
nodes.add(new WeightedLatLng(latLng, value)); // nodes.add(new WeightedLatLng(latLng, value));
} // }
} // }
//
// 通用配色1 // // 通用配色1
int[] colors = { // int[] colors = {
Color.argb(255, 77, 111, 255), // Color.argb(255, 77, 111, 255),
Color.argb(255, 0, 238, 227), // Color.argb(255, 0, 238, 227),
Color.argb(255, 113, 236, 80), // Color.argb(255, 113, 236, 80),
Color.argb(255, 255, 176, 0), // Color.argb(255, 255, 176, 0),
Color.argb(255, 255, 72, 0) // Color.argb(255, 255, 72, 0)
}; // };
float[] startPoints = {0.1f, 0.185f, 0.3571f, 0.6142f, 1f}; // float[] startPoints = {0.1f, 0.185f, 0.3571f, 0.6142f, 1f};
//
//
heatMapTileProvider = new GradientVectorOverlayProvider() // heatMapTileProvider = new GradientVectorOverlayProvider()
.weightedData(nodes).enable3D(true) // .weightedData(nodes).enable3D(true)
.radius(56).setMaxHeight(500).setAnimateDuration(3000); // .radius(56).setMaxHeight(500).setAnimateDuration(3000);
heatMapTileProvider.opacity(0.95f); // heatMapTileProvider.opacity(0.95f);
heatMapTileProvider.gradient(colors, startPoints); // heatMapTileProvider.gradient(colors, startPoints);
heatTileOverlay = mTencentMap.addVectorOverlay(heatMapTileProvider); // heatTileOverlay = mTencentMap.addVectorOverlay(heatMapTileProvider);
//
} catch (Exception e) { // } catch (Exception e) {
e.printStackTrace(); // e.printStackTrace();
} finally { // } finally {
if (br != null) { // if (br != null) {
try { // try {
br.close(); // br.close();
} catch (IOException e) { // } catch (IOException e) {
e.printStackTrace(); // e.printStackTrace();
} // }
} // }
} // }
} // }
} }

View File

@ -33,148 +33,148 @@ import java.util.ArrayList;
import java.util.Random; import java.util.Random;
public class ScatterPlotOverlayActivity extends AppCompatActivity { public class ScatterPlotOverlayActivity extends AppCompatActivity {
private MapView mMapView; // private MapView mMapView;
private TencentMap mTencentMap; // private TencentMap mTencentMap;
private VectorOverlay vectorOverlay; // private VectorOverlay vectorOverlay;
boolean mIsSelected; // boolean mIsSelected;
private DotScatterPlotOverlayProvider dotScatterPlotOverlayProvider; // private DotScatterPlotOverlayProvider dotScatterPlotOverlayProvider;
private BitmapScatterPlotOverlayProvider provider; // private BitmapScatterPlotOverlayProvider provider;
private String[] styles = new String[]{"添加点散点", "添加图片散点"}; // private String[] styles = new String[]{"添加点散点", "添加图片散点"};
private Spinner mSpinner; // private Spinner mSpinner;
//
@Override // @Override
protected void onCreate(Bundle savedInstanceState) { // protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); // super.onCreate(savedInstanceState);
setContentView(R.layout.activity_scatter_plot_overlay); // setContentView(R.layout.activity_scatter_plot_overlay);
init(); // init();
} // }
//
//
@Override // @Override
protected void onResume() { // protected void onResume() {
super.onResume(); // super.onResume();
mMapView.onResume(); // mMapView.onResume();
} // }
//
@Override // @Override
protected void onPause() { // protected void onPause() {
super.onPause(); // super.onPause();
mMapView.onPause(); // mMapView.onPause();
} // }
//
@Override // @Override
protected void onDestroy() { // protected void onDestroy() {
super.onDestroy(); // super.onDestroy();
mMapView.onDestroy(); // mMapView.onDestroy();
} // }
//
//
@Override // @Override
protected void onStart() { // protected void onStart() {
super.onStart(); // super.onStart();
mMapView.onStart(); // mMapView.onStart();
} // }
//
@Override // @Override
protected void onStop() { // protected void onStop() {
super.onStop(); // super.onStop();
mMapView.onStop(); // mMapView.onStop();
} // }
//
private void init() { // private void init() {
mMapView = findViewById(R.id.mapView); // mMapView = findViewById(R.id.mapView);
mTencentMap = mMapView.getMap(); // mTencentMap = mMapView.getMap();
mTencentMap.moveCamera(CameraUpdateFactory.zoomTo(5f)); // mTencentMap.moveCamera(CameraUpdateFactory.zoomTo(5f));
mTencentMap.moveCamera(CameraUpdateFactory.newCameraPosition(new CameraPosition(new LatLng(40.040219, 116.273348), 20, 0, 0))); // mTencentMap.moveCamera(CameraUpdateFactory.newCameraPosition(new CameraPosition(new LatLng(40.040219, 116.273348), 20, 0, 0)));
mSpinner = findViewById(R.id.sp_style); // mSpinner = findViewById(R.id.sp_style);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(getApplicationContext(), android.R.layout.simple_spinner_dropdown_item, styles); // ArrayAdapter<String> adapter = new ArrayAdapter<String>(getApplicationContext(), android.R.layout.simple_spinner_dropdown_item, styles);
mSpinner.setAdapter(adapter); // mSpinner.setAdapter(adapter);
mSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { // mSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override // @Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { // public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
switch (position) { // switch (position) {
case 0: // case 0:
if (vectorOverlay != null) { // if (vectorOverlay != null) {
vectorOverlay.remove(); // vectorOverlay.remove();
vectorOverlay = null; // vectorOverlay = null;
} // }
addDotVectorOverlay(); // addDotVectorOverlay();
mTencentMap.updateVectorOverlay(vectorOverlay, dotScatterPlotOverlayProvider); // mTencentMap.updateVectorOverlay(vectorOverlay, dotScatterPlotOverlayProvider);
break; // break;
case 1: // case 1:
if (vectorOverlay != null) { // if (vectorOverlay != null) {
vectorOverlay.remove(); // vectorOverlay.remove();
vectorOverlay = null; // vectorOverlay = null;
} // }
addBitmapVectorOverlay(); // addBitmapVectorOverlay();
mTencentMap.updateVectorOverlay(vectorOverlay, provider); // mTencentMap.updateVectorOverlay(vectorOverlay, provider);
break; // break;
} // }
} // }
//
@Override // @Override
public void onNothingSelected(AdapterView<?> parent) { // public void onNothingSelected(AdapterView<?> parent) {
//
} // }
}); // });
//
} // }
//
//
private void addDotVectorOverlay() { // private void addDotVectorOverlay() {
mIsSelected = true; // mIsSelected = true;
if (vectorOverlay == null) { // if (vectorOverlay == null) {
BufferedReader br = null; // BufferedReader br = null;
final ArrayList<ScatterLatLng> nodes = new ArrayList<ScatterLatLng>(); // final ArrayList<ScatterLatLng> nodes = new ArrayList<ScatterLatLng>();
double lat = 40.040219; // double lat = 40.040219;
double lng = 116.273348; // double lng = 116.273348;
double value = 100; // double value = 100;
Random r = new Random(); // Random r = new Random();
for (int i = 0; i < 2000; i++) { // for (int i = 0; i < 2000; i++) {
double a = r.nextInt(10) * 1E-5; // double a = r.nextInt(10) * 1E-5;
double b = r.nextInt(10) * 1E-5; // double b = r.nextInt(10) * 1E-5;
LatLng latLng = new LatLng(lat + a, lng + b); // LatLng latLng = new LatLng(lat + a, lng + b);
nodes.add(new ScatterLatLng(latLng, value)); // nodes.add(new ScatterLatLng(latLng, value));
} // }
int[] colors = { // int[] colors = {
Color.argb(255, 0, 0xd4, 0xff), // Color.argb(255, 0, 0xd4, 0xff),
Color.argb((int) (255 * 0.3), 0, 0xd4, 0xff), // Color.argb((int) (255 * 0.3), 0, 0xd4, 0xff),
Color.argb(255, 0, 0xd4, 0xff) // Color.argb(255, 0, 0xd4, 0xff)
}; // };
//
dotScatterPlotOverlayProvider = new DotScatterPlotOverlayProvider().data(nodes).opacity(2f).radius(2).animate(true).colors(colors); // dotScatterPlotOverlayProvider = new DotScatterPlotOverlayProvider().data(nodes).opacity(2f).radius(2).animate(true).colors(colors);
//
vectorOverlay = mTencentMap.addVectorOverlay(dotScatterPlotOverlayProvider); // vectorOverlay = mTencentMap.addVectorOverlay(dotScatterPlotOverlayProvider);
//
} // }
//
} // }
//
private void addBitmapVectorOverlay() { // private void addBitmapVectorOverlay() {
mIsSelected = true; // mIsSelected = true;
if (vectorOverlay == null) { // if (vectorOverlay == null) {
final ArrayList<ScatterLatLng> nodes = new ArrayList<ScatterLatLng>(); // final ArrayList<ScatterLatLng> nodes = new ArrayList<ScatterLatLng>();
double lat = 40.040219; // double lat = 40.040219;
double lng = 116.273348; // double lng = 116.273348;
double value = 10; // double value = 10;
Random r = new Random(); // Random r = new Random();
for (int i = 0; i < 1000; i++) { // for (int i = 0; i < 1000; i++) {
double a = r.nextInt(10) * 1E-5; // double a = r.nextInt(10) * 1E-5;
double b = r.nextInt(10) * 1E-5; // double b = r.nextInt(10) * 1E-5;
LatLng latLng = new LatLng(lat + a, lng + b); // LatLng latLng = new LatLng(lat + a, lng + b);
nodes.add(new ScatterLatLng(latLng, value)); // nodes.add(new ScatterLatLng(latLng, value));
} // }
BitmapDescriptor[] bitmaps = { // BitmapDescriptor[] bitmaps = {
BitmapDescriptorFactory.fromAsset("21.jpg"), // BitmapDescriptorFactory.fromAsset("21.jpg"),
BitmapDescriptorFactory.fromAsset("22.jpg"), // BitmapDescriptorFactory.fromAsset("22.jpg"),
BitmapDescriptorFactory.fromAsset("23.jpg"), // BitmapDescriptorFactory.fromAsset("23.jpg"),
BitmapDescriptorFactory.fromAsset("24.jpg"), // BitmapDescriptorFactory.fromAsset("24.jpg"),
BitmapDescriptorFactory.fromAsset("25.jpg"), // BitmapDescriptorFactory.fromAsset("25.jpg"),
BitmapDescriptorFactory.fromAsset("26.jpg"), // BitmapDescriptorFactory.fromAsset("26.jpg"),
}; // };
provider = new BitmapScatterPlotOverlayProvider().data(nodes).bitmaps(bitmaps).opacity(2f).scale(20, 10); // provider = new BitmapScatterPlotOverlayProvider().data(nodes).bitmaps(bitmaps).opacity(2f).scale(20, 10);
vectorOverlay = mTencentMap.addVectorOverlay(provider); // vectorOverlay = mTencentMap.addVectorOverlay(provider);
} // }
//
} // }
} }

View File

@ -24,124 +24,124 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
public class TrailOverlayActivity extends AppCompatActivity { public class TrailOverlayActivity extends AppCompatActivity {
private MapView mMapView; // private MapView mMapView;
private TencentMap mTencentMap; // private TencentMap mTencentMap;
private VectorOverlay vectorOverlay; // private VectorOverlay vectorOverlay;
boolean mIsSelected; // boolean mIsSelected;
private TrailOverlayProvider trailOverlayProvider; // private TrailOverlayProvider trailOverlayProvider;
//
@Override // @Override
protected void onCreate(Bundle savedInstanceState) { // protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); // super.onCreate(savedInstanceState);
setContentView(R.layout.activity_trail_overlay); // setContentView(R.layout.activity_trail_overlay);
init(); // init();
} // }
//
@Override // @Override
public boolean onCreateOptionsMenu(Menu menu) { // public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.vectorheatmap, menu); // getMenuInflater().inflate(R.menu.vectorheatmap, menu);
return true; // return true;
} // }
//
@Override // @Override
public boolean onPrepareOptionsMenu(Menu menu) { // public boolean onPrepareOptionsMenu(Menu menu) {
menu.findItem(R.id.menu_open_vectorheatmap).setVisible(!mIsSelected); // menu.findItem(R.id.menu_open_vectorheatmap).setVisible(!mIsSelected);
menu.findItem(R.id.menu_close_vectorheatmap).setVisible(mIsSelected); // menu.findItem(R.id.menu_close_vectorheatmap).setVisible(mIsSelected);
return super.onPrepareOptionsMenu(menu); // return super.onPrepareOptionsMenu(menu);
} // }
//
@Override // @Override
public boolean onOptionsItemSelected(@NonNull MenuItem item) { // public boolean onOptionsItemSelected(@NonNull MenuItem item) {
switch (item.getItemId()) { // switch (item.getItemId()) {
case R.id.menu_open_vectorheatmap: // case R.id.menu_open_vectorheatmap:
addArcLineLayer(); // addArcLineLayer();
break; // break;
case R.id.menu_close_vectorheatmap: // case R.id.menu_close_vectorheatmap:
mIsSelected = false; // mIsSelected = false;
if (vectorOverlay != null) { // if (vectorOverlay != null) {
vectorOverlay.remove(); // vectorOverlay.remove();
vectorOverlay = null; // vectorOverlay = null;
} // }
break; // break;
} // }
//
supportInvalidateOptionsMenu(); // supportInvalidateOptionsMenu();
return super.onOptionsItemSelected(item); // return super.onOptionsItemSelected(item);
} // }
//
@Override // @Override
protected void onResume() { // protected void onResume() {
super.onResume(); // super.onResume();
mMapView.onResume(); // mMapView.onResume();
} // }
//
@Override // @Override
protected void onPause() { // protected void onPause() {
super.onPause(); // super.onPause();
mMapView.onPause(); // mMapView.onPause();
} // }
//
@Override // @Override
protected void onDestroy() { // protected void onDestroy() {
super.onDestroy(); // super.onDestroy();
mMapView.onDestroy(); // mMapView.onDestroy();
} // }
//
//
@Override // @Override
protected void onStart() { // protected void onStart() {
super.onStart(); // super.onStart();
mMapView.onStart(); // mMapView.onStart();
} // }
//
@Override // @Override
protected void onStop() { // protected void onStop() {
super.onStop(); // super.onStop();
mMapView.onStop(); // mMapView.onStop();
} // }
//
private void init() { // private void init() {
mMapView = findViewById(R.id.mapView); // mMapView = findViewById(R.id.mapView);
mTencentMap = mMapView.getMap(); // mTencentMap = mMapView.getMap();
mTencentMap.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(39.942117, 116.33668), 11)); // mTencentMap.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(39.942117, 116.33668), 11));
} // }
//
private void addArcLineLayer() { // private void addArcLineLayer() {
mIsSelected = true; // mIsSelected = true;
if (vectorOverlay == null) { // if (vectorOverlay == null) {
//
mTencentMap.setPoisEnabled(false); // mTencentMap.setPoisEnabled(false);
BufferedReader br = null; // BufferedReader br = null;
long currentTime = System.currentTimeMillis(); // long currentTime = System.currentTimeMillis();
List<TrailLatLng> startLats = new ArrayList<>(); // List<TrailLatLng> startLats = new ArrayList<>();
try { // try {
br = new BufferedReader(new InputStreamReader(getResources().getAssets().open("trailData.dat"))); // br = new BufferedReader(new InputStreamReader(getResources().getAssets().open("trailData.dat")));
//
String line = null; // String line = null;
while ((line = br.readLine()) != null) { // while ((line = br.readLine()) != null) {
String[] oneDot = line.split(","); // String[] oneDot = line.split(",");
TimeLatLng[] timeLatLngs = new TimeLatLng[oneDot.length]; // TimeLatLng[] timeLatLngs = new TimeLatLng[oneDot.length];
int i = 0; // int i = 0;
for (String timeLatLng : oneDot) { // for (String timeLatLng : oneDot) {
String[] values = timeLatLng.split("\t"); // String[] values = timeLatLng.split("\t");
LatLng latlng = new LatLng((Double.parseDouble(values[0])), (Double.parseDouble(values[1]))); // LatLng latlng = new LatLng((Double.parseDouble(values[0])), (Double.parseDouble(values[1])));
int timeStamp = Integer.parseInt(values[2]); // int timeStamp = Integer.parseInt(values[2]);
timeLatLngs[i++] = new TimeLatLng(latlng, timeStamp); // timeLatLngs[i++] = new TimeLatLng(latlng, timeStamp);
} // }
TrailLatLng tmp = new TrailLatLng(timeLatLngs); // TrailLatLng tmp = new TrailLatLng(timeLatLngs);
startLats.add(tmp); // startLats.add(tmp);
} // }
} catch (Exception e) { // } catch (Exception e) {
e.printStackTrace(); // e.printStackTrace();
} // }
int[] colors = {Color.argb(0xff, 0x00, 0x00, 0xff), // int[] colors = {Color.argb(0xff, 0x00, 0x00, 0xff),
Color.argb(0x00, 0xff, 0xff, 0x00)}; // 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); // trailOverlayProvider = new TrailOverlayProvider().type(TrailOverlayProvider.TrailOverlayType.Trail).data(startLats).opacity(2f).width(10).gradient(colors).setHighlightDuration(8000).setAnimateStartTime(0, 25000);
vectorOverlay = mTencentMap.addVectorOverlay(trailOverlayProvider); // vectorOverlay = mTencentMap.addVectorOverlay(trailOverlayProvider);
//
//
} // }
//
} // }
} }

View File

@ -32,151 +32,151 @@ import java.util.ArrayList;
*/ */
public class VectorHeatMapActivity extends SupportMapFragmentActivity { public class VectorHeatMapActivity extends SupportMapFragmentActivity {
MapView mMapView; // MapView mMapView;
TencentMap mTencentMap; // TencentMap mTencentMap;
VectorHeatOverlay mOverlay; // VectorHeatOverlay mOverlay;
boolean mIsSelected; // boolean mIsSelected;
//
@Override // @Override
protected void onCreate(Bundle savedInstanceState) { // protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); // super.onCreate(savedInstanceState);
setContentView(R.layout.activity_vector_heat_map); // setContentView(R.layout.activity_vector_heat_map);
mMapView = findViewById(R.id.map_view); // mMapView = findViewById(R.id.map_view);
mTencentMap = mMapView.getMap(); // mTencentMap = mMapView.getMap();
mTencentMap.moveCamera(CameraUpdateFactory.newLatLngZoom( // mTencentMap.moveCamera(CameraUpdateFactory.newLatLngZoom(
new LatLng(36.139985, 120.402243), // new LatLng(36.139985, 120.402243),
11)); // 11));
//
mTencentMap.setOnMapClickListener(new TencentMap.OnMapClickListener() { // mTencentMap.setOnMapClickListener(new TencentMap.OnMapClickListener() {
@Override // @Override
public void onMapClick(LatLng latlng) { // public void onMapClick(LatLng latlng) {
if (mOverlay == null) { // if (mOverlay == null) {
return; // return;
} // }
VectorHeatAggregationUnit unit = mOverlay.getUnit(latlng); // VectorHeatAggregationUnit unit = mOverlay.getUnit(latlng);
if (unit == null) { // if (unit == null) {
Log.e("VectorHeatMapActivity", "no unit found"); // Log.e("VectorHeatMapActivity", "no unit found");
return; // return;
} // }
Log.e("VectorHeatMapActivity", "unit center:" + unit.getCenter() + // Log.e("VectorHeatMapActivity", "unit center:" + unit.getCenter() +
", intensity:" + unit.getIntensity() + // ", intensity:" + unit.getIntensity() +
", size:" + unit.getNodes().length); // ", size:" + unit.getNodes().length);
} // }
}); // });
} // }
//
@Override // @Override
public boolean onCreateOptionsMenu(Menu menu) { // public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.vectorheatmap, menu); // getMenuInflater().inflate(R.menu.vectorheatmap, menu);
return true; // return true;
} // }
//
@Override // @Override
public boolean onPrepareOptionsMenu(Menu menu) { // public boolean onPrepareOptionsMenu(Menu menu) {
menu.findItem(R.id.menu_open_vectorheatmap).setVisible(!mIsSelected); // menu.findItem(R.id.menu_open_vectorheatmap).setVisible(!mIsSelected);
menu.findItem(R.id.menu_close_vectorheatmap).setVisible(mIsSelected); // menu.findItem(R.id.menu_close_vectorheatmap).setVisible(mIsSelected);
return super.onPrepareOptionsMenu(menu); // return super.onPrepareOptionsMenu(menu);
} // }
//
@Override // @Override
public boolean onOptionsItemSelected(@NonNull MenuItem item) { // public boolean onOptionsItemSelected(@NonNull MenuItem item) {
switch (item.getItemId()) { // switch (item.getItemId()) {
case R.id.menu_open_vectorheatmap: // case R.id.menu_open_vectorheatmap:
addVectorHeatMap(); // addVectorHeatMap();
break; // break;
case R.id.menu_close_vectorheatmap: // case R.id.menu_close_vectorheatmap:
removeVectorHeatMap(); // removeVectorHeatMap();
break; // break;
} // }
//
supportInvalidateOptionsMenu(); // supportInvalidateOptionsMenu();
return super.onOptionsItemSelected(item); // return super.onOptionsItemSelected(item);
} // }
//
private ArrayList<WeightedLatLng> getHeatNodes() { // private ArrayList<WeightedLatLng> getHeatNodes() {
BufferedReader br = null; // BufferedReader br = null;
ArrayList<WeightedLatLng> nodes = null; // ArrayList<WeightedLatLng> nodes = null;
try { // try {
nodes = new ArrayList<>(); // nodes = new ArrayList<>();
br = new BufferedReader(new InputStreamReader( // br = new BufferedReader(new InputStreamReader(
getResources().getAssets().open("honeycomb.txt"))); // getResources().getAssets().open("honeycomb.txt")));
String line; // String line;
while ((line = br.readLine()) != null) { // while ((line = br.readLine()) != null) {
String[] lines = line.split("\t"); // String[] lines = line.split("\t");
if (lines.length == 3) { // if (lines.length == 3) {
double value = Double.parseDouble(lines[2]); // double value = Double.parseDouble(lines[2]);
LatLng latLng = new LatLng((Double.parseDouble(lines[1])), // LatLng latLng = new LatLng((Double.parseDouble(lines[1])),
(Double.parseDouble(lines[0]))); // (Double.parseDouble(lines[0])));
nodes.add(new WeightedLatLng(latLng, 1)); // nodes.add(new WeightedLatLng(latLng, 1));
} // }
} // }
} catch (Exception e) { // } catch (Exception e) {
e.printStackTrace(); // e.printStackTrace();
} finally { // } finally {
if (br != null) { // if (br != null) {
try { // try {
br.close(); // br.close();
} catch (IOException e) { // } catch (IOException e) {
e.printStackTrace(); // e.printStackTrace();
} // }
} // }
return nodes; // return nodes;
} // }
} // }
//
@Override // @Override
protected void onResume() { // protected void onResume() {
super.onResume(); // super.onResume();
if (mMapView != null) { // if (mMapView != null) {
mMapView.onResume(); // mMapView.onResume();
} // }
} // }
//
@Override // @Override
protected void onPause() { // protected void onPause() {
super.onPause(); // super.onPause();
if (mMapView != null) { // if (mMapView != null) {
mMapView.onPause(); // mMapView.onPause();
} // }
} // }
//
@Override // @Override
protected void onStop() { // protected void onStop() {
super.onStop(); // super.onStop();
if (mMapView != null) { // if (mMapView != null) {
mMapView.onStop(); // mMapView.onStop();
} // }
} // }
//
@Override // @Override
protected void onDestroy() { // protected void onDestroy() {
super.onDestroy(); // super.onDestroy();
if (mMapView != null) { // if (mMapView != null) {
mMapView.onDestroy(); // mMapView.onDestroy();
} // }
} // }
//
private void addVectorHeatMap() { // private void addVectorHeatMap() {
mIsSelected = true; // mIsSelected = true;
if (mOverlay != null) { // if (mOverlay != null) {
return; // return;
} // }
WeightedLatLng[] nodes = getHeatNodes().toArray(new WeightedLatLng[0]); // WeightedLatLng[] nodes = getHeatNodes().toArray(new WeightedLatLng[0]);
VectorHeatOverlayOptions options = new VectorHeatOverlayOptions() // VectorHeatOverlayOptions options = new VectorHeatOverlayOptions()
.nodes(nodes) // .nodes(nodes)
.size(2000) // .size(2000)
.gap(100) // .gap(100)
.colors(new int[]{0x45fa4b14, 0x99fa4b14, 0xd9fa4b14}) // .colors(new int[]{0x45fa4b14, 0x99fa4b14, 0xd9fa4b14})
.startPoints(new double[]{0, 0.6, 0.8}); // .startPoints(new double[]{0, 0.6, 0.8});
mOverlay = mTencentMap.addVectorHeatOverlay(options); // mOverlay = mTencentMap.addVectorHeatOverlay(options);
} // }
//
public void removeVectorHeatMap() { // public void removeVectorHeatMap() {
mIsSelected = false; // mIsSelected = false;
if (mOverlay == null) { // if (mOverlay == null) {
return; // return;
} // }
mOverlay.remove(); // mOverlay.remove();
mOverlay = null; // mOverlay = null;
} // }
} }

View File

@ -32,220 +32,221 @@ import com.tencent.tencentmap.mapsdk.maps.model.MyLocationStyle;
import java.util.List; import java.util.List;
import pub.devrel.easypermissions.EasyPermissions; 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 { //public class LocationLayerActivity extends SupportMapFragmentActivity implements EasyPermissions.PermissionCallbacks, LocationSource, TencentLocationListener, TencentMap.OnMapLongClickListener, RadioGroup.OnCheckedChangeListener {
//
private OnLocationChangedListener locationChangedListener; // private OnLocationChangedListener locationChangedListener;
//
private TencentLocationManager locationManager; // private TencentLocationManager locationManager;
private TencentLocationRequest locationRequest; // private TencentLocationRequest locationRequest;
private MyLocationStyle locationStyle; // private MyLocationStyle locationStyle;
private RadioGroup radioGroup; // private RadioGroup radioGroup;
//
//
@Override // @Override
protected void onCreate(Bundle savedInstanceState) { // protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); // super.onCreate(savedInstanceState);
//
//
//定位需要申请的权限 // //定位需要申请的权限
String[] perms = { // String[] perms = {
Manifest.permission.ACCESS_FINE_LOCATION, // Manifest.permission.ACCESS_FINE_LOCATION,
Manifest.permission.ACCESS_COARSE_LOCATION, // Manifest.permission.ACCESS_COARSE_LOCATION,
Manifest.permission.READ_PHONE_STATE // Manifest.permission.READ_PHONE_STATE
}; // };
//
if (EasyPermissions.hasPermissions(this, perms)) {//检查是否获取该权限 // if (EasyPermissions.hasPermissions(this, perms)) {//检查是否获取该权限
Log.i("location", "已获取权限"); // Log.i("location", "已获取权限");
} else { // } else {
EasyPermissions.requestPermissions(this, "必要的权限", 0, perms); // EasyPermissions.requestPermissions(this, "必要的权限", 0, perms);
} // }
//设置显示定位的图标 // //设置显示定位的图标
mapUiSettings.setMyLocationButtonEnabled(true); // mapUiSettings.setMyLocationButtonEnabled(true);
tencentMap.setOnMapLongClickListener(this); // tencentMap.setOnMapLongClickListener(this);
//
radioGroup = findViewById(R.id.location_type); // radioGroup = findViewById(R.id.location_type);
radioGroup.setVisibility(View.VISIBLE); // radioGroup.setVisibility(View.VISIBLE);
radioGroup.setOnCheckedChangeListener(this); // radioGroup.setOnCheckedChangeListener(this);
//
//建立定位 // //建立定位
initLocation(); // initLocation();
//SDK版本4.3.5新增内置定位标点击回调监听 // //SDK版本4.3.5新增内置定位标点击回调监听
tencentMap.setMyLocationClickListener(new TencentMap.OnMyLocationClickListener() { // tencentMap.setMyLocationClickListener(new TencentMap.OnMyLocationClickListener() {
@Override // @Override
public boolean onMyLocationClicked(LatLng latLng) { // public boolean onMyLocationClicked(LatLng latLng) {
Toast.makeText(LocationLayerActivity.this, "内置定位标点击回调", Toast.LENGTH_SHORT).show(); // Toast.makeText(LocationLayerActivity.this, "内置定位标点击回调", Toast.LENGTH_SHORT).show();
return true; // return true;
} // }
}); // });
} // }
//
/** // /**
* 定位的一些初始化设置 // * 定位的一些初始化设置
*/ // */
private void initLocation() { // private void initLocation() {
//用于访问腾讯定位服务的类, 周期性向客户端提供位置更新 // //用于访问腾讯定位服务的类, 周期性向客户端提供位置更新
locationManager = TencentLocationManager.getInstance(this); // locationManager = TencentLocationManager.getInstance(this);
//设置坐标系 // //设置坐标系
locationManager.setCoordinateType(TencentLocationManager.COORDINATE_TYPE_GCJ02); // locationManager.setCoordinateType(TencentLocationManager.COORDINATE_TYPE_GCJ02);
//创建定位请求 // //创建定位请求
locationRequest = TencentLocationRequest.create(); // locationRequest = TencentLocationRequest.create();
//设置定位周期位置监听器回调周期为3s // //设置定位周期位置监听器回调周期为3s
locationRequest.setInterval(3000); // locationRequest.setInterval(3000);
//
//地图上设置定位数据源 // //地图上设置定位数据源
tencentMap.setLocationSource(this); // tencentMap.setLocationSource(this);
//设置当前位置可见 // //设置当前位置可见
tencentMap.setMyLocationEnabled(true); // tencentMap.setMyLocationEnabled(true);
//设置定位图标样式 // //设置定位图标样式
setLocMarkerStyle(); // setLocMarkerStyle();
tencentMap.setMyLocationStyle(locationStyle); // tencentMap.setMyLocationStyle(locationStyle);
} // }
//
/** // /**
* 设置定位图标样式 // * 设置定位图标样式
*/ // */
private void setLocMarkerStyle() { // private void setLocMarkerStyle() {
locationStyle = new MyLocationStyle(); // locationStyle = new MyLocationStyle();
//创建图标 // //创建图标
BitmapDescriptor bitmapDescriptor = BitmapDescriptorFactory.fromBitmap(getBitMap(R.drawable.location_icon)); // BitmapDescriptor bitmapDescriptor = BitmapDescriptorFactory.fromBitmap(getBitMap(R.drawable.location_icon));
locationStyle.icon(bitmapDescriptor); // locationStyle.icon(bitmapDescriptor);
//设置定位圆形区域的边框宽度 // //设置定位圆形区域的边框宽度
locationStyle.strokeWidth(3); // locationStyle.strokeWidth(3);
//设置圆区域的颜色 // //设置圆区域的颜色
locationStyle.fillColor(R.color.style); // locationStyle.fillColor(R.color.style);
} // }
//
private Bitmap getBitMap(int resourceId) { // private Bitmap getBitMap(int resourceId) {
Bitmap bitmap = BitmapFactory.decodeResource(getResources(), resourceId); // Bitmap bitmap = BitmapFactory.decodeResource(getResources(), resourceId);
int width = bitmap.getWidth(); // int width = bitmap.getWidth();
int height = bitmap.getHeight(); // int height = bitmap.getHeight();
int newWidth = 55; // int newWidth = 55;
int newHeight = 55; // int newHeight = 55;
float widthScale = ((float) newWidth) / width; // float widthScale = ((float) newWidth) / width;
float heightScale = ((float) newHeight) / height; // float heightScale = ((float) newHeight) / height;
Matrix matrix = new Matrix(); // Matrix matrix = new Matrix();
matrix.postScale(widthScale, heightScale); // matrix.postScale(widthScale, heightScale);
bitmap = Bitmap.createBitmap(bitmap, 0, 0, width, height, matrix, true); // bitmap = Bitmap.createBitmap(bitmap, 0, 0, width, height, matrix, true);
return bitmap; // return bitmap;
} // }
//
/** // /**
* 实现位置监听 // * 实现位置监听
* // *
* @param tencentLocation // * @param tencentLocation
* @param i // * @param i
* @param s // * @param s
*/ // */
@Override // @Override
public void onLocationChanged(TencentLocation tencentLocation, int i, String s) { // public void onLocationChanged(TencentLocation tencentLocation, int i, String s) {
//
if (i == TencentLocation.ERROR_OK && locationChangedListener != null) { // if (i == TencentLocation.ERROR_OK && locationChangedListener != null) {
Location location = new Location(tencentLocation.getProvider()); // Location location = new Location(tencentLocation.getProvider());
//设置经纬度以及精度 // //设置经纬度以及精度
location.setLatitude(tencentLocation.getLatitude()); // location.setLatitude(tencentLocation.getLatitude());
location.setLongitude(tencentLocation.getLongitude()); // location.setLongitude(tencentLocation.getLongitude());
location.setAccuracy(tencentLocation.getAccuracy()); // location.setAccuracy(tencentLocation.getAccuracy());
locationChangedListener.onLocationChanged(location); // locationChangedListener.onLocationChanged(location);
//
//显示回调的实时位置信息 // //显示回调的实时位置信息
runOnUiThread(new Runnable() { // runOnUiThread(new Runnable() {
@Override // @Override
public void run() { // public void run() {
//打印tencentLocation的json字符串 // //打印tencentLocation的json字符串
// Toast.makeText(getApplicationContext(), new Gson().toJson(location), Toast.LENGTH_LONG).show(); //// Toast.makeText(getApplicationContext(), new Gson().toJson(location), Toast.LENGTH_LONG).show();
} // }
}); // });
} // }
} // }
//
@Override // @Override
public void onStatusUpdate(String s, int i, String s1) { // public void onStatusUpdate(String s, int i, String s1) {
//GPS, WiFi, Radio 等状态发生变化 // //GPS, WiFi, Radio 等状态发生变化
Log.v("State changed", s + "===" + s1); // Log.v("State changed", s + "===" + s1);
} // }
//
//
@Override // @Override
public void activate(OnLocationChangedListener onLocationChangedListener) { // public void activate(OnLocationChangedListener onLocationChangedListener) {
locationChangedListener = onLocationChangedListener; // locationChangedListener = onLocationChangedListener;
//
int err = locationManager.requestLocationUpdates(locationRequest, this, Looper.myLooper()); // int err = locationManager.requestLocationUpdates(locationRequest, this, Looper.myLooper());
switch (err) { // switch (err) {
case 1: // case 1:
Toast.makeText(this, "设备缺少使用腾讯定位服务需要的基本条件", Toast.LENGTH_SHORT).show(); // Toast.makeText(this, "设备缺少使用腾讯定位服务需要的基本条件", Toast.LENGTH_SHORT).show();
break; // break;
case 2: // case 2:
Toast.makeText(this, "manifest 中配置的 key 不正确", Toast.LENGTH_SHORT).show(); // Toast.makeText(this, "manifest 中配置的 key 不正确", Toast.LENGTH_SHORT).show();
break; // break;
case 3: // case 3:
Toast.makeText(this, "自动加载libtencentloc.so失败", Toast.LENGTH_SHORT).show(); // Toast.makeText(this, "自动加载libtencentloc.so失败", Toast.LENGTH_SHORT).show();
break; // break;
//
default: // default:
break; // break;
} // }
} // }
//
@Override // @Override
public void deactivate() { // public void deactivate() {
locationManager.removeUpdates(this); // locationManager.removeUpdates(this);
locationManager = null; // locationManager = null;
locationRequest = null; // locationRequest = null;
locationChangedListener = null; // locationChangedListener = null;
} // }
//
@Override // @Override
public void onPermissionsGranted(int requestCode, @NonNull List<String> perms) { // public void onPermissionsGranted(int requestCode, @NonNull List<String> perms) {
Log.e("location quest: ", "success"); // Log.e("location quest: ", "success");
} // }
//
@Override // @Override
public void onPermissionsDenied(int requestCode, @NonNull List<String> perms) { // public void onPermissionsDenied(int requestCode, @NonNull List<String> perms) {
Log.e("location quest: ", "failed"); // Log.e("location quest: ", "failed");
} // }
//
@Override // @Override
public void onMapLongClick(LatLng latLng) { // public void onMapLongClick(LatLng latLng) {
Location location = new Location("LongPressLocationProvider"); // Location location = new Location("LongPressLocationProvider");
location.setLatitude(latLng.latitude); // location.setLatitude(latLng.latitude);
location.setLongitude(latLng.longitude); // location.setLongitude(latLng.longitude);
location.setAccuracy(20); // location.setAccuracy(20);
locationChangedListener.onLocationChanged(location); // locationChangedListener.onLocationChanged(location);
Log.i("long click", new Gson().toJson(latLng)); // Log.i("long click", new Gson().toJson(latLng));
} // }
//
@Override // @Override
public void onCheckedChanged(RadioGroup radioGroup, int i) { // public void onCheckedChanged(RadioGroup radioGroup, int i) {
switch (i) { // switch (i) {
//连续定位但不会移动到地图中心点并且会跟随设备移动 // //连续定位但不会移动到地图中心点并且会跟随设备移动
case R.id.btn_follow_no_center: // case R.id.btn_follow_no_center:
//
initLocation(); // initLocation();
locationStyle = locationStyle.myLocationType(MyLocationStyle.LOCATION_TYPE_FOLLOW_NO_CENTER); // locationStyle = locationStyle.myLocationType(MyLocationStyle.LOCATION_TYPE_FOLLOW_NO_CENTER);
tencentMap.setMyLocationStyle(locationStyle); // tencentMap.setMyLocationStyle(locationStyle);
break; // break;
//连续定位且将视角移动到地图中心定位点依照设备方向旋转并且会跟随设备移动,默认是此种类型 // //连续定位且将视角移动到地图中心定位点依照设备方向旋转并且会跟随设备移动,默认是此种类型
case R.id.btn_location_rotate: // case R.id.btn_location_rotate:
//
initLocation(); // initLocation();
locationStyle = locationStyle.myLocationType(MyLocationStyle.LOCATION_TYPE_LOCATION_ROTATE); // locationStyle = locationStyle.myLocationType(MyLocationStyle.LOCATION_TYPE_LOCATION_ROTATE);
tencentMap.setMyLocationStyle(locationStyle); // tencentMap.setMyLocationStyle(locationStyle);
break; // break;
//连续定位但不会移动到地图中心点定位点依照设备方向旋转并且跟随设备移动 // //连续定位但不会移动到地图中心点定位点依照设备方向旋转并且跟随设备移动
case R.id.btn_location_rotate_no_center: // case R.id.btn_location_rotate_no_center:
//
initLocation(); // initLocation();
locationStyle = locationStyle.myLocationType(MyLocationStyle.LOCATION_TYPE_LOCATION_ROTATE_NO_CENTER); // locationStyle = locationStyle.myLocationType(MyLocationStyle.LOCATION_TYPE_LOCATION_ROTATE_NO_CENTER);
tencentMap.setMyLocationStyle(locationStyle); // tencentMap.setMyLocationStyle(locationStyle);
break; // break;
//连续定位但不会移动到地图中心点地图依照设备方向旋转并且会跟随设备移动 // //连续定位但不会移动到地图中心点地图依照设备方向旋转并且会跟随设备移动
case R.id.btn_map_rotate_no_center: // case R.id.btn_map_rotate_no_center:
//
initLocation(); // initLocation();
locationStyle = locationStyle.myLocationType(MyLocationStyle.LOCATION_TYPE_MAP_ROTATE_NO_CENTER); // locationStyle = locationStyle.myLocationType(MyLocationStyle.LOCATION_TYPE_MAP_ROTATE_NO_CENTER);
tencentMap.setMyLocationStyle(locationStyle); // tencentMap.setMyLocationStyle(locationStyle);
break; // break;
} // }
} // }
} //}

View File

@ -25,166 +25,192 @@ import com.tencent.tencentmap.mapsdk.maps.model.MyLocationStyle;
import java.util.List; import java.util.List;
import pub.devrel.easypermissions.EasyPermissions; import pub.devrel.easypermissions.EasyPermissions;
import com.tencent.tencentmap.mapsdk.maps.LocationSource.OnLocationChangedListener;
public class LocationPointActivity extends SupportMapFragmentActivity implements EasyPermissions.PermissionCallbacks,LocationSource, TencentLocationListener{ public class LocationPointActivity extends SupportMapFragmentActivity implements EasyPermissions.PermissionCallbacks,LocationSource, TencentLocationListener {
private LocationSource.OnLocationChangedListener locationChangedListener;
private TencentLocationManager locationManager;
private TencentLocationRequest locationRequest;
private MyLocationStyle locationStyle;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { public void onPermissionsGranted(int p1, List<String> p2) {
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 @Override
public void onStatusUpdate(String s, int i, String s1) { public void onPermissionsDenied(int p1, List<String> p2) {
//GPS, WiFi, Radio 等状态发生变化
Log.v("State changed", s +"===" + s1);
} }
@Override @Override
public void activate(OnLocationChangedListener onLocationChangedListener) { public void activate(LocationSource.OnLocationChangedListener p1) {
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 @Override
public void deactivate() { public void deactivate() {
locationManager.removeUpdates(this);
locationManager = null;
locationRequest = null;
locationChangedListener=null;
} }
@Override @Override
public void onPermissionsGranted(int requestCode, @NonNull List<String> perms) { public void onLocationChanged(TencentLocation p1, int p2, String p3) {
Log.e("location quest: ","success");
} }
@Override @Override
public void onPermissionsDenied(int requestCode, @NonNull List<String> perms) { public void onStatusUpdate(String p1, int p2, String p3) {
Log.e("location quest: ","failed");
} }
// 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<String> perms) {
// Log.e("location quest: ","success");
// }
//
// @Override
// public void onPermissionsDenied(int requestCode, @NonNull List<String> perms) {
// Log.e("location quest: ","failed");
// }
//
} }

View File

@ -1,281 +1,281 @@
package cc.winboll.studio.positions.demo.marker; package cc.winboll.studio.positions.demo.marker;
import androidx.appcompat.app.AppCompatActivity; //import androidx.appcompat.app.AppCompatActivity;
//
import android.graphics.PointF; //import android.graphics.PointF;
import android.opengl.GLES20; //import android.opengl.GLES20;
import android.os.Bundle; //import android.os.Bundle;
import android.util.Log; //import android.util.Log;
//
import cc.winboll.studio.positions.R; //import cc.winboll.studio.positions.R;
import com.tencent.tencentmap.mapsdk.maps.CameraUpdateFactory; //import com.tencent.tencentmap.mapsdk.maps.CameraUpdateFactory;
import com.tencent.tencentmap.mapsdk.maps.CustomRender; //import com.tencent.tencentmap.mapsdk.maps.CustomRender;
import com.tencent.tencentmap.mapsdk.maps.MapView; //import com.tencent.tencentmap.mapsdk.maps.MapView;
import com.tencent.tencentmap.mapsdk.maps.TencentMap; //import com.tencent.tencentmap.mapsdk.maps.TencentMap;
import com.tencent.tencentmap.mapsdk.maps.model.CameraPosition; //import com.tencent.tencentmap.mapsdk.maps.model.CameraPosition;
import com.tencent.tencentmap.mapsdk.maps.model.LatLng; //import com.tencent.tencentmap.mapsdk.maps.model.LatLng;
//
import java.nio.ByteBuffer; //import java.nio.ByteBuffer;
import java.nio.ByteOrder; //import java.nio.ByteOrder;
import java.nio.FloatBuffer; //import java.nio.FloatBuffer;
import java.nio.ShortBuffer; //import java.nio.ShortBuffer;
//
/** ///**
* OpenGL绘制 // * OpenGL绘制
*/ // */
public class CustomRenderActivity extends AppCompatActivity { //public class CustomRenderActivity extends AppCompatActivity {
//
private static final String TAG = CustomRenderActivity.class.getSimpleName(); // private static final String TAG = CustomRenderActivity.class.getSimpleName();
//
// 标识是否第一次绘制3D立方体 // // 标识是否第一次绘制3D立方体
private boolean mIsFirstDraw3DCube = true; // private boolean mIsFirstDraw3DCube = true;
//
// 立方体8个顶点坐标 // // 立方体8个顶点坐标
private float[] mVertices = { // private float[] mVertices = {
-1, -1, -0, // -1, -1, -0,
1, -1, -0, // 1, -1, -0,
1, 1, -0, // 1, 1, -0,
-1, 1, -0, // -1, 1, -0,
-1, -1, 1, // -1, -1, 1,
1, -1, 1, // 1, -1, 1,
1, 1, 1, // 1, 1, 1,
-1, 1, 1, // -1, 1, 1,
}; // };
//
// 3D立方体顶点绘制顺序列表 // // 3D立方体顶点绘制顺序列表
private short[] mDrawIndices = { // private short[] mDrawIndices = {
5, 4, 0, 1, 5, 0, 6, 5, 1, 2, 6, 1, // 5, 4, 0, 1, 5, 0, 6, 5, 1, 2, 6, 1,
7, 6, 2, 3, 7, 2, 4, 7, 3, 0, 4, 3, // 7, 6, 2, 3, 7, 2, 4, 7, 3, 0, 4, 3,
6, 7, 4, 5, 6, 4, 1, 0, 3, 2, 1, 3 // 6, 7, 4, 5, 6, 4, 1, 0, 3, 2, 1, 3
}; // };
//
// 3D立方体8个顶点颜色值 // // 3D立方体8个顶点颜色值
private float[] mVertexColors = { // private float[] mVertexColors = {
1f, 1f, 0f, 1f, // 1f, 1f, 0f, 1f,
0f, 1f, 1f, 1f, // 0f, 1f, 1f, 1f,
1f, 0f, 1f, 1f, // 1f, 0f, 1f, 1f,
0f, 0f, 0f, 1f, // 0f, 0f, 0f, 1f,
1f, 1f, 1f, 1f, // 1f, 1f, 1f, 1f,
1f, 0f, 0f, 1f, // 1f, 0f, 0f, 1f,
0f, 1f, 0f, 1f, // 0f, 1f, 0f, 1f,
0f, 0f, 1f, 1f // 0f, 0f, 1f, 1f
}; // };
//
// 立方体顶点坐标Buffer // // 立方体顶点坐标Buffer
private FloatBuffer mVertexBuffer; // private FloatBuffer mVertexBuffer;
//
// 顶点绘制顺序Buffer // // 顶点绘制顺序Buffer
private ShortBuffer mIndexBuffer; // private ShortBuffer mIndexBuffer;
//
// 立方体顶点颜色Buffer // // 立方体顶点颜色Buffer
private FloatBuffer mColorBuffer; // private FloatBuffer mColorBuffer;
//
// 3D立方体着色器 // // 3D立方体着色器
private CubeShader mCubeShader; // private CubeShader mCubeShader;
//
private MapView mapView; // private MapView mapView;
//
private TencentMap mMap; // private TencentMap mMap;
//
private LatLng latlng = new LatLng(40.04199816,116.27479076); // private LatLng latlng = new LatLng(40.04199816,116.27479076);
//
@Override // @Override
protected void onCreate(Bundle savedInstanceState) { // protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); // super.onCreate(savedInstanceState);
setContentView(R.layout.activity_custom_render); // setContentView(R.layout.activity_custom_render);
mapView = findViewById(R.id.map_view); // mapView = findViewById(R.id.map_view);
mMap = mapView.getMap(); // mMap = mapView.getMap();
mMap.addOnMapLoadedCallback(new TencentMap.OnMapLoadedCallback() { // mMap.addOnMapLoadedCallback(new TencentMap.OnMapLoadedCallback() {
@Override // @Override
public void onMapLoaded() { // public void onMapLoaded() {
mMap.setCustomRender(new CubeRender()); // mMap.setCustomRender(new CubeRender());
mMap.removeOnMapLoadedCallback(this); // mMap.removeOnMapLoadedCallback(this);
} // }
}); // });
//
mMap.moveCamera(CameraUpdateFactory.newCameraPosition(CameraPosition.builder() // mMap.moveCamera(CameraUpdateFactory.newCameraPosition(CameraPosition.builder()
.target(latlng).zoom(16).tilt(45).build())); // .target(latlng).zoom(16).tilt(45).build()));
//
//
} // }
//
@Override // @Override
protected void onResume() { // protected void onResume() {
// TODO Auto-generated method stub // // TODO Auto-generated method stub
super.onResume(); // super.onResume();
mapView.onResume(); // mapView.onResume();
} // }
//
@Override // @Override
protected void onDestroy() { // protected void onDestroy() {
// TODO Auto-generated method stub // // TODO Auto-generated method stub
super.onDestroy(); // super.onDestroy();
mapView.onDestroy(); // mapView.onDestroy();
} // }
//
private class CubeRender implements CustomRender { // private class CubeRender implements CustomRender {
//
private void initCubeData(float width, float height, float depth) { // private void initCubeData(float width, float height, float depth) {
// 对标地图坐标 // // 对标地图坐标
initVertices(mVertices, width, height, depth); // initVertices(mVertices, width, height, depth);
//
// 立方体顶点数据Buffer // // 立方体顶点数据Buffer
mVertexBuffer = ByteBuffer.allocateDirect(mVertices.length * 4) // mVertexBuffer = ByteBuffer.allocateDirect(mVertices.length * 4)
.order(ByteOrder.nativeOrder()) // .order(ByteOrder.nativeOrder())
.asFloatBuffer(); // .asFloatBuffer();
mVertexBuffer.put(mVertices).position(0); // mVertexBuffer.put(mVertices).position(0);
//
// 立方体顶点绘制顺序Buffer // // 立方体顶点绘制顺序Buffer
ByteBuffer byteBuffer = ByteBuffer.allocateDirect(mDrawIndices.length * 4); // ByteBuffer byteBuffer = ByteBuffer.allocateDirect(mDrawIndices.length * 4);
byteBuffer.order(ByteOrder.nativeOrder()); // byteBuffer.order(ByteOrder.nativeOrder());
mIndexBuffer = byteBuffer.asShortBuffer(); // mIndexBuffer = byteBuffer.asShortBuffer();
mIndexBuffer.put(mDrawIndices); // mIndexBuffer.put(mDrawIndices);
mIndexBuffer.position(0); // mIndexBuffer.position(0);
//
// 立方体顶点颜色Buffer // // 立方体顶点颜色Buffer
ByteBuffer byteBuffer1 = ByteBuffer.allocateDirect(mVertexColors.length * 4); // ByteBuffer byteBuffer1 = ByteBuffer.allocateDirect(mVertexColors.length * 4);
byteBuffer1.order(ByteOrder.nativeOrder()); // byteBuffer1.order(ByteOrder.nativeOrder());
mColorBuffer = byteBuffer1.asFloatBuffer(); // mColorBuffer = byteBuffer1.asFloatBuffer();
mColorBuffer.put(mVertexColors); // mColorBuffer.put(mVertexColors);
mColorBuffer.position(0); // mColorBuffer.position(0);
} // }
//
private void initCubeShader() { // private void initCubeShader() {
mCubeShader = new CubeShader(); // mCubeShader = new CubeShader();
mCubeShader.init(); // mCubeShader.init();
} // }
//
private void initVertices(float[] vertices, float width, float height, float depth) { // private void initVertices(float[] vertices, float width, float height, float depth) {
for (int i = 0; i < vertices.length / 3; i++) { // for (int i = 0; i < vertices.length / 3; i++) {
int m = i * 3; // int m = i * 3;
vertices[m] = vertices[m] * width; // vertices[m] = vertices[m] * width;
vertices[m + 1] = vertices[m + 1] * height; // vertices[m + 1] = vertices[m + 1] * height;
vertices[m + 2] = vertices[m + 2] * depth; // vertices[m + 2] = vertices[m + 2] * depth;
} // }
} // }
//
@Override // @Override
public void onDrawFrame() { // public void onDrawFrame() {
drawCube(); // drawCube();
} // }
//
private void drawCube() { // private void drawCube() {
//
if (mIsFirstDraw3DCube) { // if (mIsFirstDraw3DCube) {
float cubeWidth = 0.2f * 10000 / 2; // float cubeWidth = 0.2f * 10000 / 2;
float cubeHeight = 0.2f * 10000 / 2; // float cubeHeight = 0.2f * 10000 / 2;
float cubeDepth = 0.4f * 10000 / 2; // float cubeDepth = 0.4f * 10000 / 2;
initCubeData(cubeWidth, cubeHeight, cubeDepth); // initCubeData(cubeWidth, cubeHeight, cubeDepth);
initCubeShader(); // initCubeShader();
mIsFirstDraw3DCube = false; // mIsFirstDraw3DCube = false;
} // }
//
if (null == mCubeShader) { // if (null == mCubeShader) {
return; // return;
} // }
//
// 绑定地图移动 // // 绑定地图移动
PointF p1f = mMap.getProjection().glVertexForCoordinate(latlng); // PointF p1f = mMap.getProjection().glVertexForCoordinate(latlng);
float[] mvpMatrix = mMap.getProjection().glModelMatrix(p1f, 1); // float[] mvpMatrix = mMap.getProjection().glModelMatrix(p1f, 1);
//
// Step2 开始绘制设置 // // Step2 开始绘制设置
GLES20.glUseProgram(mCubeShader.mProgram); // GLES20.glUseProgram(mCubeShader.mProgram);
checkGlError("glUseProgram"); // checkGlError("glUseProgram");
//
GLES20.glEnable(GLES20.GL_DEPTH_TEST); // GLES20.glEnable(GLES20.GL_DEPTH_TEST);
checkGlError("glEnable"); // checkGlError("glEnable");
//
//对齐矩阵 // //对齐矩阵
GLES20.glUniformMatrix4fv(mCubeShader.mMvpMatrix, 1, false, mvpMatrix, 0); // GLES20.glUniformMatrix4fv(mCubeShader.mMvpMatrix, 1, false, mvpMatrix, 0);
checkGlError("glUniformMatrix4fv"); // checkGlError("glUniformMatrix4fv");
//
GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, 0); // GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, 0);
// 顶点指针 // // 顶点指针
GLES20.glEnableVertexAttribArray(mCubeShader.mVertex); // GLES20.glEnableVertexAttribArray(mCubeShader.mVertex);
checkGlError("glEnableVertexAttribArray"); // checkGlError("glEnableVertexAttribArray");
GLES20.glVertexAttribPointer(mCubeShader.mVertex, 3, GLES20.GL_FLOAT, false, 0, mVertexBuffer); // GLES20.glVertexAttribPointer(mCubeShader.mVertex, 3, GLES20.GL_FLOAT, false, 0, mVertexBuffer);
checkGlError("glVertexAttribPointer"); // checkGlError("glVertexAttribPointer");
//
// 颜色指针 // // 颜色指针
GLES20.glEnableVertexAttribArray(mCubeShader.mColor); // GLES20.glEnableVertexAttribArray(mCubeShader.mColor);
checkGlError("glEnableVertexAttribArray"); // checkGlError("glEnableVertexAttribArray");
GLES20.glVertexAttribPointer(mCubeShader.mColor, 4, GLES20.GL_FLOAT, false, 0, mColorBuffer); // GLES20.glVertexAttribPointer(mCubeShader.mColor, 4, GLES20.GL_FLOAT, false, 0, mColorBuffer);
checkGlError("glVertexAttribPointer"); // checkGlError("glVertexAttribPointer");
//
GLES20.glBindBuffer(GLES20.GL_ELEMENT_ARRAY_BUFFER, 0); // GLES20.glBindBuffer(GLES20.GL_ELEMENT_ARRAY_BUFFER, 0);
// 开始画 // // 开始画
GLES20.glDrawElements(GLES20.GL_TRIANGLES, mDrawIndices.length, GLES20.GL_UNSIGNED_SHORT, mIndexBuffer); // GLES20.glDrawElements(GLES20.GL_TRIANGLES, mDrawIndices.length, GLES20.GL_UNSIGNED_SHORT, mIndexBuffer);
checkGlError("glDrawElements"); // checkGlError("glDrawElements");
//
GLES20.glDisableVertexAttribArray(mCubeShader.mVertex); // GLES20.glDisableVertexAttribArray(mCubeShader.mVertex);
checkGlError("glDisableVertexAttribArray"); // checkGlError("glDisableVertexAttribArray");
//
GLES20.glDisable(GLES20.GL_DEPTH_TEST); // GLES20.glDisable(GLES20.GL_DEPTH_TEST);
checkGlError("glDisable"); // checkGlError("glDisable");
} // }
} // }
//
private static class CubeShader { // private static class CubeShader {
int mVertex; // int mVertex;
int mMvpMatrix; // int mMvpMatrix;
int mColor; // int mColor;
int mProgram; // int mProgram;
//
String vertexShader = "precision mediump float;\n" + // String vertexShader = "precision mediump float;\n" +
" attribute vec3 mVertex;//顶点数组,三维坐标\n" + // " attribute vec3 mVertex;//顶点数组,三维坐标\n" +
" attribute vec4 mColor;//颜色数组,三维坐标\n" + // " attribute vec4 mColor;//颜色数组,三维坐标\n" +
" uniform mat4 mMvpMatrix;//mvp矩阵\n" + // " uniform mat4 mMvpMatrix;//mvp矩阵\n" +
" varying vec4 color;//\n" + // " varying vec4 color;//\n" +
" void main(){\n" + // " void main(){\n" +
" gl_Position = mMvpMatrix * vec4(mVertex, 1.0);\n" + // " gl_Position = mMvpMatrix * vec4(mVertex, 1.0);\n" +
" color = mColor;\n" + // " color = mColor;\n" +
" }"; // " }";
//
String fragmentShader = "//有颜色 没有纹理\n" + // String fragmentShader = "//有颜色 没有纹理\n" +
" precision mediump float;\n" + // " precision mediump float;\n" +
" varying vec4 color;//\n" + // " varying vec4 color;//\n" +
" void main(){\n" + // " void main(){\n" +
" gl_FragColor = color;\n" + // " gl_FragColor = color;\n" +
" }"; // " }";
//
public void init() { // public void init() {
int vertexLocation = GLES20.glCreateShader(GLES20.GL_VERTEX_SHADER); // int vertexLocation = GLES20.glCreateShader(GLES20.GL_VERTEX_SHADER);
GLES20.glShaderSource(vertexLocation, vertexShader); // GLES20.glShaderSource(vertexLocation, vertexShader);
checkGlError("glShaderSource"); // checkGlError("glShaderSource");
GLES20.glCompileShader(vertexLocation); // GLES20.glCompileShader(vertexLocation);
checkGlError("glCompileShader"); // checkGlError("glCompileShader");
int fragmentLocation = GLES20.glCreateShader(GLES20.GL_FRAGMENT_SHADER); // int fragmentLocation = GLES20.glCreateShader(GLES20.GL_FRAGMENT_SHADER);
GLES20.glShaderSource(fragmentLocation, fragmentShader); // GLES20.glShaderSource(fragmentLocation, fragmentShader);
checkGlError("glShaderSource"); // checkGlError("glShaderSource");
GLES20.glCompileShader(fragmentLocation); // GLES20.glCompileShader(fragmentLocation);
checkGlError("glCompileShader"); // checkGlError("glCompileShader");
//
mProgram = GLES20.glCreateProgram(); // mProgram = GLES20.glCreateProgram();
GLES20.glAttachShader(mProgram, vertexLocation); // GLES20.glAttachShader(mProgram, vertexLocation);
GLES20.glAttachShader(mProgram, fragmentLocation); // GLES20.glAttachShader(mProgram, fragmentLocation);
GLES20.glLinkProgram(mProgram); // GLES20.glLinkProgram(mProgram);
int[] linked = new int[1]; // int[] linked = new int[1];
GLES20.glGetProgramiv(mProgram, GLES20.GL_LINK_STATUS, linked, 0); // GLES20.glGetProgramiv(mProgram, GLES20.GL_LINK_STATUS, linked, 0);
checkGlError("glLinkProgram"); // checkGlError("glLinkProgram");
if (linked[0] != GLES20.GL_TRUE) { // if (linked[0] != GLES20.GL_TRUE) {
Log.e(TAG, "Could not link program: "); // Log.e(TAG, "Could not link program: ");
Log.e(TAG, GLES20.glGetProgramInfoLog(mProgram)); // Log.e(TAG, GLES20.glGetProgramInfoLog(mProgram));
GLES20.glDeleteProgram(mProgram); // GLES20.glDeleteProgram(mProgram);
mProgram = 0; // mProgram = 0;
} // }
//
//
mVertex = GLES20.glGetAttribLocation(mProgram, "mVertex"); // mVertex = GLES20.glGetAttribLocation(mProgram, "mVertex");
mMvpMatrix = GLES20.glGetUniformLocation(mProgram, "mMvpMatrix"); // mMvpMatrix = GLES20.glGetUniformLocation(mProgram, "mMvpMatrix");
mColor = GLES20.glGetAttribLocation(mProgram, "mColor"); // mColor = GLES20.glGetAttribLocation(mProgram, "mColor");
} // }
//
} // }
//
static void checkGlError(String op) { // static void checkGlError(String op) {
int error; // int error;
while ((error = GLES20.glGetError()) != GLES20.GL_NO_ERROR) { // while ((error = GLES20.glGetError()) != GLES20.GL_NO_ERROR) {
Log.e(TAG, op + ": glError " + error); // Log.e(TAG, op + ": glError " + error);
} // }
} // }
} //}

View File

@ -1,129 +1,129 @@
package cc.winboll.studio.positions.demo.marker; package cc.winboll.studio.positions.demo.marker;
import androidx.annotation.NonNull; //import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity; //import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.FragmentActivity; //import androidx.fragment.app.FragmentActivity;
//
import android.os.Bundle; //import android.os.Bundle;
import android.view.Menu; //import android.view.Menu;
import android.view.MenuItem; //import android.view.MenuItem;
import android.view.View; //import android.view.View;
import android.widget.Button; //import android.widget.Button;
import android.widget.RadioGroup; //import android.widget.RadioGroup;
//
//
import cc.winboll.studio.positions.R; //import cc.winboll.studio.positions.R;
import cc.winboll.studio.positions.demo.basic.SupportMapFragmentActivity; //import cc.winboll.studio.positions.demo.basic.SupportMapFragmentActivity;
import com.tencent.tencentmap.mapsdk.maps.CameraUpdateFactory; //import com.tencent.tencentmap.mapsdk.maps.CameraUpdateFactory;
import com.tencent.tencentmap.mapsdk.maps.MapView; //import com.tencent.tencentmap.mapsdk.maps.MapView;
import com.tencent.tencentmap.mapsdk.maps.TencentMap; //import com.tencent.tencentmap.mapsdk.maps.TencentMap;
import com.tencent.tencentmap.mapsdk.maps.model.BitmapDescriptorFactory; //import com.tencent.tencentmap.mapsdk.maps.model.BitmapDescriptorFactory;
import com.tencent.tencentmap.mapsdk.maps.model.GroundOverlay; //import com.tencent.tencentmap.mapsdk.maps.model.GroundOverlay;
import com.tencent.tencentmap.mapsdk.maps.model.GroundOverlayOptions; //import com.tencent.tencentmap.mapsdk.maps.model.GroundOverlayOptions;
import com.tencent.tencentmap.mapsdk.maps.model.LatLng; //import com.tencent.tencentmap.mapsdk.maps.model.LatLng;
import com.tencent.tencentmap.mapsdk.maps.model.LatLngBounds; //import com.tencent.tencentmap.mapsdk.maps.model.LatLngBounds;
import com.tencent.tencentmap.mapsdk.maps.model.OverlayLevel; //import com.tencent.tencentmap.mapsdk.maps.model.OverlayLevel;
//
import java.util.ArrayList; //import java.util.ArrayList;
//
public class GroundOverlayActivity extends SupportMapFragmentActivity { //public class GroundOverlayActivity extends SupportMapFragmentActivity {
//
private MapView mMapView; // private MapView mMapView;
private TencentMap mTencentMap; // private TencentMap mTencentMap;
private GroundOverlay groundOverlay; // private GroundOverlay groundOverlay;
GroundOverlayOptions groundOverlayOptions; // GroundOverlayOptions groundOverlayOptions;
private boolean mIsSelected; // private boolean mIsSelected;
//
@Override // @Override
protected void onCreate(Bundle savedInstanceState) { // protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); // super.onCreate(savedInstanceState);
setContentView(R.layout.activity_ground_overlay); // setContentView(R.layout.activity_ground_overlay);
mMapView = findViewById(R.id.map_view); // mMapView = findViewById(R.id.map_view);
mTencentMap = mMapView.getMap(); // mTencentMap = mMapView.getMap();
mTencentMap.setIndoorEnabled(true); // mTencentMap.setIndoorEnabled(true);
} // }
//
//
@Override // @Override
protected void onResume() { // protected void onResume() {
super.onResume(); // super.onResume();
mMapView.onResume(); // mMapView.onResume();
} // }
//
@Override // @Override
protected void onPause() { // protected void onPause() {
super.onPause(); // super.onPause();
mMapView.onPause(); // mMapView.onPause();
} // }
//
@Override // @Override
protected void onDestroy() { // protected void onDestroy() {
super.onDestroy(); // super.onDestroy();
mMapView.onDestroy(); // mMapView.onDestroy();
} // }
//
//
@Override // @Override
protected void onStart() { // protected void onStart() {
super.onStart(); // super.onStart();
mMapView.onStart(); // mMapView.onStart();
} // }
//
@Override // @Override
protected void onStop() { // protected void onStop() {
super.onStop(); // super.onStop();
mMapView.onStop(); // mMapView.onStop();
} // }
//
@Override // @Override
public boolean onCreateOptionsMenu(Menu menu) { // public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.marker_groundoverlay, menu); // getMenuInflater().inflate(R.menu.marker_groundoverlay, menu);
return true; // return true;
} // }
//
@Override // @Override
public boolean onPrepareOptionsMenu(Menu menu) { // public boolean onPrepareOptionsMenu(Menu menu) {
menu.findItem(R.id.menu_add_groundoverlay).setVisible(!mIsSelected); // menu.findItem(R.id.menu_add_groundoverlay).setVisible(!mIsSelected);
menu.findItem(R.id.menu_remove_groundoverlay).setVisible(mIsSelected); // menu.findItem(R.id.menu_remove_groundoverlay).setVisible(mIsSelected);
return super.onPrepareOptionsMenu(menu); // return super.onPrepareOptionsMenu(menu);
} // }
//
@Override // @Override
public boolean onOptionsItemSelected(@NonNull MenuItem item) { // public boolean onOptionsItemSelected(@NonNull MenuItem item) {
switch (item.getItemId()) { // switch (item.getItemId()) {
case R.id.menu_add_groundoverlay: // case R.id.menu_add_groundoverlay:
addGroundOverlays(); // addGroundOverlays();
break; // break;
case R.id.menu_remove_groundoverlay: // case R.id.menu_remove_groundoverlay:
removeGroundOverlays(); // removeGroundOverlays();
break; // break;
} // }
//
supportInvalidateOptionsMenu(); // supportInvalidateOptionsMenu();
return super.onOptionsItemSelected(item); // return super.onOptionsItemSelected(item);
} // }
//
public void addGroundOverlays() { // public void addGroundOverlays() {
mIsSelected = true; // mIsSelected = true;
LatLngBounds lb = new LatLngBounds( // LatLngBounds lb = new LatLngBounds(
new LatLng(40.045226, 116.280069), // new LatLng(40.045226, 116.280069),
new LatLng(40.038918, 116.271873)); // new LatLng(40.038918, 116.271873));
groundOverlayOptions = new GroundOverlayOptions() // groundOverlayOptions = new GroundOverlayOptions()
.bitmap(BitmapDescriptorFactory // .bitmap(BitmapDescriptorFactory
.fromAsset("groundoverlay.jpg")) // .fromAsset("groundoverlay.jpg"))
.latLngBounds(lb) // .latLngBounds(lb)
.alpha(10); // .alpha(10);
groundOverlay = mTencentMap.addGroundOverlay(groundOverlayOptions); // groundOverlay = mTencentMap.addGroundOverlay(groundOverlayOptions);
mTencentMap.moveCamera(CameraUpdateFactory.newLatLngBounds(lb, 300)); // mTencentMap.moveCamera(CameraUpdateFactory.newLatLngBounds(lb, 300));
//
} // }
//
public void removeGroundOverlays() { // public void removeGroundOverlays() {
mIsSelected = false; // mIsSelected = false;
if (groundOverlay != null) { // if (groundOverlay != null) {
groundOverlay.remove(); // groundOverlay.remove();
groundOverlay = null; // groundOverlay = null;
} // }
} // }
//
} //}

View File

@ -17,58 +17,58 @@ import com.tencent.tencentmap.mapsdk.maps.model.Marker;
import com.tencent.tencentmap.mapsdk.maps.model.MarkerOptions; import com.tencent.tencentmap.mapsdk.maps.model.MarkerOptions;
public class MarkerActivity extends SupportMapFragmentActivity { public class MarkerActivity extends SupportMapFragmentActivity {
public Marker marker; // public Marker marker;
public Switch aSwitch; // public Switch aSwitch;
//
@Override // @Override
protected void onCreate(Bundle savedInstanceState) { // protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); // super.onCreate(savedInstanceState);
aSwitch = findViewById(R.id.switch_map); // aSwitch = findViewById(R.id.switch_map);
aSwitch.setVisibility(View.VISIBLE); // aSwitch.setVisibility(View.VISIBLE);
aSwitch.setText("添加标注"); // aSwitch.setText("添加标注");
setMarker(); // setMarker();
aSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { // aSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override // @Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { // public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if(isChecked){ // if(isChecked){
setMarker(); // setMarker();
}else { // }else {
if(marker!=null){ // if(marker!=null){
marker.remove(); // marker.remove();
} // }
} // }
} // }
}); // });
//
} // }
//
/** // /**
* 设置标注 // * 设置标注
*/ // */
private void setMarker(){ // private void setMarker(){
LatLng latLng = new LatLng(39.984108,116.307557); // LatLng latLng = new LatLng(39.984108,116.307557);
BitmapDescriptor bitmapDescriptor = BitmapDescriptorFactory.fromBitmap(getBitMap(R.drawable.marker)); // BitmapDescriptor bitmapDescriptor = BitmapDescriptorFactory.fromBitmap(getBitMap(R.drawable.marker));
MarkerOptions options = new MarkerOptions().position(latLng).icon(bitmapDescriptor); // MarkerOptions options = new MarkerOptions().position(latLng).icon(bitmapDescriptor);
//
//设置infowindow // //设置infowindow
options.title("地址"); // options.title("地址");
options.snippet("中国技术交易大厦"); // options.snippet("中国技术交易大厦");
marker = tencentMap.addMarker(options); // marker = tencentMap.addMarker(options);
marker.setInfoWindowEnable(true); // marker.setInfoWindowEnable(true);
} // }
//
//
private Bitmap getBitMap(int resourceId){ // private Bitmap getBitMap(int resourceId){
Bitmap bitmap = BitmapFactory.decodeResource(getResources(), resourceId); // Bitmap bitmap = BitmapFactory.decodeResource(getResources(), resourceId);
int width = bitmap.getWidth(); // int width = bitmap.getWidth();
int height = bitmap.getHeight(); // int height = bitmap.getHeight();
int newWidth = 100; // int newWidth = 100;
int newHeight = 100; // int newHeight = 100;
float widthScale = ((float)newWidth)/width; // float widthScale = ((float)newWidth)/width;
float heightScale = ((float)newHeight)/height; // float heightScale = ((float)newHeight)/height;
Matrix matrix = new Matrix(); // Matrix matrix = new Matrix();
matrix.postScale(widthScale, heightScale); // matrix.postScale(widthScale, heightScale);
bitmap = Bitmap.createBitmap(bitmap,0,0,width,height,matrix,true); // bitmap = Bitmap.createBitmap(bitmap,0,0,width,height,matrix,true);
return bitmap; // return bitmap;
} // }
} }

View File

@ -39,197 +39,197 @@ import java.util.TimerTask;
public class MarkerAnimation extends AbsMapActivity { public class MarkerAnimation extends AbsMapActivity {
private int rotate = 0; // private int rotate = 0;
private int scale = 1; // private int scale = 1;
private int alpha = 2; // private int alpha = 2;
private int translate = 3; // private int translate = 3;
private int set = 4; // private int set = 4;
private boolean mHasAdded; // private boolean mHasAdded;
private Marker marker; // private Marker marker;
private IRotateAnimation rotateAnimation; // private IRotateAnimation rotateAnimation;
private IScaleAnimation scaleAnimation; // private IScaleAnimation scaleAnimation;
private IAlphaAnimation alphaAnimation; // private IAlphaAnimation alphaAnimation;
private ITranslateAnimation translateAnimation; // private ITranslateAnimation translateAnimation;
private TencentMap tencentMap; // private TencentMap tencentMap;
private IAnimationSet animationSet; // private IAnimationSet animationSet;
private LatLng latLng; // private LatLng latLng;
//
@Override // @Override
protected void onCreate(@Nullable Bundle savedInstanceState, TencentMap mTencentMap) { // protected void onCreate(@Nullable Bundle savedInstanceState, TencentMap mTencentMap) {
super.onCreate(savedInstanceState, mTencentMap); // super.onCreate(savedInstanceState, mTencentMap);
tencentMap = mTencentMap; // tencentMap = mTencentMap;
tencentMap.moveCamera(CameraUpdateFactory.zoomTo(15)); // tencentMap.moveCamera(CameraUpdateFactory.zoomTo(15));
} // }
//
@Override // @Override
public boolean onCreateOptionsMenu(Menu menu) { // public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.marker_animation, menu); // getMenuInflater().inflate(R.menu.marker_animation, menu);
return true; // return true;
} // }
//
@Override // @Override
public boolean onPrepareOptionsMenu(Menu menu) { // public boolean onPrepareOptionsMenu(Menu menu) {
menu.findItem(R.id.menu_add_marker).setVisible(!mHasAdded); // menu.findItem(R.id.menu_add_marker).setVisible(!mHasAdded);
menu.findItem(R.id.menu_delete_marker).setVisible(mHasAdded); // menu.findItem(R.id.menu_delete_marker).setVisible(mHasAdded);
return super.onPrepareOptionsMenu(menu); // return super.onPrepareOptionsMenu(menu);
} // }
//
@Override // @Override
public boolean onOptionsItemSelected(MenuItem item) { // public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) { // switch (item.getItemId()) {
case R.id.menu_add_marker_rotate: // case R.id.menu_add_marker_rotate:
tencentMap.clear(); // tencentMap.clear();
marker = tencentMap.addMarker(setMarkerAnimation(rotate)); // marker = tencentMap.addMarker(setMarkerAnimation(rotate));
mHasAdded = true; // mHasAdded = true;
marker.setAnimation(rotateAnimation); // marker.setAnimation(rotateAnimation);
marker.startAnimation(); // marker.startAnimation();
break; // break;
//
case R.id.menu_add_marker_scale: // case R.id.menu_add_marker_scale:
tencentMap.clear(); // tencentMap.clear();
marker = tencentMap.addMarker(setMarkerAnimation(scale)); // marker = tencentMap.addMarker(setMarkerAnimation(scale));
mHasAdded = true; // mHasAdded = true;
marker.setAnimation(scaleAnimation); // marker.setAnimation(scaleAnimation);
marker.startAnimation(); // marker.startAnimation();
scaleAnimation.setAnimationListener(new AnimationListener() { // scaleAnimation.setAnimationListener(new AnimationListener() {
@Override // @Override
public void onAnimationStart() { // public void onAnimationStart() {
//
} // }
//
@Override // @Override
public void onAnimationEnd() { // public void onAnimationEnd() {
marker.startAnimation(); // marker.startAnimation();
} // }
}); // });
//
//
break; // break;
case R.id.menu_add_marker_alpha: // case R.id.menu_add_marker_alpha:
tencentMap.clear(); // tencentMap.clear();
marker = tencentMap.addMarker(setMarkerAnimation(alpha)); // marker = tencentMap.addMarker(setMarkerAnimation(alpha));
mHasAdded = true; // mHasAdded = true;
marker.setAnimation(alphaAnimation); // marker.setAnimation(alphaAnimation);
marker.startAnimation(); // marker.startAnimation();
break; // break;
case R.id.menu_add_marker_translate: // case R.id.menu_add_marker_translate:
tencentMap.clear(); // tencentMap.clear();
marker = tencentMap.addMarker(setMarkerAnimation(translate)); // marker = tencentMap.addMarker(setMarkerAnimation(translate));
mHasAdded = true; // mHasAdded = true;
Point screenLocation = tencentMap.getProjection().toScreenLocation(latLng); // Point screenLocation = tencentMap.getProjection().toScreenLocation(latLng);
//
marker.setFixingPoint(screenLocation.x, screenLocation.y); // marker.setFixingPoint(screenLocation.x, screenLocation.y);
//
marker.setAnimation(translateAnimation); // marker.setAnimation(translateAnimation);
marker.startAnimation(); // marker.startAnimation();
//
translateAnimation.setAnimationListener(new AnimationListener() { // translateAnimation.setAnimationListener(new AnimationListener() {
@Override // @Override
public void onAnimationStart() { // public void onAnimationStart() {
//
} // }
//
@Override // @Override
public void onAnimationEnd() { // public void onAnimationEnd() {
marker.setFixingPointEnable(false); // marker.setFixingPointEnable(false);
//
} // }
}); // });
break; // break;
case R.id.menu_add_marker_set: // case R.id.menu_add_marker_set:
tencentMap.clear(); // tencentMap.clear();
marker = tencentMap.addMarker(setMarkerAnimation(set)); // marker = tencentMap.addMarker(setMarkerAnimation(set));
mHasAdded = true; // mHasAdded = true;
marker.setAnimation(animationSet); // marker.setAnimation(animationSet);
marker.startAnimation(); // marker.startAnimation();
break; // break;
//
case R.id.menu_delete_marker: // case R.id.menu_delete_marker:
if (marker != null) { // if (marker != null) {
marker.remove(); // marker.remove();
marker = null; // marker = null;
mHasAdded = false; // mHasAdded = false;
} // }
break; // break;
} // }
return super.onOptionsItemSelected(item); // return super.onOptionsItemSelected(item);
} // }
//
private MarkerOptions setMarkerAnimation(int type) { // private MarkerOptions setMarkerAnimation(int type) {
latLng = new LatLng(39.984108, 116.307557); // latLng = new LatLng(39.984108, 116.307557);
BitmapDescriptor bitmapDescriptor = BitmapDescriptorFactory.fromBitmap(getBitMap(R.drawable.marker)); // BitmapDescriptor bitmapDescriptor = BitmapDescriptorFactory.fromBitmap(getBitMap(R.drawable.marker));
MarkerOptions position = new MarkerOptions().position(latLng).icon(bitmapDescriptor); // MarkerOptions position = new MarkerOptions().position(latLng).icon(bitmapDescriptor);
switch (type) { // switch (type) {
case 0: // case 0:
//旋转动画 // //旋转动画
rotateAnimation = tencentMap.getMapContext().createRotateAnimation(0, 360, 0, 0, 0); // rotateAnimation = tencentMap.getMapContext().createRotateAnimation(0, 360, 0, 0, 0);
rotateAnimation.setDuration(2000); // rotateAnimation.setDuration(2000);
break; // break;
case 1: // case 1:
//缩放动画 // //缩放动画
scaleAnimation = tencentMap.getMapContext().createScaleAnimation(0.0f, 1f, 0.0f, 1f); // scaleAnimation = tencentMap.getMapContext().createScaleAnimation(0.0f, 1f, 0.0f, 1f);
scaleAnimation.setDuration(2000); // scaleAnimation.setDuration(2000);
scaleAnimation.setInterpolator(new AccelerateDecelerateInterpolator()); // scaleAnimation.setInterpolator(new AccelerateDecelerateInterpolator());
//
case 2: // case 2:
//渐变 // //渐变
alphaAnimation = tencentMap.getMapContext().createAlphaAnimation(0f, 1f); // alphaAnimation = tencentMap.getMapContext().createAlphaAnimation(0f, 1f);
alphaAnimation.setDuration(2000); // alphaAnimation.setDuration(2000);
alphaAnimation.setInterpolator(new AccelerateDecelerateInterpolator()); // alphaAnimation.setInterpolator(new AccelerateDecelerateInterpolator());
//
break; // break;
case 3: // case 3:
//平移 // //平移
Point point = tencentMap.getProjection().toScreenLocation(latLng); // Point point = tencentMap.getProjection().toScreenLocation(latLng);
point.y -= dip2px(this, 250); // point.y -= dip2px(this, 250);
LatLng target = tencentMap.getProjection().fromScreenLocation(point); // LatLng target = tencentMap.getProjection().fromScreenLocation(point);
translateAnimation = tencentMap.getMapContext().createTranslateAnimation(target); // translateAnimation = tencentMap.getMapContext().createTranslateAnimation(target);
translateAnimation.setInterpolator(new Interpolator() { // translateAnimation.setInterpolator(new Interpolator() {
@Override // @Override
public float getInterpolation(float v) { // public float getInterpolation(float v) {
if (v <= 0.5f) { // if (v <= 0.5f) {
return (float) (0.5f - 2 * (0.5 - v) * (0.5 - v)); // return (float) (0.5f - 2 * (0.5 - v) * (0.5 - v));
} else { // } else {
return (float) (0.5f - Math.sqrt((v - 0.5f) * (1.5f - v))); // return (float) (0.5f - Math.sqrt((v - 0.5f) * (1.5f - v)));
} // }
} // }
}); // });
translateAnimation.setDuration(2000); // translateAnimation.setDuration(2000);
break; // break;
case 4: // case 4:
//组合动画 // //组合动画
animationSet = tencentMap.getMapContext().createAnimationSet(true); // animationSet = tencentMap.getMapContext().createAnimationSet(true);
if (rotateAnimation != null || scaleAnimation != null || alphaAnimation != null) { // if (rotateAnimation != null || scaleAnimation != null || alphaAnimation != null) {
animationSet.addAnimation(rotateAnimation); // animationSet.addAnimation(rotateAnimation);
animationSet.addAnimation(scaleAnimation); // animationSet.addAnimation(scaleAnimation);
animationSet.addAnimation(alphaAnimation); // animationSet.addAnimation(alphaAnimation);
} // }
//
break; // break;
//
default: // default:
throw new IllegalStateException("Unexpected value: " + type); // throw new IllegalStateException("Unexpected value: " + type);
} // }
return position; // return position;
} // }
//
private static int dip2px(Context context, float dpValue) { // private static int dip2px(Context context, float dpValue) {
final float scale = context.getResources().getDisplayMetrics().density; // final float scale = context.getResources().getDisplayMetrics().density;
return (int) (dpValue * scale + 1.5f); // return (int) (dpValue * scale + 1.5f);
} // }
//
private Bitmap getBitMap(int resourceId) { // private Bitmap getBitMap(int resourceId) {
Bitmap bitmap = BitmapFactory.decodeResource(getResources(), resourceId); // Bitmap bitmap = BitmapFactory.decodeResource(getResources(), resourceId);
int width = bitmap.getWidth(); // int width = bitmap.getWidth();
int height = bitmap.getHeight(); // int height = bitmap.getHeight();
int newWidth = 100; // int newWidth = 100;
int newHeight = 100; // int newHeight = 100;
float widthScale = ((float) newWidth) / width; // float widthScale = ((float) newWidth) / width;
float heightScale = ((float) newHeight) / height; // float heightScale = ((float) newHeight) / height;
Matrix matrix = new Matrix(); // Matrix matrix = new Matrix();
matrix.postScale(widthScale, heightScale); // matrix.postScale(widthScale, heightScale);
bitmap = Bitmap.createBitmap(bitmap, 0, 0, width, height, matrix, true); // bitmap = Bitmap.createBitmap(bitmap, 0, 0, width, height, matrix, true);
return bitmap; // return bitmap;
} // }
} }

View File

@ -1,25 +1,25 @@
package cc.winboll.studio.positions.demo.marker; package cc.winboll.studio.positions.demo.marker;
import android.os.Bundle; //import android.os.Bundle;
import android.view.View; //import android.view.View;
import android.widget.Toast; //import android.widget.Toast;
//
import com.tencent.tencentmap.mapsdk.maps.TencentMap; //import com.tencent.tencentmap.mapsdk.maps.TencentMap;
import com.tencent.tencentmap.mapsdk.maps.model.Marker; //import com.tencent.tencentmap.mapsdk.maps.model.Marker;
//
public class MarkerClickActivity extends MarkerActivity implements TencentMap.OnMarkerClickListener{ //public class MarkerClickActivity extends MarkerActivity implements TencentMap.OnMarkerClickListener{
//
@Override // @Override
protected void onCreate(Bundle savedInstanceState) { // protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); // super.onCreate(savedInstanceState);
marker.setInfoWindowEnable(false); // marker.setInfoWindowEnable(false);
aSwitch.setVisibility(View.GONE); // aSwitch.setVisibility(View.GONE);
tencentMap.setOnMarkerClickListener(this); // tencentMap.setOnMarkerClickListener(this);
} // }
//
@Override // @Override
public boolean onMarkerClick(Marker marker) { // public boolean onMarkerClick(Marker marker) {
Toast.makeText(getApplicationContext(),"您点击了标注", Toast.LENGTH_SHORT).show(); // Toast.makeText(getApplicationContext(),"您点击了标注", Toast.LENGTH_SHORT).show();
return false; // return false;
} // }
} //}

View File

@ -20,7 +20,7 @@ import androidx.annotation.Nullable;
import cc.winboll.studio.positions.demo.AbsMapActivity; import cc.winboll.studio.positions.demo.AbsMapActivity;
import cc.winboll.studio.positions.R; 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.CameraUpdate;
import com.tencent.tencentmap.mapsdk.maps.CameraUpdateFactory; import com.tencent.tencentmap.mapsdk.maps.CameraUpdateFactory;
import com.tencent.tencentmap.mapsdk.maps.TencentMap; import com.tencent.tencentmap.mapsdk.maps.TencentMap;
@ -54,334 +54,334 @@ import java.util.Set;
import java.util.Timer; import java.util.Timer;
import java.util.TimerTask; import java.util.TimerTask;
public class MarkerClusterActivity extends AbsMapActivity { //public class MarkerClusterActivity extends AbsMapActivity {
private TencentMap tencentMap; // private TencentMap tencentMap;
private boolean mHasAdded; // private boolean mHasAdded;
//点聚合坐标数据集合 // //点聚合坐标数据集合
private List<MarkerClusterItem> generalItemList = new ArrayList<>(); // private List<MarkerClusterItem> generalItemList = new ArrayList<>();
private ClusterManager<MarkerClusterItem> markerClusterItemClusterManager; // private ClusterManager<MarkerClusterItem> markerClusterItemClusterManager;
private int i = 8; // private int i = 8;
//自定义聚合 // //自定义聚合
private ClusterManager<PetaItem> petaItemClusterManager; // private ClusterManager<PetaItem> petaItemClusterManager;
private ArrayList<PetaItem> petaItems; // private ArrayList<PetaItem> petaItems;
private ArrayList<LatLng> latLngs; // private ArrayList<LatLng> latLngs;
private NonHierarchicalDistanceBasedAlgorithm<MarkerClusterItem> ndba; // private NonHierarchicalDistanceBasedAlgorithm<MarkerClusterItem> ndba;
private DefaultClusterRenderer<MarkerClusterItem> markerClusterItemDefaultClusterRenderer; // private DefaultClusterRenderer<MarkerClusterItem> markerClusterItemDefaultClusterRenderer;
private String TAG="MarkerClusterActivity"; // private String TAG="MarkerClusterActivity";
//
@Override // @Override
//
protected void onCreate(@Nullable Bundle savedInstanceState, TencentMap mTencentMap) { // protected void onCreate(@Nullable Bundle savedInstanceState, TencentMap mTencentMap) {
super.onCreate(savedInstanceState, mTencentMap); // super.onCreate(savedInstanceState, mTencentMap);
tencentMap = mTencentMap; // tencentMap = mTencentMap;
//tencentMap.enableMultipleInfowindow(true); // //tencentMap.enableMultipleInfowindow(true);
tencentMap.moveCamera(CameraUpdateFactory.zoomTo(15)); // tencentMap.moveCamera(CameraUpdateFactory.zoomTo(15));
//默认聚合管理 // //默认聚合管理
configDefaultCluterManger(); // configDefaultCluterManger();
configCustomCluterManger(); // configCustomCluterManger();
petaItemClusterManager.setOnClusterClickListener(new ClusterManager.OnClusterClickListener<PetaItem>() { // petaItemClusterManager.setOnClusterClickListener(new ClusterManager.OnClusterClickListener<PetaItem>() {
@Override // @Override
public boolean onClusterClick(Cluster<PetaItem> cluster) { // public boolean onClusterClick(Cluster<PetaItem> cluster) {
Collection<PetaItem> items = cluster.getItems(); // Collection<PetaItem> items = cluster.getItems();
//
return false; // return false;
} // }
}); // });
tencentMap.setOnCameraChangeListener(new TencentMap.OnCameraChangeListener() { // tencentMap.setOnCameraChangeListener(new TencentMap.OnCameraChangeListener() {
@Override // @Override
public void onCameraChange(CameraPosition cameraPosition) { // public void onCameraChange(CameraPosition cameraPosition) {
//
} // }
//
@Override // @Override
public void onCameraChangeFinished(CameraPosition cameraPosition) { // public void onCameraChangeFinished(CameraPosition cameraPosition) {
float zoom = cameraPosition.zoom; // float zoom = cameraPosition.zoom;
if (zoom < 6) { // if (zoom < 6) {
tencentMap.setOnCameraChangeListener(markerClusterItemClusterManager); // tencentMap.setOnCameraChangeListener(markerClusterItemClusterManager);
markerClusterItemClusterManager.addItems(getMassiveCoords()); // markerClusterItemClusterManager.addItems(getMassiveCoords());
// tencentMap.animateCamera(CameraUpdateFactory.newLatLngBounds(LatLngBounds.builder().include(latLngs).build(), 20)); // // tencentMap.animateCamera(CameraUpdateFactory.newLatLngBounds(LatLngBounds.builder().include(latLngs).build(), 20));
markerClusterItemClusterManager.cluster(); // markerClusterItemClusterManager.cluster();
//
} else { // } else {
markerClusterItemClusterManager.cancel(); // markerClusterItemClusterManager.cancel();
} // }
Log.d(TAG, "onCameraChangeFinished: " + zoom); // Log.d(TAG, "onCameraChangeFinished: " + zoom);
} // }
}); // });
} // }
//
public class PetaItem implements ClusterItem { // public class PetaItem implements ClusterItem {
private final LatLng mLatLng; // private final LatLng mLatLng;
private int mDrawableResourceId; // private int mDrawableResourceId;
//
public PetaItem(double lat, double lon, int resourceId) { // public PetaItem(double lat, double lon, int resourceId) {
mLatLng = new LatLng(lat, lon); // mLatLng = new LatLng(lat, lon);
mDrawableResourceId = resourceId; // mDrawableResourceId = resourceId;
} // }
//
@Override // @Override
public LatLng getPosition() { // public LatLng getPosition() {
return mLatLng; // return mLatLng;
} // }
//
public int getDrawableResourceId() { // public int getDrawableResourceId() {
return mDrawableResourceId; // return mDrawableResourceId;
} // }
} // }
//
//聚合设置 // //聚合设置
private void configDefaultCluterManger() { // private void configDefaultCluterManger() {
//实例化点聚合管理者 // //实例化点聚合管理者
markerClusterItemClusterManager = new ClusterManager<>(this, tencentMap); // markerClusterItemClusterManager = new ClusterManager<>(this, tencentMap);
//默认聚合策略调用时不用添加如果需要其它聚合策略可以按以下修改 // //默认聚合策略调用时不用添加如果需要其它聚合策略可以按以下修改
ndba = new NonHierarchicalDistanceBasedAlgorithm<>(this); // ndba = new NonHierarchicalDistanceBasedAlgorithm<>(this);
//设置点聚合距离 // //设置点聚合距离
ndba.setMaxDistanceAtZoom(35); // ndba.setMaxDistanceAtZoom(35);
//设置策略 // //设置策略
markerClusterItemClusterManager.setAlgorithm(ndba); // markerClusterItemClusterManager.setAlgorithm(ndba);
//设置聚合渲染器按照需要设置 // //设置聚合渲染器按照需要设置
markerClusterItemDefaultClusterRenderer = new DefaultClusterRenderer<>(this, tencentMap, markerClusterItemClusterManager); // markerClusterItemDefaultClusterRenderer = new DefaultClusterRenderer<>(this, tencentMap, markerClusterItemClusterManager);
//设置最小聚合数量默认是4 // //设置最小聚合数量默认是4
markerClusterItemDefaultClusterRenderer.setMinClusterSize(5); // markerClusterItemDefaultClusterRenderer.setMinClusterSize(5);
//定义聚合的分段例如当超过5个不满足10个数据显示5+ // //定义聚合的分段例如当超过5个不满足10个数据显示5+
markerClusterItemDefaultClusterRenderer.setBuckets(new int[]{5, 10, 20, 50}); // markerClusterItemDefaultClusterRenderer.setBuckets(new int[]{5, 10, 20, 50});
markerClusterItemClusterManager.setRenderer(markerClusterItemDefaultClusterRenderer); // markerClusterItemClusterManager.setRenderer(markerClusterItemDefaultClusterRenderer);
//
//
} // }
//
//自定义聚合样式设置 // //自定义聚合样式设置
private void configCustomCluterManger() { // private void configCustomCluterManger() {
petaItemClusterManager = new ClusterManager<>(this, tencentMap); // petaItemClusterManager = new ClusterManager<>(this, tencentMap);
CustomIconClusterRenderer customIconClusterRender = new CustomIconClusterRenderer(this, tencentMap, petaItemClusterManager); // CustomIconClusterRenderer customIconClusterRender = new CustomIconClusterRenderer(this, tencentMap, petaItemClusterManager);
customIconClusterRender.setMinClusterSize(3); // customIconClusterRender.setMinClusterSize(3);
petaItemClusterManager.setRenderer(customIconClusterRender); // petaItemClusterManager.setRenderer(customIconClusterRender);
//
} // }
//
//
//普通聚合 // //普通聚合
private Collection<MarkerClusterItem> getGeneralCoords() { // private Collection<MarkerClusterItem> getGeneralCoords() {
if (generalItemList == null || generalItemList.size() == 0) { // if (generalItemList == null || generalItemList.size() == 0) {
generalItemList = getItemWithFileName("cluster_new"); // generalItemList = getItemWithFileName("cluster_new");
} // }
return generalItemList; // return generalItemList;
} // }
//
//海量聚合 // //海量聚合
private Collection<MarkerClusterItem> getMassiveCoords() { // private Collection<MarkerClusterItem> getMassiveCoords() {
if (generalItemList == null || generalItemList.size() == 0) { // if (generalItemList == null || generalItemList.size() == 0) {
generalItemList = getItemWithFileName("datab"); // generalItemList = getItemWithFileName("datab");
} // }
return generalItemList; // return generalItemList;
} // }
//
private List<MarkerClusterItem> getItemWithFileName(String cluster_new) { // private List<MarkerClusterItem> getItemWithFileName(String cluster_new) {
ArrayList<MarkerClusterItem> arrayList = new ArrayList<>(); // ArrayList<MarkerClusterItem> arrayList = new ArrayList<>();
latLngs = new ArrayList<>(); // latLngs = new ArrayList<>();
try { // try {
InputStream inputStream = getAssets().open(cluster_new); // InputStream inputStream = getAssets().open(cluster_new);
InputStreamReader inputStreamReader = new InputStreamReader(inputStream); // InputStreamReader inputStreamReader = new InputStreamReader(inputStream);
BufferedReader bufferedReader = new BufferedReader(inputStreamReader); // BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
String line; // String line;
while ((line = bufferedReader.readLine()) != null) { // while ((line = bufferedReader.readLine()) != null) {
String[] data = line.split("\t"); // String[] data = line.split("\t");
double longitue = Double.parseDouble(data[0]); // double longitue = Double.parseDouble(data[0]);
double latitue = Double.parseDouble(data[1]); // double latitue = Double.parseDouble(data[1]);
arrayList.add(new MarkerClusterItem(latitue, longitue)); // arrayList.add(new MarkerClusterItem(latitue, longitue));
latLngs.add(new LatLng(latitue, longitue)); // latLngs.add(new LatLng(latitue, longitue));
} // }
inputStream.close(); // inputStream.close();
inputStreamReader.close(); // inputStreamReader.close();
bufferedReader.close(); // bufferedReader.close();
return arrayList; // return arrayList;
} catch (Exception e) { // } catch (Exception e) {
e.printStackTrace(); // e.printStackTrace();
} // }
return null; // return null;
} // }
//
@Override // @Override
public boolean onCreateOptionsMenu(Menu menu) { // public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.marker_cluster, menu); // getMenuInflater().inflate(R.menu.marker_cluster, menu);
return true; // return true;
} // }
//
@Override // @Override
public boolean onPrepareOptionsMenu(Menu menu) { // public boolean onPrepareOptionsMenu(Menu menu) {
menu.findItem(R.id.menu_add_marker).setVisible(!mHasAdded); // menu.findItem(R.id.menu_add_marker).setVisible(!mHasAdded);
menu.findItem(R.id.menu_delete_marker).setVisible(mHasAdded); // menu.findItem(R.id.menu_delete_marker).setVisible(mHasAdded);
return super.onPrepareOptionsMenu(menu); // return super.onPrepareOptionsMenu(menu);
} // }
//
@Override // @Override
public boolean onOptionsItemSelected(MenuItem item) { // public boolean onOptionsItemSelected(MenuItem item) {
tencentMap.setInfoWindowAdapter(new TencentMap.InfoWindowAdapter() { // tencentMap.setInfoWindowAdapter(new TencentMap.InfoWindowAdapter() {
@Override // @Override
public View getInfoWindow(Marker marker) { // public View getInfoWindow(Marker marker) {
LinearLayout inflate = (LinearLayout) View.inflate(getApplicationContext(), R.layout.custom_infowindow, null); // LinearLayout inflate = (LinearLayout) View.inflate(getApplicationContext(), R.layout.custom_infowindow, null);
TextView title = inflate.findViewById(R.id.tv_title); // TextView title = inflate.findViewById(R.id.tv_title);
Point point = tencentMap.getProjection().toScreenLocation(marker.getPosition()); // Point point = tencentMap.getProjection().toScreenLocation(marker.getPosition());
title.setText("\t\t\t\t\t\t\t\t自定义View弹窗:\n点在屏幕位置" + point); // title.setText("\t\t\t\t\t\t\t\t自定义View弹窗:\n点在屏幕位置" + point);
return inflate; // return inflate;
} // }
//
@Override // @Override
public View getInfoContents(Marker marker) { // public View getInfoContents(Marker marker) {
return null; // return null;
} // }
}); // });
final IAlphaAnimation alphaAnimation_custom = tencentMap.getMapContext().createAlphaAnimation(0f, 1f); // final IAlphaAnimation alphaAnimation_custom = tencentMap.getMapContext().createAlphaAnimation(0f, 1f);
alphaAnimation_custom.setDuration(1000); // alphaAnimation_custom.setDuration(1000);
alphaAnimation_custom.setInterpolator(new AccelerateDecelerateInterpolator()); // alphaAnimation_custom.setInterpolator(new AccelerateDecelerateInterpolator());
tencentMap.setOnMarkerClickListener(new TencentMap.OnMarkerClickListener() { // tencentMap.setOnMarkerClickListener(new TencentMap.OnMarkerClickListener() {
@Override // @Override
public boolean onMarkerClick(Marker marker) { // public boolean onMarkerClick(Marker marker) {
Point point = tencentMap.getProjection().toScreenLocation(marker.getPosition()); // Point point = tencentMap.getProjection().toScreenLocation(marker.getPosition());
marker.setTitle(point.toString()); // marker.setTitle(point.toString());
marker.setAnimation(alphaAnimation_custom); // marker.setAnimation(alphaAnimation_custom);
marker.startAnimation(); // marker.startAnimation();
return false; // return false;
} // }
}); // });
switch (item.getItemId()) { // switch (item.getItemId()) {
case R.id.menu_add_marker_general: // case R.id.menu_add_marker_general:
mHasAdded = true; // mHasAdded = true;
//markerClusterItemClusterManager.cancel(); // //markerClusterItemClusterManager.cancel();
tencentMap.setOnCameraChangeListener(markerClusterItemClusterManager); // tencentMap.setOnCameraChangeListener(markerClusterItemClusterManager);
markerClusterItemClusterManager.addItems(getGeneralCoords()); // markerClusterItemClusterManager.addItems(getGeneralCoords());
LatLng position = generalItemList.get(6).getPosition(); // LatLng position = generalItemList.get(6).getPosition();
CameraUpdate cameraUpdate; // CameraUpdate cameraUpdate;
if (i < 16) { // if (i < 16) {
i++; // i++;
cameraUpdate = CameraUpdateFactory.newLatLngZoom(position, i); // cameraUpdate = CameraUpdateFactory.newLatLngZoom(position, i);
} else { // } else {
i = 6; // i = 6;
cameraUpdate = CameraUpdateFactory.newLatLngZoom(position, i); // cameraUpdate = CameraUpdateFactory.newLatLngZoom(position, i);
} // }
tencentMap.animateCamera(cameraUpdate); // tencentMap.animateCamera(cameraUpdate);
markerClusterItemClusterManager.cluster(); // markerClusterItemClusterManager.cluster();
//
break; // break;
case R.id.menu_add_marker_massive: // case R.id.menu_add_marker_massive:
mHasAdded = true; // mHasAdded = true;
tencentMap.setOnCameraChangeListener(markerClusterItemClusterManager); // tencentMap.setOnCameraChangeListener(markerClusterItemClusterManager);
markerClusterItemClusterManager.addItems(getMassiveCoords()); // markerClusterItemClusterManager.addItems(getMassiveCoords());
//
LatLng position_massive = generalItemList.get(60).getPosition(); // LatLng position_massive = generalItemList.get(60).getPosition();
CameraUpdate cameraUpdate_massive; // CameraUpdate cameraUpdate_massive;
if (i < 16) { // if (i < 16) {
i++; // i++;
cameraUpdate_massive = CameraUpdateFactory.newLatLngZoom(position_massive, i); // cameraUpdate_massive = CameraUpdateFactory.newLatLngZoom(position_massive, i);
} else { // } else {
i = 6; // i = 6;
cameraUpdate_massive = CameraUpdateFactory.newLatLngZoom(position_massive, i); // cameraUpdate_massive = CameraUpdateFactory.newLatLngZoom(position_massive, i);
} // }
tencentMap.animateCamera(cameraUpdate_massive); // tencentMap.animateCamera(cameraUpdate_massive);
markerClusterItemClusterManager.cluster(); // markerClusterItemClusterManager.cluster();
break; // break;
case R.id.menu_add_marker_custom: // case R.id.menu_add_marker_custom:
mHasAdded = true; // mHasAdded = true;
tencentMap.setOnCameraChangeListener(petaItemClusterManager); // tencentMap.setOnCameraChangeListener(petaItemClusterManager);
addCustomClusterItem(); // addCustomClusterItem();
tencentMap.animateCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(39.971595, 116.314316), 15)); // tencentMap.animateCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(39.971595, 116.314316), 15));
petaItemClusterManager.cluster(); // petaItemClusterManager.cluster();
break; // break;
case R.id.menu_delete_marker: // case R.id.menu_delete_marker:
mHasAdded = false; // mHasAdded = false;
clusterReMove(); // clusterReMove();
break; // break;
//
} // }
return super.onOptionsItemSelected(item); // return super.onOptionsItemSelected(item);
} // }
//
private void addCustomClusterItem() { // private void addCustomClusterItem() {
//
petaItemClusterManager.addItem(new PetaItem(39.971595, 116.294747, R.mipmap.petal_blue)); // 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.971595, 116.314316, R.mipmap.petal_red));
//
petaItemClusterManager.addItem(new PetaItem(39.967385, 116.317063, R.mipmap.petal_green)); // 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.951596, 116.302300, R.mipmap.petal_yellow));
//
petaItemClusterManager.addItem(new PetaItem(39.970543, 116.290627, R.mipmap.petal_orange)); // petaItemClusterManager.addItem(new PetaItem(39.970543, 116.290627, R.mipmap.petal_orange));
//
petaItemClusterManager.addItem(new PetaItem(39.966333, 116.311569, R.mipmap.petal_purple)); // petaItemClusterManager.addItem(new PetaItem(39.966333, 116.311569, R.mipmap.petal_purple));
} // }
//
//移除聚合数据 // //移除聚合数据
private void clusterReMove() { // private void clusterReMove() {
markerClusterItemClusterManager.cancel(); // markerClusterItemClusterManager.cancel();
markerClusterItemClusterManager.cluster(); // markerClusterItemClusterManager.cluster();
generalItemList.clear(); // generalItemList.clear();
petaItemClusterManager.cancel(); // petaItemClusterManager.cancel();
petaItemClusterManager.cluster(); // petaItemClusterManager.cluster();
tencentMap.clearAllOverlays(); // tencentMap.clearAllOverlays();
//
} // }
//
class CustomIconClusterRenderer extends DefaultClusterRenderer<PetaItem> { // class CustomIconClusterRenderer extends DefaultClusterRenderer<PetaItem> {
//
private IconGenerator mIconGenerator = new IconGenerator(getApplicationContext()); // private IconGenerator mIconGenerator = new IconGenerator(getApplicationContext());
private IconGenerator mClusterIconGenerator = new IconGenerator(getApplicationContext()); // private IconGenerator mClusterIconGenerator = new IconGenerator(getApplicationContext());
private ImageView mItemImageView = new ImageView(getApplicationContext()); // private ImageView mItemImageView = new ImageView(getApplicationContext());
private ImageView mClusterImageView = new ImageView(getApplicationContext()); // private ImageView mClusterImageView = new ImageView(getApplicationContext());
//
public CustomIconClusterRenderer( // public CustomIconClusterRenderer(
Context context, TencentMap map, ClusterManager clusterManager) { // Context context, TencentMap map, ClusterManager clusterManager) {
super(context, map, clusterManager); // super(context, map, clusterManager);
mItemImageView.setLayoutParams( // mItemImageView.setLayoutParams(
new ViewGroup.LayoutParams( // new ViewGroup.LayoutParams(
ViewGroup.LayoutParams.WRAP_CONTENT, // ViewGroup.LayoutParams.WRAP_CONTENT,
ViewGroup.LayoutParams.WRAP_CONTENT)); // ViewGroup.LayoutParams.WRAP_CONTENT));
mIconGenerator.setContentView(mItemImageView); // mIconGenerator.setContentView(mItemImageView);
//
mClusterImageView.setLayoutParams( // mClusterImageView.setLayoutParams(
new ViewGroup.LayoutParams( // new ViewGroup.LayoutParams(
ViewGroup.LayoutParams.WRAP_CONTENT, // ViewGroup.LayoutParams.WRAP_CONTENT,
ViewGroup.LayoutParams.WRAP_CONTENT)); // ViewGroup.LayoutParams.WRAP_CONTENT));
mClusterIconGenerator.setContentView(mClusterImageView); // mClusterIconGenerator.setContentView(mClusterImageView);
//
setMinClusterSize(1); // setMinClusterSize(1);
} // }
//
@Override // @Override
public void onBeforeClusterRendered( // public void onBeforeClusterRendered(
Cluster<PetaItem> cluster, MarkerOptions markerOptions) { // Cluster<PetaItem> cluster, MarkerOptions markerOptions) {
int[] resources = new int[cluster.getItems().size()]; // int[] resources = new int[cluster.getItems().size()];
int i = 0; // int i = 0;
for (PetaItem item : cluster.getItems()) { // for (PetaItem item : cluster.getItems()) {
resources[i++] = item.getDrawableResourceId(); // resources[i++] = item.getDrawableResourceId();
} // }
//
PetalDrawable drawable = new PetalDrawable(getApplicationContext(), resources); // PetalDrawable drawable = new PetalDrawable(getApplicationContext(), resources);
mClusterImageView.setImageDrawable(drawable); // mClusterImageView.setImageDrawable(drawable);
Bitmap icon = mClusterIconGenerator.makeIcon(); // Bitmap icon = mClusterIconGenerator.makeIcon();
markerOptions.icon(BitmapDescriptorFactory.fromBitmap(icon)); // markerOptions.icon(BitmapDescriptorFactory.fromBitmap(icon));
} // }
//
@Override // @Override
public void onBeforeClusterItemRendered(PetaItem item, MarkerOptions markerOptions) { // public void onBeforeClusterItemRendered(PetaItem item, MarkerOptions markerOptions) {
mItemImageView.setImageResource(item.getDrawableResourceId()); // mItemImageView.setImageResource(item.getDrawableResourceId());
Bitmap icon = mIconGenerator.makeIcon(); // Bitmap icon = mIconGenerator.makeIcon();
markerOptions.icon(BitmapDescriptorFactory.fromBitmap(icon)); // markerOptions.icon(BitmapDescriptorFactory.fromBitmap(icon));
} // }
} // }
//
class MarkerClusterItem implements ClusterItem { // class MarkerClusterItem implements ClusterItem {
private final LatLng mLatLng; // private final LatLng mLatLng;
//
public MarkerClusterItem(double lat, double lon) { // public MarkerClusterItem(double lat, double lon) {
mLatLng = new LatLng(lat, lon); // mLatLng = new LatLng(lat, lon);
} // }
//
@Override // @Override
public LatLng getPosition() { // public LatLng getPosition() {
return mLatLng; // return mLatLng;
} // }
} // }
} //}

View File

@ -1,116 +1,116 @@
package cc.winboll.studio.positions.demo.marker; package cc.winboll.studio.positions.demo.marker;
import androidx.annotation.NonNull; //import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity; //import androidx.appcompat.app.AppCompatActivity;
//
import android.os.Bundle; //import android.os.Bundle;
import android.view.Menu; //import android.view.Menu;
import android.view.MenuItem; //import android.view.MenuItem;
import android.view.View; //import android.view.View;
//
import cc.winboll.studio.positions.R; //import cc.winboll.studio.positions.R;
import com.tencent.tencentmap.mapsdk.maps.CameraUpdate; //import com.tencent.tencentmap.mapsdk.maps.CameraUpdate;
import com.tencent.tencentmap.mapsdk.maps.CameraUpdateFactory; //import com.tencent.tencentmap.mapsdk.maps.CameraUpdateFactory;
import com.tencent.tencentmap.mapsdk.maps.MapView; //import com.tencent.tencentmap.mapsdk.maps.MapView;
import com.tencent.tencentmap.mapsdk.maps.TencentMap; //import com.tencent.tencentmap.mapsdk.maps.TencentMap;
import com.tencent.tencentmap.mapsdk.maps.model.BitmapDescriptor; //import com.tencent.tencentmap.mapsdk.maps.model.BitmapDescriptor;
import com.tencent.tencentmap.mapsdk.maps.model.BitmapDescriptorFactory; //import com.tencent.tencentmap.mapsdk.maps.model.BitmapDescriptorFactory;
import com.tencent.tencentmap.mapsdk.maps.model.CameraPosition; //import com.tencent.tencentmap.mapsdk.maps.model.CameraPosition;
import com.tencent.tencentmap.mapsdk.maps.model.LatLng; //import com.tencent.tencentmap.mapsdk.maps.model.LatLng;
import com.tencent.tencentmap.mapsdk.maps.model.MapPoi; //import com.tencent.tencentmap.mapsdk.maps.model.MapPoi;
import com.tencent.tencentmap.mapsdk.maps.model.Marker; //import com.tencent.tencentmap.mapsdk.maps.model.Marker;
import com.tencent.tencentmap.mapsdk.maps.model.MarkerCollisionItem; //import com.tencent.tencentmap.mapsdk.maps.model.MarkerCollisionItem;
import com.tencent.tencentmap.mapsdk.maps.model.MarkerOptions; //import com.tencent.tencentmap.mapsdk.maps.model.MarkerOptions;
//
public class MarkerCollisions extends AppCompatActivity { //public class MarkerCollisions extends AppCompatActivity {
//
private MapView mapView; // private MapView mapView;
private TencentMap tencentMap; // private TencentMap tencentMap;
private boolean mMarkerAdded; // private boolean mMarkerAdded;
private Marker mMarker; // private Marker mMarker;
//
@Override // @Override
protected void onCreate(Bundle savedInstanceState) { // protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); // super.onCreate(savedInstanceState);
setContentView(R.layout.activity_marker_collisions); // setContentView(R.layout.activity_marker_collisions);
intit(); // intit();
} // }
//
private void intit() { // private void intit() {
mapView = findViewById(R.id.mapView); // mapView = findViewById(R.id.mapView);
tencentMap = mapView.getMap(); // tencentMap = mapView.getMap();
CameraUpdate cameraSigma = // CameraUpdate cameraSigma =
CameraUpdateFactory.newCameraPosition(new CameraPosition( // CameraUpdateFactory.newCameraPosition(new CameraPosition(
new LatLng(39.984066, 116.307548), // new LatLng(39.984066, 116.307548),
15, // 15,
0f, // 0f,
0f)); // 0f));
//移动地图 // //移动地图
tencentMap.moveCamera(cameraSigma); // tencentMap.moveCamera(cameraSigma);
} // }
//
@Override // @Override
public boolean onCreateOptionsMenu(Menu menu) { // public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.markercol, menu); // getMenuInflater().inflate(R.menu.markercol, menu);
return super.onCreateOptionsMenu(menu); // return super.onCreateOptionsMenu(menu);
} // }
//
@Override // @Override
public boolean onPrepareOptionsMenu(Menu menu) { // public boolean onPrepareOptionsMenu(Menu menu) {
menu.findItem(R.id.menu_open_collisionsmap).setVisible(!mMarkerAdded); // menu.findItem(R.id.menu_open_collisionsmap).setVisible(!mMarkerAdded);
menu.findItem(R.id.menu_close_collisionsmap).setVisible(mMarkerAdded); // menu.findItem(R.id.menu_close_collisionsmap).setVisible(mMarkerAdded);
return super.onPrepareOptionsMenu(menu); // return super.onPrepareOptionsMenu(menu);
} // }
//
@Override // @Override
public boolean onOptionsItemSelected(@NonNull MenuItem item) { // public boolean onOptionsItemSelected(@NonNull MenuItem item) {
switch (item.getItemId()) { // switch (item.getItemId()) {
case R.id.menu_open_collisionsmap: // case R.id.menu_open_collisionsmap:
mMarkerAdded = true; // mMarkerAdded = true;
BitmapDescriptor custom = BitmapDescriptorFactory.fromResource(R.drawable.marker); // BitmapDescriptor custom = BitmapDescriptorFactory.fromResource(R.drawable.marker);
MarkerOptions options = new MarkerOptions().position(new LatLng(39.984066, 116.307548)); // MarkerOptions options = new MarkerOptions().position(new LatLng(39.984066, 116.307548));
options.icon(custom); // options.icon(custom);
mMarker = tencentMap.addMarker(options); // mMarker = tencentMap.addMarker(options);
mMarker.setCollisions(MarkerCollisionItem.POI); // mMarker.setCollisions(MarkerCollisionItem.POI);
break; // break;
case R.id.menu_close_collisionsmap: // case R.id.menu_close_collisionsmap:
mMarkerAdded = false; // mMarkerAdded = false;
mMarker.remove(); // mMarker.remove();
break; // break;
} // }
//
supportInvalidateOptionsMenu(); // supportInvalidateOptionsMenu();
return super.onOptionsItemSelected(item); // return super.onOptionsItemSelected(item);
} // }
//
@Override // @Override
protected void onResume() { // protected void onResume() {
super.onResume(); // super.onResume();
mapView.onResume(); // mapView.onResume();
} // }
//
@Override // @Override
protected void onPause() { // protected void onPause() {
super.onPause(); // super.onPause();
mapView.onPause(); // mapView.onPause();
} // }
//
@Override // @Override
protected void onDestroy() { // protected void onDestroy() {
super.onDestroy(); // super.onDestroy();
mapView.onDestroy(); // mapView.onDestroy();
} // }
//
//
@Override // @Override
protected void onStart() { // protected void onStart() {
super.onStart(); // super.onStart();
mapView.onStart(); // mapView.onStart();
} // }
//
@Override // @Override
protected void onStop() { // protected void onStop() {
super.onStop(); // super.onStop();
mapView.onStop(); // mapView.onStop();
} // }
} //}

View File

@ -10,36 +10,49 @@ import cc.winboll.studio.positions.R;
import com.tencent.tencentmap.mapsdk.maps.TencentMap; import com.tencent.tencentmap.mapsdk.maps.TencentMap;
import com.tencent.tencentmap.mapsdk.maps.model.Marker; import com.tencent.tencentmap.mapsdk.maps.model.Marker;
public class MarkerDragActivity extends MarkerActivity implements TencentMap.OnMarkerDragListener{ public class MarkerDragActivity extends MarkerActivity implements TencentMap.OnMarkerDragListener {
private TextView textView;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { public void onMarkerDragStart(Marker p1) {
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 @Override
public void onMarkerDragStart(Marker marker) { public void onMarkerDrag(Marker p1) {
Log.e("marker:","drag");
Toast.makeText(this, "拖拽开始", Toast.LENGTH_SHORT).show();
} }
@Override @Override
public void onMarkerDrag(Marker marker) { public void onMarkerDragEnd(Marker p1) {
} }
@Override // private TextView textView;
public void onMarkerDragEnd(Marker marker) { //
Toast.makeText(this, "拖拽结束", Toast.LENGTH_SHORT).show(); // @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();
// }
} }

View File

@ -22,233 +22,233 @@ import com.tencent.tencentmap.mapsdk.maps.model.MarkerOptions;
public class MarkerInfoWindowActivity extends AbsMapActivity { public class MarkerInfoWindowActivity extends AbsMapActivity {
private static final int TYPE_BITMAP = 0; // private static final int TYPE_BITMAP = 0;
private static final int TYPE_VIEW = 1; // private static final int TYPE_VIEW = 1;
//
private static final int STYLE_NO_FRAME = 1; // private static final int STYLE_NO_FRAME = 1;
private static final int STYLE_FRAME = 2; // private static final int STYLE_FRAME = 2;
//
private Marker mMarker; // private Marker mMarker;
private Marker mAnotherMarker; // private Marker mAnotherMarker;
private TencentMap mTencentMap; // private TencentMap mTencentMap;
private int mInfoWindowAdapterStyle; // private int mInfoWindowAdapterStyle;
private int mInfoWindowType = TYPE_BITMAP; // private int mInfoWindowType = TYPE_BITMAP;
private LinearLayout mCustomInfoWindowView; // private LinearLayout mCustomInfoWindowView;
//
/** // /**
* 自定义信息窗 // * 自定义信息窗
*/ // */
private TencentMap.InfoWindowAdapter mInfoWindowAdapter = new TencentMap.InfoWindowAdapter() { // private TencentMap.InfoWindowAdapter mInfoWindowAdapter = new TencentMap.InfoWindowAdapter() {
//
TextView tvTitle; // TextView tvTitle;
//
//返回View为信息窗自定义样式返回null时为默认信息窗样式 // //返回View为信息窗自定义样式返回null时为默认信息窗样式
@Override // @Override
public View getInfoWindow(final Marker marker) { // public View getInfoWindow(final Marker marker) {
if (mInfoWindowAdapterStyle == 1 && marker.equals(mMarker)) { // if (mInfoWindowAdapterStyle == 1 && marker.equals(mMarker)) {
return createCustomInfoView(marker); // return createCustomInfoView(marker);
} // }
return null; // return null;
} // }
//
//返回View为信息窗内容自定义样式返回null时为默认信息窗样式 // //返回View为信息窗内容自定义样式返回null时为默认信息窗样式
@Override // @Override
public View getInfoContents(Marker marker) { // public View getInfoContents(Marker marker) {
if (mInfoWindowAdapterStyle == 2 && marker.equals(mMarker)) { // if (mInfoWindowAdapterStyle == 2 && marker.equals(mMarker)) {
return createCustomInfoView(marker); // return createCustomInfoView(marker);
} // }
return null; // return null;
} // }
//
private View createCustomInfoView(Marker marker) { // private View createCustomInfoView(Marker marker) {
mCustomInfoWindowView = (LinearLayout) View.inflate( // mCustomInfoWindowView = (LinearLayout) View.inflate(
getApplicationContext(), R.layout.custom_infowindow, null); // getApplicationContext(), R.layout.custom_infowindow, null);
tvTitle = mCustomInfoWindowView.findViewById(R.id.tv_title); // tvTitle = mCustomInfoWindowView.findViewById(R.id.tv_title);
//设置自定义信息窗的内容 // //设置自定义信息窗的内容
tvTitle.setText("我是自定义信息窗口:"); // tvTitle.setText("我是自定义信息窗口:");
tvTitle.append("\n" + marker.getTitle()); // tvTitle.append("\n" + marker.getTitle());
tvTitle.append("\n" + marker.getSnippet()); // tvTitle.append("\n" + marker.getSnippet());
return mCustomInfoWindowView; // return mCustomInfoWindowView;
} // }
}; // };
private boolean mMultEnable; // private boolean mMultEnable;
//
//
@Override // @Override
protected void onCreate(@Nullable Bundle savedInstanceState, TencentMap pTencentMap) { // protected void onCreate(@Nullable Bundle savedInstanceState, TencentMap pTencentMap) {
super.onCreate(savedInstanceState, pTencentMap); // super.onCreate(savedInstanceState, pTencentMap);
mTencentMap = pTencentMap; // mTencentMap = pTencentMap;
mMarker = createMarker(); // mMarker = createMarker();
pTencentMap.setOnMarkerClickListener(new TencentMap.OnMarkerClickListener() { // pTencentMap.setOnMarkerClickListener(new TencentMap.OnMarkerClickListener() {
@Override // @Override
public boolean onMarkerClick(Marker marker) { // public boolean onMarkerClick(Marker marker) {
invalidateOptionsMenu(); // invalidateOptionsMenu();
return false; // return false;
} // }
}); // });
pTencentMap.setOnInfoWindowClickListener(new TencentMap.OnInfoWindowClickListener() { // pTencentMap.setOnInfoWindowClickListener(new TencentMap.OnInfoWindowClickListener() {
@Override // @Override
public void onInfoWindowClick(Marker marker) { // public void onInfoWindowClick(Marker marker) {
Toast.makeText(getApplicationContext(), "信息窗被点击", Toast.LENGTH_SHORT).show(); // Toast.makeText(getApplicationContext(), "信息窗被点击", Toast.LENGTH_SHORT).show();
} // }
//
@Override // @Override
public void onInfoWindowClickLocation(int i, int i1, int i2, int i3) { // public void onInfoWindowClickLocation(int i, int i1, int i2, int i3) {
Toast.makeText(getApplicationContext(), // Toast.makeText(getApplicationContext(),
"尺寸:" + i + "x" + i1 + " 位置:" + i2 + "," + i3, Toast.LENGTH_SHORT).show(); // "尺寸:" + i + "x" + i1 + " 位置:" + i2 + "," + i3, Toast.LENGTH_SHORT).show();
} // }
}); // });
} // }
//
private Marker createMarker() { // private Marker createMarker() {
if (mTencentMap == null) { // if (mTencentMap == null) {
return null; // return null;
} // }
if (mMarker != null) { // if (mMarker != null) {
mMarker.remove(); // mMarker.remove();
mMarker = null; // mMarker = null;
} // }
LatLng position = new LatLng(39.908710, 116.397499); // LatLng position = new LatLng(39.908710, 116.397499);
MarkerOptions options = new MarkerOptions(position); // MarkerOptions options = new MarkerOptions(position);
options.infoWindowEnable(true);//默认为true // options.infoWindowEnable(true);//默认为true
options.title("天安门")//标注的InfoWindow的标题 // options.title("天安门")//标注的InfoWindow的标题
.snippet("地址: 北京市东城区东长安街")//标注的InfoWindow的内容 // .snippet("地址: 北京市东城区东长安街")//标注的InfoWindow的内容
.anchor(0.5f, 1) // .anchor(0.5f, 1)
.viewInfoWindow(mInfoWindowType == TYPE_VIEW) // .viewInfoWindow(mInfoWindowType == TYPE_VIEW)
.icon(BitmapDescriptorFactory.fromResource(R.drawable.marker));//设置自定义Marker图标 // .icon(BitmapDescriptorFactory.fromResource(R.drawable.marker));//设置自定义Marker图标
mTencentMap.moveCamera(CameraUpdateFactory.newLatLngZoom(position, 15)); // mTencentMap.moveCamera(CameraUpdateFactory.newLatLngZoom(position, 15));
return mTencentMap.addMarker(options); // return mTencentMap.addMarker(options);
} // }
//
private Marker createMultMarker() { // private Marker createMultMarker() {
if (mTencentMap == null) { // if (mTencentMap == null) {
return null; // return null;
} // }
if (mAnotherMarker != null) { // if (mAnotherMarker != null) {
mAnotherMarker.remove(); // mAnotherMarker.remove();
mAnotherMarker = null; // mAnotherMarker = null;
} // }
LatLng position = new LatLng(39.902500,116.397750); // LatLng position = new LatLng(39.902500,116.397750);
MarkerOptions options = new MarkerOptions(position); // MarkerOptions options = new MarkerOptions(position);
options.infoWindowEnable(true);//默认为true // options.infoWindowEnable(true);//默认为true
options.title("毛主席纪念堂")//标注的InfoWindow的标题 // options.title("毛主席纪念堂")//标注的InfoWindow的标题
.snippet("地址: 北京市东城区前门东大街11号")//标注的InfoWindow的内容 // .snippet("地址: 北京市东城区前门东大街11号")//标注的InfoWindow的内容
.anchor(0.5f, 1) // .anchor(0.5f, 1)
.viewInfoWindow(mInfoWindowType == TYPE_VIEW) // .viewInfoWindow(mInfoWindowType == TYPE_VIEW)
.icon(BitmapDescriptorFactory.fromResource(R.drawable.marker));//设置自定义Marker图标 // .icon(BitmapDescriptorFactory.fromResource(R.drawable.marker));//设置自定义Marker图标
return mTencentMap.addMarker(options); // return mTencentMap.addMarker(options);
} // }
//
@Override // @Override
public boolean onCreateOptionsMenu(Menu menu) { // public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.infowindow, menu); // getMenuInflater().inflate(R.menu.infowindow, menu);
return super.onCreateOptionsMenu(menu); // return super.onCreateOptionsMenu(menu);
} // }
//
@Override // @Override
public boolean onPrepareOptionsMenu(Menu menu) { // public boolean onPrepareOptionsMenu(Menu menu) {
String typeName = null; // String typeName = null;
if (mInfoWindowType == TYPE_VIEW) { // if (mInfoWindowType == TYPE_VIEW) {
typeName = "View类型"; // typeName = "View类型";
} else if (mInfoWindowType == TYPE_BITMAP) { // } else if (mInfoWindowType == TYPE_BITMAP) {
typeName = "Bitmap类型"; // typeName = "Bitmap类型";
} // }
if (typeName != null) { // if (typeName != null) {
menu.findItem(R.id.menu_type).setTitle(typeName) // menu.findItem(R.id.menu_type).setTitle(typeName)
.setVisible(!mMarker.isInfoWindowShown()); // .setVisible(!mMarker.isInfoWindowShown());
} // }
menu.findItem(R.id.menu_mult).setTitle(mMultEnable ? "开启多窗口" : "关闭多窗口") // menu.findItem(R.id.menu_mult).setTitle(mMultEnable ? "开启多窗口" : "关闭多窗口")
.setVisible(!mMarker.isInfoWindowShown()); // .setVisible(!mMarker.isInfoWindowShown());
menu.findItem(R.id.menu_add).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_play).setVisible(mMarker.isInfoWindowShown());
menu.findItem(R.id.menu_delete).setVisible(mMarker.isInfoWindowShown()); // menu.findItem(R.id.menu_delete).setVisible(mMarker.isInfoWindowShown());
return super.onPrepareOptionsMenu(menu); // return super.onPrepareOptionsMenu(menu);
} // }
//
@Override // @Override
public boolean onOptionsItemSelected(MenuItem item) { // public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) { // switch (item.getItemId()) {
case R.id.menu_mult_enable: // case R.id.menu_mult_enable:
mMultEnable = true; // mMultEnable = true;
initMarkers(); // initMarkers();
hideInfoWindow(); // hideInfoWindow();
break; // break;
case R.id.menu_mult_close: // case R.id.menu_mult_close:
mMultEnable = false; // mMultEnable = false;
if (mAnotherMarker != null) { // if (mAnotherMarker != null) {
mAnotherMarker.remove(); // mAnotherMarker.remove();
mAnotherMarker = null; // mAnotherMarker = null;
} // }
//
hideInfoWindow(); // hideInfoWindow();
break; // break;
case R.id.menu_type_bitmap: // case R.id.menu_type_bitmap:
mInfoWindowType = TYPE_BITMAP; // mInfoWindowType = TYPE_BITMAP;
initMarkers(); // initMarkers();
hideInfoWindow(); // hideInfoWindow();
break; // break;
case R.id.menu_type_view: // case R.id.menu_type_view:
mInfoWindowType = TYPE_VIEW; // mInfoWindowType = TYPE_VIEW;
initMarkers(); // initMarkers();
hideInfoWindow(); // hideInfoWindow();
break; // break;
case R.id.menu_add_infowindow_default: // case R.id.menu_add_infowindow_default:
showInfoWindow(); // showInfoWindow();
break; // break;
case R.id.menu_add_infowindow_custom_1: // case R.id.menu_add_infowindow_custom_1:
mInfoWindowAdapterStyle = STYLE_NO_FRAME; // mInfoWindowAdapterStyle = STYLE_NO_FRAME;
mTencentMap.setInfoWindowAdapter(mInfoWindowAdapter); // mTencentMap.setInfoWindowAdapter(mInfoWindowAdapter);
showInfoWindow(); // showInfoWindow();
break; // break;
case R.id.menu_add_infowindow_custom_2: // case R.id.menu_add_infowindow_custom_2:
mInfoWindowAdapterStyle = STYLE_FRAME; // mInfoWindowAdapterStyle = STYLE_FRAME;
mTencentMap.setInfoWindowAdapter(mInfoWindowAdapter); // mTencentMap.setInfoWindowAdapter(mInfoWindowAdapter);
showInfoWindow(); // showInfoWindow();
break; // break;
case R.id.menu_play: // case R.id.menu_play:
animationPlay(); // animationPlay();
break; // break;
case R.id.menu_delete: // case R.id.menu_delete:
hideInfoWindow(); // hideInfoWindow();
break; // break;
} // }
//
mTencentMap.enableMultipleInfowindow(mMultEnable); // mTencentMap.enableMultipleInfowindow(mMultEnable);
return super.onOptionsItemSelected(item); // return super.onOptionsItemSelected(item);
} // }
//
private void initMarkers() { // private void initMarkers() {
mMarker = createMarker(); // mMarker = createMarker();
if (mMultEnable) { // if (mMultEnable) {
mAnotherMarker = createMultMarker(); // mAnotherMarker = createMultMarker();
} // }
} // }
//
private void showInfoWindow() { // private void showInfoWindow() {
if (mMarker != null) { // if (mMarker != null) {
mMarker.showInfoWindow(); // mMarker.showInfoWindow();
} // }
//
if (mAnotherMarker != null && mMultEnable) { // if (mAnotherMarker != null && mMultEnable) {
mAnotherMarker.showInfoWindow(); // mAnotherMarker.showInfoWindow();
} // }
} // }
//
private void hideInfoWindow() { // private void hideInfoWindow() {
if (mMarker != null) { // if (mMarker != null) {
mMarker.hideInfoWindow(); // mMarker.hideInfoWindow();
} // }
//
if (mAnotherMarker != null && mMultEnable) { // if (mAnotherMarker != null && mMultEnable) {
mAnotherMarker.hideInfoWindow(); // mAnotherMarker.hideInfoWindow();
} // }
mTencentMap.setInfoWindowAdapter(null); // mTencentMap.setInfoWindowAdapter(null);
} // }
//
private void animationPlay() { // private void animationPlay() {
//
if (mInfoWindowType == TYPE_VIEW) { // if (mInfoWindowType == TYPE_VIEW) {
//TODO :动画 // //TODO :动画
} // }
} // }
} }

View File

@ -1,54 +1,54 @@
package cc.winboll.studio.positions.demo.marker; package cc.winboll.studio.positions.demo.marker;
import android.graphics.Bitmap; //import android.graphics.Bitmap;
import android.graphics.BitmapFactory; //import android.graphics.BitmapFactory;
import android.graphics.Matrix; //import android.graphics.Matrix;
import android.os.Bundle; //import android.os.Bundle;
//
import cc.winboll.studio.positions.R; //import cc.winboll.studio.positions.R;
import cc.winboll.studio.positions.demo.basic.SupportMapFragmentActivity; //import cc.winboll.studio.positions.demo.basic.SupportMapFragmentActivity;
import com.tencent.tencentmap.mapsdk.maps.model.BitmapDescriptorFactory; //import com.tencent.tencentmap.mapsdk.maps.model.BitmapDescriptorFactory;
import com.tencent.tencentmap.mapsdk.maps.model.CircleOptions; //import com.tencent.tencentmap.mapsdk.maps.model.CircleOptions;
import com.tencent.tencentmap.mapsdk.maps.model.LatLng; //import com.tencent.tencentmap.mapsdk.maps.model.LatLng;
import com.tencent.tencentmap.mapsdk.maps.model.MarkerOptions; //import com.tencent.tencentmap.mapsdk.maps.model.MarkerOptions;
//
public class MarkerOptionsActivity extends SupportMapFragmentActivity { //public class MarkerOptionsActivity extends SupportMapFragmentActivity {
@Override // @Override
protected void onCreate(Bundle savedInstanceState) { // protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); // super.onCreate(savedInstanceState);
options.fastLoad(true); //设置是否快速加载 // options.fastLoad(true); //设置是否快速加载
options.icon(BitmapDescriptorFactory.fromBitmap(getBitMap(R.drawable.marker))); //加载图标 // options.icon(BitmapDescriptorFactory.fromBitmap(getBitMap(R.drawable.marker))); //加载图标
options.tag(tencentMap.addCircle(new CircleOptions().center(new LatLng(39.984059, 116.305756)))); //设置标签对象 // options.tag(tencentMap.addCircle(new CircleOptions().center(new LatLng(39.984059, 116.305756)))); //设置标签对象
tencentMap.addMarker(options); // tencentMap.addMarker(options);
} // }
//
private LatLng latLng = new LatLng(39.984864, 116.305756); // private LatLng latLng = new LatLng(39.984864, 116.305756);
//
private Bitmap getBitMap(int resourceId){ // private Bitmap getBitMap(int resourceId){
Bitmap bitmap = BitmapFactory.decodeResource(getResources(), resourceId); // Bitmap bitmap = BitmapFactory.decodeResource(getResources(), resourceId);
int width = bitmap.getWidth(); // int width = bitmap.getWidth();
int height = bitmap.getHeight(); // int height = bitmap.getHeight();
int newWidth = 100; // int newWidth = 100;
int newHeight = 100; // int newHeight = 100;
float widthScale = ((float)newWidth)/width; // float widthScale = ((float)newWidth)/width;
float heightScale = ((float)newHeight)/height; // float heightScale = ((float)newHeight)/height;
Matrix matrix = new Matrix(); // Matrix matrix = new Matrix();
matrix.postScale(widthScale, heightScale); // matrix.postScale(widthScale, heightScale);
bitmap = Bitmap.createBitmap(bitmap,0,0,width,height,matrix,true); // bitmap = Bitmap.createBitmap(bitmap,0,0,width,height,matrix,true);
return bitmap; // return bitmap;
} // }
//
//
private MarkerOptions options = new MarkerOptions(latLng). //坐标设置 // private MarkerOptions options = new MarkerOptions(latLng). //坐标设置
anchor(0.5f, 0.5f). //标注的锚点 // anchor(0.5f, 0.5f). //标注的锚点
clockwise(true). //旋转角度顺时针 // clockwise(true). //旋转角度顺时针
draggable(true). //标注可被拖动 // draggable(true). //标注可被拖动
flat(true). //设置3D标注 // flat(true). //设置3D标注
infoWindowEnable(true). //弹出infowindow // infoWindowEnable(true). //弹出infowindow
infoWindowAnchor(0.5f, 0.5f). //标注信息infowindow锚点 // infoWindowAnchor(0.5f, 0.5f). //标注信息infowindow锚点
rotation(90f). //旋转角度 // rotation(90f). //旋转角度
snippet("气泡infowindow内容"). //设置infowindow内容 // snippet("气泡infowindow内容"). //设置infowindow内容
title("标题内容"). //infowindow标题内容 // title("标题内容"). //infowindow标题内容
visible(true). //标注是否可见 // visible(true). //标注是否可见
zIndex(0); //堆叠顺序越大优先级越高 // zIndex(0); //堆叠顺序越大优先级越高
} //}

View File

@ -21,87 +21,87 @@ import com.tencent.tencentmap.mapsdk.maps.model.MarkerOptions;
public class SimpleMarkerActivity extends AbsMapActivity { public class SimpleMarkerActivity extends AbsMapActivity {
private TencentMap mTencentMap; // private TencentMap mTencentMap;
private Marker mSimpleMarker; // private Marker mSimpleMarker;
private Marker mCustomMarker; // private Marker mCustomMarker;
//
private boolean mMarkerAdded; // private boolean mMarkerAdded;
@Override // @Override
protected void onCreate(@Nullable Bundle savedInstanceState, TencentMap pTencentMap) { // protected void onCreate(@Nullable Bundle savedInstanceState, TencentMap pTencentMap) {
super.onCreate(savedInstanceState, pTencentMap); // super.onCreate(savedInstanceState, pTencentMap);
mTencentMap = pTencentMap; // mTencentMap = pTencentMap;
} // }
//
@Override // @Override
public boolean onCreateOptionsMenu(Menu menu) { // public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.simple_marker, menu); // getMenuInflater().inflate(R.menu.simple_marker, menu);
return super.onCreateOptionsMenu(menu); // return super.onCreateOptionsMenu(menu);
} // }
//
@Override // @Override
public boolean onPrepareOptionsMenu(Menu menu) { // public boolean onPrepareOptionsMenu(Menu menu) {
menu.findItem(R.id.menu_add).setVisible(!mMarkerAdded); // menu.findItem(R.id.menu_add).setVisible(!mMarkerAdded);
menu.findItem(R.id.menu_delete).setVisible(mMarkerAdded); // menu.findItem(R.id.menu_delete).setVisible(mMarkerAdded);
return super.onPrepareOptionsMenu(menu); // return super.onPrepareOptionsMenu(menu);
} // }
//
@Override // @Override
public boolean onOptionsItemSelected(MenuItem item) { // public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) { // switch (item.getItemId()) {
case R.id.menu_add_marker_simple: // case R.id.menu_add_marker_simple:
if (mSimpleMarker == null) { // if (mSimpleMarker == null) {
LatLng position = new LatLng(40.011313,116.391907); // LatLng position = new LatLng(40.011313,116.391907);
mSimpleMarker = mTencentMap.addMarker(new MarkerOptions(position)); // mSimpleMarker = mTencentMap.addMarker(new MarkerOptions(position));
mTencentMap.moveCamera(CameraUpdateFactory.newLatLng(position)); // mTencentMap.moveCamera(CameraUpdateFactory.newLatLng(position));
mMarkerAdded = true; // mMarkerAdded = true;
} // }
break; // break;
case R.id.menu_add_marker_custom: // case R.id.menu_add_marker_custom:
//
if (mCustomMarker == null) { // if (mCustomMarker == null) {
LatLng position = new LatLng(40.011313,116.391907); // LatLng position = new LatLng(40.011313,116.391907);
BitmapDescriptor custom = BitmapDescriptorFactory.fromResource(R.drawable.marker); // BitmapDescriptor custom = BitmapDescriptorFactory.fromResource(R.drawable.marker);
mCustomMarker = mTencentMap.addMarker(new MarkerOptions(position) // mCustomMarker = mTencentMap.addMarker(new MarkerOptions(position)
.icon(custom) // .icon(custom)
.alpha(0.7f) // .alpha(0.7f)
.flat(true) // .flat(true)
.clockwise(false) // .clockwise(false)
.rotation(30) // .rotation(30)
); // );
//
Animation animation = new AlphaAnimation(0.7f, 0f); // Animation animation = new AlphaAnimation(0.7f, 0f);
animation.setDuration(2000); // animation.setDuration(2000);
animation.setAnimationListener(new AnimationListener() { // animation.setAnimationListener(new AnimationListener() {
@Override // @Override
public void onAnimationStart() { // public void onAnimationStart() {
//
} // }
//
@Override // @Override
public void onAnimationEnd() { // public void onAnimationEnd() {
mCustomMarker.setAlpha(1); // mCustomMarker.setAlpha(1);
} // }
}); // });
mCustomMarker.setAnimation(animation); // mCustomMarker.setAnimation(animation);
mCustomMarker.startAnimation(); // mCustomMarker.startAnimation();
mTencentMap.moveCamera(CameraUpdateFactory.newLatLng(position)); // mTencentMap.moveCamera(CameraUpdateFactory.newLatLng(position));
mMarkerAdded = true; // mMarkerAdded = true;
} // }
break; // break;
case R.id.menu_delete: // case R.id.menu_delete:
if (mSimpleMarker != null) { // if (mSimpleMarker != null) {
mSimpleMarker.remove(); // mSimpleMarker.remove();
mSimpleMarker = null; // mSimpleMarker = null;
} // }
//
if (mCustomMarker != null) { // if (mCustomMarker != null) {
mCustomMarker.remove(); // mCustomMarker.remove();
mCustomMarker = null; // mCustomMarker = null;
} // }
//
mMarkerAdded = false; // mMarkerAdded = false;
break; // break;
} // }
return super.onOptionsItemSelected(item); // return super.onOptionsItemSelected(item);
} // }
} }

View File

@ -14,46 +14,51 @@ import com.tencent.tencentmap.mapsdk.maps.model.Marker;
import com.tencent.tencentmap.mapsdk.maps.model.MarkerOptions; import com.tencent.tencentmap.mapsdk.maps.model.MarkerOptions;
public class PoiClickActivity extends SupportMapFragmentActivity implements TencentMap.OnMapPoiClickListener { 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 @Override
public void onClicked(MapPoi mapPoi) { public void onClicked(MapPoi p1) {
setMarker(mapPoi.getPosition(), mapPoi.getName());
} }
/** // private Switch poiSwitch;
* 设置标注 // private Marker marker;
*/ // @Override
private void setMarker(LatLng latLng, String name){ // protected void onCreate(Bundle savedInstanceState) {
// super.onCreate(savedInstanceState);
if(marker != null) // poiSwitch = findViewById(R.id.switch_poi);
marker.remove(); // poiSwitch.setVisibility(View.VISIBLE);
MarkerOptions options = new MarkerOptions().position(latLng); // poiSwitch.setText("Poi显示");
//设置infowindow // tencentMap.setOnMapPoiClickListener(this);
options.title("地址:"); // poiSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
options.snippet(name); // @Override
marker = tencentMap.addMarker(options); // public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
marker.showInfoWindow(); // 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();
// }
} }

View File

@ -1,38 +1,38 @@
package cc.winboll.studio.positions.demo.polygon; package cc.winboll.studio.positions.demo.polygon;
import android.os.Bundle; //import android.os.Bundle;
//
import cc.winboll.studio.positions.R; //import cc.winboll.studio.positions.R;
import cc.winboll.studio.positions.demo.basic.SupportMapFragmentActivity; //import cc.winboll.studio.positions.demo.basic.SupportMapFragmentActivity;
import com.tencent.tencentmap.mapsdk.maps.TencentMap; //import com.tencent.tencentmap.mapsdk.maps.TencentMap;
import com.tencent.tencentmap.mapsdk.maps.model.LatLng; //import com.tencent.tencentmap.mapsdk.maps.model.LatLng;
import com.tencent.tencentmap.mapsdk.maps.model.Polygon; //import com.tencent.tencentmap.mapsdk.maps.model.Polygon;
import com.tencent.tencentmap.mapsdk.maps.model.PolygonOptions; //import com.tencent.tencentmap.mapsdk.maps.model.PolygonOptions;
//
public class DrawPolygonActivity extends SupportMapFragmentActivity { //public class DrawPolygonActivity extends SupportMapFragmentActivity {
//
@Override // @Override
protected void onCreate(Bundle savedInstanceState) { // protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); // super.onCreate(savedInstanceState);
LatLng[] latLngs = { // LatLng[] latLngs = {
new LatLng(39.984864, 116.305756), // new LatLng(39.984864, 116.305756),
new LatLng(39.983618, 116.305848), // new LatLng(39.983618, 116.305848),
new LatLng(39.982347, 116.305966), // new LatLng(39.982347, 116.305966),
new LatLng(39.982412, 116.308111), // new LatLng(39.982412, 116.308111),
new LatLng(39.984122, 116.308224), // new LatLng(39.984122, 116.308224),
new LatLng(39.984955, 116.308099), // new LatLng(39.984955, 116.308099),
new LatLng(39.984864, 116.305756) // new LatLng(39.984864, 116.305756)
}; // };
Polygon polygon = tencentMap.addPolygon(new PolygonOptions(). // Polygon polygon = tencentMap.addPolygon(new PolygonOptions().
add(latLngs). // add(latLngs).
fillColor(getResources().getColor(R.color.style)). // fillColor(getResources().getColor(R.color.style)).
strokeColor(getResources().getColor(R.color.colorPrimary)). // strokeColor(getResources().getColor(R.color.colorPrimary)).
strokeWidth(1)); // strokeWidth(1));
tencentMap.setOnPolygonClickListener(new TencentMap.OnPolygonClickListener() { // tencentMap.setOnPolygonClickListener(new TencentMap.OnPolygonClickListener() {
@Override // @Override
public void onPolygonClick(Polygon polygon, LatLng latLng) { // public void onPolygonClick(Polygon polygon, LatLng latLng) {
//
} // }
}); // });
} // }
} //}

View File

@ -1,73 +1,73 @@
package cc.winboll.studio.positions.demo.polygon; package cc.winboll.studio.positions.demo.polygon;
import android.os.Bundle; //import android.os.Bundle;
//
import cc.winboll.studio.positions.demo.basic.SupportMapFragmentActivity; //import cc.winboll.studio.positions.demo.basic.SupportMapFragmentActivity;
import com.tencent.tencentmap.mapsdk.maps.model.LatLng; //import com.tencent.tencentmap.mapsdk.maps.model.LatLng;
import com.tencent.tencentmap.mapsdk.maps.model.MarkerOptions; //import com.tencent.tencentmap.mapsdk.maps.model.MarkerOptions;
import com.tencent.tencentmap.mapsdk.maps.model.Polygon; //import com.tencent.tencentmap.mapsdk.maps.model.Polygon;
import com.tencent.tencentmap.mapsdk.maps.model.PolygonOptions; //import com.tencent.tencentmap.mapsdk.maps.model.PolygonOptions;
//
import java.util.ArrayList; //import java.util.ArrayList;
import java.util.List; //import java.util.List;
//
public class PolylonOptionsActivity extends SupportMapFragmentActivity { //public class PolylonOptionsActivity extends SupportMapFragmentActivity {
//
@Override // @Override
protected void onCreate(Bundle savedInstanceState) { // protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); // super.onCreate(savedInstanceState);
Polygon polygon = tencentMap.addPolygon(polygonOptions); // Polygon polygon = tencentMap.addPolygon(polygonOptions);
polygon.setPoints(transferArrayToList(latLngs)); //Options中设置顶点 // polygon.setPoints(transferArrayToList(latLngs)); //Options中设置顶点
Polygon newPolygon = tencentMap.addPolygon(newPolygonOptions); // Polygon newPolygon = tencentMap.addPolygon(newPolygonOptions);
newPolygon.setOptions(newPolygonOptions); //重新设置Options // newPolygon.setOptions(newPolygonOptions); //重新设置Options
newPolygon.setClickable(true); //设置可点击 // newPolygon.setClickable(true); //设置可点击
newPolygon.setFillColor(0xaa324354); // newPolygon.setFillColor(0xaa324354);
newPolygon.setPoints(transferArrayToList(newLatLngs)); //设置坐标 // newPolygon.setPoints(transferArrayToList(newLatLngs)); //设置坐标
newPolygon.setTag(tencentMap.addMarker(new MarkerOptions().position(new LatLng(39.984866, 116.305759)).title("设置标注").draggable(true))); // newPolygon.setTag(tencentMap.addMarker(new MarkerOptions().position(new LatLng(39.984866, 116.305759)).title("设置标注").draggable(true)));
//
//
} // }
//
private List<LatLng> transferArrayToList(LatLng[] latLngs){ //坐标数组与List转换 // private List<LatLng> transferArrayToList(LatLng[] latLngs){ //坐标数组与List转换
List<LatLng> list = new ArrayList<>(); // List<LatLng> list = new ArrayList<>();
if (latLngs == null) // if (latLngs == null)
return list; // return list;
for (int i = 0; i < latLngs.length; i++) // for (int i = 0; i < latLngs.length; i++)
list.add(latLngs[i]); // list.add(latLngs[i]);
//
return list; // return list;
//
} // }
private LatLng[] latLngs = { // private LatLng[] latLngs = {
new LatLng(39.984864, 116.305756), // new LatLng(39.984864, 116.305756),
new LatLng(39.983618, 116.305848), // new LatLng(39.983618, 116.305848),
new LatLng(39.982347, 116.305966), // new LatLng(39.982347, 116.305966),
new LatLng(39.982412, 116.308111), // new LatLng(39.982412, 116.308111),
new LatLng(39.984122, 116.308224), // new LatLng(39.984122, 116.308224),
new LatLng(39.984955, 116.308099), // new LatLng(39.984955, 116.308099),
new LatLng(39.984864, 116.305756) // new LatLng(39.984864, 116.305756)
}; // };
//
private LatLng[] newLatLngs = { // private LatLng[] newLatLngs = {
new LatLng(39.984864, 116.305756), // new LatLng(39.984864, 116.305756),
new LatLng(39.983618, 116.305848), // new LatLng(39.983618, 116.305848),
new LatLng(39.982347, 116.305966), // new LatLng(39.982347, 116.305966),
new LatLng(39.982412, 116.308111), // new LatLng(39.982412, 116.308111),
new LatLng(39.984122, 116.308224), // new LatLng(39.984122, 116.308224),
new LatLng(39.984955, 116.308099), // new LatLng(39.984955, 116.308099),
new LatLng(39.984864, 116.305756) // new LatLng(39.984864, 116.305756)
}; // };
//
//
private PolygonOptions polygonOptions = new PolygonOptions(). // private PolygonOptions polygonOptions = new PolygonOptions().
add(latLngs). // 添加图形坐标点 // add(latLngs). // 添加图形坐标点
fillColor(0x56643313). //填充颜色 // fillColor(0x56643313). //填充颜色
strokeColor(0xfa349012). //描边颜色 // strokeColor(0xfa349012). //描边颜色
strokeWidth(1). //描边宽度 // strokeWidth(1). //描边宽度
visible(true). //是否可见 // visible(true). //是否可见
zIndex(0). //堆叠顺序越大优先级越高 // zIndex(0). //堆叠顺序越大优先级越高
clickable(true); // 是否可点击 // clickable(true); // 是否可点击
//
private PolygonOptions newPolygonOptions = new PolygonOptions(). // private PolygonOptions newPolygonOptions = new PolygonOptions().
addAll(transferArrayToList(newLatLngs)); //设置批量添加顶点 // addAll(transferArrayToList(newLatLngs)); //设置批量添加顶点
} //}

View File

@ -1,178 +1,178 @@
package cc.winboll.studio.positions.demo.polygon; package cc.winboll.studio.positions.demo.polygon;
import androidx.annotation.NonNull; //import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity; //import androidx.appcompat.app.AppCompatActivity;
//
import android.os.Bundle; //import android.os.Bundle;
import android.util.Log; //import android.util.Log;
import android.view.Menu; //import android.view.Menu;
import android.view.MenuItem; //import android.view.MenuItem;
import android.view.View; //import android.view.View;
//
import cc.winboll.studio.positions.R; //import cc.winboll.studio.positions.R;
import com.tencent.tencentmap.mapsdk.maps.CameraUpdate; //import com.tencent.tencentmap.mapsdk.maps.CameraUpdate;
import com.tencent.tencentmap.mapsdk.maps.CameraUpdateFactory; //import com.tencent.tencentmap.mapsdk.maps.CameraUpdateFactory;
import com.tencent.tencentmap.mapsdk.maps.MapView; //import com.tencent.tencentmap.mapsdk.maps.MapView;
import com.tencent.tencentmap.mapsdk.maps.TencentMap; //import com.tencent.tencentmap.mapsdk.maps.TencentMap;
import com.tencent.tencentmap.mapsdk.maps.model.BitmapDescriptor; //import com.tencent.tencentmap.mapsdk.maps.model.BitmapDescriptor;
import com.tencent.tencentmap.mapsdk.maps.model.BitmapDescriptorFactory; //import com.tencent.tencentmap.mapsdk.maps.model.BitmapDescriptorFactory;
import com.tencent.tencentmap.mapsdk.maps.model.CameraPosition; //import com.tencent.tencentmap.mapsdk.maps.model.CameraPosition;
import com.tencent.tencentmap.mapsdk.maps.model.LatLng; //import com.tencent.tencentmap.mapsdk.maps.model.LatLng;
import com.tencent.tencentmap.mapsdk.maps.model.MarkerCollisionItem; //import com.tencent.tencentmap.mapsdk.maps.model.MarkerCollisionItem;
import com.tencent.tencentmap.mapsdk.maps.model.MarkerOptions; //import com.tencent.tencentmap.mapsdk.maps.model.MarkerOptions;
import com.tencent.tencentmap.mapsdk.maps.model.Tile; //import com.tencent.tencentmap.mapsdk.maps.model.Tile;
import com.tencent.tencentmap.mapsdk.maps.model.TileOverlay; //import com.tencent.tencentmap.mapsdk.maps.model.TileOverlay;
import com.tencent.tencentmap.mapsdk.maps.model.TileOverlayOptions; //import com.tencent.tencentmap.mapsdk.maps.model.TileOverlayOptions;
import com.tencent.tencentmap.mapsdk.maps.model.TileProvider; //import com.tencent.tencentmap.mapsdk.maps.model.TileProvider;
//
import java.io.ByteArrayOutputStream; //import java.io.ByteArrayOutputStream;
import java.io.IOException; //import java.io.IOException;
import java.io.InputStream; //import java.io.InputStream;
//
public class TileOverlayActivity extends AppCompatActivity { //public class TileOverlayActivity extends AppCompatActivity {
private MapView mapView; // private MapView mapView;
private TencentMap tencentMap; // private TencentMap tencentMap;
private boolean mMarkerAdded; // private boolean mMarkerAdded;
private TileOverlay mTileOverlay; // private TileOverlay mTileOverlay;
//
@Override // @Override
protected void onCreate(Bundle savedInstanceState) { // protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); // super.onCreate(savedInstanceState);
setContentView(R.layout.activity_tile_overlay); // setContentView(R.layout.activity_tile_overlay);
initView(); // initView();
} // }
//
private void initView() { // private void initView() {
mapView = findViewById(R.id.mapView); // mapView = findViewById(R.id.mapView);
tencentMap = mapView.getMap(); // tencentMap = mapView.getMap();
CameraUpdate cameraSigma = // CameraUpdate cameraSigma =
CameraUpdateFactory.newCameraPosition(new CameraPosition( // CameraUpdateFactory.newCameraPosition(new CameraPosition(
new LatLng(39.917505, 116.397657), // new LatLng(39.917505, 116.397657),
15, // 15,
0f, // 0f,
0f)); // 0f));
//移动地图 // //移动地图
tencentMap.moveCamera(cameraSigma); // tencentMap.moveCamera(cameraSigma);
} // }
//
@Override // @Override
public boolean onCreateOptionsMenu(Menu menu) { // public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.markercol, menu); // getMenuInflater().inflate(R.menu.markercol, menu);
return super.onCreateOptionsMenu(menu); // return super.onCreateOptionsMenu(menu);
} // }
//
@Override // @Override
public boolean onPrepareOptionsMenu(Menu menu) { // public boolean onPrepareOptionsMenu(Menu menu) {
menu.findItem(R.id.menu_open_collisionsmap).setVisible(!mMarkerAdded); // menu.findItem(R.id.menu_open_collisionsmap).setVisible(!mMarkerAdded);
menu.findItem(R.id.menu_close_collisionsmap).setVisible(mMarkerAdded); // menu.findItem(R.id.menu_close_collisionsmap).setVisible(mMarkerAdded);
return super.onPrepareOptionsMenu(menu); // return super.onPrepareOptionsMenu(menu);
} // }
//
@Override // @Override
public boolean onOptionsItemSelected(@NonNull MenuItem item) { // public boolean onOptionsItemSelected(@NonNull MenuItem item) {
switch (item.getItemId()) { // switch (item.getItemId()) {
case R.id.menu_open_collisionsmap: // case R.id.menu_open_collisionsmap:
mMarkerAdded = true; // mMarkerAdded = true;
if (mTileOverlay == null) { // if (mTileOverlay == null) {
mTileOverlay = tencentMap.addTileOverlay( // mTileOverlay = tencentMap.addTileOverlay(
new TileOverlayOptions(). // new TileOverlayOptions().
tileProvider(new LocalTileProvider())); // tileProvider(new LocalTileProvider()));
} // }
//
break; // break;
case R.id.menu_close_collisionsmap: // case R.id.menu_close_collisionsmap:
mMarkerAdded = false; // mMarkerAdded = false;
if (mTileOverlay != null) { // if (mTileOverlay != null) {
mTileOverlay.clearTileCache(); // mTileOverlay.clearTileCache();
mTileOverlay.remove(); // mTileOverlay.remove();
mTileOverlay = null; // mTileOverlay = null;
} // }
break; // break;
} // }
//
supportInvalidateOptionsMenu(); // supportInvalidateOptionsMenu();
return super.onOptionsItemSelected(item); // return super.onOptionsItemSelected(item);
} // }
//
class LocalTileProvider implements TileProvider { // class LocalTileProvider implements TileProvider {
//
@Override // @Override
public Tile getTile(int x, int y, int zoom) { // public Tile getTile(int x, int y, int zoom) {
LatLng latLng = new LatLng(39.917505, 116.397657); // LatLng latLng = new LatLng(39.917505, 116.397657);
int iZ = 16; // int iZ = 16;
double n = Math.pow(2, iZ); // double n = Math.pow(2, iZ);
int iX = (int) (((latLng.getLongitude() + 180) / 360) * n); // int iX = (int) (((latLng.getLongitude() + 180) / 360) * n);
int iY = (int) ((1 - (Math.log(Math.tan(Math.toRadians(latLng.getLatitude())) + // int iY = (int) ((1 - (Math.log(Math.tan(Math.toRadians(latLng.getLatitude())) +
(1 / Math.cos(Math.toRadians(latLng.getLatitude())))) / Math.PI)) / 2 * n); // (1 / Math.cos(Math.toRadians(latLng.getLatitude())))) / Math.PI)) / 2 * n);
if (iX == x && iY == y && iZ == zoom) { // if (iX == x && iY == y && iZ == zoom) {
Log.e("tile", "zoom:" + zoom + " x:" + x + " y:" + y); // Log.e("tile", "zoom:" + zoom + " x:" + x + " y:" + y);
return new Tile(256, 256, tileData()); // return new Tile(256, 256, tileData());
} // }
return TileProvider.NO_TILE; // return TileProvider.NO_TILE;
} // }
//
byte[] tileData() { // byte[] tileData() {
InputStream is = null; // InputStream is = null;
ByteArrayOutputStream baos = null; // ByteArrayOutputStream baos = null;
try { // try {
is = getApplicationContext().getAssets().open("gugong.jpg"); // is = getApplicationContext().getAssets().open("gugong.jpg");
baos = new ByteArrayOutputStream(); // baos = new ByteArrayOutputStream();
byte[] byteBuffer = new byte[1024]; // byte[] byteBuffer = new byte[1024];
int count = 0; // int count = 0;
while ((count = is.read(byteBuffer)) != -1) { // while ((count = is.read(byteBuffer)) != -1) {
baos.write(byteBuffer, 0, count); // baos.write(byteBuffer, 0, count);
} // }
return baos.toByteArray(); // return baos.toByteArray();
} catch (IOException e) { // } catch (IOException e) {
e.printStackTrace(); // e.printStackTrace();
return null; // return null;
} finally { // } finally {
if (is != null) { // if (is != null) {
try { // try {
is.close(); // is.close();
} catch (IOException e) { // } catch (IOException e) {
e.printStackTrace(); // e.printStackTrace();
} // }
} // }
if (baos != null) { // if (baos != null) {
try { // try {
baos.close(); // baos.close();
} catch (IOException e) { // } catch (IOException e) {
e.printStackTrace(); // e.printStackTrace();
} // }
} // }
} // }
} // }
} // }
//
@Override // @Override
protected void onResume() { // protected void onResume() {
super.onResume(); // super.onResume();
mapView.onResume(); // mapView.onResume();
} // }
//
@Override // @Override
protected void onPause() { // protected void onPause() {
super.onPause(); // super.onPause();
mapView.onPause(); // mapView.onPause();
} // }
//
@Override // @Override
protected void onDestroy() { // protected void onDestroy() {
super.onDestroy(); // super.onDestroy();
mapView.onDestroy(); // mapView.onDestroy();
} // }
//
//
@Override // @Override
protected void onStart() { // protected void onStart() {
super.onStart(); // super.onStart();
mapView.onStart(); // mapView.onStart();
} // }
//
@Override // @Override
protected void onStop() { // protected void onStop() {
super.onStop(); // super.onStop();
mapView.onStop(); // mapView.onStop();
} // }
} //}

View File

@ -1,194 +1,194 @@
package cc.winboll.studio.positions.demo.polyline; package cc.winboll.studio.positions.demo.polyline;
import android.graphics.Color; //import android.graphics.Color;
import android.os.Bundle; //import android.os.Bundle;
import android.view.Menu; //import android.view.Menu;
import android.view.MenuItem; //import android.view.MenuItem;
//
import androidx.annotation.Nullable; //import androidx.annotation.Nullable;
//
import cc.winboll.studio.positions.demo.AbsMapActivity; //import cc.winboll.studio.positions.demo.AbsMapActivity;
import cc.winboll.studio.positions.R; //import cc.winboll.studio.positions.R;
import com.tencent.tencentmap.mapsdk.maps.CameraUpdateFactory; //import com.tencent.tencentmap.mapsdk.maps.CameraUpdateFactory;
import com.tencent.tencentmap.mapsdk.maps.TencentMap; //import com.tencent.tencentmap.mapsdk.maps.TencentMap;
import com.tencent.tencentmap.mapsdk.maps.model.BitmapDescriptorFactory; //import com.tencent.tencentmap.mapsdk.maps.model.BitmapDescriptorFactory;
import com.tencent.tencentmap.mapsdk.maps.model.LatLng; //import com.tencent.tencentmap.mapsdk.maps.model.LatLng;
import com.tencent.tencentmap.mapsdk.maps.model.Polyline; //import com.tencent.tencentmap.mapsdk.maps.model.Polyline;
import com.tencent.tencentmap.mapsdk.maps.model.PolylineOptions; //import com.tencent.tencentmap.mapsdk.maps.model.PolylineOptions;
//
import java.util.ArrayList; //import java.util.ArrayList;
import java.util.List; //import java.util.List;
//
public class DrawLineActivity extends AbsMapActivity { //public class DrawLineActivity extends AbsMapActivity {
private int typeSimple = 0; // private int typeSimple = 0;
private int typeImage = 1; // private int typeImage = 1;
private int typeColor = 2; // private int typeColor = 2;
private int typeArrow = 3; // private int typeArrow = 3;
private int typeGradient = 4; // private int typeGradient = 4;
//
private TencentMap mTencentMap; // private TencentMap mTencentMap;
private boolean mHasAdded; // private boolean mHasAdded;
private boolean mHasEnableText; // private boolean mHasEnableText;
private Polyline polyline; // private Polyline polyline;
private PolylineOptions.Text mPolylineText; // private PolylineOptions.Text mPolylineText;
//
@Override // @Override
protected void onCreate(@Nullable Bundle savedInstanceState, TencentMap tencentMap) { // protected void onCreate(@Nullable Bundle savedInstanceState, TencentMap tencentMap) {
super.onCreate(savedInstanceState, tencentMap); // super.onCreate(savedInstanceState, tencentMap);
mTencentMap = tencentMap; // mTencentMap = tencentMap;
tencentMap.moveCamera(CameraUpdateFactory.zoomTo(15)); // tencentMap.moveCamera(CameraUpdateFactory.zoomTo(15));
} // }
//
@Override // @Override
public boolean onCreateOptionsMenu(Menu menu) { // public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.polyline, menu); // getMenuInflater().inflate(R.menu.polyline, menu);
return true; // return true;
} // }
//
@Override // @Override
public boolean onPrepareOptionsMenu(Menu menu) { // public boolean onPrepareOptionsMenu(Menu menu) {
menu.findItem(R.id.menu_add).setVisible(!mHasAdded); // menu.findItem(R.id.menu_add).setVisible(!mHasAdded);
menu.findItem(R.id.menu_text).setTitle(mHasEnableText ? "关闭路名" : "开启路名").setVisible(mHasAdded); // menu.findItem(R.id.menu_text).setTitle(mHasEnableText ? "关闭路名" : "开启路名").setVisible(mHasAdded);
menu.findItem(R.id.menu_delete).setVisible(mHasAdded); // menu.findItem(R.id.menu_delete).setVisible(mHasAdded);
return super.onPrepareOptionsMenu(menu); // return super.onPrepareOptionsMenu(menu);
} // }
//
@Override // @Override
public boolean onOptionsItemSelected(MenuItem item) { // public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) { // switch (item.getItemId()) {
case R.id.menu_add_line_simple: // case R.id.menu_add_line_simple:
mTencentMap.clear(); // mTencentMap.clear();
polyline = mTencentMap.addPolyline(setLineStyle(typeSimple)); // polyline = mTencentMap.addPolyline(setLineStyle(typeSimple));
mHasAdded = true; // mHasAdded = true;
break; // break;
//
case R.id.menu_add_line_dash: // case R.id.menu_add_line_dash:
mTencentMap.clear(); // mTencentMap.clear();
polyline = mTencentMap.addPolyline(setLineStyle(typeImage)); // polyline = mTencentMap.addPolyline(setLineStyle(typeImage));
mHasAdded = true; // mHasAdded = true;
break; // break;
case R.id.menu_add_line_segment: // case R.id.menu_add_line_segment:
mTencentMap.clear(); // mTencentMap.clear();
polyline = mTencentMap.addPolyline(setLineStyle(typeColor)); // polyline = mTencentMap.addPolyline(setLineStyle(typeColor));
int[] color = {0, 1, 2, 3, 4}; // int[] color = {0, 1, 2, 3, 4};
int[] index = {0, 1, 2, 3, 4, 5}; // int[] index = {0, 1, 2, 3, 4, 5};
polyline.setColors(color, index); // polyline.setColors(color, index);
mHasAdded = true; // mHasAdded = true;
break; // break;
case R.id.menu_add_line_texture: // case R.id.menu_add_line_texture:
mTencentMap.clear(); // mTencentMap.clear();
polyline = mTencentMap.addPolyline(setLineStyle((typeArrow))); // polyline = mTencentMap.addPolyline(setLineStyle((typeArrow)));
mHasAdded = true; // mHasAdded = true;
break; // break;
case R.id.menu_add_line_gradient: // case R.id.menu_add_line_gradient:
mTencentMap.clear(); // mTencentMap.clear();
polyline = mTencentMap.addPolyline(setLineStyle((typeGradient))); // polyline = mTencentMap.addPolyline(setLineStyle((typeGradient)));
int[] indexes = {0, 1, 2, 3, 4}; // int[] indexes = {0, 1, 2, 3, 4};
// 设置每段索引之间的颜色这个颜色同样支持纹理颜色 PolylineOptions.Colors 中定义的 [0, 10] //// 设置每段索引之间的颜色这个颜色同样支持纹理颜色 PolylineOptions.Colors 中定义的 [0, 10]
int[] colors = { // int[] colors = {
0xff00ff00, // 线上点 [0, 1] 之间为绿色 // 0xff00ff00, // 线上点 [0, 1] 之间为绿色
0xffffff00, // 线上点 [1, 2] 之间为黄色 // 0xffffff00, // 线上点 [1, 2] 之间为黄色
0xffff0000, // 线上点 [2, 3] 之间为红色 // 0xffff0000, // 线上点 [2, 3] 之间为红色
0xff131313, // 线上点 [3, 4] 之间为黄色 // 0xff131313, // 线上点 [3, 4] 之间为黄色
0xff1033f6 // 线上点 [4, 最后一个点] 之间为绿色 // 0xff1033f6 // 线上点 [4, 最后一个点] 之间为绿色
}; // };
polyline.setColors(colors, indexes); // polyline.setColors(colors, indexes);
mHasAdded = true; // mHasAdded = true;
break; // break;
case R.id.menu_text: // case R.id.menu_text:
mHasEnableText = !mHasEnableText; // mHasEnableText = !mHasEnableText;
if (mHasEnableText) { // if (mHasEnableText) {
if (mPolylineText == null) { // if (mPolylineText == null) {
mPolylineText = generateText(); // mPolylineText = generateText();
//设置显示优先级可选项有HIGH或NORMAL // //设置显示优先级可选项有HIGH或NORMAL
mPolylineText.setPriority(PolylineOptions.TextPriority.HIGH); // mPolylineText.setPriority(PolylineOptions.TextPriority.HIGH);
//设置字体大小 // //设置字体大小
mPolylineText.setTextSize(10); // mPolylineText.setTextSize(10);
//设置填充颜色 // //设置填充颜色
mPolylineText.setStrokeColor(Color.WHITE); // mPolylineText.setStrokeColor(Color.WHITE);
//设置文字颜色 // //设置文字颜色
mPolylineText.setTextColor(Color.BLACK); // mPolylineText.setTextColor(Color.BLACK);
} // }
//
polyline.setText(mPolylineText); // polyline.setText(mPolylineText);
} else { // } else {
polyline.setText(null); // polyline.setText(null);
} // }
//
break; // break;
//
case R.id.menu_delete: // case R.id.menu_delete:
if (polyline != null) { // if (polyline != null) {
polyline.remove(); // polyline.remove();
polyline = null; // polyline = null;
mHasAdded = false; // mHasAdded = false;
mHasEnableText = false; // mHasEnableText = false;
//
} // }
break; // break;
} // }
return super.onOptionsItemSelected(item); // return super.onOptionsItemSelected(item);
} // }
//
private PolylineOptions setLineStyle(int type) { // private PolylineOptions setLineStyle(int type) {
PolylineOptions polylineOptions = new PolylineOptions().addAll(getLatlons()).lineCap(true); // PolylineOptions polylineOptions = new PolylineOptions().addAll(getLatlons()).lineCap(true);
switch (type) { // switch (type) {
case 0: // case 0:
//设置折线颜色宽度 // //设置折线颜色宽度
polylineOptions // polylineOptions
.color(0xff00ff00) // .color(0xff00ff00)
.width(5f); // .width(5f);
break; // break;
case 1: // case 1:
List<Integer> list = new ArrayList<>(); // List<Integer> list = new ArrayList<>();
list.add(35); // list.add(35);
list.add(20); // list.add(20);
polylineOptions // polylineOptions
.lineType(PolylineOptions.LineType.LINE_TYPE_IMAGEINARYLINE) // .lineType(PolylineOptions.LineType.LINE_TYPE_IMAGEINARYLINE)
.width(10) // .width(10)
.pattern(list); // .pattern(list);
break; // break;
case 2: // case 2:
//线路颜色值纹理图片里的颜色索引 // //线路颜色值纹理图片里的颜色索引
polylineOptions // polylineOptions
.colorType(PolylineOptions.ColorType.LINE_COLOR_TEXTURE) // .colorType(PolylineOptions.ColorType.LINE_COLOR_TEXTURE)
.color(PolylineOptions.Colors.GREEN) // .color(PolylineOptions.Colors.GREEN)
.colorTexture(BitmapDescriptorFactory.fromAsset("color_texture.png")); // .colorTexture(BitmapDescriptorFactory.fromAsset("color_texture.png"));
break; // break;
case 3: // case 3:
polylineOptions // polylineOptions
.arrow(true) // .arrow(true)
.arrowSpacing(30) // .arrowSpacing(30)
.arrowTexture(BitmapDescriptorFactory.fromAsset("color_arrow_texture.png")); // .arrowTexture(BitmapDescriptorFactory.fromAsset("color_arrow_texture.png"));
break; // break;
case 4: // case 4:
polylineOptions // polylineOptions
.gradient(true) // .gradient(true)
.lineType(PolylineOptions.LineType.LINE_TYPE_MULTICOLORLINE) // .lineType(PolylineOptions.LineType.LINE_TYPE_MULTICOLORLINE)
.width(20); // .width(20);
break; // break;
//
} // }
return polylineOptions; // return polylineOptions;
} // }
//
private PolylineOptions.Text generateText() { // private PolylineOptions.Text generateText() {
List<PolylineOptions.SegmentText> segmentTexts = new ArrayList<>(); // List<PolylineOptions.SegmentText> segmentTexts = new ArrayList<>();
//参数分别表示坐标路径数组起点index终点index动态路名文字 // //参数分别表示坐标路径数组起点index终点index动态路名文字
segmentTexts.add(new PolylineOptions.SegmentText(0, 1, "苏州街")); // segmentTexts.add(new PolylineOptions.SegmentText(0, 1, "苏州街"));
segmentTexts.add(new PolylineOptions.SegmentText(1, 2, "北四环西路辅路")); // segmentTexts.add(new PolylineOptions.SegmentText(1, 2, "北四环西路辅路"));
segmentTexts.add(new PolylineOptions.SegmentText(2, 4, "彩和坊路")); // segmentTexts.add(new PolylineOptions.SegmentText(2, 4, "彩和坊路"));
return new PolylineOptions.Text.Builder(segmentTexts).build(); // return new PolylineOptions.Text.Builder(segmentTexts).build();
} // }
//
private List<LatLng> getLatlons() { // private List<LatLng> getLatlons() {
List<LatLng> latLngs = new ArrayList<LatLng>(); // List<LatLng> latLngs = new ArrayList<LatLng>();
latLngs.add(new LatLng(39.984864, 116.305756)); // latLngs.add(new LatLng(39.984864, 116.305756));
latLngs.add(new LatLng(39.983618, 116.305848)); // latLngs.add(new LatLng(39.983618, 116.305848));
latLngs.add(new LatLng(39.982347, 116.305966)); // latLngs.add(new LatLng(39.982347, 116.305966));
latLngs.add(new LatLng(39.982412, 116.308111)); // latLngs.add(new LatLng(39.982412, 116.308111));
latLngs.add(new LatLng(39.984122, 116.308224)); // latLngs.add(new LatLng(39.984122, 116.308224));
latLngs.add(new LatLng(39.984955, 116.308099)); // latLngs.add(new LatLng(39.984955, 116.308099));
return latLngs; // return latLngs;
} // }
} //}

View File

@ -17,116 +17,116 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
public class LineTextActivity extends SupportMapFragmentActivity { public class LineTextActivity extends SupportMapFragmentActivity {
private Polyline polyline; // private Polyline polyline;
private static List<LatLng> mPoints = new ArrayList<>(); // private static List<LatLng> mPoints = new ArrayList<>();
private Switch switch_style; // private Switch switch_style;
private Switch switch_off; // private Switch switch_off;
//
@Override // @Override
protected void onCreate(Bundle savedInstanceState) { // protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); // super.onCreate(savedInstanceState);
initView(); // initView();
tencentMap.moveCamera(CameraUpdateFactory.zoomTo(16)); // tencentMap.moveCamera(CameraUpdateFactory.zoomTo(16));
switch_style.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { // switch_style.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
//
@Override // @Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) { // public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
if (polyline == null) { // if (polyline == null) {
return; // return;
} // }
//
PolylineOptions.Text text = polyline.getText(); // PolylineOptions.Text text = polyline.getText();
removeText(); // removeText();
if (checked) { // if (checked) {
//设置显示优先级可选项有HIGH或NORMAL // //设置显示优先级可选项有HIGH或NORMAL
text.setPriority(PolylineOptions.TextPriority.HIGH); // text.setPriority(PolylineOptions.TextPriority.HIGH);
//设置字体大小 // //设置字体大小
text.setTextSize(10); // text.setTextSize(10);
//设置填充颜色 // //设置填充颜色
text.setStrokeColor(Color.WHITE); // text.setStrokeColor(Color.WHITE);
//设置文字颜色 // //设置文字颜色
text.setTextColor(Color.BLACK); // text.setTextColor(Color.BLACK);
} else { // } else {
//设置显示优先级可选项有HIGH或NORMAL // //设置显示优先级可选项有HIGH或NORMAL
text.setPriority(PolylineOptions.TextPriority.NORMAL); // text.setPriority(PolylineOptions.TextPriority.NORMAL);
//设置字体大小 // //设置字体大小
text.setTextSize(8); // text.setTextSize(8);
//设置填充颜色 // //设置填充颜色
text.setStrokeColor(Color.WHITE); // text.setStrokeColor(Color.WHITE);
//设置文字颜色 // //设置文字颜色
text.setTextColor(Color.GRAY); // text.setTextColor(Color.GRAY);
//
} // }
//
polyline.setText(text); // polyline.setText(text);
} // }
}); // });
//
switch_off.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { // switch_off.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override // @Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) { // public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
if (checked) { // if (checked) {
polyline = createLineWithText(); // polyline = createLineWithText();
} else { // } else {
removeText(); // removeText();
polyline.remove(); // polyline.remove();
polyline = null; // polyline = null;
} // }
} // }
}); // });
} // }
//
//
private void initView() { // private void initView() {
//文字 // //文字
switch_style = (Switch) findViewById(R.id.switch_style); // switch_style = (Switch) findViewById(R.id.switch_style);
switch_style.setVisibility(View.VISIBLE); // switch_style.setVisibility(View.VISIBLE);
switch_off = (Switch) findViewById(R.id.switch_off); // switch_off = (Switch) findViewById(R.id.switch_off);
switch_off.setVisibility(View.VISIBLE); // switch_off.setVisibility(View.VISIBLE);
} // }
//
public Polyline addLine() { // public Polyline addLine() {
Polyline polyline = tencentMap.addPolyline(new PolylineOptions().addAll(mPoints).color(0x22ff0000)); // Polyline polyline = tencentMap.addPolyline(new PolylineOptions().addAll(mPoints).color(0x22ff0000));
//
return polyline; // return polyline;
} // }
//
//
//生成坐标点路径 // //生成坐标点路径
private List<LatLng> generateLatLngs() { // private List<LatLng> generateLatLngs() {
if (mPoints.size() != 0) // if (mPoints.size() != 0)
mPoints = new ArrayList<>(); // mPoints = new ArrayList<>();
//苏州街 // //苏州街
mPoints.add(new LatLng(39.982382, 116.305883)); // mPoints.add(new LatLng(39.982382, 116.305883));
//北四环西路辅路 // //北四环西路辅路
mPoints.add(new LatLng(39.984914, 116.305690)); // mPoints.add(new LatLng(39.984914, 116.305690));
//彩和坊路 // //彩和坊路
mPoints.add(new LatLng(39.985045, 116.308136)); // mPoints.add(new LatLng(39.985045, 116.308136));
mPoints.add(new LatLng(39.983570, 116.308088)); // mPoints.add(new LatLng(39.983570, 116.308088));
mPoints.add(new LatLng(39.980063, 116.308297)); // mPoints.add(new LatLng(39.980063, 116.308297));
return mPoints; // return mPoints;
} // }
//
private PolylineOptions.Text generateText() { // private PolylineOptions.Text generateText() {
List<PolylineOptions.SegmentText> segmentTexts = new ArrayList<>(); // List<PolylineOptions.SegmentText> segmentTexts = new ArrayList<>();
//参数分别表示坐标路径数组起点index终点index动态路名文字 // //参数分别表示坐标路径数组起点index终点index动态路名文字
segmentTexts.add(new PolylineOptions.SegmentText(0, 1, "苏州街")); // segmentTexts.add(new PolylineOptions.SegmentText(0, 1, "苏州街"));
segmentTexts.add(new PolylineOptions.SegmentText(1, 2, "北四环西路辅路")); // segmentTexts.add(new PolylineOptions.SegmentText(1, 2, "北四环西路辅路"));
segmentTexts.add(new PolylineOptions.SegmentText(2, 4, "彩和坊路")); // segmentTexts.add(new PolylineOptions.SegmentText(2, 4, "彩和坊路"));
//
return new PolylineOptions.Text.Builder(segmentTexts).build(); // return new PolylineOptions.Text.Builder(segmentTexts).build();
} // }
//
//
private Polyline createLineWithText() { // private Polyline createLineWithText() {
Polyline polyline = tencentMap.addPolyline(new PolylineOptions().addAll(generateLatLngs()).text(generateText())); // Polyline polyline = tencentMap.addPolyline(new PolylineOptions().addAll(generateLatLngs()).text(generateText()));
PolylineOptions.Text text = polyline.getText(); // PolylineOptions.Text text = polyline.getText();
return polyline; // return polyline;
} // }
//
//
private void removeText() { // private void removeText() {
polyline.setText(null); // polyline.setText(null);
} // }
//
} }

View File

@ -23,269 +23,269 @@ import androidx.annotation.NonNull;
* @since 2020/6/11 * @since 2020/6/11
*/ */
public class MutablePolylineActivity extends SupportMapFragmentActivity { public class MutablePolylineActivity extends SupportMapFragmentActivity {
private boolean mIsAdd; // private boolean mIsAdd;
private Polyline mPolyline; // private Polyline mPolyline;
//
private final static Object[][] sData = { // private final static Object[][] sData = {
{"更新1"}, // {"更新1"},
{"更新2"}, // {"更新2"},
{"重置"}, // {"重置"},
{"删除"}, // {"删除"},
}; // };
//
private List<LatLng> mAppendPoints = new ArrayList<>(); // private List<LatLng> mAppendPoints = new ArrayList<>();
private int mAppendIndex; // private int mAppendIndex;
//
private Handler sHandler = new Handler(Looper.getMainLooper()) { // private Handler sHandler = new Handler(Looper.getMainLooper()) {
@Override // @Override
public void handleMessage(@NonNull Message msg) { // public void handleMessage(@NonNull Message msg) {
super.handleMessage(msg); // super.handleMessage(msg);
//
if (msg.what == 1 && mPolyline != null && mAppendIndex < mAppendPoints.size()) { // if (msg.what == 1 && mPolyline != null && mAppendIndex < mAppendPoints.size()) {
mPolyline.appendPoint(mAppendPoints.get(mAppendIndex)); // mPolyline.appendPoint(mAppendPoints.get(mAppendIndex));
mAppendIndex++; // mAppendIndex++;
//
sendEmptyMessageDelayed(1, 300); // sendEmptyMessageDelayed(1, 300);
} // }
} // }
}; // };
//
@Override // @Override
public boolean onCreateOptionsMenu(Menu menu) { // public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_polyline_items, menu); // getMenuInflater().inflate(R.menu.menu_polyline_items, menu);
//
MenuItem actionMenu = menu.findItem(R.id.menu_actions); // MenuItem actionMenu = menu.findItem(R.id.menu_actions);
SubMenu actionSubMenu = actionMenu.getSubMenu(); // SubMenu actionSubMenu = actionMenu.getSubMenu();
//
for (int i = 0; i < sData.length; i++) { // for (int i = 0; i < sData.length; i++) {
Object[] indoor = sData[i]; // Object[] indoor = sData[i];
actionSubMenu.add(0, i, 0, String.valueOf(indoor[0])); // actionSubMenu.add(0, i, 0, String.valueOf(indoor[0]));
} // }
return true; // return true;
} // }
//
@Override // @Override
public boolean onPrepareOptionsMenu(Menu menu) { // public boolean onPrepareOptionsMenu(Menu menu) {
menu.findItem(R.id.menu_actions).setVisible(mIsAdd); // menu.findItem(R.id.menu_actions).setVisible(mIsAdd);
return super.onPrepareOptionsMenu(menu); // return super.onPrepareOptionsMenu(menu);
} // }
//
@Override // @Override
public boolean onOptionsItemSelected(@NonNull MenuItem item) { // public boolean onOptionsItemSelected(@NonNull MenuItem item) {
//
int itemId = item.getItemId(); // int itemId = item.getItemId();
//
if (mPolyline != null && itemId >= 0 && itemId < sData.length) { // if (mPolyline != null && itemId >= 0 && itemId < sData.length) {
if (itemId == 3) { // if (itemId == 3) {
mPolyline.remove(); // mPolyline.remove();
mIsAdd = false; // mIsAdd = false;
mAppendIndex = 0; // mAppendIndex = 0;
invalidateOptionsMenu(); // invalidateOptionsMenu();
} else if (itemId == 2) { // } else if (itemId == 2) {
mPolyline.setPoints(getPoints(itemId)); // mPolyline.setPoints(getPoints(itemId));
} else { // } else {
mPolyline.appendPoints(getPoints(itemId)); // mPolyline.appendPoints(getPoints(itemId));
} // }
return true; // return true;
} // }
//
List<Integer> pattern = new ArrayList<>(); // List<Integer> pattern = new ArrayList<>();
pattern.add(35); // pattern.add(35);
pattern.add(20); // pattern.add(20);
//
PolylineOptions options = new PolylineOptions() // PolylineOptions options = new PolylineOptions()
.addAll(getCreatePoints()) // .addAll(getCreatePoints())
.width(15); // .width(15);
//
switch (item.getItemId()) { // switch (item.getItemId()) {
case R.id.menu_add: // case R.id.menu_add:
if (mIsAdd) { // if (mIsAdd) {
break; // break;
} // }
mIsAdd = true; // mIsAdd = true;
mPolyline = tencentMap.addPolyline(options); // mPolyline = tencentMap.addPolyline(options);
break; // break;
case R.id.menu_add_anim: // case R.id.menu_add_anim:
if (mIsAdd) { // if (mIsAdd) {
break; // break;
} // }
mIsAdd = true; // mIsAdd = true;
//
mPolyline = tencentMap.addPolyline(options); // mPolyline = tencentMap.addPolyline(options);
//
sHandler.sendEmptyMessage(1); // sHandler.sendEmptyMessage(1);
break; // break;
//
} // }
invalidateOptionsMenu(); // invalidateOptionsMenu();
return super.onOptionsItemSelected(item); // return super.onOptionsItemSelected(item);
} // }
//
private static List<LatLng> getCreatePoints() { // private static List<LatLng> getCreatePoints() {
List<LatLng> listPoints = new ArrayList<>(); // List<LatLng> listPoints = new ArrayList<>();
addLine(listPoints); // addLine(listPoints);
return listPoints; // return listPoints;
} // }
//
private static List<LatLng> getPoints(int itemId) { // private static List<LatLng> getPoints(int itemId) {
List<LatLng> listPoints = new ArrayList<LatLng>(); // List<LatLng> listPoints = new ArrayList<LatLng>();
if (itemId == 0) { // if (itemId == 0) {
addLine1(listPoints); // addLine1(listPoints);
} else if (itemId == 1) { // } else if (itemId == 1) {
addLine2(listPoints); // addLine2(listPoints);
} else if (itemId == 2) { // } else if (itemId == 2) {
addLine(listPoints); // addLine(listPoints);
} // }
//
return listPoints; // return listPoints;
} // }
//
private static void addLine(List<LatLng> listPoints) { // private static void addLine(List<LatLng> listPoints) {
listPoints.add(new LatLng(39.981787, 116.306649)); // listPoints.add(new LatLng(39.981787, 116.306649));
listPoints.add(new LatLng(39.982021, 116.306739)); // listPoints.add(new LatLng(39.982021, 116.306739));
listPoints.add(new LatLng(39.982351, 116.306883)); // listPoints.add(new LatLng(39.982351, 116.306883));
listPoints.add(new LatLng(39.98233, 116.306047)); // listPoints.add(new LatLng(39.98233, 116.306047));
listPoints.add(new LatLng(39.982324, 116.305867)); // listPoints.add(new LatLng(39.982324, 116.305867));
listPoints.add(new LatLng(39.981918, 116.305885)); // listPoints.add(new LatLng(39.981918, 116.305885));
listPoints.add(new LatLng(39.981298, 116.305921)); // listPoints.add(new LatLng(39.981298, 116.305921));
listPoints.add(new LatLng(39.981091, 116.305939)); // listPoints.add(new LatLng(39.981091, 116.305939));
listPoints.add(new LatLng(39.980506, 116.305975)); // listPoints.add(new LatLng(39.980506, 116.305975));
listPoints.add(new LatLng(39.980148, 116.306002)); // listPoints.add(new LatLng(39.980148, 116.306002));
listPoints.add(new LatLng(39.980121, 116.306002)); // listPoints.add(new LatLng(39.980121, 116.306002));
listPoints.add(new LatLng(39.979708, 116.306038)); // 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.979205, 116.306074)); // listPoints.add(new LatLng(39.979205, 116.306074));
listPoints.add(new LatLng(39.978813, 116.306101)); // listPoints.add(new LatLng(39.978813, 116.306101));
listPoints.add(new LatLng(39.978015, 116.306182)); // listPoints.add(new LatLng(39.978015, 116.306182));
listPoints.add(new LatLng(39.977299, 116.306227)); // listPoints.add(new LatLng(39.977299, 116.306227));
listPoints.add(new LatLng(39.976996, 116.306245)); // listPoints.add(new LatLng(39.976996, 116.306245));
listPoints.add(new LatLng(39.976913, 116.306245)); // listPoints.add(new LatLng(39.976913, 116.306245));
listPoints.add(new LatLng(39.97597, 116.306308)); // listPoints.add(new LatLng(39.97597, 116.306308));
listPoints.add(new LatLng(39.97575, 116.306326)); // listPoints.add(new LatLng(39.97575, 116.306326));
listPoints.add(new LatLng(39.97564, 116.306335)); // listPoints.add(new LatLng(39.97564, 116.306335));
listPoints.add(new LatLng(39.975178, 116.306371)); // listPoints.add(new LatLng(39.975178, 116.306371));
listPoints.add(new LatLng(39.975185, 116.306514)); // listPoints.add(new LatLng(39.975185, 116.306514));
listPoints.add(new LatLng(39.97564, 116.306272)); // listPoints.add(new LatLng(39.97564, 116.306272));
listPoints.add(new LatLng(39.975633, 116.306272)); // listPoints.add(new LatLng(39.975633, 116.306272));
listPoints.add(new LatLng(39.975715, 116.307997)); // listPoints.add(new LatLng(39.975715, 116.307997));
listPoints.add(new LatLng(39.975819, 116.311545)); // listPoints.add(new LatLng(39.975819, 116.311545));
listPoints.add(new LatLng(39.975936, 116.314878)); // listPoints.add(new LatLng(39.975936, 116.314878));
listPoints.add(new LatLng(39.975998, 116.317528)); // listPoints.add(new LatLng(39.975998, 116.317528));
listPoints.add(new LatLng(39.976025, 116.318785)); // listPoints.add(new LatLng(39.976025, 116.318785));
listPoints.add(new LatLng(39.976108, 116.321714)); // listPoints.add(new LatLng(39.976108, 116.321714));
listPoints.add(new LatLng(39.976259, 116.326843)); // listPoints.add(new LatLng(39.976259, 116.326843));
listPoints.add(new LatLng(39.976328, 116.328622)); // listPoints.add(new LatLng(39.976328, 116.328622));
listPoints.add(new LatLng(39.976397, 116.330356)); // listPoints.add(new LatLng(39.976397, 116.330356));
listPoints.add(new LatLng(39.9765, 116.333967)); // listPoints.add(new LatLng(39.9765, 116.333967));
listPoints.add(new LatLng(39.976459, 116.341019)); // listPoints.add(new LatLng(39.976459, 116.341019));
listPoints.add(new LatLng(39.976473, 116.341674)); // listPoints.add(new LatLng(39.976473, 116.341674));
listPoints.add(new LatLng(39.976473, 116.341944)); // listPoints.add(new LatLng(39.976473, 116.341944));
listPoints.add(new LatLng(39.976473, 116.342546)); // listPoints.add(new LatLng(39.976473, 116.342546));
listPoints.add(new LatLng(39.976479, 116.345295)); // listPoints.add(new LatLng(39.976479, 116.345295));
listPoints.add(new LatLng(39.976197, 116.353829)); // listPoints.add(new LatLng(39.976197, 116.353829));
listPoints.add(new LatLng(39.976459, 116.369926)); // listPoints.add(new LatLng(39.976459, 116.369926));
listPoints.add(new LatLng(39.97672, 116.381353)); // listPoints.add(new LatLng(39.97672, 116.381353));
} // }
//
private static void addLine2(List<LatLng> listPoints) { // private static void addLine2(List<LatLng> listPoints) {
listPoints.add(new LatLng(39.91254, 116.41786)); // listPoints.add(new LatLng(39.91254, 116.41786));
listPoints.add(new LatLng(39.911258, 116.417905)); // listPoints.add(new LatLng(39.911258, 116.417905));
listPoints.add(new LatLng(39.910459, 116.417923)); // listPoints.add(new LatLng(39.910459, 116.417923));
listPoints.add(new LatLng(39.908557, 116.418049)); // listPoints.add(new LatLng(39.908557, 116.418049));
listPoints.add(new LatLng(39.908337, 116.418058)); // listPoints.add(new LatLng(39.908337, 116.418058));
listPoints.add(new LatLng(39.90824, 116.418067)); // listPoints.add(new LatLng(39.90824, 116.418067));
listPoints.add(new LatLng(39.90669, 116.418148)); // listPoints.add(new LatLng(39.90669, 116.418148));
listPoints.add(new LatLng(39.904795, 116.418283)); // listPoints.add(new LatLng(39.904795, 116.418283));
listPoints.add(new LatLng(39.903416, 116.418265)); // listPoints.add(new LatLng(39.903416, 116.418265));
listPoints.add(new LatLng(39.901218, 116.418408)); // listPoints.add(new LatLng(39.901218, 116.418408));
listPoints.add(new LatLng(39.900805, 116.418417)); // listPoints.add(new LatLng(39.900805, 116.418417));
listPoints.add(new LatLng(39.900805, 116.418426)); // listPoints.add(new LatLng(39.900805, 116.418426));
listPoints.add(new LatLng(39.901335, 116.417968)); // listPoints.add(new LatLng(39.901335, 116.417968));
listPoints.add(new LatLng(39.901342, 116.417968)); // listPoints.add(new LatLng(39.901342, 116.417968));
listPoints.add(new LatLng(39.901342, 116.418004)); // listPoints.add(new LatLng(39.901342, 116.418004));
listPoints.add(new LatLng(39.901197, 116.418193)); // listPoints.add(new LatLng(39.901197, 116.418193));
listPoints.add(new LatLng(39.901204, 116.418426)); // listPoints.add(new LatLng(39.901204, 116.418426));
listPoints.add(new LatLng(39.901218, 116.418552)); // listPoints.add(new LatLng(39.901218, 116.418552));
listPoints.add(new LatLng(39.901087, 116.418624)); // listPoints.add(new LatLng(39.901087, 116.418624));
listPoints.add(new LatLng(39.901053, 116.41884)); // listPoints.add(new LatLng(39.901053, 116.41884));
listPoints.add(new LatLng(39.901004, 116.419028)); // listPoints.add(new LatLng(39.901004, 116.419028));
listPoints.add(new LatLng(39.900922, 116.419388)); // listPoints.add(new LatLng(39.900922, 116.419388));
listPoints.add(new LatLng(39.900839, 116.419774)); // listPoints.add(new LatLng(39.900839, 116.419774));
listPoints.add(new LatLng(39.900749, 116.420043)); // listPoints.add(new LatLng(39.900749, 116.420043));
listPoints.add(new LatLng(39.900722, 116.420178)); // listPoints.add(new LatLng(39.900722, 116.420178));
listPoints.add(new LatLng(39.900667, 116.42034)); // listPoints.add(new LatLng(39.900667, 116.42034));
listPoints.add(new LatLng(39.900619, 116.420519)); // listPoints.add(new LatLng(39.900619, 116.420519));
listPoints.add(new LatLng(39.900557, 116.420744)); // listPoints.add(new LatLng(39.900557, 116.420744));
listPoints.add(new LatLng(39.900515, 116.420915)); // listPoints.add(new LatLng(39.900515, 116.420915));
listPoints.add(new LatLng(39.900488, 116.421067)); // listPoints.add(new LatLng(39.900488, 116.421067));
listPoints.add(new LatLng(39.900467, 116.421274)); // 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.900467, 116.421301)); // listPoints.add(new LatLng(39.900467, 116.421301));
listPoints.add(new LatLng(39.900674, 116.428856)); // listPoints.add(new LatLng(39.900674, 116.428856));
listPoints.add(new LatLng(39.900681, 116.429287)); // listPoints.add(new LatLng(39.900681, 116.429287));
listPoints.add(new LatLng(39.900674, 116.429287)); // listPoints.add(new LatLng(39.900674, 116.429287));
listPoints.add(new LatLng(39.900694, 116.429745)); // listPoints.add(new LatLng(39.900694, 116.429745));
listPoints.add(new LatLng(39.900736, 116.43173)); // listPoints.add(new LatLng(39.900736, 116.43173));
listPoints.add(new LatLng(39.900729, 116.433132)); // listPoints.add(new LatLng(39.900729, 116.433132));
listPoints.add(new LatLng(39.900729, 116.433267)); // listPoints.add(new LatLng(39.900729, 116.433267));
listPoints.add(new LatLng(39.900743, 116.433545)); // listPoints.add(new LatLng(39.900743, 116.433545));
} // }
//
private static void addLine1(List<LatLng> listPoints) { // private static void addLine1(List<LatLng> listPoints) {
listPoints.add(new LatLng(39.976748, 116.382314)); // listPoints.add(new LatLng(39.976748, 116.382314));
listPoints.add(new LatLng(39.976851, 116.388045)); // listPoints.add(new LatLng(39.976851, 116.388045));
listPoints.add(new LatLng(39.976892, 116.393597)); // listPoints.add(new LatLng(39.976892, 116.393597));
listPoints.add(new LatLng(39.976906, 116.394199)); // listPoints.add(new LatLng(39.976906, 116.394199));
listPoints.add(new LatLng(39.976906, 116.394298)); // listPoints.add(new LatLng(39.976906, 116.394298));
listPoints.add(new LatLng(39.976996, 116.405949)); // listPoints.add(new LatLng(39.976996, 116.405949));
listPoints.add(new LatLng(39.977016, 116.407692)); // 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.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.417591));
listPoints.add(new LatLng(39.977127, 116.417582)); // listPoints.add(new LatLng(39.977127, 116.417582));
listPoints.add(new LatLng(39.969017, 116.417932)); // listPoints.add(new LatLng(39.969017, 116.417932));
listPoints.add(new LatLng(39.968549, 116.417977)); // listPoints.add(new LatLng(39.968549, 116.417977));
listPoints.add(new LatLng(39.9666, 116.418094)); // listPoints.add(new LatLng(39.9666, 116.418094));
listPoints.add(new LatLng(39.965099, 116.418193)); // listPoints.add(new LatLng(39.965099, 116.418193));
listPoints.add(new LatLng(39.963957, 116.418256)); // listPoints.add(new LatLng(39.963957, 116.418256));
listPoints.add(new LatLng(39.961533, 116.418301)); // listPoints.add(new LatLng(39.961533, 116.418301));
listPoints.add(new LatLng(39.959343, 116.418301)); // listPoints.add(new LatLng(39.959343, 116.418301));
listPoints.add(new LatLng(39.95422, 116.418732)); // listPoints.add(new LatLng(39.95422, 116.418732));
listPoints.add(new LatLng(39.952375, 116.418858)); // listPoints.add(new LatLng(39.952375, 116.418858));
listPoints.add(new LatLng(39.952106, 116.418876)); // listPoints.add(new LatLng(39.952106, 116.418876));
listPoints.add(new LatLng(39.95192, 116.418849)); // listPoints.add(new LatLng(39.95192, 116.418849));
listPoints.add(new LatLng(39.951693, 116.418696)); // listPoints.add(new LatLng(39.951693, 116.418696));
listPoints.add(new LatLng(39.951528, 116.418525)); // listPoints.add(new LatLng(39.951528, 116.418525));
listPoints.add(new LatLng(39.951383, 116.41822)); // listPoints.add(new LatLng(39.951383, 116.41822));
listPoints.add(new LatLng(39.95128, 116.417941)); // listPoints.add(new LatLng(39.95128, 116.417941));
listPoints.add(new LatLng(39.951239, 116.417609)); // listPoints.add(new LatLng(39.951239, 116.417609));
listPoints.add(new LatLng(39.951218, 116.417312)); // listPoints.add(new LatLng(39.951218, 116.417312));
listPoints.add(new LatLng(39.951218, 116.417088)); // listPoints.add(new LatLng(39.951218, 116.417088));
listPoints.add(new LatLng(39.951197, 116.416899)); // listPoints.add(new LatLng(39.951197, 116.416899));
listPoints.add(new LatLng(39.951115, 116.416675)); // listPoints.add(new LatLng(39.951115, 116.416675));
listPoints.add(new LatLng(39.950984, 116.416513)); // listPoints.add(new LatLng(39.950984, 116.416513));
listPoints.add(new LatLng(39.950839, 116.416378)); // listPoints.add(new LatLng(39.950839, 116.416378));
listPoints.add(new LatLng(39.950639, 116.41627)); // listPoints.add(new LatLng(39.950639, 116.41627));
listPoints.add(new LatLng(39.950426, 116.416217)); // listPoints.add(new LatLng(39.950426, 116.416217));
listPoints.add(new LatLng(39.950095, 116.416243)); // listPoints.add(new LatLng(39.950095, 116.416243));
listPoints.add(new LatLng(39.948835, 116.416486)); // listPoints.add(new LatLng(39.948835, 116.416486));
listPoints.add(new LatLng(39.948697, 116.416486)); // listPoints.add(new LatLng(39.948697, 116.416486));
listPoints.add(new LatLng(39.945557, 116.416648)); // listPoints.add(new LatLng(39.945557, 116.416648));
listPoints.add(new LatLng(39.941686, 116.416791)); // listPoints.add(new LatLng(39.941686, 116.416791));
listPoints.add(new LatLng(39.941005, 116.4168)); // listPoints.add(new LatLng(39.941005, 116.4168));
listPoints.add(new LatLng(39.938442, 116.416944)); // listPoints.add(new LatLng(39.938442, 116.416944));
listPoints.add(new LatLng(39.936045, 116.417016)); // listPoints.add(new LatLng(39.936045, 116.417016));
listPoints.add(new LatLng(39.933662, 116.417142)); // listPoints.add(new LatLng(39.933662, 116.417142));
listPoints.add(new LatLng(39.929247, 116.417295)); // listPoints.add(new LatLng(39.929247, 116.417295));
listPoints.add(new LatLng(39.927683, 116.417393)); // listPoints.add(new LatLng(39.927683, 116.417393));
listPoints.add(new LatLng(39.926553, 116.417438)); // listPoints.add(new LatLng(39.926553, 116.417438));
listPoints.add(new LatLng(39.924583, 116.417492)); // listPoints.add(new LatLng(39.924583, 116.417492));
listPoints.add(new LatLng(39.924369, 116.417492)); // listPoints.add(new LatLng(39.924369, 116.417492));
listPoints.add(new LatLng(39.921779, 116.417573)); // listPoints.add(new LatLng(39.921779, 116.417573));
listPoints.add(new LatLng(39.919044, 116.417654)); // listPoints.add(new LatLng(39.919044, 116.417654));
listPoints.add(new LatLng(39.917404, 116.417708)); // listPoints.add(new LatLng(39.917404, 116.417708));
listPoints.add(new LatLng(39.917287, 116.417717)); // listPoints.add(new LatLng(39.917287, 116.417717));
listPoints.add(new LatLng(39.916233, 116.417825)); // listPoints.add(new LatLng(39.916233, 116.417825));
listPoints.add(new LatLng(39.913904, 116.417807)); // listPoints.add(new LatLng(39.913904, 116.417807));
} // }
} }

View File

@ -1,87 +1,87 @@
package cc.winboll.studio.positions.demo.polyline; package cc.winboll.studio.positions.demo.polyline;
import android.os.Bundle; //import android.os.Bundle;
//
import cc.winboll.studio.positions.demo.basic.SupportMapFragmentActivity; //import cc.winboll.studio.positions.demo.basic.SupportMapFragmentActivity;
import com.tencent.tencentmap.mapsdk.maps.model.BitmapDescriptorFactory; //import com.tencent.tencentmap.mapsdk.maps.model.BitmapDescriptorFactory;
import com.tencent.tencentmap.mapsdk.maps.model.LatLng; //import com.tencent.tencentmap.mapsdk.maps.model.LatLng;
import com.tencent.tencentmap.mapsdk.maps.model.Polyline; //import com.tencent.tencentmap.mapsdk.maps.model.Polyline;
import com.tencent.tencentmap.mapsdk.maps.model.PolylineOptions; //import com.tencent.tencentmap.mapsdk.maps.model.PolylineOptions;
//
import java.util.ArrayList; //import java.util.ArrayList;
import java.util.List; //import java.util.List;
//
public class PolylineOptionsActivity extends SupportMapFragmentActivity { //public class PolylineOptionsActivity extends SupportMapFragmentActivity {
@Override // @Override
protected void onCreate(Bundle savedInstanceState) { // protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); // super.onCreate(savedInstanceState);
Polyline polyline = tencentMap.addPolyline(polylineOptions); // Polyline polyline = tencentMap.addPolyline(polylineOptions);
Polyline newPolyline = tencentMap.addPolyline(newPolylineOptions); // Polyline newPolyline = tencentMap.addPolyline(newPolylineOptions);
polyline.pattern(patternLine(patterns)); //设置虚线样式 // polyline.pattern(patternLine(patterns)); //设置虚线样式
} // }
//
private int[] patterns = {10, 15, 20}; // private int[] patterns = {10, 15, 20};
private List<Integer> patternLine(int [] patterns){ // private List<Integer> patternLine(int [] patterns){
List<Integer> patternLine = new ArrayList<>(); // List<Integer> patternLine = new ArrayList<>();
if (patterns == null) // if (patterns == null)
return patternLine; // return patternLine;
for (int i = 0; i < patterns.length; i++) // for (int i = 0; i < patterns.length; i++)
patternLine.add(patterns[i]); // patternLine.add(patterns[i]);
return patternLine; // return patternLine;
} // }
//
//
private List<LatLng> transferArrayToList(LatLng[] latLngs){ //坐标数组与List转换 // private List<LatLng> transferArrayToList(LatLng[] latLngs){ //坐标数组与List转换
List<LatLng> list = new ArrayList<>(); // List<LatLng> list = new ArrayList<>();
if (latLngs == null) // if (latLngs == null)
return list; // return list;
for (int i = 0; i < latLngs.length; i++) // for (int i = 0; i < latLngs.length; i++)
list.add(latLngs[i]); // list.add(latLngs[i]);
//
return list; // return list;
//
} // }
//
private LatLng[] latLngs = { // private LatLng[] latLngs = {
new LatLng(39.984864, 116.305756), // new LatLng(39.984864, 116.305756),
new LatLng(39.983618, 116.305848), // new LatLng(39.983618, 116.305848),
new LatLng(39.982347, 116.305966), // new LatLng(39.982347, 116.305966),
new LatLng(39.982412, 116.308111), // new LatLng(39.982412, 116.308111),
new LatLng(39.984122, 116.308224), // new LatLng(39.984122, 116.308224),
new LatLng(39.984955, 116.308099), // new LatLng(39.984955, 116.308099),
new LatLng(39.984864, 116.305756) // new LatLng(39.984864, 116.305756)
}; // };
//
private LatLng[] newLatLngs = { // private LatLng[] newLatLngs = {
new LatLng(39.984864, 116.305756), // new LatLng(39.984864, 116.305756),
new LatLng(39.983618, 116.305848), // new LatLng(39.983618, 116.305848),
new LatLng(39.982347, 116.305966), // new LatLng(39.982347, 116.305966),
new LatLng(39.982412, 116.308111), // new LatLng(39.982412, 116.308111),
new LatLng(39.984122, 116.308224), // new LatLng(39.984122, 116.308224),
new LatLng(39.984955, 116.308099), // new LatLng(39.984955, 116.308099),
new LatLng(39.984864, 116.305756) // new LatLng(39.984864, 116.305756)
}; // };
private PolylineOptions polylineOptions = new PolylineOptions(). // private PolylineOptions polylineOptions = new PolylineOptions().
addAll(transferArrayToList(latLngs)). //添加顶点 // addAll(transferArrayToList(latLngs)). //添加顶点
alpha(0.5f). //设置透明度 // alpha(0.5f). //设置透明度
arrow(true). //导航用 接口 // arrow(true). //导航用 接口
arrowSpacing(110). // 设置方向箭头间距 // arrowSpacing(110). // 设置方向箭头间距
arrowTexture(BitmapDescriptorFactory.fromAsset("color_arrow_texture.png")). // 设置箭头纹理 // arrowTexture(BitmapDescriptorFactory.fromAsset("color_arrow_texture.png")). // 设置箭头纹理
borderColor(0xaa323456). //设置描边颜色 // borderColor(0xaa323456). //设置描边颜色
borderWidth(1f). //设置描边宽度 // borderWidth(1f). //设置描边宽度
clickable(true). //可点击 // clickable(true). //可点击
color(PolylineOptions.Colors.LIGHT_BLUE). //线的颜色 // color(PolylineOptions.Colors.LIGHT_BLUE). //线的颜色
colorTexture(BitmapDescriptorFactory.fromAsset("color_texture.png")). //颜色纹理 // colorTexture(BitmapDescriptorFactory.fromAsset("color_texture.png")). //颜色纹理
lineCap(true). //路线是否显示半圆端点 // lineCap(true). //路线是否显示半圆端点
lineType(PolylineOptions.LineType.LINE_TYPE_MULTICOLORLINE). //设置线的类型 // lineType(PolylineOptions.LineType.LINE_TYPE_MULTICOLORLINE). //设置线的类型
visible(true). //设置折线可见性 // visible(true). //设置折线可见性
width(10f). //设置线的宽度 // width(10f). //设置线的宽度
zIndex(0); //堆叠顺序越大优先级越高 // zIndex(0); //堆叠顺序越大优先级越高
//
//
private PolylineOptions newPolylineOptions = new PolylineOptions().add(newLatLngs). // private PolylineOptions newPolylineOptions = new PolylineOptions().add(newLatLngs).
lineType(PolylineOptions.LineType.LINE_TYPE_DOTTEDLINE). // lineType(PolylineOptions.LineType.LINE_TYPE_DOTTEDLINE).
visible(true). // visible(true).
pattern(patternLine(patterns)). // pattern(patternLine(patterns)).
zIndex(1); // zIndex(1);
} //}

View File

@ -21,154 +21,154 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
public class DistrictActivity extends SupportMapFragmentActivity { public class DistrictActivity extends SupportMapFragmentActivity {
private Spinner spProvince; // private Spinner spProvince;
private Spinner spCity; // private Spinner spCity;
private Spinner spDistrict; // private Spinner spDistrict;
private TextView tvResult; // private TextView tvResult;
private List<LatLng> latLngs = new ArrayList<>(); // private List<LatLng> latLngs = new ArrayList<>();
//
@Override // @Override
protected void onCreate(Bundle savedInstanceState) { // protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); // super.onCreate(savedInstanceState);
initView(); // initView();
initSpinner(); // initSpinner();
} // }
//
protected void initView() { // protected void initView() {
spProvince = (Spinner) findViewById(R.id.sp_province); // spProvince = (Spinner) findViewById(R.id.sp_province);
spCity = (Spinner) findViewById(R.id.sp_city); // spCity = (Spinner) findViewById(R.id.sp_city);
spDistrict = (Spinner) findViewById(R.id.sp_district); // spDistrict = (Spinner) findViewById(R.id.sp_district);
tvResult = (TextView) findViewById(R.id.tv_result); // tvResult = (TextView) findViewById(R.id.tv_result);
spProvince.setVisibility(View.VISIBLE); // spProvince.setVisibility(View.VISIBLE);
spCity.setVisibility(View.VISIBLE); // spCity.setVisibility(View.VISIBLE);
spDistrict.setVisibility(View.VISIBLE); // spDistrict.setVisibility(View.VISIBLE);
tvResult.setVisibility(View.VISIBLE); // tvResult.setVisibility(View.VISIBLE);
} // }
//
protected void initSpinner() { // protected void initSpinner() {
//
//初始化行政区划像北京市等只有市和区两级的数据可能会输出错误id // //初始化行政区划像北京市等只有市和区两级的数据可能会输出错误id
getDistrict(0, R.id.sp_province); // getDistrict(0, R.id.sp_province);
AdapterView.OnItemSelectedListener onItemSelectedListener = new AdapterView.OnItemSelectedListener() { // AdapterView.OnItemSelectedListener onItemSelectedListener = new AdapterView.OnItemSelectedListener() {
//
@Override // @Override
public void onItemSelected(AdapterView<?> parent, View view, // public void onItemSelected(AdapterView<?> parent, View view,
int position, long id) { // int position, long id) {
// TODO Auto-generated method stub // // TODO Auto-generated method stub
switch (parent.getId()) { // switch (parent.getId()) {
case R.id.sp_province: // case R.id.sp_province:
getDistrict(((List<Integer>) parent.getTag()). // getDistrict(((List<Integer>) parent.getTag()).
get(position).intValue(), R.id.sp_city); // get(position).intValue(), R.id.sp_city);
break; // break;
case R.id.sp_city: // case R.id.sp_city:
getDistrict(((List<Integer>) parent.getTag()). // getDistrict(((List<Integer>) parent.getTag()).
get(position).intValue(), R.id.sp_district); // get(position).intValue(), R.id.sp_district);
break; // break;
case R.id.sp_district: // case R.id.sp_district:
getDistrict(((List<Integer>) parent.getTag()). // getDistrict(((List<Integer>) parent.getTag()).
get(position).intValue(), R.id.sp_district); // get(position).intValue(), R.id.sp_district);
tencentMap.moveCamera(CameraUpdateFactory.newCameraPosition(new CameraPosition(latLngs.get(position), 15f, 0, 0))); // tencentMap.moveCamera(CameraUpdateFactory.newCameraPosition(new CameraPosition(latLngs.get(position), 15f, 0, 0)));
default: // default:
break; // break;
} // }
} // }
//
@Override // @Override
public void onNothingSelected(AdapterView<?> parent) { // public void onNothingSelected(AdapterView<?> parent) {
// TODO Auto-generated method stub // // TODO Auto-generated method stub
//
} // }
}; // };
spProvince.setOnItemSelectedListener(onItemSelectedListener); // spProvince.setOnItemSelectedListener(onItemSelectedListener);
spCity.setOnItemSelectedListener(onItemSelectedListener); // spCity.setOnItemSelectedListener(onItemSelectedListener);
spDistrict.setOnItemSelectedListener(onItemSelectedListener); // spDistrict.setOnItemSelectedListener(onItemSelectedListener);
} // }
//
/** // /**
* 获取行政区划 // * 获取行政区划
*/ // */
protected void getDistrict(int pDistrict, final int spId) { // protected void getDistrict(int pDistrict, final int spId) {
TencentSearch tencentSearch = new TencentSearch(this); // TencentSearch tencentSearch = new TencentSearch(this);
DistrictChildrenParam districtChildrenParam = new DistrictChildrenParam(); // DistrictChildrenParam districtChildrenParam = new DistrictChildrenParam();
Log.d("eqrwqeqewr", "getDistrict: " + spId); // Log.d("eqrwqeqewr", "getDistrict: " + spId);
//如果不设置id则获取全部数据 // //如果不设置id则获取全部数据
if (spId != R.id.sp_province && spId == R.id.sp_city) { // if (spId != R.id.sp_province && spId == R.id.sp_city) {
districtChildrenParam.id(pDistrict); // districtChildrenParam.id(pDistrict);
} // }
if (spId != R.id.sp_province && spId != R.id.sp_city) { // if (spId != R.id.sp_province && spId != R.id.sp_city) {
districtChildrenParam.id(pDistrict); // districtChildrenParam.id(pDistrict);
} // }
//
tencentSearch.getDistrictChildren(districtChildrenParam, new HttpResponseListener<BaseObject>() { // tencentSearch.getDistrictChildren(districtChildrenParam, new HttpResponseListener<BaseObject>() {
//
@Override // @Override
public void onSuccess(int arg0, BaseObject arg1) { // public void onSuccess(int arg0, BaseObject arg1) {
// TODO Auto-generated method stub // // TODO Auto-generated method stub
if (arg1 == null) { // if (arg1 == null) {
return; // return;
} // }
DistrictResultObject obj = (DistrictResultObject) arg1; // DistrictResultObject obj = (DistrictResultObject) arg1;
switch (spId) { // switch (spId) {
case R.id.sp_province: // case R.id.sp_province:
setDistrictAdapter(spProvince, obj); // setDistrictAdapter(spProvince, obj);
break; // break;
case R.id.sp_city: // case R.id.sp_city:
setDistrictAdapter(spCity, obj); // setDistrictAdapter(spCity, obj);
break; // break;
case R.id.sp_district: // case R.id.sp_district:
setDistrictAdapter(spDistrict, obj); // setDistrictAdapter(spDistrict, obj);
break; // break;
//
default: // default:
break; // break;
} // }
} // }
//
@Override // @Override
public void onFailure(int arg0, String arg1, Throwable arg2) { // public void onFailure(int arg0, String arg1, Throwable arg2) {
// TODO Auto-generated method stub // // TODO Auto-generated method stub
// printResult(arg1); // // printResult(arg1);
} // }
}); // });
} // }
//
/** // /**
* 设置行政区划的adapter // * 设置行政区划的adapter
* // *
* @param spinner 要设置adapter的spinner // * @param spinner 要设置adapter的spinner
* @param obj 用于填充adapter的数据源 // * @param obj 用于填充adapter的数据源
*/ // */
protected void setDistrictAdapter(Spinner spinner, final DistrictResultObject obj) { // protected void setDistrictAdapter(Spinner spinner, final DistrictResultObject obj) {
List<String> names = new ArrayList<String>(); // List<String> names = new ArrayList<String>();
List<Integer> ids = new ArrayList<Integer>(); // List<Integer> ids = new ArrayList<Integer>();
latLngs.clear(); // latLngs.clear();
final List<DistrictResultObject.DistrictResult> districtResults = obj.result.get(0); // final List<DistrictResultObject.DistrictResult> districtResults = obj.result.get(0);
for (final DistrictResultObject.DistrictResult result : districtResults) { // for (final DistrictResultObject.DistrictResult result : districtResults) {
names.add(result.fullname); // names.add(result.fullname);
ids.add(result.id); // ids.add(result.id);
latLngs.add(result.latLng); // latLngs.add(result.latLng);
Log.d("位置", "setDistrictAdapter: " + result.fullname); // Log.d("位置", "setDistrictAdapter: " + result.fullname);
//
} // }
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, // ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_spinner_item, names); // android.R.layout.simple_spinner_item, names);
spinner.setAdapter(adapter); // spinner.setAdapter(adapter);
//将行政区划编码附到spinner方便后续查询 // //将行政区划编码附到spinner方便后续查询
spinner.setTag(ids); // spinner.setTag(ids);
//
} // }
//
//
protected void printResult(final String result) { // protected void printResult(final String result) {
runOnUiThread(new Runnable() { // runOnUiThread(new Runnable() {
//
@Override // @Override
public void run() { // public void run() {
// TODO Auto-generated method stub // // TODO Auto-generated method stub
tvResult.setText(result); // tvResult.setText(result);
} // }
}); // });
} // }
//
} }

View File

@ -18,58 +18,58 @@ import com.tencent.tencentmap.mapsdk.maps.model.PolylineOptions;
import java.util.List; import java.util.List;
public class DrivingRouteActivity extends SupportMapFragmentActivity { public class DrivingRouteActivity extends SupportMapFragmentActivity {
@Override // @Override
protected void onCreate(Bundle savedInstanceState) { // protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); // super.onCreate(savedInstanceState);
CameraUpdate cameraSigma = // CameraUpdate cameraSigma =
CameraUpdateFactory.newCameraPosition(new CameraPosition( // CameraUpdateFactory.newCameraPosition(new CameraPosition(
new LatLng(24.66493, 117.09568), // new LatLng(24.66493, 117.09568),
15, // 15,
0f, // 0f,
0f)); // 0f));
//移动地图 // //移动地图
tencentMap.moveCamera(cameraSigma); // tencentMap.moveCamera(cameraSigma);
getDrivingRoute(); // getDrivingRoute();
} // }
//
private LatLng fromPoint = new LatLng(24.66493, 117.09568); // 起点坐标 // private LatLng fromPoint = new LatLng(24.66493, 117.09568); // 起点坐标
private LatLng toPoint = new LatLng(26.8857, 120.00514); //终点坐标 // private LatLng toPoint = new LatLng(26.8857, 120.00514); //终点坐标
//
/** // /**
* 获取驾车路线规划 // * 获取驾车路线规划
*/ // */
private void getDrivingRoute() { // private void getDrivingRoute() {
long l = (System.currentTimeMillis() / 1000)+1000; // long l = (System.currentTimeMillis() / 1000)+1000;
Log.d("时间戳", "getDrivingRoute: " + l); // Log.d("时间戳", "getDrivingRoute: " + l);
DrivingParam drivingParam = new DrivingParam(fromPoint, toPoint); //创建导航参数 // DrivingParam drivingParam = new DrivingParam(fromPoint, toPoint); //创建导航参数
drivingParam.roadType(DrivingParam.RoadType.ON_MAIN_ROAD_BELOW_BRIDGE); // drivingParam.roadType(DrivingParam.RoadType.ON_MAIN_ROAD_BELOW_BRIDGE);
drivingParam.heading(90); // drivingParam.heading(90);
drivingParam.accuracy(30); // drivingParam.accuracy(30);
//drivingParam.departureTime(l) // //drivingParam.departureTime(l)
TencentSearch tencentSearch = new TencentSearch(this); // TencentSearch tencentSearch = new TencentSearch(this);
tencentSearch.getRoutePlan(drivingParam, new HttpResponseListener<DrivingResultObject>() { // tencentSearch.getRoutePlan(drivingParam, new HttpResponseListener<DrivingResultObject>() {
//
@Override // @Override
public void onSuccess(int i, DrivingResultObject drivingResultObject) { // public void onSuccess(int i, DrivingResultObject drivingResultObject) {
if (drivingResultObject == null) { // if (drivingResultObject == null) {
return; // return;
} // }
for (DrivingResultObject.Route route : drivingResultObject.result.routes) { // for (DrivingResultObject.Route route : drivingResultObject.result.routes) {
List<LatLng> lines = route.polyline; // List<LatLng> lines = route.polyline;
tencentMap.addPolyline(new PolylineOptions().addAll(lines).color(0x22ff0000)); // tencentMap.addPolyline(new PolylineOptions().addAll(lines).color(0x22ff0000));
tencentMap.moveCamera(CameraUpdateFactory.newLatLngBounds(LatLngBounds.builder() // tencentMap.moveCamera(CameraUpdateFactory.newLatLngBounds(LatLngBounds.builder()
.include(route.polyline).build(), 100)); // .include(route.polyline).build(), 100));
tencentMap.moveCamera(CameraUpdateFactory.newLatLngBounds(LatLngBounds.builder() // tencentMap.moveCamera(CameraUpdateFactory.newLatLngBounds(LatLngBounds.builder()
.include(lines).build(), 100)); // .include(lines).build(), 100));
} // }
} // }
//
@Override // @Override
public void onFailure(int i, String s, Throwable throwable) { // public void onFailure(int i, String s, Throwable throwable) {
//
} // }
}); // });
} // }
} }

View File

@ -25,162 +25,162 @@ import com.tencent.tencentmap.mapsdk.maps.model.MarkerOptions;
public class GeoCoderActivity extends SupportMapFragmentActivity { public class GeoCoderActivity extends SupportMapFragmentActivity {
private EditText etGeocoder; // private EditText etGeocoder;
private Button btnGeocoder; // private Button btnGeocoder;
private EditText etRegeocoder; // private EditText etRegeocoder;
private Button btnRegeocoder; // private Button btnRegeocoder;
private TextView tvResult; // private TextView tvResult;
//
@Override // @Override
protected void onCreate(Bundle savedInstanceState) { // protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); // super.onCreate(savedInstanceState);
initView(); // initView();
} // }
//
//
private void initView(){ // private void initView(){
etGeocoder = (EditText) findViewById(R.id.et_geocoder); // etGeocoder = (EditText) findViewById(R.id.et_geocoder);
btnGeocoder = (Button) findViewById(R.id.btn_geocoder); // btnGeocoder = (Button) findViewById(R.id.btn_geocoder);
etRegeocoder = (EditText) findViewById(R.id.et_regeocoder); // etRegeocoder = (EditText) findViewById(R.id.et_regeocoder);
btnRegeocoder = (Button) findViewById(R.id.btn_regeocoder); // btnRegeocoder = (Button) findViewById(R.id.btn_regeocoder);
etGeocoder.setVisibility(View.VISIBLE); // etGeocoder.setVisibility(View.VISIBLE);
btnGeocoder.setVisibility(View.VISIBLE); // btnGeocoder.setVisibility(View.VISIBLE);
etRegeocoder.setVisibility(View.VISIBLE); // etRegeocoder.setVisibility(View.VISIBLE);
btnRegeocoder.setVisibility(View.VISIBLE); // btnRegeocoder.setVisibility(View.VISIBLE);
tvResult = (TextView) findViewById(R.id.tv_result); // tvResult = (TextView) findViewById(R.id.tv_result);
tvResult.setVisibility(View.VISIBLE); // tvResult.setVisibility(View.VISIBLE);
btnGeocoder.setOnClickListener(new View.OnClickListener() { // btnGeocoder.setOnClickListener(new View.OnClickListener() {
@Override // @Override
public void onClick(View view) { // public void onClick(View view) {
geocoder(); // geocoder();
} // }
}); // });
//
btnRegeocoder.setOnClickListener(new View.OnClickListener() { // btnRegeocoder.setOnClickListener(new View.OnClickListener() {
@Override // @Override
public void onClick(View view) { // public void onClick(View view) {
reGeocoder(); // reGeocoder();
} // }
}); // });
} // }
/** // /**
*地理编码 // *地理编码
*/ // */
protected void geocoder() { // protected void geocoder() {
TencentSearch tencentSearch = new TencentSearch(this); // TencentSearch tencentSearch = new TencentSearch(this);
String address = etGeocoder.getText().toString(); // String address = etGeocoder.getText().toString();
Address2GeoParam address2GeoParam = // Address2GeoParam address2GeoParam =
new Address2GeoParam(address).region("北京"); // new Address2GeoParam(address).region("北京");
tencentSearch.address2geo(address2GeoParam, new HttpResponseListener<BaseObject>() { // tencentSearch.address2geo(address2GeoParam, new HttpResponseListener<BaseObject>() {
//
@Override // @Override
public void onSuccess(int arg0, BaseObject arg1) { // public void onSuccess(int arg0, BaseObject arg1) {
// TODO Auto-generated method stub // // TODO Auto-generated method stub
if (arg1 == null) { // if (arg1 == null) {
return; // return;
} // }
Address2GeoResultObject obj = (Address2GeoResultObject)arg1; // Address2GeoResultObject obj = (Address2GeoResultObject)arg1;
StringBuilder sb = new StringBuilder(); // StringBuilder sb = new StringBuilder();
sb.append("地址解析"); // sb.append("地址解析");
if (obj.result.latLng != null) { // if (obj.result.latLng != null) {
sb.append("\n坐标" + obj.result.latLng.toString()); // sb.append("\n坐标" + obj.result.latLng.toString());
} else { // } else {
sb.append("\n无坐标"); // sb.append("\n无坐标");
} // }
printResult(sb.toString()); // printResult(sb.toString());
tencentMap.moveCamera(CameraUpdateFactory.newCameraPosition(new CameraPosition(obj.result.latLng,15f, 0, 0))); // tencentMap.moveCamera(CameraUpdateFactory.newCameraPosition(new CameraPosition(obj.result.latLng,15f, 0, 0)));
tencentMap.addMarker(new MarkerOptions() // tencentMap.addMarker(new MarkerOptions()
.position(obj.result.latLng)); // .position(obj.result.latLng));
} // }
//
@Override // @Override
public void onFailure(int arg0, String arg1, Throwable arg2) { // public void onFailure(int arg0, String arg1, Throwable arg2) {
// TODO Auto-generated method stub // // TODO Auto-generated method stub
printResult(arg1); // printResult(arg1);
} // }
}); // });
} // }
//
/** // /**
* 逆地理编码 // * 逆地理编码
*/ // */
protected void reGeocoder() { // protected void reGeocoder() {
String str = etRegeocoder.getText().toString().trim(); // String str = etRegeocoder.getText().toString().trim();
LatLng latLng = str2Coordinate(this, str); // LatLng latLng = str2Coordinate(this, str);
if (latLng == null) { // if (latLng == null) {
return; // return;
} // }
TencentSearch tencentSearch = new TencentSearch(this); // TencentSearch tencentSearch = new TencentSearch(this);
//还可以传入其他坐标系的坐标不过需要用coord_type()指明所用类型 // //还可以传入其他坐标系的坐标不过需要用coord_type()指明所用类型
//这里设置返回周边poi列表可以在一定程度上满足用户获取指定坐标周边poi的需求 // //这里设置返回周边poi列表可以在一定程度上满足用户获取指定坐标周边poi的需求
Geo2AddressParam geo2AddressParam = new Geo2AddressParam(latLng).getPoi(true) // Geo2AddressParam geo2AddressParam = new Geo2AddressParam(latLng).getPoi(true)
.setPoiOptions(new Geo2AddressParam.PoiOptions() // .setPoiOptions(new Geo2AddressParam.PoiOptions()
.setRadius(1000).setCategorys("面包") // .setRadius(1000).setCategorys("面包")
.setPolicy(Geo2AddressParam.PoiOptions.POLICY_O2O)); // .setPolicy(Geo2AddressParam.PoiOptions.POLICY_O2O));
tencentSearch.geo2address(geo2AddressParam, new HttpResponseListener<BaseObject>() { // tencentSearch.geo2address(geo2AddressParam, new HttpResponseListener<BaseObject>() {
//
@Override // @Override
public void onSuccess(int arg0, BaseObject arg1) { // public void onSuccess(int arg0, BaseObject arg1) {
// TODO Auto-generated method stub // // TODO Auto-generated method stub
if (arg1 == null) { // if (arg1 == null) {
return; // return;
} // }
Geo2AddressResultObject obj = (Geo2AddressResultObject)arg1; // Geo2AddressResultObject obj = (Geo2AddressResultObject)arg1;
StringBuilder sb = new StringBuilder(); // StringBuilder sb = new StringBuilder();
sb.append("逆地址解析"); // sb.append("逆地址解析");
sb.append("\n地址" + obj.result.address); // sb.append("\n地址" + obj.result.address);
sb.append("\npois:"); // sb.append("\npois:");
for (Poi poi : obj.result.pois) { // for (Poi poi : obj.result.pois) {
sb.append("\n\t" + poi.title); // sb.append("\n\t" + poi.title);
tencentMap.addMarker(new MarkerOptions() // tencentMap.addMarker(new MarkerOptions()
.position(poi.latLng) //标注的位置 // .position(poi.latLng) //标注的位置
.title(poi.title) //标注的InfoWindow的标题 // .title(poi.title) //标注的InfoWindow的标题
.snippet(poi.address) //标注的InfoWindow的内容 // .snippet(poi.address) //标注的InfoWindow的内容
); // );
} // }
//printResult(sb.toString()); // //printResult(sb.toString());
} // }
//
@Override // @Override
public void onFailure(int arg0, String arg1, Throwable arg2) { // public void onFailure(int arg0, String arg1, Throwable arg2) {
// TODO Auto-generated method stub // // TODO Auto-generated method stub
printResult(arg1); // printResult(arg1);
} // }
}); // });
} // }
//
//
/** // /**
* 由字符串获取坐标 // * 由字符串获取坐标
* @param context // * @param context
* @param str // * @param str
* @return // * @return
*/ // */
public static LatLng str2Coordinate(Context context, String str) { // public static LatLng str2Coordinate(Context context, String str) {
if (!str.contains(",")) { // if (!str.contains(",")) {
Toast.makeText(context, "经纬度用\",\"分割", Toast.LENGTH_SHORT).show(); // Toast.makeText(context, "经纬度用\",\"分割", Toast.LENGTH_SHORT).show();
return null; // return null;
} // }
String[] strs = str.split(","); // String[] strs = str.split(",");
double lat = 0; // double lat = 0;
double lng = 0; // double lng = 0;
try { // try {
lat = Double.parseDouble(strs[0]); // lat = Double.parseDouble(strs[0]);
lng = Double.parseDouble(strs[1]); // lng = Double.parseDouble(strs[1]);
} catch (NumberFormatException e) { // } catch (NumberFormatException e) {
Toast.makeText(context, e.toString(), Toast.LENGTH_SHORT).show(); // Toast.makeText(context, e.toString(), Toast.LENGTH_SHORT).show();
return null; // return null;
} // }
return new LatLng(lat, lng); // return new LatLng(lat, lng);
} // }
protected void printResult(final String result) { // protected void printResult(final String result) {
runOnUiThread(new Runnable() { // runOnUiThread(new Runnable() {
//
@Override // @Override
public void run() { // public void run() {
// TODO Auto-generated method stub // // TODO Auto-generated method stub
tvResult.setText(result); // tvResult.setText(result);
} // }
}); // });
} // }
} }

View File

@ -34,272 +34,272 @@ import java.lang.ref.WeakReference;
import java.util.List; import java.util.List;
public class SearchBasicActivity extends SupportMapFragmentActivity { public class SearchBasicActivity extends SupportMapFragmentActivity {
private EditText etSearch; // private EditText etSearch;
private Button btnSearch; // private Button btnSearch;
private ListView lvSuggesion; // private ListView lvSuggesion;
private SuggestionAdapter suggestionAdapter; // private SuggestionAdapter suggestionAdapter;
private final int MSG_SUGGESTION = 10000; // private final int MSG_SUGGESTION = 10000;
private final MyHandler handler = new MyHandler(this); // private final MyHandler handler = new MyHandler(this);
//
private static class MyHandler extends Handler { // private static class MyHandler extends Handler {
private final WeakReference<SearchBasicActivity> mActivity; // private final WeakReference<SearchBasicActivity> mActivity;
//
public MyHandler(SearchBasicActivity activity) { // public MyHandler(SearchBasicActivity activity) {
// TODO Auto-generated constructor stub // // TODO Auto-generated constructor stub
mActivity = new WeakReference<>(activity); // mActivity = new WeakReference<>(activity);
} // }
//
@Override // @Override
public void handleMessage(Message msg) { // public void handleMessage(Message msg) {
// TODO Auto-generated method stub // // TODO Auto-generated method stub
SearchBasicActivity activity = mActivity.get(); // SearchBasicActivity activity = mActivity.get();
if (activity != null) { // if (activity != null) {
activity.handleMessage(msg); // activity.handleMessage(msg);
} // }
} // }
} // }
@Override // @Override
protected void onCreate(Bundle savedInstanceState) { // protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); // super.onCreate(savedInstanceState);
initView(); // initView();
} // }
//
protected void initView(){ // protected void initView(){
etSearch = (EditText) findViewById(R.id.et_search_poi); // etSearch = (EditText) findViewById(R.id.et_search_poi);
btnSearch = (Button) findViewById(R.id.btn_search_poi); // btnSearch = (Button) findViewById(R.id.btn_search_poi);
etSearch.setVisibility(View.VISIBLE); // etSearch.setVisibility(View.VISIBLE);
btnSearch.setVisibility(View.VISIBLE); // btnSearch.setVisibility(View.VISIBLE);
lvSuggesion = (ListView) findViewById(R.id.lv_suggestions); // lvSuggesion = (ListView) findViewById(R.id.lv_suggestions);
//
etSearch.addTextChangedListener(textWatcher); // etSearch.addTextChangedListener(textWatcher);
etSearch.setOnFocusChangeListener(new View.OnFocusChangeListener() { // etSearch.setOnFocusChangeListener(new View.OnFocusChangeListener() {
//
@Override // @Override
public void onFocusChange(View v, boolean hasFocus) { // public void onFocusChange(View v, boolean hasFocus) {
// TODO Auto-generated method stub // // TODO Auto-generated method stub
if (!etSearch.hasFocus()) { // if (!etSearch.hasFocus()) {
lvSuggesion.setVisibility(View.GONE); // lvSuggesion.setVisibility(View.GONE);
} // }
} // }
}); // });
//
lvSuggesion.setOnItemClickListener(new AdapterView.OnItemClickListener() { // lvSuggesion.setOnItemClickListener(new AdapterView.OnItemClickListener() {
//
@Override // @Override
public void onItemClick(AdapterView<?> parent, View view, // public void onItemClick(AdapterView<?> parent, View view,
int position, long id) { // int position, long id) {
// TODO Auto-generated method stub // // TODO Auto-generated method stub
etSearch.removeTextChangedListener(textWatcher); // etSearch.removeTextChangedListener(textWatcher);
CharSequence cs = // CharSequence cs =
((TextView)view.findViewById(R.id.label)).getText(); // ((TextView)view.findViewById(R.id.label)).getText();
etSearch.setText(cs); // etSearch.setText(cs);
lvSuggesion.setVisibility(View.GONE); // lvSuggesion.setVisibility(View.GONE);
etSearch.addTextChangedListener(textWatcher); // etSearch.addTextChangedListener(textWatcher);
} // }
}); // });
//
btnSearch.setOnClickListener(new View.OnClickListener() { // btnSearch.setOnClickListener(new View.OnClickListener() {
@Override // @Override
public void onClick(View view) { // public void onClick(View view) {
searchPoi(); // searchPoi();
} // }
}); // });
} // }
//
final TextWatcher textWatcher = new TextWatcher() { // final TextWatcher textWatcher = new TextWatcher() {
//
@Override // @Override
public void onTextChanged(CharSequence s, int start, int before, int count) { // public void onTextChanged(CharSequence s, int start, int before, int count) {
// TODO Auto-generated method stub // // TODO Auto-generated method stub
suggestion(s.toString()); // suggestion(s.toString());
} // }
//
@Override // @Override
public void beforeTextChanged(CharSequence s, int start, int count, // public void beforeTextChanged(CharSequence s, int start, int count,
int after) { // int after) {
// TODO Auto-generated method stub // // TODO Auto-generated method stub
//
} // }
//
@Override // @Override
public void afterTextChanged(Editable s) { // public void afterTextChanged(Editable s) {
// TODO Auto-generated method stub // // TODO Auto-generated method stub
//
} // }
}; // };
//
//
//
/** // /**
* poi检索 // * poi检索
*/ // */
protected void searchPoi() { // protected void searchPoi() {
TencentSearch tencentSearch = new TencentSearch(this); // TencentSearch tencentSearch = new TencentSearch(this);
String keyWord = etSearch.getText().toString().trim(); // String keyWord = etSearch.getText().toString().trim();
//城市搜索 // //城市搜索
SearchParam.Region region = new SearchParam.Region("北京").//设置搜索城市 // SearchParam.Region region = new SearchParam.Region("北京").//设置搜索城市
autoExtend(false);//设置搜索范围不扩大 // autoExtend(false);//设置搜索范围不扩大
//圆形范围搜索 // //圆形范围搜索
LatLng latLng1 = new LatLng(39.984154, 116.307490); // LatLng latLng1 = new LatLng(39.984154, 116.307490);
SearchParam.Nearby nearBy = new SearchParam.Nearby(latLng1, 1000); // SearchParam.Nearby nearBy = new SearchParam.Nearby(latLng1, 1000);
//矩形搜索这里的范围是故宫 // //矩形搜索这里的范围是故宫
LatLng latLng2 = new LatLng(39.913127, 116.392164); // LatLng latLng2 = new LatLng(39.913127, 116.392164);
LatLng latLng3 = new LatLng(39.923034, 116.402078); // LatLng latLng3 = new LatLng(39.923034, 116.402078);
SearchParam.Rectangle rectangle = new SearchParam.Rectangle(latLng2, latLng3); // SearchParam.Rectangle rectangle = new SearchParam.Rectangle(latLng2, latLng3);
//
//filter()方法可以设置过滤类别 // //filter()方法可以设置过滤类别
//search接口还提供了排序方式返回条目数返回页码具体用法见文档 // //search接口还提供了排序方式返回条目数返回页码具体用法见文档
//同时也可以参考官网的webservice对应接口的说明 // //同时也可以参考官网的webservice对应接口的说明
SearchParam searchParam = new SearchParam(keyWord, region);//.pageIndex(0).pageSize(20).filter("大学,中学"); // SearchParam searchParam = new SearchParam(keyWord, region);//.pageIndex(0).pageSize(20).filter("大学,中学");
tencentSearch.search(searchParam, new HttpResponseListener<BaseObject>() { // tencentSearch.search(searchParam, new HttpResponseListener<BaseObject>() {
//
@Override // @Override
public void onFailure(int arg0, String arg2, // public void onFailure(int arg0, String arg2,
Throwable arg3) { // Throwable arg3) {
Toast.makeText(getApplicationContext(), arg2, Toast.LENGTH_LONG).show(); // Toast.makeText(getApplicationContext(), arg2, Toast.LENGTH_LONG).show();
} // }
//
@Override // @Override
public void onSuccess(int arg0, BaseObject arg1) { // public void onSuccess(int arg0, BaseObject arg1) {
if (arg1 == null) { // if (arg1 == null) {
return; // return;
} // }
SearchResultObject obj = (SearchResultObject) arg1; // SearchResultObject obj = (SearchResultObject) arg1;
if(obj.data == null){ // if(obj.data == null){
return; // return;
} // }
tencentMap.moveCamera(CameraUpdateFactory.newCameraPosition(new CameraPosition(obj.data.get(0).latLng,15f, 0, 0))); // tencentMap.moveCamera(CameraUpdateFactory.newCameraPosition(new CameraPosition(obj.data.get(0).latLng,15f, 0, 0)));
for(SearchResultObject.SearchResultData data : obj.data){ // for(SearchResultObject.SearchResultData data : obj.data){
Log.v("SearchDemo","title:"+data.title + ";" + data.address); // Log.v("SearchDemo","title:"+data.title + ";" + data.address);
tencentMap.addMarker(new MarkerOptions() // tencentMap.addMarker(new MarkerOptions()
.position(data.latLng) //标注的位置 // .position(data.latLng) //标注的位置
.title(data.title) //标注的InfoWindow的标题 // .title(data.title) //标注的InfoWindow的标题
.snippet(data.address) //标注的InfoWindow的内容 // .snippet(data.address) //标注的InfoWindow的内容
); // );
//
} // }
} // }
}); // });
} // }
//
public void handleMessage(Message msg) { // public void handleMessage(Message msg) {
switch (msg.what) { // switch (msg.what) {
case MSG_SUGGESTION: // case MSG_SUGGESTION:
showAutoComplete((SuggestionResultObject)msg.obj); // showAutoComplete((SuggestionResultObject)msg.obj);
break; // break;
//
default: // default:
break; // break;
} // }
} // }
//
/** // /**
* 显示完整ListView // * 显示完整ListView
* @param obj // * @param obj
*/ // */
protected void showAutoComplete(SuggestionResultObject obj) { // protected void showAutoComplete(SuggestionResultObject obj) {
if (obj.data.size() == 0) { // if (obj.data.size() == 0) {
lvSuggesion.setVisibility(View.GONE); // lvSuggesion.setVisibility(View.GONE);
return; // return;
} // }
if (suggestionAdapter == null) { // if (suggestionAdapter == null) {
suggestionAdapter = new SuggestionAdapter(obj.data); // suggestionAdapter = new SuggestionAdapter(obj.data);
lvSuggesion.setAdapter(suggestionAdapter); // lvSuggesion.setAdapter(suggestionAdapter);
} else { // } else {
suggestionAdapter.setDatas(obj.data); // suggestionAdapter.setDatas(obj.data);
suggestionAdapter.notifyDataSetChanged(); // suggestionAdapter.notifyDataSetChanged();
} // }
lvSuggesion.setVisibility(View.VISIBLE); // lvSuggesion.setVisibility(View.VISIBLE);
} // }
/** // /**
* 关键字提示 // * 关键字提示
* @param keyword // * @param keyword
*/ // */
protected void suggestion(String keyword) { // protected void suggestion(String keyword) {
if (keyword.trim().length() == 0) { // if (keyword.trim().length() == 0) {
lvSuggesion.setVisibility(View.GONE); // lvSuggesion.setVisibility(View.GONE);
return; // return;
} // }
TencentSearch tencentSearch = new TencentSearch(this); // TencentSearch tencentSearch = new TencentSearch(this);
SuggestionParam suggestionParam = new SuggestionParam(keyword, "北京"); // SuggestionParam suggestionParam = new SuggestionParam(keyword, "北京");
//suggestion也提供了filter()方法和region方法 // //suggestion也提供了filter()方法和region方法
//具体说明见文档或者官网的webservice对应接口 // //具体说明见文档或者官网的webservice对应接口
tencentSearch.suggestion(suggestionParam, new HttpResponseListener<BaseObject>() { // tencentSearch.suggestion(suggestionParam, new HttpResponseListener<BaseObject>() {
//
@Override // @Override
public void onSuccess(int arg0, BaseObject arg1) { // public void onSuccess(int arg0, BaseObject arg1) {
if (arg1 == null || // if (arg1 == null ||
etSearch.getText().toString().trim().length() == 0) { // etSearch.getText().toString().trim().length() == 0) {
lvSuggesion.setVisibility(View.GONE); // lvSuggesion.setVisibility(View.GONE);
return; // return;
} // }
//
Message msg = new Message(); // Message msg = new Message();
msg.what = MSG_SUGGESTION; // msg.what = MSG_SUGGESTION;
msg.obj = arg1; // msg.obj = arg1;
handler.sendMessage(msg); // handler.sendMessage(msg);
} // }
//
@Override // @Override
public void onFailure(int arg0, String arg1, Throwable arg2) { // public void onFailure(int arg0, String arg1, Throwable arg2) {
//printResult(arg1); // //printResult(arg1);
} // }
}); // });
} // }
//
class SuggestionAdapter extends BaseAdapter { // class SuggestionAdapter extends BaseAdapter {
//
List<SuggestionResultObject.SuggestionData> mSuggestionDatas; // List<SuggestionResultObject.SuggestionData> mSuggestionDatas;
//
public SuggestionAdapter(List<SuggestionResultObject.SuggestionData> suggestionDatas) { // public SuggestionAdapter(List<SuggestionResultObject.SuggestionData> suggestionDatas) {
// TODO Auto-generated constructor stub // // TODO Auto-generated constructor stub
setDatas(suggestionDatas); // setDatas(suggestionDatas);
} // }
//
public void setDatas(List<SuggestionResultObject.SuggestionData> suggestionDatas) { // public void setDatas(List<SuggestionResultObject.SuggestionData> suggestionDatas) {
mSuggestionDatas = suggestionDatas; // mSuggestionDatas = suggestionDatas;
} // }
//
@Override // @Override
public int getCount() { // public int getCount() {
// TODO Auto-generated method stub // // TODO Auto-generated method stub
return mSuggestionDatas.size(); // return mSuggestionDatas.size();
} // }
//
@Override // @Override
public Object getItem(int position) { // public Object getItem(int position) {
// TODO Auto-generated method stub // // TODO Auto-generated method stub
return mSuggestionDatas.get(position); // return mSuggestionDatas.get(position);
} // }
//
@Override // @Override
public long getItemId(int position) { // public long getItemId(int position) {
// TODO Auto-generated method stub // // TODO Auto-generated method stub
return position; // return position;
} // }
//
@Override // @Override
public View getView(int position, View convertView, ViewGroup parent) { // public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub // // TODO Auto-generated method stub
ViewHolder viewHolder; // ViewHolder viewHolder;
if (convertView == null) { // if (convertView == null) {
convertView = View.inflate(SearchBasicActivity.this, // convertView = View.inflate(SearchBasicActivity.this,
R.layout.suggestion_list_item, null); // R.layout.suggestion_list_item, null);
viewHolder = new ViewHolder(); // viewHolder = new ViewHolder();
viewHolder.tvTitle = (TextView) convertView.findViewById(R.id.label); // viewHolder.tvTitle = (TextView) convertView.findViewById(R.id.label);
viewHolder.tvAddress = (TextView) convertView.findViewById(R.id.desc); // viewHolder.tvAddress = (TextView) convertView.findViewById(R.id.desc);
convertView.setTag(viewHolder); // convertView.setTag(viewHolder);
} else { // } else {
viewHolder = (ViewHolder) convertView.getTag(); // viewHolder = (ViewHolder) convertView.getTag();
} // }
viewHolder.tvTitle.setText(mSuggestionDatas.get(position).title); // viewHolder.tvTitle.setText(mSuggestionDatas.get(position).title);
viewHolder.tvAddress.setText(mSuggestionDatas.get(position).address); // viewHolder.tvAddress.setText(mSuggestionDatas.get(position).address);
return convertView; // return convertView;
} // }
//
private class ViewHolder{ // private class ViewHolder{
TextView tvTitle; // TextView tvTitle;
TextView tvAddress; // TextView tvAddress;
} // }
} // }
} }

View File

@ -1,93 +1,93 @@
package cc.winboll.studio.positions.demo.search; package cc.winboll.studio.positions.demo.search;
import android.os.Bundle; //import android.os.Bundle;
import android.util.Log; //import android.util.Log;
//
import com.tencent.lbssearch.TencentSearch; //import com.tencent.lbssearch.TencentSearch;
import com.tencent.lbssearch.httpresponse.HttpResponseListener; //import com.tencent.lbssearch.httpresponse.HttpResponseListener;
import com.tencent.lbssearch.object.param.TransitParam; //import com.tencent.lbssearch.object.param.TransitParam;
import com.tencent.lbssearch.object.result.TransitResultObject; //import com.tencent.lbssearch.object.result.TransitResultObject;
import cc.winboll.studio.positions.demo.basic.SupportMapFragmentActivity; //import cc.winboll.studio.positions.demo.basic.SupportMapFragmentActivity;
import com.tencent.tencentmap.mapsdk.maps.CameraUpdateFactory; //import com.tencent.tencentmap.mapsdk.maps.CameraUpdateFactory;
import com.tencent.tencentmap.mapsdk.maps.TencentMap; //import com.tencent.tencentmap.mapsdk.maps.TencentMap;
import com.tencent.tencentmap.mapsdk.maps.model.CameraPosition; //import com.tencent.tencentmap.mapsdk.maps.model.CameraPosition;
import com.tencent.tencentmap.mapsdk.maps.model.LatLng; //import com.tencent.tencentmap.mapsdk.maps.model.LatLng;
import com.tencent.tencentmap.mapsdk.maps.model.PolylineOptions; //import com.tencent.tencentmap.mapsdk.maps.model.PolylineOptions;
//
import java.util.List; //import java.util.List;
//
public class TransitRouteActivity extends SupportMapFragmentActivity { //public class TransitRouteActivity extends SupportMapFragmentActivity {
private LatLng fromPoint = new LatLng(40.127265, 116.208051); // 起点坐标 // private LatLng fromPoint = new LatLng(40.127265, 116.208051); // 起点坐标
private LatLng toPoint = new LatLng(40.040219, 116.273348); //终点坐标 // private LatLng toPoint = new LatLng(40.040219, 116.273348); //终点坐标
//
@Override // @Override
protected void onCreate(Bundle savedInstanceState) { // protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); // super.onCreate(savedInstanceState);
//移动地图 // //移动地图
tencentMap.moveCamera(CameraUpdateFactory.newCameraPosition(new CameraPosition( // tencentMap.moveCamera(CameraUpdateFactory.newCameraPosition(new CameraPosition(
new LatLng(40.080287, 116.244949), // new LatLng(40.080287, 116.244949),
12, // 12,
0f, // 0f,
0f))); // 0f)));
getTransitRoute(); // getTransitRoute();
tencentMap.setOnMapClickListener(new TencentMap.OnMapClickListener() { // tencentMap.setOnMapClickListener(new TencentMap.OnMapClickListener() {
@Override // @Override
public void onMapClick(LatLng latLng) { // public void onMapClick(LatLng latLng) {
Log.d("TAG", "onMapClick: "+latLng); // Log.d("TAG", "onMapClick: "+latLng);
} // }
}); // });
} // }
//
/** // /**
* 获取公交路径规划 // * 获取公交路径规划
* TransitResultObject中的Segment是抽象类要转换成具体的子类才能获取数据 // * TransitResultObject中的Segment是抽象类要转换成具体的子类才能获取数据
*/ // */
private void getTransitRoute() { // private void getTransitRoute() {
TransitParam transitParam = new TransitParam(fromPoint, toPoint); // TransitParam transitParam = new TransitParam(fromPoint, toPoint);
TencentSearch tencentSearch = new TencentSearch(this); // TencentSearch tencentSearch = new TencentSearch(this);
transitParam.policy(TransitParam.Policy.LEAST_WALKING, TransitParam.Preference.NO_SUBWAY); // transitParam.policy(TransitParam.Policy.LEAST_WALKING, TransitParam.Preference.NO_SUBWAY);
tencentSearch.getRoutePlan(transitParam, new HttpResponseListener<TransitResultObject>() { // tencentSearch.getRoutePlan(transitParam, new HttpResponseListener<TransitResultObject>() {
//
@Override // @Override
public void onSuccess(int i, TransitResultObject transitResultObject) { // public void onSuccess(int i, TransitResultObject transitResultObject) {
if (transitResultObject == null) { // if (transitResultObject == null) {
Log.i("TAG", "baseObject为空"); // Log.i("TAG", "baseObject为空");
return; // return;
} // }
showTransitRoute(transitResultObject); // showTransitRoute(transitResultObject);
//
} // }
//
@Override // @Override
public void onFailure(int i, String s, Throwable throwable) { // public void onFailure(int i, String s, Throwable throwable) {
Log.d("TransitRouteActivity", "onFailure: " + s); // Log.d("TransitRouteActivity", "onFailure: " + s);
} // }
}); // });
} // }
//
private void showTransitRoute(TransitResultObject transitResultObject) { // private void showTransitRoute(TransitResultObject transitResultObject) {
tencentMap.clearAllOverlays(); // tencentMap.clearAllOverlays();
if (transitResultObject.result != null && transitResultObject.result.routes != null && transitResultObject.result.routes.size() > 0) { // if (transitResultObject.result != null && transitResultObject.result.routes != null && transitResultObject.result.routes.size() > 0) {
for (int i = 0; i < transitResultObject.result.routes.size(); i++) { // for (int i = 0; i < transitResultObject.result.routes.size(); i++) {
TransitResultObject.Route route = transitResultObject.result.routes.get(i); // TransitResultObject.Route route = transitResultObject.result.routes.get(i);
//
List<TransitResultObject.Segment> steps = route.steps; // List<TransitResultObject.Segment> steps = route.steps;
for (int j = 0; j < steps.size(); j++) { // for (int j = 0; j < steps.size(); j++) {
TransitResultObject.Segment segment = steps.get(j); // TransitResultObject.Segment segment = steps.get(j);
if (segment instanceof TransitResultObject.Transit) { // if (segment instanceof TransitResultObject.Transit) {
TransitResultObject.Transit transit = (TransitResultObject.Transit) segment; // TransitResultObject.Transit transit = (TransitResultObject.Transit) segment;
tencentMap.addPolyline(new PolylineOptions().addAll(transit.lines.get(0).polyline).color(i + 1).width(20)); // tencentMap.addPolyline(new PolylineOptions().addAll(transit.lines.get(0).polyline).color(i + 1).width(20));
//
} else if (segment instanceof TransitResultObject.Walking) { // } else if (segment instanceof TransitResultObject.Walking) {
TransitResultObject.Walking walking = (TransitResultObject.Walking) segment; // TransitResultObject.Walking walking = (TransitResultObject.Walking) segment;
tencentMap.addPolyline(new PolylineOptions().addAll(walking.polyline).color(j + 1).lineType(PolylineOptions.LineType.LINE_TYPE_IMAGEINARYLINE).width(20)); // tencentMap.addPolyline(new PolylineOptions().addAll(walking.polyline).color(j + 1).lineType(PolylineOptions.LineType.LINE_TYPE_IMAGEINARYLINE).width(20));
} // }
//
} // }
} // }
//
} else { // } else {
Log.i("TAG", "路线结果为空"); // Log.i("TAG", "路线结果为空");
} // }
} // }
} //}

View File

@ -24,54 +24,54 @@ import com.tencent.tencentmap.mapsdk.maps.model.PolylineOptions;
import java.util.List; import java.util.List;
public class TruckingRouteActivity extends SupportMapFragmentActivity { public class TruckingRouteActivity extends SupportMapFragmentActivity {
private LatLng fromPoint = new LatLng(40.127265, 116.208051); // 起点坐标 // private LatLng fromPoint = new LatLng(40.127265, 116.208051); // 起点坐标
private LatLng toPoint = new LatLng(40.040219, 116.273348); //终点坐标 // private LatLng toPoint = new LatLng(40.040219, 116.273348); //终点坐标
//
@Override // @Override
protected void onCreate(Bundle savedInstanceState) { // protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); // super.onCreate(savedInstanceState);
CameraUpdate cameraSigma = // CameraUpdate cameraSigma =
CameraUpdateFactory.newCameraPosition(new CameraPosition( // CameraUpdateFactory.newCameraPosition(new CameraPosition(
new LatLng(40.040219, 116.273348), // new LatLng(40.040219, 116.273348),
15, // 15,
0f, // 0f,
0f)); // 0f));
//移动地图 // //移动地图
tencentMap.moveCamera(cameraSigma); // tencentMap.moveCamera(cameraSigma);
geTruckingRoute(); // geTruckingRoute();
} // }
//
private void geTruckingRoute() { // private void geTruckingRoute() {
TruckingParam truckingParam = new TruckingParam(); // TruckingParam truckingParam = new TruckingParam();
truckingParam.from(fromPoint); // truckingParam.from(fromPoint);
truckingParam.to(toPoint); // truckingParam.to(toPoint);
truckingParam.setMultRoute(1); // truckingParam.setMultRoute(1);
// truckingParam.setNoPolyline(1); // // truckingParam.setNoPolyline(1);
truckingParam.trafficSpeed(true); // truckingParam.trafficSpeed(true);
TencentSearch tencentSearch = new TencentSearch(this); // TencentSearch tencentSearch = new TencentSearch(this);
tencentSearch.getRoutePlan(truckingParam, new HttpResponseListener<TruckingResultObject>() { // tencentSearch.getRoutePlan(truckingParam, new HttpResponseListener<TruckingResultObject>() {
//
@Override // @Override
public void onSuccess(int i, TruckingResultObject truckingResultObject) { // public void onSuccess(int i, TruckingResultObject truckingResultObject) {
if (null != truckingResultObject.result && null != truckingResultObject.result.routes && truckingResultObject.result.routes.size() > 0) { // if (null != truckingResultObject.result && null != truckingResultObject.result.routes && truckingResultObject.result.routes.size() > 0) {
for (int j = 0; j < truckingResultObject.result.routes.size(); j++) { // for (int j = 0; j < truckingResultObject.result.routes.size(); j++) {
TruckingResultObject.Result result = truckingResultObject.result; // TruckingResultObject.Result result = truckingResultObject.result;
TruckingResultObject.Route route = result.routes.get(j); // TruckingResultObject.Route route = result.routes.get(j);
// List<TruckingResultObject.Step> steps = route.steps; // // List<TruckingResultObject.Step> steps = route.steps;
tencentMap.addPolyline(new PolylineOptions().addAll(route.polyline).color(i + 1).width(20)); // tencentMap.addPolyline(new PolylineOptions().addAll(route.polyline).color(i + 1).width(20));
tencentMap.moveCamera(CameraUpdateFactory.newLatLngBounds(LatLngBounds.builder() // tencentMap.moveCamera(CameraUpdateFactory.newLatLngBounds(LatLngBounds.builder()
.include(route.polyline).build(), 100)); // .include(route.polyline).build(), 100));
//
} // }
} // }
} // }
//
@Override // @Override
public void onFailure(int i, String s, Throwable throwable) { // public void onFailure(int i, String s, Throwable throwable) {
Log.d("TruckingRouteActivity", "onFailure: " + s); // Log.d("TruckingRouteActivity", "onFailure: " + s);
//
} // }
}); // });
//
} // }
} }

View File

@ -17,60 +17,60 @@ import com.tencent.tencentmap.mapsdk.maps.model.PolylineOptions;
public class WalkingRouteActivity extends SupportMapFragmentActivity { public class WalkingRouteActivity extends SupportMapFragmentActivity {
private LatLng fromPoint = new LatLng(40.040219, 116.273348); // 起点坐标 // private LatLng fromPoint = new LatLng(40.040219, 116.273348); // 起点坐标
private LatLng toPoint = new LatLng(40.048055, 116.281166); //终点坐标 // private LatLng toPoint = new LatLng(40.048055, 116.281166); //终点坐标
//
@Override // @Override
protected void onCreate(Bundle savedInstanceState) { // protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); // super.onCreate(savedInstanceState);
getWalkingRoute(); // getWalkingRoute();
} // }
//
/** // /**
* 获取步行路线规划 // * 获取步行路线规划
*/ // */
private void getWalkingRoute() { // private void getWalkingRoute() {
WalkingParam walkingParam = new WalkingParam(); // WalkingParam walkingParam = new WalkingParam();
walkingParam.from(fromPoint); // walkingParam.from(fromPoint);
walkingParam.to(toPoint); // walkingParam.to(toPoint);
TencentSearch tencentSearch = new TencentSearch(getApplicationContext()); // TencentSearch tencentSearch = new TencentSearch(getApplicationContext());
Log.i("TAG", "checkParams:" + walkingParam.checkParams()); // Log.i("TAG", "checkParams:" + walkingParam.checkParams());
tencentSearch.getRoutePlan(walkingParam, new HttpResponseListener<WalkingResultObject>() { // tencentSearch.getRoutePlan(walkingParam, new HttpResponseListener<WalkingResultObject>() {
@Override // @Override
public void onSuccess(int statusCode, WalkingResultObject object) { // public void onSuccess(int statusCode, WalkingResultObject object) {
if (object == null) { // if (object == null) {
Log.i("TAG", "baseObject为空"); // Log.i("TAG", "baseObject为空");
return; // return;
} // }
showWalkingRoute(object); // showWalkingRoute(object);
Log.i("TAG", "message:" + object.message); // Log.i("TAG", "message:" + object.message);
} // }
//
@Override // @Override
public void onFailure(int statusCode, String responseString, Throwable throwable) { // public void onFailure(int statusCode, String responseString, Throwable throwable) {
Log.i("TAG:", statusCode + " " + responseString); // Log.i("TAG:", statusCode + " " + responseString);
} // }
}); // });
} // }
//
private void showWalkingRoute(WalkingResultObject object) { // private void showWalkingRoute(WalkingResultObject object) {
tencentMap.clearAllOverlays(); // tencentMap.clearAllOverlays();
if (object.result != null && object.result.routes != null && object.result.routes.size() > 0) { // if (object.result != null && object.result.routes != null && object.result.routes.size() > 0) {
for (int i = 0; i < object.result.routes.size(); i++) { // for (int i = 0; i < object.result.routes.size(); i++) {
WalkingResultObject.Route result = object.result.routes.get(i); // WalkingResultObject.Route result = object.result.routes.get(i);
tencentMap.addPolyline(new PolylineOptions().addAll(result.polyline).color(i + 1).width(20)); // tencentMap.addPolyline(new PolylineOptions().addAll(result.polyline).color(i + 1).width(20));
Log.i("TAG", "distance:" + result.distance + " duration:" + result.duration // Log.i("TAG", "distance:" + result.distance + " duration:" + result.duration
+ " mode:" + result.mode + " direction:" + result.direction); // + " mode:" + result.mode + " direction:" + result.direction);
for (RoutePlanningObject.Step step : result.steps) { // for (RoutePlanningObject.Step step : result.steps) {
Log.i("TAG", "step:" + step.road_name + " " + step.distance + " " // Log.i("TAG", "step:" + step.road_name + " " + step.distance + " "
+ step.instruction + " " + step.act_desc + " " + step.dir_desc); // + step.instruction + " " + step.act_desc + " " + step.dir_desc);
} // }
tencentMap.moveCamera(CameraUpdateFactory.newLatLngBounds(LatLngBounds.builder() // tencentMap.moveCamera(CameraUpdateFactory.newLatLngBounds(LatLngBounds.builder()
.include(result.polyline).build(), 100)); // .include(result.polyline).build(), 100));
} // }
//
} else { // } else {
Log.i("TAG", "路线结果为空"); // Log.i("TAG", "路线结果为空");
} // }
} // }
} }

View File

@ -36,216 +36,222 @@ import java.util.TimerTask;
import static com.tencent.tencentmap.mapsdk.vector.utils.animation.MarkerTranslateAnimator.MarkerTranslateStatusListener.AnimationStatus.AnimationComplete; import static com.tencent.tencentmap.mapsdk.vector.utils.animation.MarkerTranslateAnimator.MarkerTranslateStatusListener.AnimationStatus.AnimationComplete;
public class SmoothMoveActivity extends AppCompatActivity implements View.OnClickListener { 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<Float> skews;
private ArrayList<Float> roates;
private String parentPath;
private ImageView imageView;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { public void onClick(View p1)
super.onCreate(savedInstanceState); {
setContentView(R.layout.activity_smooth_move); }
mapView = findViewById(R.id.map);
map = mapView.getMap(); // 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";
init(); // private TencentMap map;
Button btLin = findViewById(R.id.button_set); // private Polyline mPolyline;
Button btStart = findViewById(R.id.satrt); // private Marker mCarMarker;
Button btStop = findViewById(R.id.stop); // private LatLng[] mCarLatLngArray;
btLin.setOnClickListener(this); // private MarkerTranslateAnimator mAnimator;
btStart.setOnClickListener(this); // private Polyline polyline;
btStop.setOnClickListener(this); // private ArrayList<Float> skews;
} // private ArrayList<Float> roates;
// private String parentPath;
private void init() { // private ImageView imageView;
String[] linePointsStr = mLine.split(","); //
mCarLatLngArray = new LatLng[linePointsStr.length / 4]; // @Override
skews = new ArrayList<>(); // protected void onCreate(Bundle savedInstanceState) {
roates = new ArrayList<>(); // super.onCreate(savedInstanceState);
// setContentView(R.layout.activity_smooth_move);
for (int i = 0; i < mCarLatLngArray.length; i++) { // mapView = findViewById(R.id.map);
double latitude = Double.parseDouble(linePointsStr[i * 4]); // map = mapView.getMap();
double longitude = Double.parseDouble(linePointsStr[i * 4 + 1]); // //解析路线
// float skew = Float.parseFloat(linePointsStr[i * 4 + 2]); // init();
// float roate = Float.parseFloat(linePointsStr[i * 4 + 3]); // Button btLin = findViewById(R.id.button_set);
mCarLatLngArray[i] = new LatLng(latitude, longitude); // Button btStart = findViewById(R.id.satrt);
// skews.add(skew); // Button btStop = findViewById(R.id.stop);
// roates.add(roate); // btLin.setOnClickListener(this);
} // btStart.setOnClickListener(this);
} // btStop.setOnClickListener(this);
// }
@Override //
protected void onStart() { // private void init() {
super.onStart(); // String[] linePointsStr = mLine.split(",");
mapView.onStart(); // mCarLatLngArray = new LatLng[linePointsStr.length / 4];
} // skews = new ArrayList<>();
// roates = new ArrayList<>();
@Override //
protected void onResume() { // for (int i = 0; i < mCarLatLngArray.length; i++) {
super.onResume(); // double latitude = Double.parseDouble(linePointsStr[i * 4]);
mapView.onResume(); // double longitude = Double.parseDouble(linePointsStr[i * 4 + 1]);
} // // float skew = Float.parseFloat(linePointsStr[i * 4 + 2]);
// // float roate = Float.parseFloat(linePointsStr[i * 4 + 3]);
@Override // mCarLatLngArray[i] = new LatLng(latitude, longitude);
protected void onPause() { // // skews.add(skew);
super.onPause(); // // roates.add(roate);
mapView.onPause(); // }
} // }
//
@Override // @Override
protected void onStop() { // protected void onStart() {
super.onStop(); // super.onStart();
mapView.onStop(); // mapView.onStart();
} // }
//
@Override // @Override
protected void onDestroy() { // protected void onResume() {
super.onDestroy(); // super.onResume();
mapView.onDestroy(); // mapView.onResume();
} // }
//
@Override // @Override
protected void onRestart() { // protected void onPause() {
super.onRestart(); // super.onPause();
mapView.onRestart(); // mapView.onPause();
} // }
//
@Override // @Override
public void onClick(View v) { // protected void onStop() {
switch (v.getId()) { // super.onStop();
case R.id.button_set: // mapView.onStop();
if (polyline == null && mCarMarker == null) { // }
//添加小车路线 //
polyline = map.addPolyline(new PolylineOptions().add(mCarLatLngArray).color(R.color.colorPrimaryDark)); // @Override
LatLng carLatLng = mCarLatLngArray[0]; // protected void onDestroy() {
mCarMarker = map.addMarker( // super.onDestroy();
new MarkerOptions(carLatLng) // mapView.onDestroy();
.anchor(0.5f, 0.5f) // }
.title("即将到达终点") //
.icon(BitmapDescriptorFactory.fromBitmap(getBitMap(R.drawable.taxi))) // @Override
.flat(true) // protected void onRestart() {
.clockwise(false)); // super.onRestart();
//调整最佳视界 // mapView.onRestart();
map.animateCamera(CameraUpdateFactory.newLatLngBounds(LatLngBounds.builder().include(Arrays.asList(mCarLatLngArray)).build(), 50)); // }
TimerTask timerTask = new TimerTask() { //
@Override // @Override
public void run() { // public void onClick(View v) {
if (polyline != null) { // switch (v.getId()) {
snapshot(); // 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];
Timer timer = new Timer(); // mCarMarker = map.addMarker(
timer.schedule(timerTask, 800); // new MarkerOptions(carLatLng)
} // .anchor(0.5f, 0.5f)
break; // .title("即将到达终点")
case R.id.satrt: // .icon(BitmapDescriptorFactory.fromBitmap(getBitMap(R.drawable.taxi)))
if (mAnimator == null) { // .flat(true)
//创建移动动画 // .clockwise(false));
mAnimator = new MarkerTranslateAnimator(mCarMarker, 100 * 1000, mCarLatLngArray, true, new MarkerTranslateAnimator.MarkerTranslateStatusListener() { // //调整最佳视界
private CameraUpdate cameraSigma; // map.animateCamera(CameraUpdateFactory.newLatLngBounds(LatLngBounds.builder().include(Arrays.asList(mCarLatLngArray)).build(), 50));
// TimerTask timerTask = new TimerTask() {
@Override // @Override
public void onInterpolatePoint(LatLng latLng, int i, AnimationStatus animationStatus) { // public void run() {
//路线擦出 // if (polyline != null) {
polyline.setEraseable(true); // snapshot();
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) { // Timer timer = new Timer();
cameraSigma = // timer.schedule(timerTask, 800);
CameraUpdateFactory.newCameraPosition(new CameraPosition( // }
latLng, // break;
18, // case R.id.satrt:
60, // if (mAnimator == null) {
mCarMarker.getRotation() + 180)); // //创建移动动画
} else if (mCarMarker.getRotation() >= 90 && mCarMarker.getRotation() <= 180) { // mAnimator = new MarkerTranslateAnimator(mCarMarker, 100 * 1000, mCarLatLngArray, true, new MarkerTranslateAnimator.MarkerTranslateStatusListener() {
cameraSigma = // private CameraUpdate cameraSigma;
CameraUpdateFactory.newCameraPosition(new CameraPosition( //
latLng, // @Override
18, // public void onInterpolatePoint(LatLng latLng, int i, AnimationStatus animationStatus) {
60, // //路线擦出
-mCarMarker.getRotation())); // polyline.setEraseable(true);
} else { // polyline.eraseTo(i, latLng);
cameraSigma = //
CameraUpdateFactory.newCameraPosition(new CameraPosition( // /* CameraUpdate cameraUpdate = CameraUpdateFactory.newLatLngBoundsWithMapCenter(LatLngBounds.builder().include(Arrays.asList(mCarLatLngArray)).build(), latLng, 10);
latLng, // map.animateCamera(cameraUpdate);*/
18, // if (mCarMarker.getRotation() < 90 && mCarMarker.getRotation() > 0) {
60, // cameraSigma =
-mCarMarker.getRotation())); // CameraUpdateFactory.newCameraPosition(new CameraPosition(
} // latLng,
// 18,
//移动地图 // 60,
map.moveCamera(cameraSigma); // mCarMarker.getRotation() + 180));
map.enableMultipleInfowindow(true); // } else if (mCarMarker.getRotation() >= 90 && mCarMarker.getRotation() <= 180) {
if (i == 41) { // cameraSigma =
mCarMarker.startAnimation(); // CameraUpdateFactory.newCameraPosition(new CameraPosition(
mCarMarker.showInfoWindow(); // latLng,
} // 18,
if (animationStatus == AnimationComplete) { // 60,
mCarMarker.setTitle("到达目的地"); // -mCarMarker.getRotation()));
} // } else {
} // cameraSigma =
}); // CameraUpdateFactory.newCameraPosition(new CameraPosition(
// latLng,
// 18,
//开启动画 // 60,
mAnimator.startAnimation(); // -mCarMarker.getRotation()));
} // }
break; //
case R.id.stop: // //移动地图
if (mAnimator != null && polyline != null && mCarMarker != null) { // map.moveCamera(cameraSigma);
mAnimator.endAnimation(); // map.enableMultipleInfowindow(true);
//mAnimator.cancelAnimation(); // if (i == 41) {
polyline.remove(); // mCarMarker.startAnimation();
polyline = null; // mCarMarker.showInfoWindow();
mCarMarker.remove(); // }
mCarMarker = null; // if (animationStatus == AnimationComplete) {
mAnimator = null; // mCarMarker.setTitle("到达目的地");
} // }
// }
// });
break; //
default: //
throw new IllegalStateException("Unexpected value: " + v.getId()); // //开启动画
} // mAnimator.startAnimation();
} // }
// break;
private void snapshot() { // case R.id.stop:
imageView = findViewById(R.id.iv); // if (mAnimator != null && polyline != null && mCarMarker != null) {
// mAnimator.endAnimation();
map.snapshot(new TencentMap.SnapshotReadyCallback() { // //mAnimator.cancelAnimation();
@Override // polyline.remove();
public void onSnapshotReady(Bitmap bitmap) { // polyline = null;
RoundedBitmapDrawable roundedBitmapDrawable = RoundedBitmapDrawableFactory.create(getResources(), bitmap); // mCarMarker.remove();
roundedBitmapDrawable.setCircular(true); // mCarMarker = null;
imageView.setImageDrawable(roundedBitmapDrawable); // mAnimator = null;
} // }
}, Bitmap.Config.ARGB_8888); //
} //
// break;
//设置图片 // default:
private Bitmap getBitMap(int resourceId) { // throw new IllegalStateException("Unexpected value: " + v.getId());
Bitmap bitmap = BitmapFactory.decodeResource(getResources(), resourceId); // }
int width = bitmap.getWidth(); // }
int height = bitmap.getHeight(); //
int newWidth = 100; // private void snapshot() {
int newHeight = 150; // imageView = findViewById(R.id.iv);
float widthScale = ((float) newWidth) / width; //
float heightScale = ((float) newHeight) / height; // map.snapshot(new TencentMap.SnapshotReadyCallback() {
Matrix matrix = new Matrix(); // @Override
matrix.postScale(widthScale, heightScale); // public void onSnapshotReady(Bitmap bitmap) {
bitmap = Bitmap.createBitmap(bitmap, 0, 0, width, height, matrix, true); // RoundedBitmapDrawable roundedBitmapDrawable = RoundedBitmapDrawableFactory.create(getResources(), bitmap);
return 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;
// }
} }

View File

@ -13,49 +13,54 @@ import com.tencent.tencentmap.mapsdk.maps.model.LatLng;
public class AnimateCameraActivity extends SupportMapFragmentActivity implements View.OnClickListener { public class AnimateCameraActivity extends SupportMapFragmentActivity implements View.OnClickListener {
private Button btn;
private boolean flag;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { public void onClick(View p1) {
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;
}
}
// 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;
// }
//
// }
//
} }

View File

@ -13,49 +13,54 @@ import com.tencent.tencentmap.mapsdk.maps.model.LatLng;
public class MoveCameraActivity extends SupportMapFragmentActivity implements View.OnClickListener { public class MoveCameraActivity extends SupportMapFragmentActivity implements View.OnClickListener {
private Button btn;
private boolean flag;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { public void onClick(View p1) {
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;
}
}
// 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;
// }
//
// }
} }

View File

@ -1,28 +1,28 @@
package cc.winboll.studio.positions.demo.transaction; package cc.winboll.studio.positions.demo.transaction;
import android.os.Bundle; //import android.os.Bundle;
import android.view.View; //import android.view.View;
import android.widget.Button; //import android.widget.Button;
//
import cc.winboll.studio.positions.R; //import cc.winboll.studio.positions.R;
import cc.winboll.studio.positions.demo.basic.SupportMapFragmentActivity; //import cc.winboll.studio.positions.demo.basic.SupportMapFragmentActivity;
import com.tencent.tencentmap.mapsdk.maps.CameraUpdate; //import com.tencent.tencentmap.mapsdk.maps.CameraUpdate;
import com.tencent.tencentmap.mapsdk.maps.CameraUpdateFactory; //import com.tencent.tencentmap.mapsdk.maps.CameraUpdateFactory;
//
public class RotateMapActivity extends SupportMapFragmentActivity { //public class RotateMapActivity extends SupportMapFragmentActivity {
private Button btn; // private Button btn;
@Override // @Override
protected void onCreate(Bundle savedInstanceState) { // protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); // super.onCreate(savedInstanceState);
btn = findViewById(R.id.btn_bottom); // btn = findViewById(R.id.btn_bottom);
btn.setVisibility(View.VISIBLE); // btn.setVisibility(View.VISIBLE);
btn.setText("旋转地图"); // btn.setText("旋转地图");
btn.setOnClickListener(new View.OnClickListener() { // btn.setOnClickListener(new View.OnClickListener() {
@Override // @Override
public void onClick(View v) { // public void onClick(View v) {
CameraUpdate cameraUpdate = CameraUpdateFactory.rotateTo(90f,1.5f); // CameraUpdate cameraUpdate = CameraUpdateFactory.rotateTo(90f,1.5f);
tencentMap.animateCamera(cameraUpdate); // tencentMap.animateCamera(cameraUpdate);
} // }
}); // });
} // }
} //}

View File

@ -13,70 +13,75 @@ import com.tencent.tencentmap.mapsdk.maps.CameraUpdateFactory;
import com.tencent.tencentmap.mapsdk.maps.TencentMap; import com.tencent.tencentmap.mapsdk.maps.TencentMap;
public class ScollMapActivity extends SupportMapFragmentActivity implements View.OnClickListener { public class ScollMapActivity extends SupportMapFragmentActivity implements View.OnClickListener {
private static final int SCROLL_BY_PX = 100;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { public void onClick(View p1) {
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);
}
});*/
} }
// private static final int SCROLL_BY_PX = 100;
// 根据动画按钮状态调用函数animateCamera或moveCamera来改变可视区域 //
// @Override
private void changeCamera(CameraUpdate update, TencentMap.CancelableCallback callback) { // protected void onCreate(Bundle savedInstanceState) {
boolean animated = ((CompoundButton) findViewById(R.id.animate)) // super.onCreate(savedInstanceState);
.isChecked(); // LinearLayout linearLayout = findViewById(R.id.ll);
if (animated) { // linearLayout.setVisibility(View.VISIBLE);
tencentMap.animateCamera(update, 1000, callback); // Button scrollLeft = (Button) findViewById(R.id.scroll_left);
} else { // scrollLeft.setOnClickListener(this);
tencentMap.moveCamera(update); //
} // Button scrollRight = (Button) findViewById(R.id.scroll_right);
} // scrollRight.setOnClickListener(this);
//
@Override // Button scrollUp = (Button) findViewById(R.id.scroll_up);
public void onClick(View v) { // scrollUp.setOnClickListener(this);
switch (v.getId()) { //
//点击向左移动按钮响应事件camera将向左边移动 // Button scrollDown = (Button) findViewById(R.id.scroll_down);
// scrollDown.setOnClickListener(this);
case R.id.scroll_left: //
changeCamera(CameraUpdateFactory.scrollBy(-SCROLL_BY_PX, 0), null); // /* btn.setOnClickListener(new View.OnClickListener() {
break; // @Override
// 点击向右移动按钮响应事件camera将向右边移动 // public void onClick(View v) {
case R.id.scroll_right: // CameraUpdate cameraUpdate = CameraUpdateFactory.scrollBy(50f,50f);
changeCamera(CameraUpdateFactory.scrollBy(SCROLL_BY_PX, 0), null); // tencentMap.animateCamera(cameraUpdate);
break; // }
// 点击向上移动按钮响应事件camera将向上边移动 // });*/
case R.id.scroll_up: // }
changeCamera(CameraUpdateFactory.scrollBy(0, -SCROLL_BY_PX), null); //
break; //
// 点击向下移动按钮响应事件camera将向下边移动 // // 根据动画按钮状态调用函数animateCamera或moveCamera来改变可视区域
case R.id.scroll_down: //
changeCamera(CameraUpdateFactory.scrollBy(0, SCROLL_BY_PX), null); // private void changeCamera(CameraUpdate update, TencentMap.CancelableCallback callback) {
break; // boolean animated = ((CompoundButton) findViewById(R.id.animate))
// .isChecked();
default: // if (animated) {
break; // 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;
// }
// }
} }

View File

@ -20,54 +20,54 @@ import java.util.ArrayList;
public class ZoomCalulateActivity extends SupportMapFragmentActivity { public class ZoomCalulateActivity extends SupportMapFragmentActivity {
private Button btn; // private Button btn;
private int leftpadding = 50,rightpadding =50, toppadding = 50, bottompadding=50; // private int leftpadding = 50,rightpadding =50, toppadding = 50, bottompadding=50;
//
@Override // @Override
protected void onCreate(Bundle savedInstanceState) { // protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); // super.onCreate(savedInstanceState);
btn = findViewById(R.id.btn_bottom); // btn = findViewById(R.id.btn_bottom);
btn.setVisibility(View.VISIBLE); // btn.setVisibility(View.VISIBLE);
btn.setText("根据点集缩放地图"); // btn.setText("根据点集缩放地图");
btn.setOnClickListener(new View.OnClickListener() { // btn.setOnClickListener(new View.OnClickListener() {
@Override // @Override
public void onClick(View v) { // public void onClick(View v) {
CameraUpdate cameraUpdate = CameraUpdateFactory.newCameraPosition(addMarker()); // CameraUpdate cameraUpdate = CameraUpdateFactory.newCameraPosition(addMarker());
tencentMap.moveCamera(cameraUpdate); // tencentMap.moveCamera(cameraUpdate);
} // }
}); // });
} // }
//
//
private CameraPosition addMarker(){ // private CameraPosition addMarker(){
ArrayList<LatLng> points = new ArrayList<>(); // ArrayList<LatLng> points = new ArrayList<>();
points.add(new LatLng(39.984059,116.307621)); // points.add(new LatLng(39.984059,116.307621));
points.add(new LatLng(39.984049,116.307631)); // points.add(new LatLng(39.984049,116.307631));
// points.add(new LatLng(39.981527,116.308994)); //// points.add(new LatLng(39.981527,116.308994));
// points.add(new LatLng(39.984026,116.316419)); //// points.add(new LatLng(39.984026,116.316419));
// points.add(new LatLng(39.978501,116.311827)); //// points.add(new LatLng(39.978501,116.311827));
//根据markers计算缩放级别 // //根据markers计算缩放级别
for(int i=0; i<points.size();i++){ // for(int i=0; i<points.size();i++){
MarkerOptions markerOptions = new MarkerOptions().position(points.get(i)).icon(BitmapDescriptorFactory.fromBitmap(getBitMap(R.drawable.marker))); // MarkerOptions markerOptions = new MarkerOptions().position(points.get(i)).icon(BitmapDescriptorFactory.fromBitmap(getBitMap(R.drawable.marker)));
tencentMap.addMarker(markerOptions); // tencentMap.addMarker(markerOptions);
} // }
//
//
CameraPosition cameraPosition = tencentMap.calculateZoomToSpanLevel(null,points,leftpadding,rightpadding,toppadding,bottompadding); // CameraPosition cameraPosition = tencentMap.calculateZoomToSpanLevel(null,points,leftpadding,rightpadding,toppadding,bottompadding);
return cameraPosition; // return cameraPosition;
} // }
//
private Bitmap getBitMap(int resourceId){ // private Bitmap getBitMap(int resourceId){
Bitmap bitmap = BitmapFactory.decodeResource(getResources(), resourceId); // Bitmap bitmap = BitmapFactory.decodeResource(getResources(), resourceId);
int width = bitmap.getWidth(); // int width = bitmap.getWidth();
int height = bitmap.getHeight(); // int height = bitmap.getHeight();
int newWidth = 50; // int newWidth = 50;
int newHeight = 50; // int newHeight = 50;
float widthScale = ((float)newWidth)/width; // float widthScale = ((float)newWidth)/width;
float heightScale = ((float)newHeight)/height; // float heightScale = ((float)newHeight)/height;
Matrix matrix = new Matrix(); // Matrix matrix = new Matrix();
matrix.postScale(widthScale, heightScale); // matrix.postScale(widthScale, heightScale);
bitmap = Bitmap.createBitmap(bitmap,0,0,width,height,matrix,true); // bitmap = Bitmap.createBitmap(bitmap,0,0,width,height,matrix,true);
return bitmap; // return bitmap;
} // }
} }

View File

@ -1,47 +1,47 @@
package cc.winboll.studio.positions.demo.transaction; package cc.winboll.studio.positions.demo.transaction;
import android.os.Bundle; //import android.os.Bundle;
import android.view.View; //import android.view.View;
import android.widget.Button; //import android.widget.Button;
//
import cc.winboll.studio.positions.R; //import cc.winboll.studio.positions.R;
import cc.winboll.studio.positions.demo.basic.SupportMapFragmentActivity; //import cc.winboll.studio.positions.demo.basic.SupportMapFragmentActivity;
import com.tencent.tencentmap.mapsdk.maps.CameraUpdate; //import com.tencent.tencentmap.mapsdk.maps.CameraUpdate;
import com.tencent.tencentmap.mapsdk.maps.CameraUpdateFactory; //import com.tencent.tencentmap.mapsdk.maps.CameraUpdateFactory;
//
public class ZoomMapActivity extends SupportMapFragmentActivity implements View.OnClickListener{ //public class ZoomMapActivity extends SupportMapFragmentActivity implements View.OnClickListener{
//
private Button btn,zoomin,zoomout; // private Button btn,zoomin,zoomout;
@Override // @Override
protected void onCreate(Bundle savedInstanceState) { // protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); // super.onCreate(savedInstanceState);
btn = findViewById(R.id.btn_bottom); // btn = findViewById(R.id.btn_bottom);
zoomin = findViewById(R.id.btn_zoomin); // zoomin = findViewById(R.id.btn_zoomin);
zoomout = findViewById(R.id.btn_zoomout); // zoomout = findViewById(R.id.btn_zoomout);
btn.setOnClickListener(this); // btn.setOnClickListener(this);
zoomout.setOnClickListener(this); // zoomout.setOnClickListener(this);
zoomin.setOnClickListener(this); // zoomin.setOnClickListener(this);
btn.setVisibility(View.VISIBLE); // btn.setVisibility(View.VISIBLE);
btn.setText("缩放至17级"); // btn.setText("缩放至17级");
zoomin.setVisibility(View.VISIBLE); // zoomin.setVisibility(View.VISIBLE);
zoomout.setVisibility(View.VISIBLE); // zoomout.setVisibility(View.VISIBLE);
} // }
//
@Override // @Override
public void onClick(View v) { // public void onClick(View v) {
switch (v.getId()){ // switch (v.getId()){
case R.id.btn_bottom: // case R.id.btn_bottom:
CameraUpdate cameraUpdate = CameraUpdateFactory.zoomTo(17f); // CameraUpdate cameraUpdate = CameraUpdateFactory.zoomTo(17f);
tencentMap.animateCamera(cameraUpdate); // tencentMap.animateCamera(cameraUpdate);
break; // break;
case R.id.btn_zoomin: // case R.id.btn_zoomin:
CameraUpdate cameraUpdate1 = CameraUpdateFactory.zoomIn(); // CameraUpdate cameraUpdate1 = CameraUpdateFactory.zoomIn();
tencentMap.animateCamera(cameraUpdate1); // tencentMap.animateCamera(cameraUpdate1);
break; // break;
case R.id.btn_zoomout: // case R.id.btn_zoomout:
CameraUpdate cameraUpdate2 = CameraUpdateFactory.zoomOut(); // CameraUpdate cameraUpdate2 = CameraUpdateFactory.zoomOut();
tencentMap.animateCamera(cameraUpdate2); // tencentMap.animateCamera(cameraUpdate2);
break; // break;
} // }
} // }
} //}

View File

@ -15,43 +15,43 @@ import com.tencent.tencentmap.mapsdk.maps.TencentMap.OnMapLongClickListener;
import com.tencent.tencentmap.mapsdk.maps.model.LatLng; import com.tencent.tencentmap.mapsdk.maps.model.LatLng;
import com.tencent.tencentmap.mapsdk.maps.model.VisibleRegion; import com.tencent.tencentmap.mapsdk.maps.model.VisibleRegion;
public class CoordinateActivity extends SupportMapFragmentActivity implements OnMapLongClickListener, TencentMap.OnMapClickListener { //public class CoordinateActivity extends SupportMapFragmentActivity implements OnMapLongClickListener, TencentMap.OnMapClickListener {
private TextView textView; // private TextView textView;
//
@Override // @Override
protected void onCreate(Bundle savedInstanceState) { // protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); // super.onCreate(savedInstanceState);
textView = findViewById(R.id.tv_info); // textView = findViewById(R.id.tv_info);
textView.setVisibility(View.VISIBLE); // textView.setVisibility(View.VISIBLE);
tencentMap.setOnMapClickListener(this); // tencentMap.setOnMapClickListener(this);
tencentMap.setOnMapLongClickListener(this); // tencentMap.setOnMapLongClickListener(this);
} // }
//
/** // /**
* 点击地图显示对应点击点的屏幕坐标 // * 点击地图显示对应点击点的屏幕坐标
* // *
* @param latLng // * @param latLng
*/ // */
@Override // @Override
public void onMapLongClick(LatLng latLng) { // public void onMapLongClick(LatLng latLng) {
Projection projection = tencentMap.getProjection(); // Projection projection = tencentMap.getProjection();
Point screen = projection.toScreenLocation(latLng); // Point screen = projection.toScreenLocation(latLng);
LatLng transferLatLng = projection.fromScreenLocation(screen); // LatLng transferLatLng = projection.fromScreenLocation(screen);
textView.setText("屏幕坐标:" + new Gson().toJson(screen)); // textView.setText("屏幕坐标:" + new Gson().toJson(screen));
Toast.makeText(this, new Gson().toJson(transferLatLng), Toast.LENGTH_SHORT).show(); // Toast.makeText(this, new Gson().toJson(transferLatLng), Toast.LENGTH_SHORT).show();
} // }
//
//
/** // /**
* 长点击地图 显示当前地图的坐标范围 // * 长点击地图 显示当前地图的坐标范围
* // *
* @param latLng // * @param latLng
*/ // */
@Override // @Override
public void onMapClick(LatLng latLng) { // public void onMapClick(LatLng latLng) {
Projection projection = tencentMap.getProjection(); // Projection projection = tencentMap.getProjection();
VisibleRegion region = projection.getVisibleRegion(); // VisibleRegion region = projection.getVisibleRegion();
textView.setText("当前地图视野的经纬度:" + new Gson().toJson(region)); // textView.setText("当前地图视野的经纬度:" + new Gson().toJson(region));
Toast.makeText(this, new Gson().toJson(region), Toast.LENGTH_LONG).show(); // Toast.makeText(this, new Gson().toJson(region), Toast.LENGTH_LONG).show();
} // }
} //}

View File

@ -1,135 +1,135 @@
package cc.winboll.studio.positions.demo.utils; package cc.winboll.studio.positions.demo.utils;
import android.app.Activity; //import android.app.Activity;
import android.graphics.Bitmap; //import android.graphics.Bitmap;
import android.os.Bundle; //import android.os.Bundle;
import android.os.Handler; //import android.os.Handler;
import android.view.Menu; //import android.view.Menu;
import android.view.MenuItem; //import android.view.MenuItem;
import android.widget.ImageView; //import android.widget.ImageView;
//
import cc.winboll.studio.positions.R; //import cc.winboll.studio.positions.R;
import cc.winboll.studio.positions.demo.basic.SupportMapFragmentActivity; //import cc.winboll.studio.positions.demo.basic.SupportMapFragmentActivity;
import com.tencent.tencentmap.mapsdk.maps.CameraUpdate; //import com.tencent.tencentmap.mapsdk.maps.CameraUpdate;
import com.tencent.tencentmap.mapsdk.maps.CameraUpdateFactory; //import com.tencent.tencentmap.mapsdk.maps.CameraUpdateFactory;
import com.tencent.tencentmap.mapsdk.maps.MapView; //import com.tencent.tencentmap.mapsdk.maps.MapView;
import com.tencent.tencentmap.mapsdk.maps.TencentMap; //import com.tencent.tencentmap.mapsdk.maps.TencentMap;
import com.tencent.tencentmap.mapsdk.maps.model.CameraPosition; //import com.tencent.tencentmap.mapsdk.maps.model.CameraPosition;
import com.tencent.tencentmap.mapsdk.maps.model.LatLng; //import com.tencent.tencentmap.mapsdk.maps.model.LatLng;
//
public class SnapshotActivity extends SupportMapFragmentActivity { //public class SnapshotActivity extends SupportMapFragmentActivity {
public MapView mapview = null; // public MapView mapview = null;
//
public TencentMap tencentMap = null; // public TencentMap tencentMap = null;
//
private ImageView imgView = null; // private ImageView imgView = null;
//
public TencentMap.SnapshotReadyCallback snapshotReadyCallback = new TencentMap.SnapshotReadyCallback() { // public TencentMap.SnapshotReadyCallback snapshotReadyCallback = new TencentMap.SnapshotReadyCallback() {
@Override // @Override
public void onSnapshotReady(Bitmap snapshot) { // public void onSnapshotReady(Bitmap snapshot) {
imgView.setImageBitmap(snapshot); // imgView.setImageBitmap(snapshot);
// Log.d("线程", "run: "+Thread.currentThread().getName()); // // Log.d("线程", "run: "+Thread.currentThread().getName());
} // }
}; // };
//
Handler handScreen = new Handler(); // Handler handScreen = new Handler();
//
final CameraPosition camerPosition_GUGONG = new CameraPosition.Builder() // final CameraPosition camerPosition_GUGONG = new CameraPosition.Builder()
.target(new LatLng(39.91822, 116.397165)).zoom(14.5f).bearing(200).tilt(50).build(); // .target(new LatLng(39.91822, 116.397165)).zoom(14.5f).bearing(200).tilt(50).build();
//
final CameraPosition camerPosition_YINKE = new CameraPosition.Builder() // final CameraPosition camerPosition_YINKE = new CameraPosition.Builder()
.target(new LatLng(31.226407, 121.48298)).zoom(17.5f).bearing(0).tilt(25).build(); // .target(new LatLng(31.226407, 121.48298)).zoom(17.5f).bearing(0).tilt(25).build();
//
private Runnable runScreenShot = new Runnable() { // private Runnable runScreenShot = new Runnable() {
//
@Override // @Override
public void run() { // public void run() {
// TODO Auto-generated method stub // // TODO Auto-generated method stub
tencentMap.snapshot(snapshotReadyCallback, Bitmap.Config.ARGB_8888); // tencentMap.snapshot(snapshotReadyCallback, Bitmap.Config.ARGB_8888);
} // }
//
}; // };
//
// TencentMap.OnTrafficUpdateListener trafficUpdateListener = new // // TencentMap.OnTrafficUpdateListener trafficUpdateListener = new
// TencentMap.OnTrafficUpdateListener() { // // TencentMap.OnTrafficUpdateListener() {
// // //
// @Override // // @Override
// public void onTrafficUpdate(String city) { // // public void onTrafficUpdate(String city) {
// Log.e("zxy", "onTrafficUpdate(): " + city); // // Log.e("zxy", "onTrafficUpdate(): " + city);
// // TODO Auto-generated method stub\ // // // TODO Auto-generated method stub\
// handScreen.postDelayed(runScreenShot, 2000); // // handScreen.postDelayed(runScreenShot, 2000);
// // //
// }}; // // }};
//
@Override // @Override
protected void onCreate(Bundle savedInstanceState) { // protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); // super.onCreate(savedInstanceState);
//
setContentView(R.layout.screenshot); // setContentView(R.layout.screenshot);
mapview = (MapView) findViewById(R.id.map); // mapview = (MapView) findViewById(R.id.map);
//
tencentMap = mapview.getMap(); // tencentMap = mapview.getMap();
//
// tencentMap.setOnTrafficUpdate(trafficUpdateListener); // // tencentMap.setOnTrafficUpdate(trafficUpdateListener);
tencentMap.setTrafficEnabled(true); // tencentMap.setTrafficEnabled(true);
tencentMap.setIndoorEnabled(true); // tencentMap.setIndoorEnabled(true);
handScreen.postDelayed(runScreenShot, 2000); // handScreen.postDelayed(runScreenShot, 2000);
//runOnUiThread(runScreenShot); // //runOnUiThread(runScreenShot);
imgView = (ImageView) this.findViewById(R.id.imgview); // imgView = (ImageView) this.findViewById(R.id.imgview);
imgView.setScaleType(ImageView.ScaleType.CENTER); // imgView.setScaleType(ImageView.ScaleType.CENTER);
} // }
//
@Override // @Override
protected void onPause() { // protected void onPause() {
// TODO Auto-generated method stub // // TODO Auto-generated method stub
super.onPause(); // super.onPause();
mapview.onPause(); // mapview.onPause();
} // }
//
@Override // @Override
protected void onResume() { // protected void onResume() {
// TODO Auto-generated method stub // // TODO Auto-generated method stub
super.onResume(); // super.onResume();
mapview.onResume(); // mapview.onResume();
} // }
//
@Override // @Override
protected void onDestroy() { // protected void onDestroy() {
// TODO Auto-generated method stub // // TODO Auto-generated method stub
super.onDestroy(); // super.onDestroy();
mapview.onDestroy(); // mapview.onDestroy();
} // }
//
@Override // @Override
public boolean onCreateOptionsMenu(Menu menu) { // public boolean onCreateOptionsMenu(Menu menu) {
// TODO Auto-generated method stub // // TODO Auto-generated method stub
menu.add(0, 1, 0, "截屏坐标1"); // menu.add(0, 1, 0, "截屏坐标1");
menu.add(0, 2, 0, "截屏坐标2"); // menu.add(0, 2, 0, "截屏坐标2");
return super.onCreateOptionsMenu(menu); // return super.onCreateOptionsMenu(menu);
} // }
//
@Override // @Override
public boolean onOptionsItemSelected(MenuItem item) { // public boolean onOptionsItemSelected(MenuItem item) {
// TODO Auto-generated method stub // // TODO Auto-generated method stub
switch (item.getItemId()) { // switch (item.getItemId()) {
case 1: // case 1:
setCoord1(); // setCoord1();
handScreen.postDelayed(runScreenShot, 2000); // handScreen.postDelayed(runScreenShot, 2000);
break; // break;
case 2: // case 2:
setCoor2(); // setCoor2();
handScreen.postDelayed(runScreenShot, 2000); // handScreen.postDelayed(runScreenShot, 2000);
break; // break;
} // }
return super.onOptionsItemSelected(item); // return super.onOptionsItemSelected(item);
} // }
//
private void setCoord1() { // private void setCoord1() {
CameraUpdate update = CameraUpdateFactory.newCameraPosition(camerPosition_GUGONG); // CameraUpdate update = CameraUpdateFactory.newCameraPosition(camerPosition_GUGONG);
tencentMap.moveCamera(update); // tencentMap.moveCamera(update);
} // }
//
private void setCoor2() { // private void setCoor2() {
CameraUpdate update = CameraUpdateFactory.newCameraPosition(camerPosition_YINKE); // CameraUpdate update = CameraUpdateFactory.newCameraPosition(camerPosition_YINKE);
tencentMap.moveCamera(update); // tencentMap.moveCamera(update);
} // }
} //}