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

renvoyer la tuile de rendu si le point est en bordure, pas seulement celle théorique #316

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 19 additions & 3 deletions lib/util/geo.cjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
const {range, min, flatten} = require('lodash')
const {concave, buffer, bbox, bboxPolygon, centroid, feature, featureCollection, truncate, pointOnFeature, booleanPointInPolygon, lineString, pointToLineDistance} = require('@turf/turf')
const proj = require('@etalab/project-legal')
const {pointToTile} = require('@mapbox/tilebelt')
const {pointToTileFraction} = require('@mapbox/tilebelt')

const extent = 4096

function computeBufferedBbox(features, distanceInMeters) {
if (!features || features.length === 0) {
Expand Down Expand Up @@ -73,12 +75,26 @@ function derivePositionProps(position, minZoom, maxZoom) {
return {lon, lat, x, y}
}

const nestedTile = []
const tiles = range(minZoom, maxZoom + 1).map(zoom => {
const [x, y, z] = pointToTile(lon, lat, zoom)
const [xf, yf, z] = pointToTileFraction(lon, lat, zoom)

// Positon theroique
const x = Math.floor(xf)
const y = Math.floor(yf)

// Sauf que le rendu est sur mvt v2.1 sur une etendue (extent)
const overX = (Math.ceil(xf) - xf) < 1 / (2 * extent)
const overY = (Math.ceil(yf) - yf) < 1 / (2 * extent)
if (overX || overY) { // L'arrondit du pixel depassera l'etendue
console.log(`la position s'affichera sur la tuile suivante ${z}/${overX ? x + 1 : x}/${overY ? y + 1 : y}`)
nestedTile.push(`${z}/${overX ? x + 1 : x}/${overY ? y + 1 : y}`)
}

return `${z}/${x}/${y}`
})

return {lon, lat, x, y, tiles}
return {lon, lat, x, y, tiles: [...tiles, ...nestedTile]}
}

function getRings(polygon) {
Expand Down
Loading