Search code examples
javascriptmagentoprototypejsgoogle-maps-markers

Magento validate category using JS


I'm using an extension on google maps and I want to add different points depending the category.

Here its the part of the code

var image = 'images/custom_icon.png';
var image = 'images/custom_icon2.png';
var marker = new google.maps.Marker(
   {
           position: new google.maps.LatLng(product.lat, product.lng),

           map: this.map,

           title: (product.items_count < 2)? product.product_name : "" + product.items_count + "items",

           icon: image

   }

);

what I want is to do something like that

  var marker = new google.maps.Marker(
   {
           position: new google.maps.LatLng(product.lat, product.lng),

           map: this.map,

           title: (product.items_count < 2)? product.product_name : "" + product.items_count + "items",


           if (category == A) {
               icon: image
           }
           else {
               icon: image2
           }
   }

Could be possible to do something like that?


Solution

  • there are many possible ways, but not you mentioned

         var marker = new google.maps.Marker(
         {
           position: new google.maps.LatLng(product.lat, product.lng),
    
           map: this.map,
    
           title: (product.items_count < 2)? product.product_name : "" + product.items_count + "items",
    
           icon: (category == A) ? image : image2
    
          }