gpt4 book ai didi

Map not showing in mapbox(地图框中未显示地图)

转载 作者:bug小助手 更新时间:2023-10-22 15:58:54 27 4
gpt4 key购买 nike



I'm using mapbox api for my application where user can add markers based on his current location. The map was loading just fine while it was running on localhost but after hosting it in netlify, all other components are loading but not the map. Even the markers on the map are showing but the map isn't showing up. This is my App link. There are some errors on the console. But I'm not sure what is causing this behavior. I saw a similar question before, but those solution didn't work for me. I even created a new api key, there were no URL restrictions. So any suggestions would be appreciated.

我正在为我的应用程序使用mapboxapi,用户可以根据当前位置添加标记。映射在localhost上运行时加载得很好,但在netlify中托管后,所有其他组件都在加载,但没有加载映射。甚至地图上的标记也在显示,但地图没有显示。这是我的应用程序链接。控制台上有一些错误。但我不确定是什么导致了这种行为。我以前也看到过类似的问题,但这些解决方案对我不起作用。我甚至创建了一个新的api密钥,没有URL限制。因此,任何建议都将不胜感激。


<ReactMapGL
mapboxApiAccessToken={process.env.REACT_APP_MAPBOX}
{...viewport}
onViewportChange={(nextViewport) => setViewport(nextViewport)}
mapStyle={process.env.REACT_APP_MAP_STYLE}
onDblClick={handleAddPlace}
transitionDuration={200}
>
{pins.map((pin, idx) => (
<div key={idx}>
<Marker
latitude={pin.lat}
longitude={pin.long}
offsetLeft={-viewport.zoom * 3.5}
offsetTop={-viewport.zoom * 7}
onClick={() => handlePinClick(pin._id, pin.lat, pin.long)}
>
<FaMapMarkerAlt
style={{
fontSize: viewport.zoom * 7,
color: pin.username === currentUser ? "#ff0984" : "#4f56a5",
cursor: "pointer",
}}
/>
</Marker>
...
</ReactMapGL>

更多回答

Did you ever find a resolution to this? I am having this exact issue. Everything seems to work with no errors but no base map. Everything works perfect on my local environment but when I move it to Google hosting the base map is absent. Plotted points show up, no errors in console or network tab in debugger.

你找到解决这个问题的办法了吗?我有这个问题。一切似乎都正常工作,没有错误,但没有基本地图。在我的本地环境中,一切都很完美,但当我把它移到谷歌托管时,基本地图就不存在了。打印的点显示出来,在控制台或调试器的网络选项卡中没有错误。

@pachyderm94 No I didn't. I even contacted their customer support but no luck...Let me know if you find any solution.

@厚皮动物94不,我没有。我甚至联系了他们的客户支持,但没有运气。。。如果你找到任何解决方案,请告诉我。

If you follow the link given in the error message Mapbox does offer up three ways to fix the issue. I ended up using the browser white list option and our maps are now showing up.

如果你按照错误消息中给出的链接,Mapbox确实提供了三种方法来解决这个问题。我最终使用了浏览器白名单选项,我们的地图现在显示出来了。

@pachyderm94 how did you whitelisted the browsers? through package.json? could you share what did you do?

@pachyderm94你是如何将浏览器列入白名单的?通过package.json?你能分享一下你做了什么吗?

优秀答案推荐

Yes in the package.json I added the following:

在package.json中,我添加了以下内容:


  "browserslist": {
"production": [
">0.2%",
"not dead",
"not ie 11",
"not chrome < 51",
"not safari < 10",
"not android < 51",
"not op_mini all"
],

The "browserlist" attribute was already there I just augmented it to include more and that fixed the issue for me. The mapbox page is not super clear on how to implement the recommended fixes within a react app, so you have to do some translation of their suggestions. I hope this works for you as well.

“browserlist”属性已经存在,我只是增加了它以包含更多内容,这为我解决了这个问题。地图框页面不太清楚如何在react应用程序中实现推荐的修复,所以你必须对他们的建议进行一些翻译。我希望这对你也有用。


更多回答

Sorry should have been added as a comment not an answer. Read comments below original question to follow.

抱歉应该添加为评论而不是回答。阅读原问题下面的评论。

i had these browser lists from the beginning. here's what mine looks like ` "browserslist": { "production": [ ">0.25%", "not dead", "not op_mini all" ], "development": [ "last 1 chrome version", "last 1 firefox version", "last 1 safari version" ] }`

我从一开始就有这些浏览器列表。以下是我的浏览器列表:{“production”:[“>0.25%”,“not dead”,“not op_mini all”],“development”:[最后1个chrome版本,“最后1个firefox版本”,“最后一个safari版本”]}`

Correct. As I said in my earlier comment. The attribute is there already but you need to change it to include the entire list. That fixed it for me. Since it only happens when I published up to Google Cloud I only updated the "production" list.

对的正如我在前面的评论中所说。该属性已经存在,但您需要更改它以包括整个列表。这对我来说已经解决了。因为只有当我发布到谷歌云时才会发生这种情况,所以我只更新了“生产”列表。

This magically work for some reason :o

这神奇地起作用是有原因的:o

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com