Skip to content
Toggle navigation
Toggle navigation
This project
Loading...
Sign in
蒋波涛
/
landsurvey
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
fde2caee
authored
2018-03-30 10:38:09 +0800
by
chiangbt
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
百度地图图层
1 parent
e877532b
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
272 additions
and
1 deletions
app/src/main/java/com/pashanhoo/landsurvey/GoogleMapActivity.java
app/src/main/java/com/pashanhoo/landsurvey/layers/baidu/BaiduMapLayerTypes.java
app/src/main/java/com/pashanhoo/landsurvey/layers/baidu/BaiduMapsTiledServiceLayer.java
app/src/main/java/com/pashanhoo/landsurvey/GoogleMapActivity.java
View file @
fde2cae
...
...
@@ -11,6 +11,8 @@ 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.layers.baidu.BaiduMapLayerTypes
;
import
com.pashanhoo.landsurvey.layers.baidu.BaiduMapsTiledServiceLayer
;
import
com.pashanhoo.landsurvey.layers.gaode.GaodeMapLayerTypes
;
import
com.pashanhoo.landsurvey.layers.gaode.GaodeMapsTiledServiceLayer
;
import
com.pashanhoo.landsurvey.layers.geoq.GeoQMapLayerTypes
;
...
...
@@ -56,9 +58,13 @@ public class GoogleMapActivity extends AppCompatActivity {
// GaodeMapsTiledServiceLayer gaodeMapsTiledServiceLayer = new GaodeMapsTiledServiceLayer(GaodeMapLayerTypes.AMAP_ROAD);
// 高德实时交通图层
// GaodeMapsTiledServiceLayer gaodeMapsTiledServiceLayer = new GaodeMapsTiledServiceLayer(GaodeMapLayerTypes.AMAP_TRAFFIC);
mapView
.
addLayer
(
gaodeMapsTiledServiceLayer
);
//
mapView.addLayer(gaodeMapsTiledServiceLayer);
//---------------------------------------------------------------------------------------------------------------------
BaiduMapsTiledServiceLayer
baiduMapsTiledServiceLayer
=
new
BaiduMapsTiledServiceLayer
(
BaiduMapLayerTypes
.
BAIDU_TRAFFIC
);
mapView
.
addLayer
(
baiduMapsTiledServiceLayer
);
//---------------------------------------------------------------------------------------------------------------------
// GeoQMapsTiledServiceLayer geoQMapsTiledServiceLayer = new GeoQMapsTiledServiceLayer(GeoQMapLayerTypes.ChinaOnlineCommunity_Mobile);
// mapView.addLayer(geoQMapsTiledServiceLayer);
...
...
app/src/main/java/com/pashanhoo/landsurvey/layers/baidu/BaiduMapLayerTypes.java
0 → 100644
View file @
fde2cae
package
com
.
pashanhoo
.
landsurvey
.
layers
.
baidu
;
import
com.pashanhoo.landsurvey.layers.BaseTiledMapServiceType
;
public
enum
BaiduMapLayerTypes
implements
BaseTiledMapServiceType
{
/**
* 百度矢量图层(含路网,含注记)
*/
BAIDU_VECTOR
,
/**
* 百度影像图层(不含路网,不含注记)
*/
BAIDU_IMAGE
,
/**
* 百度路网图层(含路网,含注记)
*/
BAIDU_ROAD
,
/**
* 百度实时交通图层
*/
BAIDU_TRAFFIC
;
@Override
public
String
getName
()
{
return
this
.
name
().
toString
();
}
}
app/src/main/java/com/pashanhoo/landsurvey/layers/baidu/BaiduMapsTiledServiceLayer.java
0 → 100644
View file @
fde2cae
package
com
.
pashanhoo
.
landsurvey
.
layers
.
baidu
;
import
android.annotation.SuppressLint
;
import
android.content.ContentValues
;
import
android.database.Cursor
;
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
;
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.layers.gaode.GaodeMapLayerTypes
;
import
com.pashanhoo.landsurvey.utils.AppInfo
;
import
com.pashanhoo.landsurvey.utils.GADBHelper
;
import
java.util.Calendar
;
import
java.util.TimeZone
;
import
java.util.concurrent.RejectedExecutionException
;
/**
* Created by jiangbotao on 2018/3/28.
*/
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
[]
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
};
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
};
private
static
String
URL
=
"http://maps.iwxlh.com"
;
private
ResponseListener
responseListener
;
private
static
Point
origin
=
new
Point
(-
20037508.342787
,
20037508.342787
);
private
BaiduMapLayerTypes
baiduMapLayerTypes
;
public
BaiduMapsTiledServiceLayer
(
BaiduMapLayerTypes
layerType
)
{
this
(
true
);
this
.
baiduMapLayerTypes
=
layerType
;
// 新建数据表,主要在Activity中必须有AppInfo.Settings()初始数据库
GADBHelper
.
createTable
(
AppInfo
.
mapcachedb
,
this
.
baiduMapLayerTypes
.
getName
());
}
public
BaiduMapsTiledServiceLayer
(
boolean
initLayer
)
{
super
(
URL
);
this
.
isBingMap
=
true
;
if
(!(
initLayer
))
return
;
try
{
getServiceExecutor
().
submit
(
new
Runnable
()
{
public
void
run
()
{
BaiduMapsTiledServiceLayer
.
this
.
initLayer
();
}
});
}
catch
(
RejectedExecutionException
localRejectedExecutionException
)
{
Log
.
e
(
"ArcGIS"
,
"initialization of the layer failed."
,
localRejectedExecutionException
);
}
}
public
static
double
[]
getRes
()
{
return
res
;
}
protected
void
initLayer
()
{
if
(
getID
()
==
0L
)
{
this
.
nativeHandle
=
create
();
}
if
(
getID
()
==
0L
)
{
this
.
changeStatus
(
OnStatusChangedListener
.
STATUS
.
fromInt
(-
1000
));
}
else
{
try
{
this
.
setDefaultSpatialReference
(
SpatialReference
.
create
(
102100
));
this
.
setFullExtent
(
new
Envelope
(
xmin
,
ymin
,
xmax
,
ymax
));
this
.
setTileInfo
(
new
TileInfo
(
origin
,
scale
,
res
,
scale
.
length
,
96
,
256
,
256
));
super
.
initLayer
();
}
catch
(
Exception
localException
)
{
this
.
changeStatus
(
OnStatusChangedListener
.
STATUS
.
fromInt
(-
1005
));
Log
.
e
(
"ArcGIS"
,
"Bing map url ="
+
getUrl
(),
localException
);
}
}
}
@SuppressLint
(
"DefaultLocale"
)
protected
byte
[]
getTile
(
int
level
,
int
col
,
int
row
)
throws
Exception
{
byte
[]
result
=
null
;
String
url
=
""
;
String
s
=
"Galil"
;
switch
(
baiduMapLayerTypes
)
{
case
BAIDU_VECTOR:
int
offsetV
=
(
int
)
(
Math
.
pow
(
2
,
level
-
1
));
url
=
"http://online"
+
((
col
+
row
)
%
8
+
1
)
+
".map.bdimg.com/onlinelabel/?qt=tile"
+
"&x="
+
(
col
-
offsetV
)
+
"&y="
+
(
offsetV
-
row
-
1
)
+
"&z="
+
level
+
"&styles=sl"
;
break
;
case
BAIDU_IMAGE:
int
offsetI
=
(
int
)
(
Math
.
pow
(
2
,
level
-
1
));
url
=
"http://online"
+
((
col
+
row
)
%
8
+
1
)
+
".map.bdimg.com/onlinelabel/?qt=tile"
+
"&x="
+
(
col
-
offsetI
)
+
"&y="
+
(
offsetI
-
row
-
1
)
+
"&z="
+
level
+
"&styles=pl"
;
break
;
case
BAIDU_ROAD:
url
=
"http://webst02.is.autonavi.com/appmaptile?style=8&x="
+
col
+
"&y="
+
row
+
"&z="
+
level
;
break
;
case
BAIDU_TRAFFIC:
int
offsetT
=
(
int
)
(
Math
.
pow
(
2
,
level
-
1
));
url
=
"http://its.map.baidu.com:8002/traffic/TrafficTileService?"
+
"level="
+
level
+
"&x="
+
(
col
-
offsetT
)
+
"&y="
+
(
offsetT
-
row
-
1
)
+
"&time="
+
System
.
currentTimeMillis
();
break
;
}
Log
.
i
(
"baidu"
,
url
);
try
{
// 首先从离线数据库中读取
result
=
getOfflineCacheDB
(
level
,
col
,
row
);
// 如果没有就直接从web上读取
if
(
result
==
null
)
{
result
=
a
.
a
(
url
,
null
,
null
,
this
.
responseListener
);
// 将读取的数据存入mbtiles中
AddOfflineCacheDB
(
level
,
col
,
row
,
result
);
}
}
catch
(
Exception
ex
)
{
ex
.
printStackTrace
();
}
return
result
;
}
public
void
refresh
()
{
try
{
getServiceExecutor
().
submit
(
new
Runnable
()
{
public
void
run
()
{
if
(!(
BaiduMapsTiledServiceLayer
.
this
.
isInitialized
()))
return
;
try
{
BaiduMapsTiledServiceLayer
.
this
.
clearTiles
();
}
catch
(
Exception
localException
)
{
Log
.
e
(
"ArcGIS"
,
"Re-initialization of the layer failed."
,
localException
);
}
}
});
}
catch
(
RejectedExecutionException
localRejectedExecutionException
)
{
return
;
}
}
public
void
reinitializeLayer
(
UserCredentials
usercredentials
)
{
}
public
void
reinitializeLayer
(
String
appID
)
{
super
.
reinitializeLayer
(
null
);
}
private
byte
[]
getOfflineCacheDB
(
int
level
,
int
col
,
int
row
)
throws
Exception
{
byte
[]
result
=
null
;
String
sql
=
"select * from "
+
this
.
baiduMapLayerTypes
.
getName
()
+
" where TILELEVEL = "
+
level
+
" and TILECOL = "
+
col
+
" and TILEROW = "
+
row
;
Cursor
mCursor
=
AppInfo
.
mapcachedb
.
rawQuery
(
sql
,
null
);
boolean
hasData
=
false
;
while
(
mCursor
.
moveToNext
())
{
//判断是否存在数据
hasData
=
true
;
}
if
(
hasData
)
{
//数据库中有数据
try
{
if
(
mCursor
.
moveToFirst
())
{
result
=
mCursor
.
getBlob
(
mCursor
.
getColumnIndex
(
"TILEDATA"
));
}
mCursor
.
close
();
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
result
=
null
;
}
}
return
result
;
}
private
void
AddOfflineCacheDB
(
int
level
,
int
col
,
int
row
,
byte
[]
bytes
)
{
ContentValues
values
=
new
ContentValues
();
values
.
put
(
"TILELEVEL"
,
level
);
values
.
put
(
"TILECOL"
,
col
);
values
.
put
(
"TILEROW"
,
row
);
values
.
put
(
"TILEDATA"
,
bytes
);
AppInfo
.
mapcachedb
.
insert
(
this
.
baiduMapLayerTypes
.
getName
(),
null
,
values
);
}
}
Please
register
or
sign in
to post a comment