update 3.28
Showing
7 changed files
with
506 additions
and
34 deletions
1 | <?xml version="1.0" encoding="utf-8"?> | 1 | <?xml version="1.0" encoding="utf-8"?> |
2 | <manifest xmlns:android="http://schemas.android.com/apk/res/android" | 2 | <manifest xmlns:android="http://schemas.android.com/apk/res/android" |
3 | package="com.pashanhoo.landsurvey"> | 3 | package="com.pashanhoo.landsurvey"> |
4 | |||
4 | <uses-feature | 5 | <uses-feature |
5 | android:glEsVersion="0x00020000" | 6 | android:glEsVersion="0x00020000" |
6 | android:required="true" /> | 7 | android:required="true" /> |
8 | |||
7 | <uses-permission android:name="android.permission.INTERNET" /> | 9 | <uses-permission android:name="android.permission.INTERNET" /> |
8 | <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> | 10 | <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> |
9 | <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> | 11 | <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> |
12 | |||
10 | <application | 13 | <application |
11 | android:allowBackup="true" | 14 | android:allowBackup="true" |
12 | android:icon="@mipmap/logo" | 15 | android:icon="@mipmap/logo" |
13 | android:label="@string/app_name" | 16 | android:label="@string/app_name" |
14 | android:supportsRtl="true" | 17 | android:supportsRtl="true" |
15 | android:theme="@style/AppTheme"> | 18 | android:theme="@style/AppTheme"> |
19 | <activity android:name=".BootActivity"> | ||
20 | |||
21 | </activity> | ||
16 | <activity | 22 | <activity |
17 | android:name=".BootActivity"> | 23 | android:name=".MainActivity" |
24 | android:label="@string/app_name" | ||
25 | android:screenOrientation="landscape" | ||
26 | android:theme="@style/AppTheme.NoActionBar"> <!-- 禁止屏幕旋转 --> | ||
27 | </activity> | ||
28 | <activity android:name=".GoogleMapActivity"> | ||
18 | <intent-filter> | 29 | <intent-filter> |
19 | <action android:name="android.intent.action.MAIN" /> | 30 | <action android:name="android.intent.action.MAIN" /> |
20 | 31 | ||
21 | <category android:name="android.intent.category.LAUNCHER" /> | 32 | <category android:name="android.intent.category.LAUNCHER" /> |
22 | </intent-filter> | 33 | </intent-filter> |
23 | </activity> | 34 | </activity> |
24 | <activity android:name=".MainActivity" | ||
25 | android:label="@string/app_name" | ||
26 | android:theme="@style/AppTheme.NoActionBar" | ||
27 | android:screenOrientation="landscape"> <!-- 禁止屏幕旋转 --> | ||
28 | </activity> | ||
29 | </application> | 35 | </application> |
30 | 36 | ||
31 | </manifest> | 37 | </manifest> |
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
1 | package com.pashanhoo.landsurvey; | ||
2 | |||
3 | import android.support.v7.app.AppCompatActivity; | ||
4 | import android.os.Bundle; | ||
5 | |||
6 | import com.esri.android.map.MapView; | ||
7 | import com.esri.android.runtime.ArcGISRuntime; | ||
8 | import com.esri.core.geometry.Point; | ||
9 | import com.pashanhoo.landsurvey.R; | ||
10 | import com.pashanhoo.landsurvey.layers.google.GoogleMapLayer; | ||
11 | import com.pashanhoo.landsurvey.layers.google.GoogleMapLayerTypes; | ||
12 | import com.pashanhoo.landsurvey.layers.google.GoogleMapsTiledServiceLayer; | ||
13 | import com.pashanhoo.landsurvey.layers.tianditu.TDTTileinfo; | ||
14 | import com.pashanhoo.landsurvey.utils.AppInfo; | ||
15 | import com.pashanhoo.landsurvey.utils.GisHolder; | ||
16 | |||
17 | public class GoogleMapActivity extends AppCompatActivity { | ||
18 | |||
19 | private MapView mapView; | ||
20 | |||
21 | @Override | ||
22 | protected void onCreate(Bundle savedInstanceState) { | ||
23 | super.onCreate(savedInstanceState); | ||
24 | setContentView(R.layout.activity_google_map); | ||
25 | |||
26 | ArcGISRuntime.setClientId("1eFHW78avlnRUPHm"); | ||
27 | mapView = (MapView) findViewById(R.id.map); | ||
28 | mapView.setEsriLogoVisible(false); | ||
29 | mapView.enableWrapAround(false); | ||
30 | |||
31 | GoogleMapsTiledServiceLayer GOOGLE_VECTOR_Layer = new GoogleMapsTiledServiceLayer(); | ||
32 | mapView.addLayer(GOOGLE_VECTOR_Layer); | ||
33 | |||
34 | mapView.setMaxResolution(156543.03392800014); | ||
35 | mapView.setMinResolution(1.1943285668550503); | ||
36 | |||
37 | Point pt = GisHolder.lonLat2Mercator(AppInfo.initPoint); | ||
38 | mapView.zoomToResolution(pt, 19.1092570712683); | ||
39 | |||
40 | } | ||
41 | } |
1 | package com.pashanhoo.landsurvey.layers.google; | 1 | package com.pashanhoo.landsurvey.layers.google; |
2 | 2 | ||
3 | import android.util.Log; | ||
4 | |||
3 | import com.esri.android.map.TiledServiceLayer; | 5 | import com.esri.android.map.TiledServiceLayer; |
4 | import com.esri.core.geometry.Envelope; | 6 | import com.esri.core.geometry.Envelope; |
5 | import com.esri.core.geometry.Point; | 7 | import com.esri.core.geometry.Point; |
... | @@ -20,19 +22,45 @@ public class GoogleMapLayer extends TiledServiceLayer { | ... | @@ -20,19 +22,45 @@ public class GoogleMapLayer extends TiledServiceLayer { |
20 | private String[] subDomains = new String[]{"mt1", "mt2", "mt3"}; | 22 | private String[] subDomains = new String[]{"mt1", "mt2", "mt3"}; |
21 | 23 | ||
22 | private double[] scales = new double[]{591657527.591555, | 24 | private double[] scales = new double[]{591657527.591555, |
23 | 295828763.79577702, 147914381.89788899, 73957190.948944002, | 25 | 295828763.79577702, |
24 | 36978595.474472001, 18489297.737236001, 9244648.8686180003, | 26 | 147914381.89788899, |
25 | 4622324.4343090001, 2311162.217155, 1155581.108577, 577790.554289, | 27 | 73957190.948944002, |
26 | 288895.277144, 144447.638572, 72223.819286, 36111.909643, | 28 | 36978595.474472001, |
27 | 18055.954822, 9027.9774109999998, 4513.9887049999998, 2256.994353, | 29 | 18489297.737236001, |
30 | 9244648.8686180003, | ||
31 | 4622324.4343090001, | ||
32 | 2311162.217155, | ||
33 | 1155581.108577, | ||
34 | 577790.554289, | ||
35 | 288895.277144, | ||
36 | 144447.638572, | ||
37 | 72223.819286, | ||
38 | 36111.909643, | ||
39 | 18055.954822, | ||
40 | 9027.9774109999998, | ||
41 | 4513.9887049999998, | ||
42 | 2256.994353, | ||
28 | 1128.4971760000001}; | 43 | 1128.4971760000001}; |
44 | |||
29 | private double[] resolutions = new double[]{156543.03392800014, | 45 | private double[] resolutions = new double[]{156543.03392800014, |
30 | 78271.516963999937, 39135.758482000092, 19567.879240999919, | 46 | 78271.516963999937, |
31 | 9783.9396204999593, 4891.9698102499797, 2445.9849051249898, | 47 | 39135.758482000092, |
32 | 1222.9924525624949, 611.49622628138, 305.748113140558, | 48 | 19567.879240999919, |
33 | 152.874056570411, 76.4370282850732, 38.2185141425366, | 49 | 9783.9396204999593, |
34 | 19.1092570712683, 9.55462853563415, 4.7773142679493699, | 50 | 4891.9698102499797, |
35 | 2.3886571339746849, 1.1943285668550503, 0.59716428355981721, | 51 | 2445.9849051249898, |
52 | 1222.9924525624949, | ||
53 | 611.49622628138, | ||
54 | 305.748113140558, | ||
55 | 152.874056570411, | ||
56 | 76.4370282850732, | ||
57 | 38.2185141425366, | ||
58 | 19.1092570712683, | ||
59 | 9.55462853563415, | ||
60 | 4.7773142679493699, | ||
61 | 2.3886571339746849, | ||
62 | 1.1943285668550503, | ||
63 | 0.59716428355981721, | ||
36 | 0.29858214164761665}; | 64 | 0.29858214164761665}; |
37 | 65 | ||
38 | private Point origin = new Point(-20037508.342787, 20037508.342787); | 66 | private Point origin = new Point(-20037508.342787, 20037508.342787); |
... | @@ -42,8 +70,11 @@ public class GoogleMapLayer extends TiledServiceLayer { | ... | @@ -42,8 +70,11 @@ public class GoogleMapLayer extends TiledServiceLayer { |
42 | private int tileWidth = 256; | 70 | private int tileWidth = 256; |
43 | private int tileHeight = 256; | 71 | private int tileHeight = 256; |
44 | 72 | ||
45 | public GoogleMapLayer() { | 73 | private int GoogleMapLayerType; |
74 | |||
75 | public GoogleMapLayer(int layerType) { | ||
46 | super(true); | 76 | super(true); |
77 | this.GoogleMapLayerType = layerType; | ||
47 | this.init(); | 78 | this.init(); |
48 | } | 79 | } |
49 | 80 | ||
... | @@ -54,22 +85,34 @@ public class GoogleMapLayer extends TiledServiceLayer { | ... | @@ -54,22 +85,34 @@ public class GoogleMapLayer extends TiledServiceLayer { |
54 | GoogleMapLayer.this.initLayer(); | 85 | GoogleMapLayer.this.initLayer(); |
55 | } | 86 | } |
56 | }); | 87 | }); |
57 | } catch (RejectedExecutionException rejectedexecutionexception) { | 88 | } catch(RejectedExecutionException rejectedexecutionexception) { |
58 | 89 | Log.e("Google Map Layer", "initialization of the layer failed.", | |
90 | rejectedexecutionexception); | ||
59 | } | 91 | } |
60 | } | 92 | } |
61 | 93 | ||
62 | protected byte[] getTile(int level, int col, int row) throws Exception { | 94 | protected byte[] getTile(int level, int col, int row) throws Exception { |
63 | if (level > maxLevel || level < minLevel) | 95 | if (level > maxLevel || level <minLevel) { |
64 | return new byte[0]; | 96 | return new byte[0]; |
65 | String subDomain = subDomains[(level + col + row) % subDomains.length]; | 97 | } |
66 | 98 | String s = "Galileo".substring(0, ((3 * col + row) % 8)); | |
67 | //构建待拼接字符串 | 99 | String url = ""; |
68 | String _mapType = "m@225000000"; | 100 | switch (GoogleMapLayerType) { |
69 | String url = "http://" + subDomain | 101 | case GoogleMapLayerTypes.IMAGE_GOOGLE_MAP: |
70 | + ".google.cn/vt/lyrs=" + _mapType + "&hl=zh-CN&gl=CN&src=app&" + "x=" + col + "&" + "y=" + row + "&" + "z=" + level + "&s=Ga"; | 102 | url = "http://mt" + (col % 4) + ".google.com/vt/lyrs=s&hl=zh-CN&gl=cn&" + "x=" + col + "&" + "y=" + row + "&" + "z=" + level + "&" + "s=" + s; |
71 | 103 | break; | |
72 | 104 | case GoogleMapLayerTypes.VECTOR_GOOGLE_MAP: | |
105 | url = "http://mt" + (col % 4) + ".google.com/vt/lyrs=m@158000000&hl=zh-CN&gl=cn&" + "x=" + col + "&" + "y=" + row + "&" + "z=" + level + "&" + "s=" + s; | ||
106 | break; | ||
107 | case GoogleMapLayerTypes.TERRAIN_GOOGLE_MAP: | ||
108 | 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; | ||
109 | break; | ||
110 | case GoogleMapLayerTypes.ANNOTATION_GOOGLE_MAP: | ||
111 | 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; | ||
112 | // 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; | ||
113 | break; | ||
114 | } | ||
115 | Log.v(GoogleMapLayer.class.getName(), "url:"+url); | ||
73 | Map<String, String> map = null; | 116 | Map<String, String> map = null; |
74 | return com.esri.core.internal.io.handler.a.a(url, map); | 117 | return com.esri.core.internal.io.handler.a.a(url, map); |
75 | } | 118 | } |
... | @@ -77,13 +120,11 @@ public class GoogleMapLayer extends TiledServiceLayer { | ... | @@ -77,13 +120,11 @@ public class GoogleMapLayer extends TiledServiceLayer { |
77 | protected void initLayer() { | 120 | protected void initLayer() { |
78 | if (getID() == 0L) { | 121 | if (getID() == 0L) { |
79 | nativeHandle = create(); | 122 | nativeHandle = create(); |
80 | changeStatus(com.esri.android.map.event.OnStatusChangedListener.STATUS | 123 | changeStatus(com.esri.android.map.event.OnStatusChangedListener.STATUS .fromInt(-1000)); |
81 | .fromInt(-1000)); | ||
82 | } else { | 124 | } else { |
83 | this.setDefaultSpatialReference(SpatialReference.create(102113)); | 125 | this.setDefaultSpatialReference(SpatialReference.create(102113)); |
84 | this.setFullExtent(new Envelope(-22041257.773878, | 126 | this.setFullExtent(new Envelope(-22041257.773878, -32673939.6727517, 22041257.773878, 20851350.0432886)); |
85 | -32673939.6727517, 22041257.773878, 20851350.0432886)); | 127 | this.setTileInfo(new TileInfo(origin, scales, resolutions, scales.length, dpi, tileWidth, tileHeight)); |
86 | this.setTileInfo(new TileInfo(origin, scales, resolutions,scales.length, dpi, tileWidth, tileHeight)); | ||
87 | super.initLayer(); | 128 | super.initLayer(); |
88 | } | 129 | } |
89 | } | 130 | } | ... | ... |
1 | package com.pashanhoo.landsurvey.layers.google; | ||
2 | |||
3 | /** | ||
4 | * Created by jiangbotao on 2018/3/28. | ||
5 | */ | ||
6 | |||
7 | public interface GoogleMapLayerTypes { | ||
8 | |||
9 | /** * Google vector map service by city map*/ | ||
10 | final int VECTOR_GOOGLE_MAP = 1; | ||
11 | /** * Google image map service by satellite map */ | ||
12 | final int IMAGE_GOOGLE_MAP = 2; | ||
13 | /** * Google topographic map service ======= topographic map */ | ||
14 | final int TERRAIN_GOOGLE_MAP = 3; | ||
15 | /** * Google road POI map service = = = = net road map */ | ||
16 | final int ANNOTATION_GOOGLE_MAP = 4; | ||
17 | } |
app/src/main/java/com/pashanhoo/landsurvey/layers/google/GoogleMapsTiledServiceLayer.java
0 → 100644
1 | package com.pashanhoo.landsurvey.layers.google; | ||
2 | |||
3 | import com.esri.android.map.TiledServiceLayer; | ||
4 | import java.util.concurrent.RejectedExecutionException; | ||
5 | |||
6 | import android.annotation.SuppressLint; | ||
7 | import android.util.Log; | ||
8 | |||
9 | import com.esri.android.map.TiledServiceLayer; | ||
10 | import com.esri.android.map.event.OnStatusChangedListener; | ||
11 | import com.esri.core.geometry.Envelope; | ||
12 | import com.esri.core.geometry.Point; | ||
13 | import com.esri.core.geometry.SpatialReference; | ||
14 | import com.esri.core.internal.io.handler.ResponseListener; | ||
15 | import com.esri.core.internal.io.handler.a; | ||
16 | import com.esri.core.io.UserCredentials; | ||
17 | import com.pashanhoo.landsurvey.utils.GisHolder; | ||
18 | |||
19 | /** | ||
20 | * Created by jiangbotao on 2018/3/28. | ||
21 | */ | ||
22 | |||
23 | public class GoogleMapsTiledServiceLayer extends TiledServiceLayer { | ||
24 | private static final double xmin = -22041257.773878; | ||
25 | private static final double ymin = -32673939.6727517; | ||
26 | private static final double xmax = 22041257.773878; | ||
27 | private static final double ymax = 20851350.0432886; | ||
28 | |||
29 | private static final double XMin = 110.35992000000005; | ||
30 | private static final double YMin = 31.382360000000062; | ||
31 | private static final double XMax = 116.65036000000009; | ||
32 | private static final double YMax = 36.36647000000005; | ||
33 | |||
34 | private static final double[] res = { 156543.03392800014, 78271.516963999937, 39135.758482000092, 19567.879240999919, 9783.9396204999593, 4891.9698102499797, 2445.9849051249898, | ||
35 | 1222.9924525624949, 611.49622628138, 305.748113140558, 152.874056570411, 76.4370282850732, 38.2185141425366, 19.1092570712683, 9.55462853563415, 4.7773142679493699, 2.3886571339746849, | ||
36 | 1.1943285668550503 /* , 0.59716428355981721, 0.29858214164761665 */}; | ||
37 | |||
38 | private static final double[] scale = { 591657527.591555, 295828763.79577702, 147914381.89788899, 73957190.948944002, 36978595.474472001, 18489297.737236001, 9244648.8686180003, | ||
39 | 4622324.4343090001, 2311162.217155, 1155581.108577, 577790.554289, 288895.277144, 144447.638572, 72223.819286, 6111.909643, 18055.954822, 9027.9774109999998, 4513.9887049999998 | ||
40 | /* ,2256.994353, 1128.4971760000001 */}; | ||
41 | |||
42 | private static String URL = "http://maps.iwxlh.com"; | ||
43 | private ResponseListener responseListener; | ||
44 | private static Point origin = new Point(-20037508.342787, 20037508.342787); | ||
45 | |||
46 | public GoogleMapsTiledServiceLayer() { | ||
47 | this(true); | ||
48 | } | ||
49 | |||
50 | public GoogleMapsTiledServiceLayer(boolean initLayer) { | ||
51 | super(URL); | ||
52 | this.isBingMap = true; | ||
53 | |||
54 | if (!(initLayer)) | ||
55 | return; | ||
56 | try { | ||
57 | getServiceExecutor().submit(new Runnable() { | ||
58 | public void run() { | ||
59 | GoogleMapsTiledServiceLayer.this.initLayer(); | ||
60 | } | ||
61 | }); | ||
62 | } catch (RejectedExecutionException localRejectedExecutionException) { | ||
63 | Log.e("ArcGIS", "initialization of the layer failed.", localRejectedExecutionException); | ||
64 | } | ||
65 | } | ||
66 | |||
67 | protected void initLayer() { | ||
68 | if (getID() == 0L) { | ||
69 | this.nativeHandle = create(); | ||
70 | } | ||
71 | if (getID() == 0L) { | ||
72 | changeStatus(OnStatusChangedListener.STATUS.fromInt(-1000)); | ||
73 | } else { | ||
74 | try { | ||
75 | setDefaultSpatialReference(SpatialReference.create(102100)); | ||
76 | |||
77 | GisHolder.lonLat2Mercator(new Point(XMin, YMin)); | ||
78 | GisHolder.lonLat2Mercator(new Point(XMax, YMax)); | ||
79 | |||
80 | setFullExtent(new Envelope(xmin, ymin, xmax, ymax)); | ||
81 | // setFullExtent(new Envelope(minMercatorPoint.getX(), | ||
82 | // minMercatorPoint.getY(), maxMercatorPoint.getX(), | ||
83 | // maxMercatorPoint.getY())); | ||
84 | setTileInfo(new TiledServiceLayer.TileInfo(origin, scale, res, scale.length, 96, 256, 256)); | ||
85 | super.initLayer(); | ||
86 | } catch (Exception localException) { | ||
87 | changeStatus(OnStatusChangedListener.STATUS.fromInt(-1005)); | ||
88 | Log.e("ArcGIS", "Bing map url =" + getUrl(), localException); | ||
89 | } | ||
90 | } | ||
91 | } | ||
92 | |||
93 | 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"; | ||
94 | 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"; | ||
95 | |||
96 | String get(int lev, int col, int row) { | ||
97 | 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街道图 | ||
98 | } | ||
99 | |||
100 | @SuppressLint("DefaultLocale") | ||
101 | protected byte[] getTile(int lev, int col, int row) throws Exception { | ||
102 | String url = String.format(BASE_URL, col % 4, col, row, lev); // 加载Google街道图 | ||
103 | // String url2 = String.format(BASE_URL_2, col, row, lev); // 加载Google街道图 | ||
104 | // PtaDebug.d("url", url); | ||
105 | // PtaDebug.e("url2", url2); | ||
106 | return a.a(url, null, null, this.responseListener); | ||
107 | } | ||
108 | |||
109 | public void refresh() { | ||
110 | try { | ||
111 | getServiceExecutor().submit(new Runnable() { | ||
112 | public void run() { | ||
113 | if (!(GoogleMapsTiledServiceLayer.this.isInitialized())) | ||
114 | return; | ||
115 | try { | ||
116 | GoogleMapsTiledServiceLayer.this.clearTiles(); | ||
117 | } catch (Exception localException) { | ||
118 | Log.e("ArcGIS", "Re-initialization of the layer failed.", localException); | ||
119 | } | ||
120 | } | ||
121 | }); | ||
122 | } catch (RejectedExecutionException localRejectedExecutionException) { | ||
123 | return; | ||
124 | } | ||
125 | } | ||
126 | |||
127 | public void reinitializeLayer(UserCredentials usercredentials) { | ||
128 | } | ||
129 | |||
130 | public void reinitializeLayer(String appID) { | ||
131 | super.reinitializeLayer(null); | ||
132 | } | ||
133 | } |
1 | package com.pashanhoo.landsurvey.utils; | ||
2 | |||
3 | /** | ||
4 | * Created by jiangbotao on 2018/3/28. | ||
5 | */ | ||
6 | |||
7 | import java.text.DecimalFormat; | ||
8 | import java.util.ArrayList; | ||
9 | import java.util.List; | ||
10 | |||
11 | import android.graphics.Bitmap; | ||
12 | import android.util.Log; | ||
13 | |||
14 | import com.esri.android.map.GraphicsLayer; | ||
15 | import com.esri.android.map.MapView; | ||
16 | import com.esri.core.geometry.GeometryEngine; | ||
17 | import com.esri.core.geometry.Line; | ||
18 | import com.esri.core.geometry.Point; | ||
19 | import com.esri.core.geometry.Polygon; | ||
20 | import com.esri.core.geometry.Polyline; | ||
21 | import com.esri.core.geometry.SpatialReference; | ||
22 | import com.esri.core.map.Graphic; | ||
23 | import com.esri.core.symbol.SimpleLineSymbol; | ||
24 | |||
25 | /** | ||
26 | * GIS相关持有工具类 | ||
27 | * | ||
28 | * @author JiangXusheng | ||
29 | * @date 2013-7-6 下午1:16:07 | ||
30 | */ | ||
31 | public class GisHolder { | ||
32 | public static final int VALIDATE_X_Y = 999; | ||
33 | |||
34 | public static final double AX = 0.83; | ||
35 | public static final double BX = 1 - AX; | ||
36 | |||
37 | static final String TAG = GisHolder.class.getName(); | ||
38 | |||
39 | public enum MarkerSymbolType { | ||
40 | TEXT, IMAGE, SIMPLE, IMAGE_TEXT, SIMPLE_TEXT, SIMPLE_LINE; | ||
41 | } | ||
42 | |||
43 | private static final double EARTH_RADIUS = 6378137.0; | ||
44 | |||
45 | /** 计算两点间的距离 */ | ||
46 | public static double gps2m(double lat_a, double lng_a, double lat_b, double lng_b) { | ||
47 | double radLat1 = (lat_a * Math.PI / 180.0); | ||
48 | double radLat2 = (lat_b * Math.PI / 180.0); | ||
49 | double a = radLat1 - radLat2; | ||
50 | double b = (lng_a - lng_b) * Math.PI / 180.0; | ||
51 | double s = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(a / 2), 2) + Math.cos(radLat1) * Math.cos(radLat2) * Math.pow(Math.sin(b / 2), 2))); | ||
52 | s = s * EARTH_RADIUS; | ||
53 | s = Math.round(s * 10000) / 10000; | ||
54 | return s; | ||
55 | } | ||
56 | |||
57 | // 计算方位角pab。 | ||
58 | /** 计算方位角 */ | ||
59 | public static double gps2d(double lat_a, double lng_a, double lat_b, double lng_b) { | ||
60 | double d = 0; | ||
61 | lat_a = lat_a * Math.PI / 180; | ||
62 | lng_a = lng_a * Math.PI / 180; | ||
63 | lat_b = lat_b * Math.PI / 180; | ||
64 | lng_b = lng_b * Math.PI / 180; | ||
65 | |||
66 | d = Math.sin(lat_a) * Math.sin(lat_b) + Math.cos(lat_a) * Math.cos(lat_b) * Math.cos(lng_b - lng_a); | ||
67 | d = Math.sqrt(1 - d * d); | ||
68 | d = Math.cos(lat_b) * Math.sin(lng_b - lng_a) / d; | ||
69 | d = Math.asin(d) * 180 / Math.PI; | ||
70 | |||
71 | // d = Math.round(d*10000); | ||
72 | return d; | ||
73 | } | ||
74 | |||
75 | public static double calulateXYAnagle(double startx, double starty, double endx, double endy) { | ||
76 | double tan = Math.atan(Math.abs((endy - starty) / (endx - startx))) * 180 / Math.PI; | ||
77 | if (endx > startx && endy > starty)// 第一象限 | ||
78 | { | ||
79 | return -tan; | ||
80 | } else if (endx > startx && endy < starty)// 第二象限 | ||
81 | { | ||
82 | return tan; | ||
83 | } else if (endx < startx && endy > starty)// 第三象限 | ||
84 | { | ||
85 | return tan - 180; | ||
86 | } else { | ||
87 | return 180 - tan; | ||
88 | } | ||
89 | |||
90 | } | ||
91 | |||
92 | |||
93 | private static double getPieValue(double dN, double dPieN_1) { | ||
94 | return AX * dN + BX * dPieN_1; | ||
95 | } | ||
96 | |||
97 | public static double getScreenM(MapView mapView, Point point1, Point point2, boolean toMocha) { | ||
98 | |||
99 | point1 = GisHolder.checkGeometryPoint(point1); | ||
100 | point2 = GisHolder.checkGeometryPoint(point2); | ||
101 | |||
102 | if (toMocha) { | ||
103 | point1 = GisHolder.lonLat2Mercator(point1); | ||
104 | point2 = GisHolder.lonLat2Mercator(point2); | ||
105 | } | ||
106 | |||
107 | Point screenPoint1 = mapView.toScreenPoint(point1); | ||
108 | Point screenPoint2 = mapView.toScreenPoint(point2); | ||
109 | return Math.sqrt((screenPoint1.getX() - screenPoint2.getX()) * (screenPoint1.getX() - screenPoint2.getX()) + (screenPoint1.getY() - screenPoint2.getY()) | ||
110 | * (screenPoint1.getY() - screenPoint2.getY())); | ||
111 | } | ||
112 | |||
113 | public static boolean isValidateData(Point point) { | ||
114 | boolean rst = false; | ||
115 | if (null != point && !point.isEmpty() && point.getX() != VALIDATE_X_Y && point.getY() != VALIDATE_X_Y && point.getX() != 0.0 && point.getY() != 0.0) { | ||
116 | rst = true; | ||
117 | } | ||
118 | return rst; | ||
119 | } | ||
120 | |||
121 | |||
122 | public static long double2Long(double x) { | ||
123 | return (long) (x * 1000000 + 0.5); | ||
124 | } | ||
125 | |||
126 | public static double long2Double(long x) { | ||
127 | return (x / 1000000.0); | ||
128 | } | ||
129 | |||
130 | public static Point checkGeometryPoint(Point point) { | ||
131 | try { | ||
132 | if (null == point) { | ||
133 | point = new Point(); | ||
134 | } | ||
135 | if (point.isEmpty()) { | ||
136 | point.setX(VALIDATE_X_Y); | ||
137 | point.setY(VALIDATE_X_Y); | ||
138 | } | ||
139 | } catch (Exception e) { | ||
140 | point.setX(VALIDATE_X_Y); | ||
141 | point.setY(VALIDATE_X_Y); | ||
142 | } | ||
143 | return point; | ||
144 | } | ||
145 | |||
146 | |||
147 | |||
148 | |||
149 | private static DecimalFormat format = new DecimalFormat("0.0"); | ||
150 | |||
151 | // 经纬度转墨卡托 | ||
152 | /** | ||
153 | * SpatialReference.WKID_WGS84(4326) to | ||
154 | * SpatialReference.WKID_WGS84_WEB_MERCATOR_AUXILIARY_SPHERE(102100) | ||
155 | * | ||
156 | * @param lonLat | ||
157 | * @return | ||
158 | */ | ||
159 | public static Point lonLat2Mercator(Point lonLat) { | ||
160 | |||
161 | // double x = lonLat.getX() * 20037508.34 / 180; | ||
162 | // double y = Math.log(Math.tan((90 + lonLat.getY()) * Math.PI / 360)) / | ||
163 | // (Math.PI / 180); | ||
164 | // y = y * 20037508.34 / 180; | ||
165 | |||
166 | Point point = (Point) GeometryEngine.project(lonLat, SpatialReference.create(SpatialReference.WKID_WGS84), SpatialReference.create(SpatialReference.WKID_WGS84_WEB_MERCATOR_AUXILIARY_SPHERE)); | ||
167 | |||
168 | // PtaDebug.e(TAG, "x:"+x+".."+point.getX()+",y"+y+".."+point.getY()); | ||
169 | |||
170 | return point; | ||
171 | } | ||
172 | |||
173 | // 墨卡托转经纬度 | ||
174 | /** | ||
175 | * SpatialReference.WKID_WGS84_WEB_MERCATOR_AUXILIARY_SPHERE(102100) to | ||
176 | * SpatialReference.WKID_WGS84(4326) | ||
177 | * | ||
178 | * @param mercator | ||
179 | * @return | ||
180 | */ | ||
181 | public static Point mercator2lonLat(Point mercator) { | ||
182 | // double x = mercator.getX() / 20037508.34 * 180; | ||
183 | // double y = mercator.getY() / 20037508.34 * 180; | ||
184 | // y = 180 / Math.PI * (2 * Math.atan(Math.exp(y * Math.PI / 180)) - | ||
185 | // Math.PI / 2); | ||
186 | |||
187 | Point point = (Point) GeometryEngine | ||
188 | .project(mercator, SpatialReference.create(SpatialReference.WKID_WGS84_WEB_MERCATOR_AUXILIARY_SPHERE), SpatialReference.create(SpatialReference.WKID_WGS84)); | ||
189 | return point; | ||
190 | } | ||
191 | |||
192 | public static Point[] getPoints(Point center, double radius) { | ||
193 | Point[] points = new Point[50]; | ||
194 | double sin; | ||
195 | double cos; | ||
196 | double x; | ||
197 | double y; | ||
198 | for (double i = 0; i < 50; i++) { | ||
199 | sin = Math.sin(Math.PI * 2 * i / 50); | ||
200 | cos = Math.cos(Math.PI * 2 * i / 50); | ||
201 | x = center.getX() + radius * 1.2 * sin; | ||
202 | y = center.getY() + radius * cos; | ||
203 | points[(int) i] = new Point(x, y); | ||
204 | } | ||
205 | return points; | ||
206 | } | ||
207 | |||
208 | public static void getCircle(Point center, double radius, Polygon circle) { | ||
209 | circle.setEmpty(); | ||
210 | try { | ||
211 | Point[] points = getPoints(center, radius); | ||
212 | circle.startPath(GisHolder.lonLat2Mercator(points[0])); | ||
213 | for (int i = 1; i < points.length; i++) { | ||
214 | points[i] = GisHolder.checkGeometryPoint(points[i]); | ||
215 | circle.lineTo(GisHolder.lonLat2Mercator(points[i])); | ||
216 | } | ||
217 | } catch (Exception e) { | ||
218 | Log.e("", "", e); | ||
219 | } | ||
220 | } | ||
221 | } |
1 | <?xml version="1.0" encoding="utf-8"?> | ||
2 | <android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
3 | xmlns:app="http://schemas.android.com/apk/res-auto" | ||
4 | xmlns:tools="http://schemas.android.com/tools" | ||
5 | android:layout_width="match_parent" | ||
6 | android:layout_height="match_parent" | ||
7 | tools:context="com.pashanhoo.landsurvey.GoogleMapActivity"> | ||
8 | |||
9 | <com.esri.android.map.MapView | ||
10 | android:id="@+id/map" | ||
11 | android:layout_width="fill_parent" | ||
12 | android:layout_height="fill_parent"></com.esri.android.map.MapView> | ||
13 | </android.support.constraint.ConstraintLayout> |
-
Please register or sign in to post a comment