From f1efbff64abede8b220d475bfee42b61c5706272 Mon Sep 17 00:00:00 2001 From: maslke Date: Mon, 23 Oct 2023 16:26:31 +0800 Subject: [PATCH 1/2] bugfix: Fix the bug in Marker that doesn't support setting the 'label offset' property. --- components/marker/index.js | 9 +++++++++ components/utils/isObject.js | 5 +++++ 2 files changed, 14 insertions(+) create mode 100644 components/utils/isObject.js diff --git a/components/marker/index.js b/components/marker/index.js index 6e8d686..ac5792f 100644 --- a/components/marker/index.js +++ b/components/marker/index.js @@ -12,6 +12,8 @@ import { toPixel } from '../utils/common' +import isObject from '../utils/isObject' + class Marker extends React.Component { map: Object @@ -135,6 +137,13 @@ class Marker extends React.Component { if (key in this.converterMap) { return this.converterMap[key](val) } + if (isObject(val)) { + for (let ikey in val) { + if (Object.prototype.hasOwnProperty.call(val, ikey)) { + val[ikey] = this.getSetterParam(ikey, val[ikey]); + } + } + } return val } diff --git a/components/utils/isObject.js b/components/utils/isObject.js new file mode 100644 index 0000000..79345e3 --- /dev/null +++ b/components/utils/isObject.js @@ -0,0 +1,5 @@ +const isObject = (args) => { + return !!args && Object.prototype.toString.call(args).slice(8, -1) === 'Object'; +} + +export default isObject; From 64fe330687b42269e61fd2dfce150fead0e8804f Mon Sep 17 00:00:00 2001 From: maslke Date: Thu, 26 Oct 2023 16:28:27 +0800 Subject: [PATCH 2/2] feature: enhancement of the Marker class functionality. 1. Added dynamic rendering support for the 'label' and 'shadow' properties of the Marker class. --- components/marker/index.js | 18 ++++++--------- components/utils/common.js | 44 ++++++++++++++++++++++++++++++++++-- components/utils/isObject.js | 5 ---- 3 files changed, 49 insertions(+), 18 deletions(-) delete mode 100644 components/utils/isObject.js diff --git a/components/marker/index.js b/components/marker/index.js index ac5792f..9d66e7e 100644 --- a/components/marker/index.js +++ b/components/marker/index.js @@ -9,11 +9,11 @@ import { } from '../utils/markerUtils' import { toLnglat, - toPixel + toPixel, + toLabel, + toIcon } from '../utils/common' -import isObject from '../utils/isObject' - class Marker extends React.Component { map: Object @@ -44,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() @@ -137,13 +140,6 @@ class Marker extends React.Component { if (key in this.converterMap) { return this.converterMap[key](val) } - if (isObject(val)) { - for (let ikey in val) { - if (Object.prototype.hasOwnProperty.call(val, ikey)) { - val[ikey] = this.getSetterParam(ikey, val[ikey]); - } - } - } return val } 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 } diff --git a/components/utils/isObject.js b/components/utils/isObject.js deleted file mode 100644 index 79345e3..0000000 --- a/components/utils/isObject.js +++ /dev/null @@ -1,5 +0,0 @@ -const isObject = (args) => { - return !!args && Object.prototype.toString.call(args).slice(8, -1) === 'Object'; -} - -export default isObject;