Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

map tile urls are wrong when using mapbox provodier #213

Closed
JaosnHsieh opened this issue Jul 26, 2022 · 0 comments
Closed

map tile urls are wrong when using mapbox provodier #213

JaosnHsieh opened this issue Jul 26, 2022 · 0 comments
Assignees
Labels
feature in progress has active branch
Milestone

Comments

@JaosnHsieh
Copy link

Mapbox tile requires to set offset zoom level -1, which causes wrong urls generated.

We can know first and last tile image x y z by below code

result

first tile image url x 13691 y 7078
last tile image url x 13697 y 7084
const zoom = 14;

const northWestLatLng = [23.75156801631958, 120.83896636962892];
const southEastLatLng = [23.628483651032216, 120.96118927001955];

console.log(
  `first tile image url x ${lon2tileX(northWestLatLng[1], zoom)} y ${lat2tileY(
    northWestLatLng[0],
    zoom,
  )}`,
);
console.log(
  `last tile image url x ${lon2tileX(southEastLatLng[1], zoom)} y ${lat2tileY(
    southEastLatLng[0],
    zoom,
  )}`,
);

function lon2tileX(lon, zoom) {
  return Math.floor(((lon + 180) / 360) * Math.pow(2, zoom));
}
function lat2tileY(lat, zoom) {
  return Math.floor(
    ((1 -
      Math.log(Math.tan((lat * Math.PI) / 180) + 1 / Math.cos((lat * Math.PI) / 180)) / Math.PI) /
      2) *
      Math.pow(2, zoom),
  );
}
// lon2tileX, lat2tileY are from: https://wiki.openstreetmap.org/wiki/Slippy_map_tilenames#ECMAScript_(JavaScript/ActionScript,_etc.)

Whereas, by using getTileUrls, we can wrong urls result as below

first tile image url x 6845 y 3539 z 14
last tile image url x 6848 y 3542 z 14

I run below code on docs/src/index.js file

const map = L.map('map');
// offline baselayer, will use offline source if available
const baseLayer = L.tileLayer
  .offline(urlTemplate, {
    attribution:
      '© <a href="https://www.mapbox.com/about/maps/">Mapbox</a> © <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>',
    urlTemplate:
      'https://api.mapbox.com/styles/v1/mapbox/outdoors-v11/tiles/{z}/{x}/{y}?access_token=xxxxx,
    zoomOffset: -1,
    tileSize: 512,
  })
  .addTo(map);

const zoom = 14;
const northWestLatLng = [23.75156801631958, 120.83896636962892];
const southEastLatLng = [23.628483651032216, 120.96118927001955];

const bounds = new L.Bounds(
  map.project(northWestLatLng, zoom),
  map.project(southEastLatLng, zoom)
);
const tiles = baseLayer.getTileUrls(bounds, zoom);
const firstTile = tiles[0];
const lastTile = tiles[tiles.length - 1];
console.log(`first tile image url x ${firstTile.x} y ${firstTile.y} z ${zoom}`);
console.log(`last tile image url x ${lastTile.x} y ${lastTile.y} z ${zoom}`);

It seems to be caused by zoomOffset is not added to Leaflet map.project so we have to set offset zoom level manually.

To get correct urls, +1 on map.project zoom level

from

const bounds = new L.Bounds(
  map.project(northWestLatLng, zoom),
  map.project(southEastLatLng, zoom)
);

