Skip to content

Commit

Permalink
Merge pull request #10 from huolongshe/dev008
Browse files Browse the repository at this point in the history
增加天地图
  • Loading branch information
huolongshe authored Feb 25, 2021
2 parents 6c802fa + 56d2c3c commit 82d9c5a
Show file tree
Hide file tree
Showing 6 changed files with 188 additions and 17 deletions.
2 changes: 1 addition & 1 deletion app/globals/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@


APP_NAME = 'Spider户外轨迹编辑器'
APP_VERSION = 'v2.0.7'
APP_VERSION = 'v2.0.9'

DB_FILE_NAME = 'data.db'
CFG_FILE_NAME = 'last.yml'
Expand Down
6 changes: 2 additions & 4 deletions app/model/map_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,9 @@


class MapSource:
id_index = 0


def __init__(self, source, visible=False):
MapSource.id_index += 1
self.id = 'map%03d' % MapSource.id_index
self.id = source['id']
self.name = source['name']
self.url_pattern = source['url']
self.zoom_min = source['zoom_min']
Expand Down
116 changes: 108 additions & 8 deletions app/resource/map_cfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@


google_map = {
'id': 'map005',
'name': '谷歌地图',
'url': 'http://mt{$serverpart}.google.cn/vt/lyrs=m&hl=zh-CN&gl=cn&src=app&x={$x}&y={$y}&z={$z}',
'zoom_min': 1,
Expand All @@ -16,6 +17,7 @@


google_satellite = {
'id': 'map003',
'name': '谷歌卫星地图',
'url': 'http://mt{$serverpart}.google.cn/vt/lyrs=s&hl=zh-CN&gl=cn&src=app&x={$x}&y={$y}&z={$z}',
'zoom_min': 1,
Expand All @@ -29,8 +31,10 @@


google_satellite_hybrid = {
'id': 'map001',
'name': '谷歌卫星混合地图',
'url': 'http://mt{$serverpart}.google.cn/vt/lyrs=y&hl=zh-CN&gl=cn&src=app&x={$x}&y={$y}&z={$z}',
# 'url': 'http://mt{$serverpart}.google.cn/vt/lyrs=y&hl=zh-CN&gl=cn&src=app&x={$x}&y={$y}&z={$z}',
'url': 'http://webst0{$serverpart}.is.autonavi.com/appmaptile?lang=zh_cn&style=6&z={$z}&x={$x}&y={$y}', # Google无法访问,用高德的代替
'zoom_min': 1,
'zoom_max': 19,
'server_part': '0,1,2,3',
Expand All @@ -42,6 +46,7 @@


google_topographic = {
'id': 'map004',
'name': '谷歌地形图',
'url': 'http://mt{$serverpart}.google.cn/vt/lyrs=t,r&hl=zh-CN&gl=cn&src=app&x={$x}&y={$y}&z={$z}',
'zoom_min': 1,
Expand All @@ -55,6 +60,7 @@


google_landmark = {
'id': 'map015',
'name': '谷歌透明路网',
'url': 'http://mt{$serverpart}.google.cn/vt/lyrs=h&hl=zh-CN&gl=cn&src=app&x={$x}&y={$y}&z={$z}',
'zoom_min': 1,
Expand All @@ -68,6 +74,7 @@


gaode_map = {
'id': 'map006',
'name': '高德地图',
'url': 'http://webrd0{$serverpart}.is.autonavi.com/appmaptile?lang=zh_cn&size=1&scale=1&style=7&z={$z}&x={$x}&y={$y}',
'zoom_min': 1,
Expand All @@ -81,6 +88,7 @@


gaode_satellite = {
'id': 'map007',
'name': '高德卫星地图',
'url': 'http://webst0{$serverpart}.is.autonavi.com/appmaptile?lang=zh_cn&style=6&z={$z}&x={$x}&y={$y}',
'zoom_min': 1,
Expand All @@ -94,6 +102,7 @@


gaode_landmark= {
'id': 'map014',
'name': '高德透明路网',
'url': 'http://webst0{$serverpart}.is.autonavi.com/appmaptile?lang=zh_cn&style=8&z={$z}&x={$x}&y={$y}',
'zoom_min': 1,
Expand All @@ -107,6 +116,7 @@


qq_map = {
'id': 'map008',
'name': '腾讯地图',
'url': 'http://p{$serverpart}.map.gtimg.com/maptilesv3/{$z}/{$dx}/{$dy}/{$x}_{$y}.png',
'zoom_min': 1,
Expand All @@ -120,6 +130,7 @@


qq_satellite = {
'id': 'map009',
'name': '腾讯卫星地图',
'url': 'http://p{$serverpart}.map.gtimg.com/sateTiles/{$z}/{$dx}/{$dy}/{$x}_{$y}.jpg',
'zoom_min': 1,
Expand All @@ -133,6 +144,7 @@


qq_topographic = {
'id': 'map002',
'name': '腾讯地形图',
'url': 'http://p{$serverpart}.map.gtimg.com/demTiles/{$z}/{$dx}/{$dy}/{$x}_{$y}.jpg',
'zoom_min': 1,
Expand All @@ -146,6 +158,7 @@


qq_landmark = {
'id': 'map014',
'name': '腾讯透明路网',
'url': 'http://rt{$serverpart}.map.gtimg.com/tile?z={$z}&x={$x}&y={$y}&type=vector&styleid=3&version=251',
'zoom_min': 1,
Expand All @@ -158,10 +171,66 @@
}


tianditu_landmark= {
'name': '天地图透明路网',
'url': 'http://t{$serverpart}.tianditu.cn/DataServer?T=cia_w&X={$x}&Y={$y}&L={$z}',
'zoom_min': 3,
tianditu_cia = {
'id': 'map016',
'name': '天地图卫星标记',
'url': 'http://t{$serverpart}.tianditu.gov.cn/cia_w/wmts?SERVICE=WMTS&REQUEST=GetTile&VERSION=1.0.0&LAYER=cia&STYLE=default&TILEMATRIXSET=w&FORMAT=tiles&TILECOL={$x}&TILEROW={$y}&TILEMATRIX={$z}&tk=c8e0b9ae169804fa3d0dbdcc04017804',
'zoom_min': 1,
'zoom_max': 18,
'server_part': '0,1,2,3,4,5,6,7',
'coordinates': 'WGS84',
'transparent': True,
'visible': False,
'format': 'png'
}


tianditu_img = {
'id': 'map017',
'name': '天地图卫星地图',
'url': 'http://t{$serverpart}.tianditu.gov.cn/img_w/wmts?SERVICE=WMTS&REQUEST=GetTile&VERSION=1.0.0&LAYER=img&STYLE=default&TILEMATRIXSET=w&FORMAT=tiles&TILECOL={$x}&TILEROW={$y}&TILEMATRIX={$z}&tk=c8e0b9ae169804fa3d0dbdcc04017804',
'zoom_min': 1,
'zoom_max': 18,
'server_part': '0,1,2,3,4,5,6,7',
'coordinates': 'WGS84',
'transparent': False,
'visible': False,
'format': 'png'
}


tianditu_cta= {
'id': 'map018',
'name': '天地图地形标记',
'url': 'http://t{$serverpart}.tianditu.gov.cn/cta_w/wmts?SERVICE=WMTS&REQUEST=GetTile&VERSION=1.0.0&LAYER=cta&STYLE=default&TILEMATRIXSET=w&FORMAT=tiles&TILECOL={$x}&TILEROW={$y}&TILEMATRIX={$z}&tk=c8e0b9ae169804fa3d0dbdcc04017804',
'zoom_min': 1,
'zoom_max': 18,
'server_part': '0,1,2,3,4,5,6,7',
'coordinates': 'WGS84',
'transparent': True,
'visible': False,
'format': 'png'
}


tianditu_ter = {
'id': 'map019',
'name': '天地图地形图',
'url': 'http://t{$serverpart}.tianditu.gov.cn/ter_w/wmts?SERVICE=WMTS&REQUEST=GetTile&VERSION=1.0.0&LAYER=ter&STYLE=default&TILEMATRIXSET=w&FORMAT=tiles&TILECOL={$x}&TILEROW={$y}&TILEMATRIX={$z}&tk=c8e0b9ae169804fa3d0dbdcc04017804',
'zoom_min': 1,
'zoom_max': 18,
'server_part': '0,1,2,3,4,5,6,7',
'coordinates': 'WGS84',
'transparent': False,
'visible': False,
'format': 'png'
}

tianditu_cva= {
'id': 'map020',
'name': '天地图矢量标记',
'url': 'http://t{$serverpart}.tianditu.gov.cn/cva_w/wmts?SERVICE=WMTS&REQUEST=GetTile&VERSION=1.0.0&LAYER=cva&STYLE=default&TILEMATRIXSET=w&FORMAT=tiles&TILECOL={$x}&TILEROW={$y}&TILEMATRIX={$z}&tk=c8e0b9ae169804fa3d0dbdcc04017804',
'zoom_min': 1,
'zoom_max': 18,
'server_part': '0,1,2,3,4,5,6,7',
'coordinates': 'WGS84',
Expand All @@ -171,7 +240,35 @@
}


tianditu_vec = {
'id': 'map021',
'name': '天地图矢量图',
'url': 'http://t{$serverpart}.tianditu.gov.cn/vec_w/wmts?SERVICE=WMTS&REQUEST=GetTile&VERSION=1.0.0&LAYER=vec&STYLE=default&TILEMATRIXSET=w&FORMAT=tiles&TILECOL={$x}&TILEROW={$y}&TILEMATRIX={$z}&tk=c8e0b9ae169804fa3d0dbdcc04017804',
'zoom_min': 1,
'zoom_max': 18,
'server_part': '0,1,2,3,4,5,6,7',
'coordinates': 'WGS84',
'transparent': False,
'visible': False,
'format': 'png'
}


tianditu_ibo = {
'id': 'map022',
'name': '天地图全球境界',
'url': 'http://t{$serverpart}.tianditu.gov.cn/ibo_w/wmts?SERVICE=WMTS&REQUEST=GetTile&VERSION=1.0.0&LAYER=ibo&STYLE=default&TILEMATRIXSET=w&FORMAT=tiles&TILECOL={$x}&TILEROW={$y}&TILEMATRIX={$z}&tk=c8e0b9ae169804fa3d0dbdcc04017804',
'zoom_min': 1,
'zoom_max': 18,
'server_part': '0,1,2,3,4,5,6,7',
'coordinates': 'WGS84',
'transparent': True,
'visible': False,
'format': 'png'
}

opencycle_map = {
'id': 'map012',
'name': 'OpenCycle Map',
'url': 'https://{$serverpart}.tile.thunderforest.com/outdoors/{$z}/{$x}/{$y}.png?apikey=351c7245beea4461bb88917bd2e9bfd4',
'zoom_min': 1,
Expand All @@ -185,6 +282,7 @@


biying_map = {
'id': 'map010',
'name': '必应地图',
'url': 'http://dynamic.t{$serverpart}.tiles.ditu.live.com/comp/ch/{$QuadKey}?it=G,TW,L,LA&mkt=zh-cn&og=109&cstl=w4c&ur=CN&n=z',
'zoom_min': 1,
Expand All @@ -196,7 +294,9 @@
'format': 'png'
}


biying_satellite = {
'id': 'map011',
'name': '必应卫星地图',
'url': 'http://ecn.t{$serverpart}.tiles.virtualearth.net/tiles/a{$QuadKey}?g=677&mkt=zh-CN',
'zoom_min': 1,
Expand All @@ -209,6 +309,6 @@
}


main_map_list = [google_satellite_hybrid, qq_topographic, google_satellite, google_topographic, google_map, gaode_map,
gaode_satellite, qq_map, qq_satellite, biying_map, biying_satellite, opencycle_map]
transparent_map_list =[qq_landmark, gaode_landmark, google_landmark, tianditu_landmark]
main_map_list = [tianditu_vec, tianditu_img, tianditu_ter, google_satellite_hybrid, qq_topographic, google_satellite, google_topographic, google_map, gaode_map,
gaode_satellite, qq_map, qq_satellite, opencycle_map]
transparent_map_list =[tianditu_ibo, tianditu_cva, tianditu_cia, tianditu_cta, qq_landmark, gaode_landmark, google_landmark]
3 changes: 2 additions & 1 deletion app/service/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from app.globals import const
from app.service import google_search
from app.service import baidu_search
from app.service import tianditu_search


def find_pos_from_name(name, api):
Expand Down Expand Up @@ -34,6 +35,6 @@ def find_name_from_pos(lon, lat, api):


def find_drive_route(start, end, api):
return google_search.find_drive_route(start, end) # 百度路径搜索暂时没搞定,先用google的
return tianditu_search.find_drive_route(start, end) # 百度路径搜索暂时没搞定,先用tianditu的


72 changes: 72 additions & 0 deletions app/service/tianditu_search.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
import json
import requests


def find_drive_route(start, end):

url = 'http://api.tianditu.gov.cn/drive?postStr={"orig":"%.06f,%.06f","dest":"%.06f,%.06f","style":"1"}&type=search&tk=c8e0b9ae169804fa3d0dbdcc04017804' % (start[0], start[1], end[0], end[1])

try:
res = requests.get(url)
except:
return []

if res.status_code != 200:
return []

text = res.text
route = []
while text.find('<streetLatLon>') >= 0:
points = text[text.find('<streetLatLon>') + 14: text.find('</streetLatLon>') - 1].split(';')
for point in points:
tmp = point.split(',')
route.append([float(tmp[0]), float(tmp[1])])
text = text[text.find('</streetLatLon>') + 15:]

if len(route) > 0:
return [route]

return []


def decode_points(encoded):
points = []
index = 0
length = len(encoded)
lon_e5 = 0
lat_e5 = 0
while index < length:
shift = 0
result = 0
while 1:
b = ord(encoded[index]) - 63
index += 1
result |= (b & 0x1f) << shift
shift += 5
if b < 0x20:
break

dlat = ~(result >> 1) if result & 1 else result >> 1
lat_e5 += dlat

shift = 0
result = 0
while 1:
b = ord(encoded[index]) - 63
index += 1
result |= (b & 0x1f) << shift
shift += 5
if b < 0x20:
break

dlon = ~(result >> 1) if result & 1 else result >> 1
lon_e5 += dlon

lon = float(lon_e5) / 100000.0
lat = float(lat_e5) / 100000.0
points.append([lon, lat])

return points

6 changes: 3 additions & 3 deletions app/service/tile_mgr.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def get_tile_file(self, tile_id, file_format):
file_time = os.path.getmtime(tile_path)
now = datetime.datetime.now()
time_delta = (now - datetime.datetime.fromtimestamp(file_time)).days
if time_delta < 30:
if time_delta < 30 or tile_id.startswith('map001'):
try:
with open(tile_path, 'rb') as fn:
self._tile_cache[tile_id] = wx.Bitmap(wx.Image(io.BytesIO(fn.read())))
Expand All @@ -76,8 +76,8 @@ def get_tile_file(self, tile_id, file_format):
def get_tile_network(self, tile_url, tile_id, file_format):
tile_path = os.path.join(self._cache_path, '%s.%s' % (tile_id, file_format))
try:
headers = {'User-Agent': 'Mozilla/5.0'}
response = requests.get(tile_url, headers=headers, timeout=const.DOWNLOAD_TIMEOUT)
# headers = {'User-Agent': 'Mozilla/5.0'}
response = requests.get(tile_url, timeout=const.DOWNLOAD_TIMEOUT)
if 200 == response.status_code :
img = response.content
self._tile_cache[tile_id] = wx.Bitmap(wx.Image(io.BytesIO(img)))
Expand Down

0 comments on commit 82d9c5a

Please sign in to comment.