Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions components/marker/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ import {
} from '../utils/markerUtils'
import {
toLnglat,
toPixel
toPixel,
toLabel,
toIcon
} from '../utils/common'

class Marker extends React.Component<MarkerProps, {}> {
Expand Down Expand Up @@ -42,7 +44,10 @@ class Marker extends React.Component<MarkerProps, {}> {
}
this.converterMap = {
position: toLnglat,
offset: toPixel
offset: toPixel,
label: toLabel,
icon: toIcon,
shadow: toIcon
}
this.map = props.__map__
this.element = this.map.getContainer()
Expand Down
44 changes: 42 additions & 2 deletions components/utils/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}