export function createCanvasTreeMarker(tree) {
  let image;
  if (tree.id == -1) {  // For Doghead farm.
    image = FoodStore.getState().farmImage;
  } else {
    let food = FoodStore.getFood(tree.food);
    if (food != null) {
      image = food.image;
    } else {
      image = FoodStore.getState().tempImage;
    }
  }
  let marker = new L.CanvasMarker(
    new L.LatLng(tree.lat, tree.lng), 5, {
      id: tree.id,
      food: tree.food,
      type: "canvas",
      image: image,
      shadow: FoodStore.getState().shadowImage
    });
  marker.on('click', function() {
    if (!isMarkerEventActivated) {
      isMarkerEventActivated = true;
      isMarkerEventActivatedResetTimer = setTimeout(function() {
        isMarkerEventActivated = false;
      }, 500);
      TreeActions.setCode(0);
      browserHistory.push({pathname: ServerSetting.uBase + '/tree/' + tree.id});
    }
  });
  return marker;
}
export function createCanvasTreeSourceMarker(tree) {
  let checkImage, marker, image;
    if (tree.checked) {
      checkImage = FoodStore.getState().checkImage;
    }
  if (tree.id == -1) {  // Doghead farm doesn't need to be rendered as a source tree.
    return null;
  } else {
    let food = FoodStore.getFood(tree.food);
    if (food) {
      image = food.image;
    } else {
      image = FoodStore.getState().tempImage;
    }
  }
  marker = new L.CanvasMarker(
    new L.LatLng(tree.lat, tree.lng), 5, {
      id: tree.id,
      food: tree.food,
      type: "canvas",
      image: image,
      shadow: FoodStore.getState().shadowImage,
      checkMode: true,
      checked: checkImage,
    });
  marker.on('click', function() {
    if (DonateStore.getState().temp && DonateStore.getState().temp.editing) {
      // Click event for adding a tree item as a source of the current donation.
      if (tree.checked) {
        tree.checked = false;
        DonateStore.getState().temp.removeSource(tree.id);
      } else {
        tree.checked = true;
        DonateStore.getState().temp.addSource(tree.id);
      }
      TreeActions.setCode(200);

      DonateActions.setCode(94);
    }
  });
  return marker;
}