Skip to content

Commit

Permalink
renvoie la tuile de rendu si le point est en bordure
Browse files Browse the repository at this point in the history
  • Loading branch information
IGNFBourcier committed Oct 27, 2023
1 parent eb28248 commit d5abb9d
Showing 1 changed file with 19 additions and 3 deletions.
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

0 comments on commit d5abb9d

Please sign in to comment.