barkure

barkure

telegram
github

Load Mapbox maps in web pages

I have always wanted to add a map to the "About" page, but for various reasons (lazy), I never took action. Today, I have some free time, so I will work on it.


I initially thought about using services like AMap, but there are complications such as registering a developer account and real-name verification.

So, I turned my attention to foreign map service providers.

GoogleMap was excluded first due to well-known reasons. After a long selection process, I decided to use Mapbox services.

image

Register/Login Mapbox Account#

Click the link to go to the official website and register and log in to your account.

After logging in, the interface should look like thisimage

Install Mapbox SDK#

  • Since we are using it for a webpage, choose Webimage
  • Select Use the Mapbox CDNimage
  • Include the GL JS files
  1. Copy the CSS and JS filesimage
  2. Paste them in the <head> (adjust according to your own situation)image
  • Add the map to your site, also copy and paste, similar to before

Use Mapbox Studio#

  • Visit Mapbox Studio and click New Style
    image

  • Choose a template based on your needs. Here, I selected Satellite Streetsimage and then Customize

  • Adjust the map according to your needs, including layers, colors, tiles, and other information. Finally, publish (I used the satellite image of Beijing's Tiananmen Square as an example here)
    image

  • Go back to the Studio interface and share the map you just created. Copy the Style URL and Access token, and replace the URL and token in the "Add the map to your site" section
    image


Alright (●°u°●)​ 」, under normal circumstances, the map should be able to load now:

Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.