react-amap icon indicating copy to clipboard operation
react-amap copied to clipboard

请更新文档中关于offset的描述错误

Open allen0815 opened this issue 7 years ago • 3 comments

  • [x] 我已经搜索过 issue,没有类似的问题,或者类似的问题仍然没有解决方案。
  • [x] 我已经搜索过文档,并且仍然没有找到解决方案。
  • [x] 我写了个问题重现的例子,链接或者代码将会贴在下面。

Reproduce Example Link or Code Fragment

const offset = {x: -100, y: -110};

const buildMarker = xx => ( <Marker key={xx.id} position={xx.position} offset={offset}> <MapMarker xx={xx} /> </Marker> );

What is Expected?

使用设置的offset渲染marker

What is actually happening?

文档中关于offset的描述为 {x, y} 或 Pixel, 使用后无效。

在我阅读源代码后,我发现offset使用[x, y]。文档有误,请更新。

allen0815 avatar Aug 29 '18 08:08 allen0815

是的,这个我跑回去查原始文档才知道怎么用。 文档可以举个栗子: offset={{ x: -10, y: -34 }}

wellenzhong avatar Sep 29 '18 02:09 wellenzhong

offset={[-10,-34]}

faceface2 avatar Nov 06 '18 06:11 faceface2

文档描述传入的是对象,但查看源码发现该传入的应该是数组

var toPixel = exports.toPixel = function toPixel(ofst) {
  if (!ofst) {
    return ofst;
  }
  if ('getX' in ofst && 'getY' in ofst) {
    return ofst;
  }
  var x = 0;
  var y = 0;
  if ({}.toString.call(ofst) === '[object Array]') {  // 数组判定
    x = ofst[0];
    y = ofst[1];
  }
  return hasWindow ? new window.AMap.Pixel(x, y) : null;
};

lewisYe avatar Jan 16 '19 07:01 lewisYe