{"id":23210027,"url":"https://github.com/dqunbp/use-mapbox-gl","last_synced_at":"2025-08-19T05:32:05.663Z","repository":{"id":35123453,"uuid":"209657351","full_name":"dqunbp/use-mapbox-gl","owner":"dqunbp","description":"mapbox-gl react hook","archived":false,"fork":false,"pushed_at":"2023-03-06T20:47:58.000Z","size":8581,"stargazers_count":6,"open_issues_count":15,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-12-17T05:57:32.610Z","etag":null,"topics":["mapbox","mapbox-gl","react","react-hook"],"latest_commit_sha":null,"homepage":"https://dqunbp.github.io/use-mapbox-gl/","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dqunbp.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-09-19T22:13:36.000Z","updated_at":"2023-04-15T11:24:32.000Z","dependencies_parsed_at":"2023-01-15T14:17:55.550Z","dependency_job_id":null,"html_url":"https://github.com/dqunbp/use-mapbox-gl","commit_stats":null,"previous_names":[],"tags_count":21,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dqunbp%2Fuse-mapbox-gl","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dqunbp%2Fuse-mapbox-gl/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dqunbp%2Fuse-mapbox-gl/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dqunbp%2Fuse-mapbox-gl/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dqunbp","download_url":"https://codeload.github.com/dqunbp/use-mapbox-gl/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":230321275,"owners_count":18208336,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["mapbox","mapbox-gl","react","react-hook"],"created_at":"2024-12-18T18:31:37.746Z","updated_at":"2024-12-18T18:31:38.286Z","avatar_url":"https://github.com/dqunbp.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# use-mapbox-gl\n\nSimple, 0 dependency hook around [mapbox-gl](https://docs.mapbox.com/mapbox-gl-js/api/)\n\n[![NPM](https://img.shields.io/npm/v/use-mapbox-gl.svg)](https://www.npmjs.com/package/use-mapbox-gl) \n[![Conventional Commits](https://img.shields.io/badge/Conventional%20Commits-1.0.0-yellow.svg)](https://conventionalcommits.org)\n\n## 🖥 Demo\nCheck out the [demo](https://dqunbp.github.io/use-mapbox-gl/)\n\n\n## 📦 Installation\n\n  ##### with npm\n\n    $ npm install --save use-mapbox-gl\n\n  ##### with yarn\n\n    $ yarn add use-mapbox-gl\n\n## ⚠️ Don't forget install peer dependencies! If it not alredy installed\n  ##### with npm\n\n    $ npm install --save mapbox-gl\n\n  ##### with yarn\n\n    $ yarn add mapbox-gl\n\n\n## 💅 Import styles. You also need to use `mapbox-gl` styles\n\n\nIf you are using `create-react-app` add this link to the `public/index.html` into the `head` tag\n\n```html\n\u003clink\n  href=\"https://api.mapbox.com/mapbox-gl-js/v1.12.0/mapbox-gl.css\"\n  rel=\"stylesheet\"\n/\u003e\n```\n\n**OR** You can also import styles from `mapbox-gl` dependencies\n\nAdd this import to your `src/index.js`\n```js\nimport \"mapbox-gl/dist/index.css\"\n```\n\n\n## 📖 Examples\n\n### 🔗 With token\n\n```jsx\nimport React from \"react\";\nimport { useMapboxGl } from \"use-mapbox-gl\";\n\nfunction BasicMap() {\n  const containerRef = useRef();\n\n  useMapboxGl(containerRef, {\n    style: \"mapbox://styles/mapbox/streets-v11\",\n    accessToken: \"your_access_token\",\n  });\n\n  return \u003cdiv ref={containerRef} /\u003e;\n}\n\nexport default BasicMap\n```\n\n### 🔗 Without token\n\nFor using without token, you need to define custom base map style, as example:\n\n```js\nimport React from \"react\";\nimport { useMapboxGl } from \"use-mapbox-gl\";\n\nconst osmStyle = {\n  version: 8,\n  sources: {\n    osm: {\n      type: \"raster\",\n      tiles: [\n        \"https://a.tile.openstreetmap.org/{z}/{x}/{y}.png\",\n        \"https://b.tile.openstreetmap.org/{z}/{x}/{y}.png\",\n        \"https://c.tile.openstreetmap.org/{z}/{x}/{y}.png\",\n      ],\n      tileSize: 256,\n    },\n  },\n  layers: [\n    {\n      id: \"osm\",\n      source: \"osm\",\n      type: \"raster\",\n    },\n  ],\n};\n\nfunction WithoutTokenMap() {\n  const containerRef = useRef();\n\n  useMapboxGl(containerRef, {\n    style: osmStyle,\n    zoom: 9,\n    center: [30, 50],\n  });\n\n  return \u003cdiv ref={containerRef} /\u003e;\n}\n\nexport default WithoutTokenMap\n```\n\n## 🕹 API\n\n#### 🔗 useMapboxGl\n\n- **container** - The HTML element `React` `ref` in which Mapbox GL JS will render the map\n- **options** *(optional)* - object with native [mapbox-gl](https://docs.mapbox.com/mapbox-gl-js/api/map/#map-parameters) parameters, without container prop\n- **setMapApi** *(optional)* - map load callback, called when the [mapbox-gl load event] (https://docs.mapbox.com/mapbox-gl-js/api/map/#map.event:load) occurs\n- **cleanMapApi** *(optional)* - map cleanup callback, called when the map container is unmounted\n\n```ts\nuseMapboxGl(\n  container: React.MutableRefObject\u003cHTMLElement\u003e \n  options?: Omit\u003cMapboxOptions, \"container\"\u003e\n  setMapApi?: (map: mapboxgl.Map) =\u003e void \n  cleanMapAPI?: () =\u003e void\n)\n```\n\n---\n\n## License\n\nMIT © [dqunbp](https://github.com/dqunbp)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdqunbp%2Fuse-mapbox-gl","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdqunbp%2Fuse-mapbox-gl","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdqunbp%2Fuse-mapbox-gl/lists"}