diff --git a/components/marker/index.js b/components/marker/index.js index 6e8d686..9d66e7e 100644 --- a/components/marker/index.js +++ b/components/marker/index.js @@ -9,7 +9,9 @@ import { } from '../utils/markerUtils' import { toLnglat, - toPixel + toPixel, + toLabel, + toIcon } from '../utils/common' class Marker extends React.Component { @@ -42,7 +44,10 @@ class Marker extends React.Component { } this.converterMap = { position: toLnglat, - offset: toPixel + offset: toPixel, + label: toLabel, + icon: toIcon, + shadow: toIcon } this.map = props.__map__ this.element = this.map.getContainer() diff --git a/components/utils/common.js b/components/utils/common.js index 9b9c255..400c77a 100644 --- a/components/utils/common.js +++ b/components/utils/common.js @@ -54,11 +54,51 @@ export const toSize = (size) => { if ('getWidth' in size) { return size } - return hasWindow ? new window.AMap.Size(size.width, size.height) : null + + let width = 0; + let height = 0; + + if (({}).toString.call(size) === '[object Array]') { + width = size[0]; + height = size[1]; + } else if ('width' in size && 'height' in size) { + width = size.width; + height = size.height; + } + + return hasWindow ? new window.AMap.Size(width, height) : null +} + +export const toLabel = (label) => { + if (!label) { + return label + } + + label.offset = toPixel(label.offset) + return label +} + +export const toIcon = (icon) => { + if (!icon) { + return icon + } + + if (typeof icon === 'string' || 'getImageSize' in icon) { + return icon + } + + return hasWindow ? new window.AMap.Icon({ + size: toSize(icon.size), + imageOffset: toPixel(icon.imageOffset), + image: icon.image, + imageSize: toSize(icon.imageSize) + }) : null; } export default { toLnglat, toPixel, - toSize + toSize, + toLabel, + toIcon }