2

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: enter image description here

Note the not loaded icon at hte bottom, I am thniking of some sollutuion but cant figure out how to do it:

  1. Check the HTTP status code and then display the image
  2. Display an alternative image when ship does not load with mms with a fallback to imo
  3. 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?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
SparklyUnicorn
  • 1
  • 2
  • 5
  • 18
  • 1
    I just tested your id with both `imo` and `mmsi` links. Imo works, are you sure you're trying to fetch the correct image ? Example used : https://photos.marinetraffic.com/ais/showphoto.aspx?imo=7361518 – Mojo Allmighty Nov 14 '18 at 14:32
  • 1
    Yes both work, https://photos.marinetraffic.com/ais/showphoto.aspx?mmsi=7361518 does not work offcourse. When you try to search by mmsi and pass a imo number. My question is more about how to us https://photos.marinetraffic.com/ais/showphoto.aspx?imo=7361518 as a fallback for https://photos.marinetraffic.com/ais/showphoto.aspx?mmsi=7361518 – SparklyUnicorn Nov 14 '18 at 14:43
  • 1
    Best solution is to use javascript. here is a nice answer for your problem : https://stackoverflow.com/a/38359177/6949388 – Mojo Allmighty Nov 14 '18 at 15:08
  • 1
    I am using React too, so I will look into it – SparklyUnicorn Nov 14 '18 at 15:36

0 Answers0