Code Monkey home page Code Monkey logo

offline-tileserver's Introduction

离线瓦片地图

1. 获取瓦片地图

1.1 主要地图瓦片坐标系定义及计算原理

瓦片地图具有如下特点:

  • 具有唯一的瓦片等级和瓦片坐标编号;

  • 分辨率为 256*256;

  • 瓦片等级越高,展示的地图信息约详尽,瓦片数量也越多;

  • 上一等级的一张瓦片地图可分割为下一等级的四张瓦片地图。

参考文章: 《国内主要地图瓦片坐标系定义及计算原理》

1.2 pyGeoTile 库的使用(计算瓦片地图坐标)

GitHub: https://github.com/geometalab/pyGeoTile

安装:pip install pygeotile

from pygeotile.tile import Tile

lon, lat = 109.227, - 20.196
zoom = 12

tile = Tile.for_latitude_longitude(latitude = lat, longitude = lon, zoom = zoom)
print('mintile', 'X:', tile.tms_x, 'Y:', tile.tms_y, 'zoom:', tile.zoom)

1.3 多进程/多线程/异步爬取瓦片地图

三种方式爬取等级12瓦片地图(6164张图片)的效率对比

爬取方式:使用时间(秒)

  • 多进程:24.49594s

  • 多线程:16.11365s

  • 异步:14.01809s

2. Flask + Leaflet 瓦片地图

2.1 瓦片地图路由定义

@app.route("/tile")
def tile():
    x = request.args['x']
    y = request.args['y']
    z = request.args['z']
    with open('./tilefile/%s/%s_%s.png'%(z, x, y), 'rb') as f:
        image = f.read()
    return Response(image, mimetype='image/jpeg')
  • 瓦片地图接口 url: /tile?x={x}&y={y}&z={z}

GitHub:https://github.com/Leaflet/Leaflet

var url = '/tile?x={x}&y={y}&z={z}';


var latlng = new L.latLng(23.461, 111.921);
var map = new L.map('mapDiv', {
	center: latlng,
	zoom:  4,
	detectRetina: true
});

L.tileLayer(url).addTo(map);

offline-tileserver's People

Contributors

jasonje avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.