

/**
 * 创建并获取一个点标记
 * @param lng 经度
 * @param lat 纬度
 * @param icon 图片路径
 * @param offset 偏移量
 */
export function createMaker(lng, lat, icon = null, offset = null, size = null) {
  let option = {
    position: [lng, lat],
  }
  if (icon != null) {
    option.icon = icon;
  }
  if (offset != null) {
    option.offset = new AMap.Pixel(offset[0], offset[1]);
  }
  if (size != null) {
    option.size = new AMap.Size(size[0], size[1]);
  }
  return new AMap.Marker(option);
}


export function createIcon(image, size, imageSize, offset) {
  // 创建一个 icon
  return new AMap.Icon({
    size: new AMap.Size(size[0], size[1]),
    image: '//a.amap.com/jsapi_demos/static/demo-center/icons/dir-marker.png',
    imageSize: new AMap.Size(imageSize[0], imageSize[1]),
    imageOffset: new AMap.Pixel(offset[0], offset[1])
  });
}

/**
 *  点标记工厂
 *  用于创造各种类型的点标记
 */
export const makerFactory = {
  /// 创建指定类型点标记
  createMaker(lng, lat, type) {
    switch(type) {
      case 'store': return this.createStoreMaker(lng, lat);
      default: return createMaker(lng, lat);
    }
  },
  // 创建店铺点标记
  createStoreMaker(lng, lat) {
    let icon = new AMap.Icon({
      size: new AMap.Size(36, 43),
      image: 'https://api.ccttiot.com/Fofy3sTm5cYkYGcQDCFsMzcxkcF8',
      imageSize: new AMap.Size(36, 43),
      imageOffset: new AMap.Pixel(0, 0)
    });
    return createMaker(lng, lat, icon, [-18, -43]);
  }
}
