{"id":15211144,"url":"https://github.com/gampleman/elm-mapbox","last_synced_at":"2025-10-29T18:31:38.044Z","repository":{"id":44160389,"uuid":"137859956","full_name":"gampleman/elm-mapbox","owner":"gampleman","description":"MapboxGL bindings for Elm","archived":false,"fork":false,"pushed_at":"2023-01-07T03:08:20.000Z","size":1760,"stargazers_count":61,"open_issues_count":36,"forks_count":17,"subscribers_count":7,"default_branch":"master","last_synced_at":"2025-02-06T17:42:51.737Z","etag":null,"topics":["elm","elm-mapbox","mapbox-gl","maps"],"latest_commit_sha":null,"homepage":"https://package.elm-lang.org/packages/gampleman/elm-mapbox/latest/","language":"Elm","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/gampleman.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-06-19T08:06:16.000Z","updated_at":"2024-11-29T08:09:49.000Z","dependencies_parsed_at":"2023-02-06T11:01:22.189Z","dependency_job_id":null,"html_url":"https://github.com/gampleman/elm-mapbox","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gampleman%2Felm-mapbox","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gampleman%2Felm-mapbox/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gampleman%2Felm-mapbox/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gampleman%2Felm-mapbox/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gampleman","download_url":"https://codeload.github.com/gampleman/elm-mapbox/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":238579800,"owners_count":19495549,"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":["elm","elm-mapbox","mapbox-gl","maps"],"created_at":"2024-09-28T08:05:12.937Z","updated_at":"2025-10-29T18:31:32.530Z","avatar_url":"https://github.com/gampleman.png","language":"Elm","funding_links":[],"categories":[],"sub_categories":[],"readme":"# elm-mapbox\n\nGreat looking and performant maps in Elm using MapboxGl. Discuss in #maps on the Elm Slack.\n\n### High Quality Mapping in Elm\n\nThere have been [some attempts](https://github.com/gampleman/elm-visualization/wiki/Data-Visualization-Packages#maps) to make native elm mapping packages. However, Mapbox offers a very complex solution that offers some killer features that are difficult to reproduce:\n\n- client side high quality cartography\n- high performance with large datasets\n\nThe way this works, the map accepts a configuration object called a **style**. The main thing in a style is a list of **layers**. Layers control what you see on the screen. Their order controls their layering (duh). Each layer references a data **source** and has a list of properties. Properties are a bit like CSS for maps in the sense that you can use them to specify colors, line thickness, etc. However, unlike CSS, the values that you pass to these use are **expressions** in a little language, that allows you to style based on other factors like the map's zoom level or actual data in any of the **features** being styled.\n\n**Sources** specify how to get the data that powers the layers. Multiple layers can take in a single source.\n\nThis library allows you to specify the **style** declaratively passing it into a specific element in your view function. However, the map element holds some internal state: mostly about the position of the viewport and all the event handling needed to manipulate it. In my experience this is mostly what you want - the default map interactions tend to be appropriate. So this library includes commands that tell the map to modify its internal state (including stuff like animations etc).\n\n### How does this Work?\n\nThis is a hybrid library that consists both of Elm and JavaScript parts. It uses a combination of ports and custom elements for communication between them.\n\n### Getting Started\n\nTo get going, install the package and the accompanying npm library:\n\n    elm install gampleman/elm-mapbox\n    npm install --save elm-mapbox\n\nMicrosoft Edge needs a polyfill to use custom elements. The polyfill provided by\nwebcomponents.org is known to work https://github.com/webcomponents/custom-elements:\n\n    npm install --save @webcomponents/custom-elements\n\nThen include the library into your page. How exactly to do this depends on how you are building your application. We recommend using [Parcel](https://parceljs.org/), since it is super easy to setup. Then you will want to make your `index.js` look something like this:\n\n```javascript\n// polyfill for custom elements. Optional, see https://caniuse.com/#feat=custom-elementsv1\nimport \"@webcomponents/custom-elements\";\n\nimport { registerCustomElement, registerPorts } from \"elm-mapbox\";\n\n// This brings in mapbox required CSS\nimport \"mapbox-gl/dist/mapbox-gl.css\";\n\n// Your Elm application\nimport { Elm } from \"./src/Main.elm\";\n\n// A Mapbox API token. Register at https://mapbox.com to get one of these. It's free.\nconst token =\n    \"pk.eyJ1Ijovm,vedfg\";\n\n// This will add elm-mapbox custom element into the page's registry.\n// This **must** happen before your application attempts to render a map.\nregisterCustomElement({\n    token\n});\n\n// Initialize your Elm application. There are a few different ways\n// to do this, whichever you choose doesn't matter.\nvar app = Elm.Main.init({ flags: {} });\n\n// Register ports. You only need to do this if you use the port integration.\n// I usually keep this commented out until I need it.\nregisterPorts(app);\n```\n\nNext, optionally, setup a ports module. The best way to do this is to to copy [this file](https://github.com/gampleman/elm-mapbox/blob/master/examples/MapCommands.elm) into your project. I usually name it `Map/Cmd.elm` This will allow you to easily use the commands to control parts of your map interactions imperatively - for example you can command your map to fly to a particular location.\n\nFinally, you will need to setup a base style. You can copy some of the [example styles](https://github.com/gampleman/elm-mapbox/blob/master/examples/Styles), or you can use the (beta) [Style code generator](https://code.gampleman.eu/elm-mapbox/style-generator/) in conjunction with [Mapbox Studio](https://www.mapbox.com/mapbox-studio/).\n\n### Example\n\nSee [Example01](https://github.com/gampleman/elm-geospatial/blob/master/examples/src/Example01.elm) for an example application.\n\n\n### Support\n\nThis library is supported in all modern browsers. The `elmMapbox` library\nhas a `supported` function that can be injected via flags:\n\n```javascript\nimport {supported} from \"elm-mapbox\";\n\nvar app = Elm.MyApp.fullscreen({\n  mapboxSupported: supported({\n    // If  true , the function will return  false if the performance of\n    // Mapbox GL JS would be dramatically worse than expected (e.g. a\n    // software WebGL renderer would be used).\n    failIfMajorPerformanceCaveat: true\n  })\n});\n```\n\n### Customizing the JS side\n\nThe `registerCustomElement` function accepts an options object that takes the following options:\n\n - `token`: the Mapbox token. If you don't pass it here, you will need to use the `token` Elm attribute.\n - `onMount` a callback that gives you access to the mapbox instance whenever a map gets instantiated. Mostly useful for registering [plugins](https://www.mapbox.com/mapbox-gl-js/plugins).\n\nFurthermore, the elm-mapbox element exposes its internal mapboxgl.js reference as a `map` property, which you can use if necessary (although, worth mentioning on slack if you are needing to do this).\n\nThe `registerPorts` function accepts an option object that takes the following options:\n\n - `easingFunctions`: an object whose values are easing functions (i.e. they take a number between 0..1 and return a number between 0..1). You can refer to these with the `easing` option in the Cmd.Option module.\n\n### License\n\n(c) Jakub Hampl 2018, 2019\n\nMIT License\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgampleman%2Felm-mapbox","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgampleman%2Felm-mapbox","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgampleman%2Felm-mapbox/lists"}