Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Uncaught ReferenceError: BMAP_DRAWING_POLYGON is not defined #320

Closed
sunny-token opened this issue Nov 30, 2023 · 6 comments
Closed

Uncaught ReferenceError: BMAP_DRAWING_POLYGON is not defined #320

sunny-token opened this issue Nov 30, 2023 · 6 comments

Comments

@sunny-token
Copy link

sunny-token commented Nov 30, 2023

引入了 "@uiw/react-baidu-map-types": "^2.6.2",
在使用的地方报错了:Uncaught ReferenceError: BMAP_DRAWING_POLYGON is not defined
是需要引入什么文件吗?

const { drawingManager } = useDrawingManager({
		map,
		isOpen: false,
		enableDrawingTool: true,
		rectangleOptions: styleOptions,
		polygonOptions: styleOptions,
		drawingToolOptions: {
			anchor: BMAP_ANCHOR_TOP_RIGHT, drawingModes: [
				BMAP_DRAWING_POLYGON,
				BMAP_DRAWING_RECTANGLE
			]
		}
	})
@jaywcjlove
Copy link
Member

@sunny-token 如果你可以提供可以重现的在线示例,我可以免费帮你排查一下错误,判断是什么问题,但是我预测大概率可能是类似下面的问题

@sunny-token
Copy link
Author

sunny-token commented Dec 1, 2023

@jaywcjlove 这是在线示例,麻烦帮忙排查一下哈,谢谢!

https://codesandbox.io/p/sandbox/xenodochial-mayer-nwkszf?file=%2Fsrc%2FDemo.js%3A34%2C15-34%2C35

@jaywcjlove
Copy link
Member

@sunny-token 我查看示例并没有报错

image

并且我查看了 对象是存在的

image

所以你参考我搞的 高德地图 uiwjs/react-amap#45 (comment) 来解决你的问题

造成这个原因只有 3 种,

  1. 百度的 SDK 加载失败,对象 BMAP_DRAWING_POLYGON 没有挂在到全局对象
  2. 遇到过,有一种开发环境必须 window.BMAP_ANCHOR_TOP_LEFT 去使用
  3. 你在使用 <APILoader> (该组件用于加载 SDK)组件之前,使用了 BMAP_ANCHOR_TOP_LEFT

因为你的示例没有报错,我也无法找出问题,你可以提供可以重现的示例

@sunny-token
Copy link
Author

sunny-token commented Dec 1, 2023

@jaywcjlove 示例好像少点东西

drawingToolOptions: {
      anchor: BMAP_ANCHOR_TOP_RIGHT, // 位置
      offset: new BMap.Size(5, 5), // 偏离值
      drawingModes: [BMAP_DRAWING_POLYGON, BMAP_DRAWING_RECTANGLE],
    },

我已经更新了示例代码
代码示例

@jaywcjlove
Copy link
Member

@sunny-token
Copy link
Author

@jaywcjlove 好的,谢谢!
问题解决了,需要使用挂载window下面的常量

drawingToolOptions: {
			anchor: window.BMAP_ANCHOR_TOP_RIGHT, drawingModes: [
				window.BMAP_DRAWING_POLYGON,
				window.BMAP_DRAWING_RECTANGLE
			]
		}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants