I am building a web application, it is catalog for static ship information, I collect data from different sources. One of them is https://www.marinetraffic.com/, I use this source also to retrieve an image of the ship. Retrieving an image is as simple as this:
<img src="https://photos.marinetraffic.com/ais/showphoto.aspx?mmsi=273914200>
That will load this image:
<img src="https://photos.marinetraffic.com/ais/showphoto.aspx?mmsi=273914200">
Note mmsi part in the url this is one possible identifier a ship can have, the problem is that ships can have multiple identifiers so is there also a imo number, callSign and eni number. On https://photos.marinetraffic.com/ it is possible to search for ships on both imo or mmsi number to retrieve an image.
So this <img src="https://photos.marinetraffic.com/ais/showphoto.aspx?imo=6600553">
Returns the same image:
For this particular ship I have both identifiers in my database, but there are also ships with only one identifier. For example I have this ship with only imo number 7361518 when I want to retrieve the image I try to do this:
<img src="https://photos.marinetraffic.com/ais/showphoto.aspx?mmsi=7361518"
But that returns a 404 error.
Currently I solved it doing this:
<img width="100%" height="100%" src={`https://photos.marinetraffic.com/ais/showphoto.aspx?mmsi={id}`}/>
<img width="100%" height="100%" src=`https://photos.marinetraffic.com/ais/showphoto.aspx?imo={id}`}/>
So I am placing two image tags above each other passing the ship id value to the url, the id can be either imo or mmsi number, this causes on of the images not to load.
this causes in a result like this:
Note the not loaded icon at hte bottom, I am thniking of some sollutuion but cant figure out how to do it:
- Check the HTTP status code and then display the image
- Display an alternative image when ship does not load with mms with a fallback to imo
- Remove the image not loaded icon, to make the image invisible when image has no result.
So after this whole explanation of a case study, a real wrold scenario and the image problem does anyone know an implementation to any of my sollutions or have an addiotional sollution for this problem?