07d77721 by chiangbt

update 3.28

1 parent 85a18886
package com.pashanhoo.landsurvey;
import android.location.Location;
import android.location.LocationListener;
import android.support.design.widget.FloatingActionButton;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import com.esri.android.map.LocationDisplayManager;
import com.esri.android.map.MapView;
import com.esri.android.runtime.ArcGISRuntime;
import com.esri.core.geometry.Point;
import com.pashanhoo.landsurvey.R;
import com.pashanhoo.landsurvey.layers.google.GoogleMapLayer;
import com.pashanhoo.landsurvey.layers.google.GoogleMapLayerTypes;
import com.pashanhoo.landsurvey.layers.google.GoogleMapsTiledServiceLayer;
import com.pashanhoo.landsurvey.layers.tianditu.TDTTileinfo;
import com.pashanhoo.landsurvey.utils.AppInfo;
import com.pashanhoo.landsurvey.utils.GisHolder;
import com.pashanhoo.landsurvey.utils.GISHelper;
import com.pashanhoo.landsurvey.utils.JZLocationConverter;
public class GoogleMapActivity extends AppCompatActivity {
private MapView mapView;
// GPS定位器对象
private LocationDisplayManager locationDisplayManager;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
......@@ -28,14 +33,58 @@ public class GoogleMapActivity extends AppCompatActivity {
mapView.setEsriLogoVisible(false);
mapView.enableWrapAround(false);
GoogleMapsTiledServiceLayer GOOGLE_VECTOR_Layer = new GoogleMapsTiledServiceLayer();
GoogleMapsTiledServiceLayer GOOGLE_VECTOR_Layer = new GoogleMapsTiledServiceLayer(GoogleMapLayerTypes.VECTOR_GOOGLE_MAP);
// GoogleMapsTiledServiceLayer GOOGLE_TER_Layer = new GoogleMapsTiledServiceLayer(GoogleMapLayerTypes.TERRAIN_GOOGLE_MAP);
// GoogleMapsTiledServiceLayer GOOGLE_IMAGE_Layer = new GoogleMapsTiledServiceLayer(GoogleMapLayerTypes.IMAGE_GOOGLE_MAP);
mapView.addLayer(GOOGLE_VECTOR_Layer);
// GoogleMapsTiledServiceLayer GOOGLE_ANNO_Layer = new GoogleMapsTiledServiceLayer(GoogleMapLayerTypes.ANNOTATION_GOOGLE_MAP);
// mapView.addLayer(GOOGLE_ANNO_Layer);
mapView.setMaxResolution(156543.03392800014);
mapView.setMinResolution(1.1943285668550503);
mapView.setMinResolution(0.29858214164761665);
Point pt = GISHelper.lonLat2Mercator(AppInfo.initPoint);
mapView.zoomToResolution(pt, GoogleMapsTiledServiceLayer.getRes()[16]);
locationDisplayManager = mapView.getLocationDisplayManager();
locationDisplayManager.setShowLocation(true);
locationDisplayManager.setAutoPanMode(LocationDisplayManager.AutoPanMode.LOCATION);//设置模式
locationDisplayManager.setShowPings(true);
locationDisplayManager.setLocationListener(new LocationListener() {
@Override
public void onLocationChanged(Location location) {
Point pt = new Point(location.getLongitude(), location.getLatitude());
Point gcjPt = JZLocationConverter.wgs84ToGcj02(pt);
mapView.zoomToResolution(GISHelper.lonLat2Mercator(gcjPt),
GoogleMapsTiledServiceLayer.getRes()[18]);
}
@Override
public void onStatusChanged(String s, int i, Bundle bundle) {
}
Point pt = GisHolder.lonLat2Mercator(AppInfo.initPoint);
mapView.zoomToResolution(pt, 19.1092570712683);
@Override
public void onProviderEnabled(String s) {
}
@Override
public void onProviderDisabled(String s) {
}
});
FloatingActionButton gps = (FloatingActionButton) findViewById(R.id.gps);
gps.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
// 设置GPS功能
if (locationDisplayManager.isStarted()) {
locationDisplayManager.stop();
} else {
locationDisplayManager.start();
mapView.zoomToResolution(GISHelper.lonLat2Mercator(locationDisplayManager.getPoint()),
GoogleMapsTiledServiceLayer.getRes()[18]);
}
}
});
}
}
......
package com.pashanhoo.landsurvey.layers.google;
import android.util.Log;
import com.esri.android.map.TiledServiceLayer;
import com.esri.core.geometry.Envelope;
import com.esri.core.geometry.Point;
import com.esri.core.geometry.SpatialReference;
import java.util.Map;
import java.util.concurrent.RejectedExecutionException;
/**
* Created by jiangbotao on 2018/3/28.
*/
public class GoogleMapLayer extends TiledServiceLayer {
private int minLevel = 0;
private int maxLevel = 19;
private String[] subDomains = new String[]{"mt1", "mt2", "mt3"};
private double[] scales = new double[]{591657527.591555,
295828763.79577702,
147914381.89788899,
73957190.948944002,
36978595.474472001,
18489297.737236001,
9244648.8686180003,
4622324.4343090001,
2311162.217155,
1155581.108577,
577790.554289,
288895.277144,
144447.638572,
72223.819286,
36111.909643,
18055.954822,
9027.9774109999998,
4513.9887049999998,
2256.994353,
1128.4971760000001};
private double[] resolutions = new double[]{156543.03392800014,
78271.516963999937,
39135.758482000092,
19567.879240999919,
9783.9396204999593,
4891.9698102499797,
2445.9849051249898,
1222.9924525624949,
611.49622628138,
305.748113140558,
152.874056570411,
76.4370282850732,
38.2185141425366,
19.1092570712683,
9.55462853563415,
4.7773142679493699,
2.3886571339746849,
1.1943285668550503,
0.59716428355981721,
0.29858214164761665};
private Point origin = new Point(-20037508.342787, 20037508.342787);
private int dpi = 96;
private int tileWidth = 256;
private int tileHeight = 256;
private int GoogleMapLayerType;
public GoogleMapLayer(int layerType) {
super(true);
this.GoogleMapLayerType = layerType;
this.init();
}
private void init() {
try {
getServiceExecutor().submit(new Runnable() {
public void run() {
GoogleMapLayer.this.initLayer();
}
});
} catch(RejectedExecutionException rejectedexecutionexception) {
Log.e("Google Map Layer", "initialization of the layer failed.",
rejectedexecutionexception);
}
}
protected byte[] getTile(int level, int col, int row) throws Exception {
if (level > maxLevel || level <minLevel) {
return new byte[0];
}
String s = "Galileo".substring(0, ((3 * col + row) % 8));
String url = "";
switch (GoogleMapLayerType) {
case GoogleMapLayerTypes.IMAGE_GOOGLE_MAP:
url = "http://mt" + (col % 4) + ".google.com/vt/lyrs=s&hl=zh-CN&gl=cn&" + "x=" + col + "&" + "y=" + row + "&" + "z=" + level + "&" + "s=" + s;
break;
case GoogleMapLayerTypes.VECTOR_GOOGLE_MAP:
url = "http://mt" + (col % 4) + ".google.com/vt/lyrs=m@158000000&hl=zh-CN&gl=cn&" + "x=" + col + "&" + "y=" + row + "&" + "z=" + level + "&" + "s=" + s;
break;
case GoogleMapLayerTypes.TERRAIN_GOOGLE_MAP:
url = "http://mt" + (col % 4) + ".google.cn/vt/lyrs=t@131,r@227000000&hl=zh-CN&gl=cn&" + "x=" + col + "&" + "y=" + row + "&" + "z=" + level + "&" + "s=" + s;
break;
case GoogleMapLayerTypes.ANNOTATION_GOOGLE_MAP:
url = "http://mt" + (col % 4) + ".google.com/vt/imgtp=png32&lyrs=h@169000000&hl=zh-CN&gl=cn&" + "x=" + col + "&" + "y=" + row + "&" + "z=" + level + "&" + "s=" + s;
// url = "http://mt"+ (col % 4) +".google.cn/vt/lyrs=m@256000000&hl=zh-CN&gl=CN&src=app&x=" + col + "&y=" + row + "&z=" + level + "&s=" + s;
break;
}
Log.v(GoogleMapLayer.class.getName(), "url:"+url);
Map<String, String> map = null;
return com.esri.core.internal.io.handler.a.a(url, map);
}
protected void initLayer() {
if (getID() == 0L) {
nativeHandle = create();
changeStatus(com.esri.android.map.event.OnStatusChangedListener.STATUS .fromInt(-1000));
} else {
this.setDefaultSpatialReference(SpatialReference.create(102113));
this.setFullExtent(new Envelope(-22041257.773878, -32673939.6727517, 22041257.773878, 20851350.0432886));
this.setTileInfo(new TileInfo(origin, scales, resolutions, scales.length, dpi, tileWidth, tileHeight));
super.initLayer();
}
}
}
package com.pashanhoo.landsurvey.layers.google;
import com.esri.android.map.TiledServiceLayer;
import java.util.concurrent.RejectedExecutionException;
import android.annotation.SuppressLint;
import android.util.Log;
import com.esri.android.map.TiledServiceLayer;
import com.esri.android.map.event.OnStatusChangedListener;
import com.esri.core.geometry.Envelope;
import com.esri.core.geometry.Point;
......@@ -14,7 +14,7 @@ import com.esri.core.geometry.SpatialReference;
import com.esri.core.internal.io.handler.ResponseListener;
import com.esri.core.internal.io.handler.a;
import com.esri.core.io.UserCredentials;
import com.pashanhoo.landsurvey.utils.GisHolder;
import com.pashanhoo.landsurvey.utils.GISHelper;
/**
* Created by jiangbotao on 2018/3/28.
......@@ -28,23 +28,27 @@ public class GoogleMapsTiledServiceLayer extends TiledServiceLayer {
private static final double XMin = 110.35992000000005;
private static final double YMin = 31.382360000000062;
private static final double XMax = 116.65036000000009;
private static final double YMax = 36.36647000000005;
private static final double[] res = { 156543.03392800014, 78271.516963999937, 39135.758482000092, 19567.879240999919, 9783.9396204999593, 4891.9698102499797, 2445.9849051249898,
private static final double[] res = {156543.03392800014, 78271.516963999937, 39135.758482000092, 19567.879240999919, 9783.9396204999593, 4891.9698102499797, 2445.9849051249898,
1222.9924525624949, 611.49622628138, 305.748113140558, 152.874056570411, 76.4370282850732, 38.2185141425366, 19.1092570712683, 9.55462853563415, 4.7773142679493699, 2.3886571339746849,
1.1943285668550503 /* , 0.59716428355981721, 0.29858214164761665 */};
1.1943285668550503 , 0.59716428355981721, 0.29858214164761665 };
private static final double[] scale = { 591657527.591555, 295828763.79577702, 147914381.89788899, 73957190.948944002, 36978595.474472001, 18489297.737236001, 9244648.8686180003,
private static final double[] scale = {591657527.591555, 295828763.79577702, 147914381.89788899, 73957190.948944002, 36978595.474472001, 18489297.737236001, 9244648.8686180003,
4622324.4343090001, 2311162.217155, 1155581.108577, 577790.554289, 288895.277144, 144447.638572, 72223.819286, 6111.909643, 18055.954822, 9027.9774109999998, 4513.9887049999998
/* ,2256.994353, 1128.4971760000001 */};
,2256.994353, 1128.4971760000001 };
private static String URL = "http://maps.iwxlh.com";
private ResponseListener responseListener;
private static Point origin = new Point(-20037508.342787, 20037508.342787);
public GoogleMapsTiledServiceLayer() {
private int GoogleMapLayerType;
public GoogleMapsTiledServiceLayer(int layerType) {
this(true);
this.GoogleMapLayerType = layerType;
}
public GoogleMapsTiledServiceLayer(boolean initLayer) {
......@@ -64,6 +68,10 @@ public class GoogleMapsTiledServiceLayer extends TiledServiceLayer {
}
}
public static double[] getRes() {
return res;
}
protected void initLayer() {
if (getID() == 0L) {
this.nativeHandle = create();
......@@ -74,8 +82,8 @@ public class GoogleMapsTiledServiceLayer extends TiledServiceLayer {
try {
setDefaultSpatialReference(SpatialReference.create(102100));
GisHolder.lonLat2Mercator(new Point(XMin, YMin));
GisHolder.lonLat2Mercator(new Point(XMax, YMax));
GISHelper.lonLat2Mercator(new Point(XMin, YMin));
GISHelper.lonLat2Mercator(new Point(XMax, YMax));
setFullExtent(new Envelope(xmin, ymin, xmax, ymax));
// setFullExtent(new Envelope(minMercatorPoint.getX(),
......@@ -90,19 +98,26 @@ public class GoogleMapsTiledServiceLayer extends TiledServiceLayer {
}
}
static final String BASE_URL = "http://mt%d.google.cn/vt/lyrs=m@161000000&v=w2.114&hl=zh-CN&gl=cn&x=%d&y=%d&z=%d&s=Galil";
static final String BASE_URL_2 = "http://mt2.google.cn/vt/v=w2.116&hl=zh-CN&gl=cn&x=%d&y=%d&z=%d&s=G";
String get(int lev, int col, int row) {
return "http://mt" + (col % 4) + ".google.cn/vt/lyrs=m@161000000&v=w2.114&hl=zh-CN&gl=cn&" + "x=" + col + "&" + "y=" + row + "&" + "z=" + lev + "&s=Galil"; // 加载Google街道图
}
@SuppressLint("DefaultLocale")
protected byte[] getTile(int lev, int col, int row) throws Exception {
String url = String.format(BASE_URL, col % 4, col, row, lev); // 加载Google街道图
// String url2 = String.format(BASE_URL_2, col, row, lev); // 加载Google街道图
// PtaDebug.d("url", url);
// PtaDebug.e("url2", url2);
protected byte[] getTile(int level, int col, int row) throws Exception {
String url = "";
String s = "Galil";
switch (GoogleMapLayerType) {
case GoogleMapLayerTypes.IMAGE_GOOGLE_MAP:
url = "http://mt" + (col % 4) + ".google.cn/vt/lyrs=s&hl=zh-CN&gl=cn&" + "x=" + col + "&" + "y=" + row + "&" + "z=" + level + "&" + "s=" + s;
break;
case GoogleMapLayerTypes.VECTOR_GOOGLE_MAP:
url = "http://mt" + (col % 4) + ".google.cn/vt/lyrs=m@161000000&v=w2.114&hl=zh-CN&gl=cn&" + "x=" + col + "&" + "y=" + row + "&" + "z=" + level + "&" + "s=" + s;
break;
case GoogleMapLayerTypes.TERRAIN_GOOGLE_MAP:
url = "http://mt" + (col % 4) + ".google.cn/vt/lyrs=t@131,r@227000000&hl=zh-CN&gl=cn&" + "x=" + col + "&" + "y=" + row + "&" + "z=" + level + "&" + "s=" + s;
break;
case GoogleMapLayerTypes.ANNOTATION_GOOGLE_MAP:
// url = "http://mt2.google.cn/vt/lyrs=m@161000000&v=w2.114&hl=zh-CN&gl=CN&src=app&x=" + col + "&y=" + row + "&z=" + level + "&s=" + s;
url = "http://webst02.is.autonavi.com/appmaptile?style=8&x="+ col +"&y="+ row +"&z="+level;
break;
}
return a.a(url, null, null, this.responseListener);
}
......
......@@ -5,22 +5,14 @@ package com.pashanhoo.landsurvey.utils;
*/
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.List;
import android.graphics.Bitmap;
import android.util.Log;
import com.esri.android.map.GraphicsLayer;
import com.esri.android.map.MapView;
import com.esri.core.geometry.GeometryEngine;
import com.esri.core.geometry.Line;
import com.esri.core.geometry.Point;
import com.esri.core.geometry.Polygon;
import com.esri.core.geometry.Polyline;
import com.esri.core.geometry.SpatialReference;
import com.esri.core.map.Graphic;
import com.esri.core.symbol.SimpleLineSymbol;
/**
* GIS相关持有工具类
......@@ -28,13 +20,13 @@ import com.esri.core.symbol.SimpleLineSymbol;
* @author JiangXusheng
* @date 2013-7-6 下午1:16:07
*/
public class GisHolder {
public class GISHelper {
public static final int VALIDATE_X_Y = 999;
public static final double AX = 0.83;
public static final double BX = 1 - AX;
static final String TAG = GisHolder.class.getName();
static final String TAG = GISHelper.class.getName();
public enum MarkerSymbolType {
TEXT, IMAGE, SIMPLE, IMAGE_TEXT, SIMPLE_TEXT, SIMPLE_LINE;
......@@ -42,7 +34,9 @@ public class GisHolder {
private static final double EARTH_RADIUS = 6378137.0;
/** 计算两点间的距离 */
/**
* 计算两点间的距离
*/
public static double gps2m(double lat_a, double lng_a, double lat_b, double lng_b) {
double radLat1 = (lat_a * Math.PI / 180.0);
double radLat2 = (lat_b * Math.PI / 180.0);
......@@ -55,7 +49,10 @@ public class GisHolder {
}
// 计算方位角pab。
/** 计算方位角 */
/**
* 计算方位角
*/
public static double gps2d(double lat_a, double lng_a, double lat_b, double lng_b) {
double d = 0;
lat_a = lat_a * Math.PI / 180;
......@@ -94,21 +91,6 @@ public class GisHolder {
return AX * dN + BX * dPieN_1;
}
public static double getScreenM(MapView mapView, Point point1, Point point2, boolean toMocha) {
point1 = GisHolder.checkGeometryPoint(point1);
point2 = GisHolder.checkGeometryPoint(point2);
if (toMocha) {
point1 = GisHolder.lonLat2Mercator(point1);
point2 = GisHolder.lonLat2Mercator(point2);
}
Point screenPoint1 = mapView.toScreenPoint(point1);
Point screenPoint2 = mapView.toScreenPoint(point2);
return Math.sqrt((screenPoint1.getX() - screenPoint2.getX()) * (screenPoint1.getX() - screenPoint2.getX()) + (screenPoint1.getY() - screenPoint2.getY())
* (screenPoint1.getY() - screenPoint2.getY()));
}
public static boolean isValidateData(Point point) {
boolean rst = false;
......@@ -127,28 +109,11 @@ public class GisHolder {
return (x / 1000000.0);
}
public static Point checkGeometryPoint(Point point) {
try {
if (null == point) {
point = new Point();
}
if (point.isEmpty()) {
point.setX(VALIDATE_X_Y);
point.setY(VALIDATE_X_Y);
}
} catch (Exception e) {
point.setX(VALIDATE_X_Y);
point.setY(VALIDATE_X_Y);
}
return point;
}
private static DecimalFormat format = new DecimalFormat("0.0");
// 经纬度转墨卡托
/**
* SpatialReference.WKID_WGS84(4326) to
* SpatialReference.WKID_WGS84_WEB_MERCATOR_AUXILIARY_SPHERE(102100)
......@@ -171,6 +136,7 @@ public class GisHolder {
}
// 墨卡托转经纬度
/**
* SpatialReference.WKID_WGS84_WEB_MERCATOR_AUXILIARY_SPHERE(102100) to
* SpatialReference.WKID_WGS84(4326)
......@@ -189,33 +155,4 @@ public class GisHolder {
return point;
}
public static Point[] getPoints(Point center, double radius) {
Point[] points = new Point[50];
double sin;
double cos;
double x;
double y;
for (double i = 0; i < 50; i++) {
sin = Math.sin(Math.PI * 2 * i / 50);
cos = Math.cos(Math.PI * 2 * i / 50);
x = center.getX() + radius * 1.2 * sin;
y = center.getY() + radius * cos;
points[(int) i] = new Point(x, y);
}
return points;
}
public static void getCircle(Point center, double radius, Polygon circle) {
circle.setEmpty();
try {
Point[] points = getPoints(center, radius);
circle.startPath(GisHolder.lonLat2Mercator(points[0]));
for (int i = 1; i < points.length; i++) {
points[i] = GisHolder.checkGeometryPoint(points[i]);
circle.lineTo(GisHolder.lonLat2Mercator(points[i]));
}
} catch (Exception e) {
Log.e("", "", e);
}
}
}
......
......@@ -10,4 +10,22 @@
android:id="@+id/map"
android:layout_width="fill_parent"
android:layout_height="fill_parent"></com.esri.android.map.MapView>
<android.support.v7.widget.LinearLayoutCompat
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_marginTop="16dp"
android:layout_marginLeft="16dp"
android:layout_marginBottom="16dp"
android:layout_gravity="top|start">
<android.support.design.widget.FloatingActionButton
android:id="@+id/gps"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="top|start"
android:layout_marginTop="0dp"
android:layout_marginLeft="0dp"
app:srcCompat="@mipmap/ic_my_location_white_48dp" />
</android.support.v7.widget.LinearLayoutCompat>
</android.support.constraint.ConstraintLayout>
......