uiwjs / react-baidu-map

基于 React 封装的百度地图组件,支持 React Hook,帮助你轻松的接入地图到 React 项目中。
https://uiwjs.github.io/react-baidu-map
MIT License
222 stars 22 forks source link

hooks方式使用map,自定义样式 mapStyleV2 报错 "cross-origin error" #253

Closed x011223 closed 1 year ago

x011223 commented 2 years ago

样式json 在组件方式使用时正常,另外百度官方的 json url 同样报错.

A cross-origin error was thrown. React doesn't have access to the actual error object in development.

使用方式 - 全报错

  1. local json
  2. js 变量
  3. oss json
  4. map.setMapStyleV2({ styleJson });

复现demo: https://codesandbox.io/s/modern-butterfly-crvlcn?file=/src/App.js

报错及代码截图

jaywcjlove commented 2 years ago

https://codesandbox.io/s/eager-nightingale-4inotu?file=/src/App.js 这个示例不知道怎么建的感觉有问题,跟组件没有关系吧 @Feafortecsy

image

我这个示例里面 JS 引入 没有 加 crossorigin,上面示例都加了这个,这个是 codesandbox 的问题吧 https://codesandbox.io/s/uiwjs-react-md-editor-issues-351-ep1qb0?file=/index.html

image

x011223 commented 2 years ago

codesandbox默认的react模版,除了添加库没有别的操作了。而且有个问题 是 在组件方式使用时正常,在hooks使用时就报错 @jaywcjlove

jaywcjlove commented 2 years ago

https://codesandbox.io/s/react-baidu-map-demo-forked-g8vq3s?file=/src/index.js

@Feafortecsy 我不太清楚,你可以尝试我上面示例。

你可以研究研究 codesandbox 官方文档: https://codesandbox.io/docs/configuration#sandbox-configuration

x011223 commented 2 years ago

@jaywcjlove fork了你的这个示例,虽然没报错 但是自定义样式也没有生效,暂时找不到原因。我这边先跳过了,回头有时间再看

jaywcjlove commented 2 years ago

https://github.com/uiwjs/react-baidu-map/blob/de7213ea71fff7c07688d2bbc219d49522647d40/packages/map/README.md?plain=1#L107-L168

@Feafortecsy Hook 的新玩儿法。

x011223 commented 2 years ago

@jaywcjlove 大佬牛逼。不过今天上线,还是稳妥为上,等下次迭代我再看看。