44ea6c1a by chiangbt

更新百度地图数据及应用案例

1 parent 4165197e
No preview for this file type
......@@ -16,9 +16,7 @@
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".BootActivity">
</activity>
<activity android:name=".BootActivity" />
<activity
android:name=".MainActivity"
android:label="@string/app_name"
......@@ -32,6 +30,9 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".BaiduMapActivity">
</activity>
</application>
</manifest>
\ No newline at end of file
......
package com.pashanhoo.landsurvey;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.Toast;
import com.esri.android.map.LocationDisplayManager;
import com.esri.android.map.MapView;
import com.esri.android.map.event.OnStatusChangedListener;
import com.esri.android.runtime.ArcGISRuntime;
import com.esri.core.geometry.Point;
import com.pashanhoo.landsurvey.layers.baidu.BaiduMapLayerTypes;
import com.pashanhoo.landsurvey.layers.baidu.BaiduMapsTiledServiceLayer;
import com.pashanhoo.landsurvey.layers.google.GoogleMapsTiledServiceLayer;
import com.pashanhoo.landsurvey.utils.AppInfo;
import com.pashanhoo.landsurvey.utils.GISHelper;
import com.pashanhoo.landsurvey.utils.JZLocationConverter;
public class BaiduMapActivity extends AppCompatActivity {
private MapView mapView;
// GPS定位器对象
private LocationDisplayManager locationDisplayManager;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_baidu_map);
AppInfo.Settings();
ArcGISRuntime.setClientId("1eFHW78avlnRUPHm");
mapView = (MapView) findViewById(R.id.map);
mapView.setEsriLogoVisible(false);
mapView.enableWrapAround(false);
BaiduMapsTiledServiceLayer baiduMapsTiledServiceLayer = new BaiduMapsTiledServiceLayer(BaiduMapLayerTypes.BAIDU_VECTOR);
mapView.addLayer(baiduMapsTiledServiceLayer);
mapView.setOnStatusChangedListener(new OnStatusChangedListener() {
@Override
public void onStatusChanged(Object o, STATUS status) {
if(status == STATUS.INITIALIZED){
Point curPt = JZLocationConverter.wgs84ToGcj02(AppInfo.initPoint);
Point pt = GISHelper.lonLat2Mercator(curPt);
mapView.zoomToResolution(pt, BaiduMapsTiledServiceLayer.getRes()[10]);
Toast.makeText(BaiduMapActivity.this,
mapView.getCenter().getX() + ":" + mapView.getCenter().getY(),
Toast.LENGTH_LONG).show();
}
}
});
}
}
......@@ -2,10 +2,12 @@ package com.pashanhoo.landsurvey;
import android.location.Location;
import android.location.LocationListener;
import android.os.Environment;
import android.support.design.widget.FloatingActionButton;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Toast;
import com.esri.android.map.LocationDisplayManager;
import com.esri.android.map.MapView;
......@@ -53,7 +55,7 @@ public class GoogleMapActivity extends AppCompatActivity {
//---------------------------------------------------------------------------------------------------------------------
// 高德矢量图层(含路网,含注记)
// GaodeMapsTiledServiceLayer gaodeMapsTiledServiceLayer = new GaodeMapsTiledServiceLayer(GaodeMapLayerTypes.AMAP_VECTOR);
GaodeMapsTiledServiceLayer gaodeMapsTiledServiceLayer = new GaodeMapsTiledServiceLayer(GaodeMapLayerTypes.AMAP_VECTOR);
// 高德影像图层(不含路网,不含注记)
// GaodeMapsTiledServiceLayer gaodeMapsTiledServiceLayer = new GaodeMapsTiledServiceLayer(GaodeMapLayerTypes.AMAP_IMAGE);
// 高德路网图层(含路网,含注记)
......@@ -70,11 +72,14 @@ public class GoogleMapActivity extends AppCompatActivity {
// GeoQMapsTiledServiceLayer geoQMapsTiledServiceLayer = new GeoQMapsTiledServiceLayer(GeoQMapLayerTypes.ChinaOnlineCommunity_Mobile);
// mapView.addLayer(geoQMapsTiledServiceLayer);
mapView.setMaxResolution(156543.03392800014);
mapView.setMinResolution(0.29858214164761665);
Point pt = GISHelper.lonLat2Mercator(AppInfo.initPoint);
mapView.zoomToResolution(pt, GoogleMapsTiledServiceLayer.getRes()[16]);
Point curPt = JZLocationConverter.wgs84ToGcj02(AppInfo.initPoint);
Point pt = GISHelper.lonLat2Mercator(curPt);
mapView.zoomToResolution(pt, GoogleMapsTiledServiceLayer.getRes()[17]);
locationDisplayManager = mapView.getLocationDisplayManager();
locationDisplayManager.setShowLocation(true);
......@@ -113,8 +118,40 @@ public class GoogleMapActivity extends AppCompatActivity {
locationDisplayManager.start();
mapView.zoomToResolution(GISHelper.lonLat2Mercator(locationDisplayManager.getPoint()),
GoogleMapsTiledServiceLayer.getRes()[18]);
Point cupt = GISHelper.mercator2lonLat(mapView.getCenter());
Toast.makeText(GoogleMapActivity.this,
cupt.getX() + ":" + cupt.getY(),
Toast.LENGTH_LONG).show();
}
}
});
}
@Override
public void onResume() {
super.onResume();
mapView.unpause();
if (locationDisplayManager != null) {
locationDisplayManager.resume();
}
}
@Override
public void onPause() {
super.onPause();
mapView.pause();
if (locationDisplayManager != null) {
locationDisplayManager.pause();
}
}
@Override
public void onStop() {
super.onStop();
if (locationDisplayManager != null) {
locationDisplayManager.stop();
}
}
}
......
......@@ -240,7 +240,7 @@ public class MainActivity extends AppCompatActivity {
mapView.zoomToResolution(poipt, t_vec.getRes()[19]);
graphicsLayer.addGraphic(new Graphic(poipt,
new PictureMarkerSymbol(getResources().getDrawable(R.mipmap.locator)).setOffsetY(16)));
mapinfoView.setText("当前地图级别为:"+ t_vec.getCurrentLevel());
mapinfoView.setText("当前地图级别为:" + t_vec.getCurrentLevel());
}
@Override
......
......@@ -8,6 +8,8 @@ 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.GeometryEngine;
import com.esri.core.geometry.GeometryUtil;
import com.esri.core.geometry.Point;
import com.esri.core.geometry.SpatialReference;
import com.esri.core.internal.io.handler.ResponseListener;
......@@ -26,15 +28,10 @@ import java.util.concurrent.RejectedExecutionException;
*/
public class BaiduMapsTiledServiceLayer extends TiledServiceLayer {
private static final double xmin = -22041257.773878;
private static final double ymin = -32673939.6727517;
private static final double xmax = 22041257.773878;
private static final double ymax = 20851350.0432886;
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 xmin = -20037508.3427892;
private static final double ymin = -20037508.3427892;
private static final double xmax = 20037508.3427892;
private static final double ymax = 20037508.3427892;
private static final double[] res = {156543.03392800014,
78271.516963999937,
......@@ -73,13 +70,13 @@ public class BaiduMapsTiledServiceLayer extends TiledServiceLayer {
72223.819286, 6111.909643,
18055.954822,
9027.9774109999998,
4513.9887049999998
, 2256.994353,
4513.9887049999998,
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);
private static Point origin = new Point(-20037508.3427892, 20037508.3427892);
private BaiduMapLayerTypes baiduMapLayerTypes;
......@@ -136,26 +133,32 @@ public class BaiduMapsTiledServiceLayer extends TiledServiceLayer {
Log.i("baidu", level + "/"+col+"/"+row);
String url = "";
String s = "Galil";
int offsetV = (int) (Math.pow(2, level - 1));
int zoom = level - 1;
int offsetX = (int)Math.pow(2, level - 1);
int offsetY = offsetX - 1;
int numX = col - (int)Math.pow(2, level - 1);
int numY = (-row) + offsetY;
zoom = level + 1;
int num = (col + row) % 8 + 1;
num = 2;
switch (baiduMapLayerTypes) {
case BAIDU_VECTOR:
url= "http://online" + ((col + row) % 8 + 1) + ".map.bdimg.com/onlinelabel/?qt=tile"
+ "&x=" + (col - offsetV) + "&y=" + (offsetV - row - 1) + "&z=" + level
+ "&styles=pl";
break;
case BAIDU_IMAGE:
url= "http://online" + ((col + row) % 8 + 1) + ".map.bdimg.com/onlinelabel/?qt=tile"
+ "&x=" + (col - offsetV) + "&y=" + (offsetV - row - 1) + "&z=" + level
+ "&styles=sl";
// url= "http://online" + num + ".map.bdimg.com/tile/?qt=tile&x="+numX+"&y="+numY+"&z="+level+"&styles=pl&scaler=1&udt=20141103";
url = "http://online" + num +".map.bdimg.com/tile/?qt=tile&x=" + numX + "&y=" + numY + "&z=" + zoom + "&styles=pl";
break;
case BAIDU_ROAD:
url = "http://online" + num +".map.bdimg.com/tile/?qt=tile&x=" + numX + "&y=" + numY + "&z=" + zoom + "&styles=sl";
break;
case BAIDU_IMAGE:
url = "http://shangetu" + ((col + row) % 8 + 1) + ".map.bdimg.com/it/u="
+ "x=" + (col - offsetV) + ";y=" + (offsetV - row - 1) + ";z=" + level
+ "x=" + numX + ";y=" + numY+ ";z=" + zoom
+ ";v=009;type=sate&fm=46";
break;
case BAIDU_TRAFFIC:
url = "http://its.map.baidu.com:8002/traffic/TrafficTileService?"
+ "level=" + level + "&x=" + (col - offsetV) + "&y=" + (offsetV - row - 1)
+ "level=" + zoom + "&x=" + numX + "&y=" + numY
+ "&time=" + System.currentTimeMillis();
break;
}
......
......@@ -24,22 +24,10 @@ public enum TianDiTuLayerTypes implements BaseTiledMapServiceType {
* 影像注记
* */
CIA_C,
/**
* 矢量数据,web墨卡托4326
*/
VEC_W,
/**
* 影像数据
* */
IMG_W,
/**
* 矢量注记
* */
CVA_W,
/**
* 影像注记
* */
CIA_W;
TER_C,
CTA_C;
public void setName()
{
......
......@@ -190,6 +190,12 @@ public class TianDiTuTiledMapServiceLayer extends TiledServiceLayer {
case IMG_C:
url.append(".tianditu.com/DataServer?T=img_c&X=").append(col).append("&Y=").append(row).append("&L=").append(level);
break;
case TER_C:
url.append(".tianditu.com/DataServer?T=ter_c&X=").append(col).append("&Y=").append(row).append("&L=").append(level);
break;
case CTA_C:
url.append(".tianditu.com/DataServer?T=cta_c&X=").append(col).append("&Y=").append(row).append("&L=").append(level);
break;
default:
return null;
}
......
......@@ -19,9 +19,9 @@ public class AppInfo {
public static SQLiteDatabase mapcachedb;
public static Point initPoint = new Point(121.56, 29.862149);
public static Point initPoint = new Point(116.39167, 39.90333);
public static double initRes = TDTTileinfo.getRes4490()[6];
public static double initRes = TDTTileinfo.getRes4490()[17];
// public static double initRes = TDTTileinfo.getRes4326()[6];
......
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".BaiduMapActivity">
<com.esri.android.map.MapView
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>
\ No newline at end of file
......@@ -9,4 +9,5 @@
<string name="drawer_item_section_header1">图层控制</string>
<string name="drawer_item_section_header2">版权信息</string>
<string name="title_activity_baidu_map">BaiduMapActivity</string>
</resources>
......
......@@ -13,8 +13,10 @@
- TianDiTuLayerTypes
- VEC_C,矢量图层
- IMG_C,影像图层
- TER_C,地形层
- CVA_C,矢量注记层
- CIA_C,影像注记层
- CTA_C,地形注记层
腾讯图层
......@@ -62,7 +64,7 @@ Point initPoint = new Point(121.56, 29.862149);
mapView.zoomToResolution(initPoint, t_vec.getRes()[16]);
```
其它
其它(以Tencent图层为例)
```
TencentMapsTiledServiceLayer tencentMapsTiledServiceLayer = new TencentMapsTiledServiceLayer(TencentMapLayerTypes.TENCENT_MAP_VECTOR);
mapView.addLayer(tencentMapsTiledServiceLayer);
......