Giter Site home page Giter Site logo

ghettovoice / ol-tilecache Goto Github PK

View Code? Open in Web Editor NEW
10.0 3.0 2.0 619 KB

OpenLayers tile url function to load tile seeded with TileCache URL scheme

License: MIT License

JavaScript 91.46% HTML 8.54%
openlayers ol tilecache ol-tilecache ol3 ol4 openlayers3 openlayers4 ol-plugins hacktoberfest

ol-tilecache's Introduction

Build Status Coverage Status GitHub tag view on npm License

TileCache url function for OpenLayers

Allows create custom ol.TileUrlFunctionType to load tiles seeded with TileCache.

Installation

Install it with NPM (recommended):

# ES6 version for bundling with Webpack, Rollup and etc.
npm install ol ol-tilecache
// Use as ES2015 module (based on NPM package `ol`)
import Map from 'ol/Map'
...
import * as TileCacheUrlFn from 'ol-tilecache'
// or only what you need
import { createTileUrlFunction } from 'ol-tilecache'

Or add from CDN:

<script src="https://cdn.jsdelivr.net/gh/openlayers/openlayers.github.io@master/en/v6.0.0/build/ol.js"></script>
<script src="https://unpkg.com/ol-tilecache@latest/dist/ol-tilecache.umd.js"></script>
<script>
  // plugin exports global variable TileCacheUrlFn
  // in addition it also exported to `ol.tileCacheUrlFn` field (for backward compatibility).
</script>

Usage

Usage same as standard OpenLayers tile url functions.

Members

createTileUrlFunction

Arguments

  • url : string URL template
  • tileGrid : ol.tilegrid.TileGrid Custom tile grid. Default is EPSG:3857 x/y/z grid

Returns: ol.TileUrlFunctionType

Available URL placeholders:

z | 0z - zoom level (simple number or padded with zero)
x1, x2, x3 - X axis index parts (remnant from dividing the tile X index on 10^9 broken down by 3 digits)
y1, y2, y3 - Y axis index parts (remnant from dividing the tile Y index on 10^9 broken down by 3 digits)
-y1, -y2, -y3 - inverted Y axis index parts (remnant from dividing the tile Y index on 10^9 broken down by 3 digits)

Example usage:

import Map from 'ol/Map'
import View from 'ol/View'
import TileLayer from 'ol/layer/Tile'
import XyzSource from 'ol/source/XYZ'
import { createTileUrlFunction } from 'ol-tilecache'

const map = new Map({
  target: 'map',
  view: new View({
    projection: 'EPSG:3857',
    center: [ 4189972.14, 7507950.67 ],
    zoom: 5
  }),
  layers: [
    new TileLayer({
      source: new XyzSource({
        tileUrlFunction: createTileUrlFunction('http://{a-z}.tiles.org/{0z}/{x1}/{x2}/{x3}/{-y1}/{-y2}/{-y3}.png')
      })
    })
  ]
})

Build

git clone https://github.com/ghettovoice/ol-tilecache.git
npm install
# build
npm run build
# run test app
npm start
# run unit tests
npm test

License

MIT (c) 2016-2020, Vladimir Vershinin

ol-tilecache's People

Contributors

ghettovoice avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

brncsk colinkyo

ol-tilecache's Issues

Rename package

Rename repo and package name to "ol-tilecache" to avoid confusion with a supported version of OpenLayers

Using ol-tilecache with EPSG:4326 Tiles

The library is really helpful.
I have used custom tilegrids also. It is displaying the map but not the correct tiles. In Zoom 0 it shows only partial map and the tiles seems to be distorted. I am using OL5.
The code snippet is below, Please suggest resolution-
var projection = ol.proj.get('EPSG:4326');
var map_extent=projection.getExtent();
var origin = ol.extent.getTopLeft(projection.getExtent());
var resolution_map= [0.703125, 0.3515625, 0.17578125, 0.087890625,
0.0439453125, 0.02197265625, 0.010986328125,
0.0054931640625, 0.00274658203125, 0.001373291015625, 0.0006866455078125, 0.00034332275390625, 0.000171661376953125,
0.0000858306884765625, 0.00004291534423828125, 0.000021457672119140625,0.000010728836059570,0.000005364418029785];
var tileGrid = new ol.tilegrid.TileGrid({ resolutions: resolution_map,
tileSize: 256,
origin: origin });
var maplayer = new ol.layer.Tile({
source: new ol.source.XYZ({
tileUrlFunction: createTileUrlFunction('https://URL_To_Tilecache/{0z}/{x1}/{x2}/{x3}/{-y1}/{-y2}/{-y3}.jpeg',tileGrid,map_extent)
})
});

Does it works with custom extent?

HI,

I'm trying to use this plugin to display tiles from Tilecache with ol3 but I the URL generated are not Okay.

The projection of my map is EPSG3943 (http://epsg.io/3943-1753.js)

The resolutions associated to this projection are :
[35.2777777778, 17.6388888889, 8.81944444444, 3.52777777778, 1.76388888889, 0.881944444444, 0.705555555556, 0.352777777778, 0.176388888889, 0.0881944444444]

The extent associated is : 
        extent.xmax=1343422.962875;
        extent.xmin=1335234.08035;
        extent.ymax=2267712.102675;
        extent.ymin=2259212.04695;

and when I try to display my map at [1339328.5216125,2263462.0748125] and zoom level 0, i got
http://myTilecacheServer/myTileset/12/000/002/185/000/002/279.png
instead of
http://myTilecacheServer/myTileset/00/000/000/000/000/000/000.png

I don't see in the code of this plugin any relation with the map extent but in the tilecache.js of OL2 there are in the getUrl :

        var bbox = this.maxExtent;
        ...
        var tileX = Math.round((bounds.left - bbox.left) / (res * size.w));
        var tileY = Math.round((bounds.bottom - bbox.bottom) / (res * size.h));

Does this plugin works only with WorldWide tileset? Or did id do a mistake in my code ?

My code :

       layer=new ol.layer.Tile({
                  source: new ol.source.XYZ({
                      tileUrlFunction: 
                      ol.TileCacheUrlFunction.createTileUrlFunction('http://myTilecacheServer/myTileset/{0z}/{x1}/{x2}/{x3}/{-y1}/{-y2}/{-y3}.png'),
                      projection: 'EPSG:3943'
                  })
              });
        maptest = new ol.Map({
          target: 'map',
          view: new ol.View({
              projection: 'EPSG:3943',
              center: [1339328.5216125,2263462.0748125],
              zoom: 0,
              maxExtent:maxExtent,
              resolutions:resolutions
          }),
          layers: [layer]
      });

Thanks

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.