to
```javascript

const bounds = new L.Bounds(
  map.project(northWestLatLng, zoom+1),
  map.project(southEastLatLng, zoom+1)
);
allartk added a commit that referenced this issue Mar 1, 2023
@allartk allartk self-assigned this Mar 1, 2023
@allartk allartk added in progress has active branch feature labels Mar 1, 2023
allartk added a commit that referenced this issue Mar 1, 2023
* Include js docs website

* Bump typedoc-plugin-markdown from 3.13.6 to 3.14.0 (#252)

Bumps [typedoc-plugin-markdown](https://github.com/tgreyuk/typedoc-plugin-markdown/tree/HEAD/packages/typedoc-plugin-markdown) from 3.13.6 to 3.14.0.
- [Release notes](https://github.com/tgreyuk/typedoc-plugin-markdown/releases)
- [Changelog](https://github.com/tgreyuk/typedoc-plugin-markdown/blob/master/packages/typedoc-plugin-markdown/CHANGELOG.md)
- [Commits](https://github.com/tgreyuk/typedoc-plugin-markdown/commits/typedoc-plugin-markdown@3.14.0/packages/typedoc-plugin-markdown)

---
updated-dependencies:
- dependency-name: typedoc-plugin-markdown
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* forEach won't wait

* Bump ua-parser-js from 0.7.31 to 0.7.33 (#256)

Bumps [ua-parser-js](https://github.com/faisalman/ua-parser-js) from 0.7.31 to 0.7.33.
- [Release notes](https://github.com/faisalman/ua-parser-js/releases)
- [Changelog](https://github.com/faisalman/ua-parser-js/blob/master/changelog.md)
- [Commits](faisalman/ua-parser-js@0.7.31...0.7.33)

---
updated-dependencies:
- dependency-name: ua-parser-js
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Respect zoomoffset refs #213

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
allartk added a commit that referenced this issue Apr 19, 2023
* Bump @typescript-eslint/parser from 5.27.0 to 5.48.1 (#254)

* Avoid downloading images if already in the database (#159)

* Avoid downloading images if already in the database

* Avoid downloading images if already in the database

* Syntax correction

* Refactoring

* Syntax correction

* Correction alwaysDownload is not defined

* Correction variable not defined

* correction

* correction variable declaration

* factoring _loadTile

* Syntac correction

* don't use the database during download (#161)

* don't use the database during download

* Syntax correction

* options initialization correction

* refactor: use Promise.reject instead of throw an exception

* 2.2.0

* Bump @typescript-eslint/parser from 5.27.0 to 5.48.1

Bumps [@typescript-eslint/parser](https://github.com/typescript-eslint/typescript-eslint/tree/HEAD/packages/parser) from 5.27.0 to 5.48.1.
- [Release notes](https://github.com/typescript-eslint/typescript-eslint/releases)
- [Changelog](https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/parser/CHANGELOG.md)
- [Commits](https://github.com/typescript-eslint/typescript-eslint/commits/v5.48.1/packages/parser)

---
updated-dependencies:
- dependency-name: "@typescript-eslint/parser"
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: Stéphane <51455661+harry-73@users.noreply.github.com>
Co-authored-by: allartk <allartk@gmail.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Bump prettier from 2.7.1 to 2.8.2 (#251)

Bumps [prettier](https://github.com/prettier/prettier) from 2.7.1 to 2.8.2.
- [Release notes](https://github.com/prettier/prettier/releases)
- [Changelog](https://github.com/prettier/prettier/blob/main/CHANGELOG.md)
- [Commits](prettier/prettier@2.7.1...2.8.2)

---
updated-dependencies:
- dependency-name: prettier
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Bump husky from 7.0.4 to 8.0.3 (#253)

* Avoid downloading images if already in the database (#159)

* Avoid downloading images if already in the database

* Avoid downloading images if already in the database

* Syntax correction

* Refactoring

* Syntax correction

* Correction alwaysDownload is not defined

* Correction variable not defined

* correction

* correction variable declaration

* factoring _loadTile

* Syntac correction

* don't use the database during download (#161)

* don't use the database during download

* Syntax correction

* options initialization correction

* refactor: use Promise.reject instead of throw an exception

* 2.2.0

* Bump husky from 7.0.4 to 8.0.3

Bumps [husky](https://github.com/typicode/husky) from 7.0.4 to 8.0.3.
- [Release notes](https://github.com/typicode/husky/releases)
- [Commits](typicode/husky@v7.0.4...v8.0.3)

---
updated-dependencies:
- dependency-name: husky
  dependency-type: direct:development
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: Stéphane <51455661+harry-73@users.noreply.github.com>
Co-authored-by: allartk <allartk@gmail.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Respect zoomoffset refs #213 (#261)

* Include js docs website

* Bump typedoc-plugin-markdown from 3.13.6 to 3.14.0 (#252)

Bumps [typedoc-plugin-markdown](https://github.com/tgreyuk/typedoc-plugin-markdown/tree/HEAD/packages/typedoc-plugin-markdown) from 3.13.6 to 3.14.0.
- [Release notes](https://github.com/tgreyuk/typedoc-plugin-markdown/releases)
- [Changelog](https://github.com/tgreyuk/typedoc-plugin-markdown/blob/master/packages/typedoc-plugin-markdown/CHANGELOG.md)
- [Commits](https://github.com/tgreyuk/typedoc-plugin-markdown/commits/typedoc-plugin-markdown@3.14.0/packages/typedoc-plugin-markdown)

---
updated-dependencies:
- dependency-name: typedoc-plugin-markdown
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* forEach won't wait

* Bump ua-parser-js from 0.7.31 to 0.7.33 (#256)

Bumps [ua-parser-js](https://github.com/faisalman/ua-parser-js) from 0.7.31 to 0.7.33.
- [Release notes](https://github.com/faisalman/ua-parser-js/releases)
- [Changelog](https://github.com/faisalman/ua-parser-js/blob/master/changelog.md)
- [Commits](faisalman/ua-parser-js@0.7.31...0.7.33)

---
updated-dependencies:
- dependency-name: ua-parser-js
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Respect zoomoffset refs #213

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Bump eslint-config-airbnb-typescript from 16.2.0 to 17.0.0 (#259)

Bumps [eslint-config-airbnb-typescript](https://github.com/iamturns/eslint-config-airbnb-typescript) from 16.2.0 to 17.0.0.
- [Release notes](https://github.com/iamturns/eslint-config-airbnb-typescript/releases)
- [Changelog](https://github.com/iamturns/eslint-config-airbnb-typescript/blob/master/CHANGELOG.md)
- [Commits](iamturns/eslint-config-airbnb-typescript@v16.2.0...v17.0.0)

---
updated-dependencies:
- dependency-name: eslint-config-airbnb-typescript
  dependency-type: direct:development
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Bump chai from 4.3.6 to 4.3.7 (#258)

Bumps [chai](https://github.com/chaijs/chai) from 4.3.6 to 4.3.7.
- [Release notes](https://github.com/chaijs/chai/releases)
- [Changelog](https://github.com/chaijs/chai/blob/4.x.x/History.md)
- [Commits](chaijs/chai@v4.3.6...v4.3.7)

---
updated-dependencies:
- dependency-name: chai
  dependency-type: direct:development
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Bump leaflet from 1.7.1 to 1.9.3 (#265)

Bumps [leaflet](https://github.com/Leaflet/Leaflet) from 1.7.1 to 1.9.3.
- [Release notes](https://github.com/Leaflet/Leaflet/releases)
- [Changelog](https://github.com/Leaflet/Leaflet/blob/main/CHANGELOG.md)
- [Commits](Leaflet/Leaflet@v1.7.1...v1.9.3)

---
updated-dependencies:
- dependency-name: leaflet
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Bump @rollup/plugin-node-resolve from 14.1.0 to 15.0.1 (#264)

Bumps [@rollup/plugin-node-resolve](https://github.com/rollup/plugins/tree/HEAD/packages/node-resolve) from 14.1.0 to 15.0.1.
- [Release notes](https://github.com/rollup/plugins/releases)
- [Changelog](https://github.com/rollup/plugins/blob/master/packages/node-resolve/CHANGELOG.md)
- [Commits](https://github.com/rollup/plugins/commits/node-resolve-v15.0.1/packages/node-resolve)

---
updated-dependencies:
- dependency-name: "@rollup/plugin-node-resolve"
  dependency-type: direct:development
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* only update direct deps

* npm update (#268)

* Bump @rollup/plugin-commonjs from 23.0.3 to 24.0.1 (#263)

Bumps [@rollup/plugin-commonjs](https://github.com/rollup/plugins/tree/HEAD/packages/commonjs) from 23.0.3 to 24.0.1.
- [Release notes](https://github.com/rollup/plugins/releases)
- [Changelog](https://github.com/rollup/plugins/blob/master/packages/commonjs/CHANGELOG.md)
- [Commits](https://github.com/rollup/plugins/commits/commonjs-v24.0.1/packages/commonjs)

---
updated-dependencies:
- dependency-name: "@rollup/plugin-commonjs"
  dependency-type: direct:development
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Bump @babel/core from 7.21.3 to 7.21.4 (#273)

Bumps [@babel/core](https://github.com/babel/babel/tree/HEAD/packages/babel-core) from 7.21.3 to 7.21.4.
- [Release notes](https://github.com/babel/babel/releases)
- [Changelog](https://github.com/babel/babel/blob/main/CHANGELOG.md)
- [Commits](https://github.com/babel/babel/commits/v7.21.4/packages/babel-core)

---
updated-dependencies:
- dependency-name: "@babel/core"
  dependency-type: direct:development
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Bump @babel/preset-typescript from 7.21.0 to 7.21.4 (#270)

Bumps [@babel/preset-typescript](https://github.com/babel/babel/tree/HEAD/packages/babel-preset-typescript) from 7.21.0 to 7.21.4.
- [Release notes](https://github.com/babel/babel/releases)
- [Changelog](https://github.com/babel/babel/blob/main/CHANGELOG.md)
- [Commits](https://github.com/babel/babel/commits/v7.21.4/packages/babel-preset-typescript)

---
updated-dependencies:
- dependency-name: "@babel/preset-typescript"
  dependency-type: direct:development
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Feature/ts5 (#275)

* Include js docs website

* Bump typedoc-plugin-markdown from 3.13.6 to 3.14.0 (#252)

Bumps [typedoc-plugin-markdown](https://github.com/tgreyuk/typedoc-plugin-markdown/tree/HEAD/packages/typedoc-plugin-markdown) from 3.13.6 to 3.14.0.
- [Release notes](https://github.com/tgreyuk/typedoc-plugin-markdown/releases)
- [Changelog](https://github.com/tgreyuk/typedoc-plugin-markdown/blob/master/packages/typedoc-plugin-markdown/CHANGELOG.md)
- [Commits](https://github.com/tgreyuk/typedoc-plugin-markdown/commits/typedoc-plugin-markdown@3.14.0/packages/typedoc-plugin-markdown)

---
updated-dependencies:
- dependency-name: typedoc-plugin-markdown
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* forEach won't wait

* Bump ua-parser-js from 0.7.31 to 0.7.33 (#256)

Bumps [ua-parser-js](https://github.com/faisalman/ua-parser-js) from 0.7.31 to 0.7.33.
- [Release notes](https://github.com/faisalman/ua-parser-js/releases)
- [Changelog](https://github.com/faisalman/ua-parser-js/blob/master/changelog.md)
- [Commits](faisalman/ua-parser-js@0.7.31...0.7.33)

---
updated-dependencies:
- dependency-name: ua-parser-js
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Bump lint-staged from 12.3.7 to 13.1.0 (#248)

Bumps [lint-staged](https://github.com/okonet/lint-staged) from 12.3.7 to 13.1.0.
- [Release notes](https://github.com/okonet/lint-staged/releases)
- [Commits](lint-staged/lint-staged@v12.3.7...v13.1.0)

---
updated-dependencies:
- dependency-name: lint-staged
  dependency-type: direct:development
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Bump webpack from 5.70.0 to 5.76.0 in /docs (#267)

Bumps [webpack](https://github.com/webpack/webpack) from 5.70.0 to 5.76.0.
- [Release notes](https://github.com/webpack/webpack/releases)
- [Commits](webpack/webpack@v5.70.0...v5.76.0)

---
updated-dependencies:
- dependency-name: webpack
  dependency-type: direct:development
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Bump dns-packet from 5.3.1 to 5.4.0 in /docs (#266)

Bumps [dns-packet](https://github.com/mafintosh/dns-packet) from 5.3.1 to 5.4.0.
- [Release notes](https://github.com/mafintosh/dns-packet/releases)
- [Changelog](https://github.com/mafintosh/dns-packet/blob/master/CHANGELOG.md)
- [Commits](mafintosh/dns-packet@v5.3.1...5.4.0)

---
updated-dependencies:
- dependency-name: dns-packet
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* first batch of updates

* USe new node lts

* Fix error reports from none ts files in IDE

* Update prettier

* run prettier

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Add 2 tests :)

* fix linting

* develop will be deleted

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Stéphane <51455661+harry-73@users.noreply.github.com>
@allartk allartk added this to the 3.0.1 milestone Sep 3, 2023
@allartk allartk closed this as completed Sep 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature in progress has active branch
Projects
None yet
Development

No branches or pull requests

2 participants