Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

250
Vistas
canvas clip image into a geojson polygon, rotated and scaled

I am trying to make a thing that clips images like the css clip-path but with a canvas. I have a 3d mapbox map where I want to put this image, as a texture for a plane in three js, but first I have to clip it. I have an image that has a defined geojson shape, the topleft of the image on the map, the NE and the SW. The SE corner was calculated and then a polygon was shaped, ImageShape in the jsfiddle. Same for the building the buildingShape, and then I found out where they intersected with turf and got intersectPoly.

I have made one try at doing this, and it works somewhat. If the image is not rotated it works perfectly, but when the image is rotated on the map, it does not work and I can't figure out why, anyone who has any idea or any way to solve this, please help!

https://jsfiddle.net/ha15e2cy/

const pixelPerLon = canvas.width / Math.abs(topleftOfImage[1] - NEOfImage[1]);
const pixelPerLat = canvas.height / Math.abs(topleftOfImage[0] - SWOfImage[0]);

for (let i = 0; i < (intersect.geometry.coordinates[0].length - 1); i++) {
    const coords: any = intersect.geometry.coordinates[0][i];
    const xlength = Math.abs(topleftOfImage[0] - coords[0]);
    const ylength = Math.abs(topleftOfImage[1] - coords[1]);
    r.lineTo(xlength * pixelPerLon, ylength * pixelPerLat);
}

Any help appreciated!

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda