Giter Club home page Giter Club logo

map-tile-downloader's Introduction

Map Tile Downloader

The purpose of this module is to download or cache map tiles shown to the user that fall within a specified area (bbox, polygon, wkt) and a designated zoom range.

To use map services (xyz, wms, and wmts), you need to know the URL address of the map service you want to download. The tile URL address contains {s} subdomains, {z} zoom level, {x}, and {y} information, which are always present. While {s} is not mandatory, it has also been included for all scenarios. If {s} is used, don't forget to add subdomains.

After these operations, three different export methods are provided. You should be aware that the hierarchical folder and file structure of the downloaded tiles is in the format zoom_levels/{z}/{x}/{y}. Apart from this, you can download them to the path you define on your server or computer in zip or folder structure, or if you are going to use them within an API, you can access them as a Zip Buffer Array.

Let's illustrate these operations with a few examples..

Installation

intall npm package

npm install map-tile-downloader

Tile Options

You can use 3 different service for tile URL, This sample for XYZ Tiles

 // type can be url, wms, wmts
 // subdomians sometimes can be -> ['a','b','c','d']
 // min max zoom range is 0 to 22
 // format can be png, gif, pbf, jpg, jpeg

var tileOptions = {
    type: 'url',
    url: 'https://server{s}.service-domain.com/abcd/{z}/{x}/{y}.png',
    subdomains: [0, 1, 2, 3],  
    minZoom: 0,
    maxZoom: 15,
    format: 'png'
};

Downloading Area Options

You can use 3 different geometry type for filtering area

Area Options 1 - GeoJSON

// Area Sample 1 - GeoJSON - Polygon

var areaOptions = {
    type: 'geojson',
    data: {
      type: "Feature",
      properties: {},
      geometry: {
        type: "Polygon",
        coordinates: [
          [
            [27.12637, 38.42191],
            [27.15161, 38.42013],
            [27.16448, 38.44603],
            [27.14505, 38.44900],
            [27.12637, 38.42712],
            [27.12402, 38.42284],
            [27.12637, 38.42191]
          ]
        ]
      }
    }
};

Area Options 2 - BBOX

// Area Sample 1 - BBOX

var areaOptions = {
  type: 'bbox',
  data: [27.12402, 38.42013, 27.16448, 38.44900]
};

Area Options 3 - WKT

// Area Sample 1 - WKT Polygon

var areaOptions = {
    type: 'wkt',
    data: 'POLYGON ((27.126379667467944 38.42191945460772, 27.151617849934297 38.420139862716354, 27.16448932299207 38.44603848581883, 27.145055922492958 38.449003384245714, 27.126379667467944 38.42712615684721, 27.124024103770523 38.422842188698525, 27.126379667467944 38.42191945460772))'
};

MapTileDownloader Module Usage

var MapTileDownloader = require('map-tile-downloader');

var areaOptions = {
  type: 'bbox',
  data: [27.12402, 38.42013, 27.16448, 38.44900]
};

var tileOptions = {
    type: 'url',
    url: 'https://server{s}.service-domain.com/abcd/{z}/{x}/{y}.png',
    subdomains: [0, 1, 2, 3],  
    minZoom: 0,
    maxZoom: 15,
    format: 'png'
};

var options = {
  tile: tileOptions,
  area: areaOptions,
};
var downloader = new MapTileDownloader(options);

Get Zip Buffer Array

When you use this method, it'll return a zip buffer array in callback parameter. Then you can use it whatever you want. Generaly this usage best for API respond

downloader.getAsZip((zipFile)=>{
    //bufferArray
});

Download Zip File to Defined Path

You can download zip file to any file path in your server or pc.

downloader.downloadZipToPath('D:/export.zip',(status)=>{
    console.log(status);
});

Generate Folder/Files to Defined Path

When you use this method tiles will download in hierarchical folders step by step

downloader.generateToPath('D:/',(status)=>{
    console.log(status);
});

Author

Sr. GIS Dev. Ali Kilic | [email protected] | https://akilic.com

map-tile-downloader's People

Contributors

alikilicmina avatar gislayer avatar

Stargazers

zhangcy avatar Muhammed Sami Marufoglu avatar

Watchers

 avatar

Forkers

data-walker

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.