0

The code in question:

console.log(marker.getIcon() == selectedDestinationMarkerImage);
console.log(marker.getIcon());
console.log(selectedDestinationMarkerImage);

if(marker.getIcon() == selectedDestinationMarkerImage)
{
    return true;
}

The console output

false
Object{url: "images/icons/dd-end.png", size: W}
Object{url: "images/icons/dd-end.png", size: W}

The icon on the marker is set to selectedDestinationMarkerImage at some point before this check. I would actually expect even the === comparison to return true. (I tried that as well, it doesn't)

DoubleDouble
  • 1,493
  • 10
  • 25
  • Why do you think it should be `true`? – melpomene Oct 22 '15 at 21:36
  • Object equality in JS is complicated; if `getIcon` generates a new object each time, then they are not equivalent, even if the keys/values are the same. – Evan Davis Oct 22 '15 at 21:36
  • @melpomene When the page is loaded, `marker.setIcon(selectedDestinationMarkerImage)` is used. – DoubleDouble Oct 22 '15 at 21:55
  • @Mathletics It's definitely confusing, after looking up the `getIcon` method it just returns the object that it has.. I've decided to side-step the problem and just compare on the .url of the objects. – DoubleDouble Oct 22 '15 at 21:56
  • @DoubleDouble You'd have to show the code for `setIcon` and `getIcon` and the definition of `marker`. – melpomene Oct 22 '15 at 22:03
  • @melpomene [Marker](https://developers.google.com/maps/documentation/javascript/markers) comes from the Google Maps API, but what I have works so its fine. – DoubleDouble Oct 22 '15 at 22:09

0 Answers0