Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

253
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda