'Mapbox GL: Add GeoTiff to Map without uploading to Mapbox

I have a GeoTiff file taken by a drone and I want to add it as a layer on my map using .addSource() and it doesn't seem to work.

mapboxMap.addSource("satellite", {
    type: "raster",
    url: "http://localhost:3000/images/satellite.tif",
  });

Is uploading to Mapbox the only way to implement a GeoTiff to my Map?

The .png I tested before worked fine, both files are in the public folder right now.

Thanks!



Solution 1:[1]

As the documentation says, the raster type is:

A raster tile source.

Note the tile bit.

If you want a non-tiled raster source, you want to use the image type. I'm not certain if Mapbox GL JS supports TIFF, and whether it supports GeoTIFF. You may need to provide the coordinates explicitly.

Solution 2:[2]

One Solution is to move makeStyles in the component and if you don't want to move it in the component then you can try this hack

import {  makeStyles, Typography } from "@material-ui/core";

let style;

const useStyles = makeStyles((theme) => ({

    container: {
        backgroundColor: "white", display: style
    },

}));
export default function HomePage() {
    const [displayStyle, setDisplayStyle] = useState("flex")
    style = displayStyle;
    const classes = useStyles();

    return (
        <>
            <div>My Page</div>
            <div className={classes.container}>
                <div >
                    <Typography  >
                        Our Orders
                    </Typography>
                </div>
            </div>
        </>
    );
}

Solution 3:[3]

Just simply make the displayStyle available to useStyle function by defining the state in the useStyle function.

Move this line inside the useStyle function.

const [displayStyle, setDisplayStyle] = useState("flex");

So our component looks like this

import {  makeStyles, Typography } from "@material-ui/core";
const useStyles = makeStyles((theme) => ({

    const [displayStyle, setDisplayStyle] = useState("flex")

    container: {
        backgroundColor: "white", display: displayStyle
    },

}));
export default function HomePage() {

    const classes = useStyles();

    return (
        <>
            <div>My Page</div>
            <div className={classes.container}>
                <div >
                    <Typography  >
                        Our Orders
                    </Typography>
                </div>
            </div>
        </>
    );
}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Steve Bennett
Solution 2 Kunal Tyagi
Solution 3 Mohit Maroliya B17CS036