All Projects → gampleman → elm-mapbox

gampleman / elm-mapbox

Licence: MIT license
MapboxGL bindings for Elm

Programming Languages

elm
856 projects
javascript
184084 projects - #8 most used programming language
HTML
75241 projects

Projects that are alternatives of or similar to elm-mapbox

Mappa
A canvas wrapper for Maps 🗺 🌍
Stars: ✭ 290 (+427.27%)
Mutual labels:  mapbox-gl, maps
Mapbox Gl Native
Interactive, thoroughly customizable maps in native Android, iOS, macOS, Node.js, and Qt applications, powered by vector tiles and OpenGL
Stars: ✭ 4,091 (+7338.18%)
Mutual labels:  mapbox-gl, maps
angular-mapboxgl-directive
AngularJS directive for Mapbox GL
Stars: ✭ 43 (-21.82%)
Mutual labels:  mapbox-gl, maps
Editor
An open source visual editor for the 'Mapbox Style Specification'
Stars: ✭ 1,167 (+2021.82%)
Mutual labels:  mapbox-gl, maps
react-map-gl-cluster
Urbica React Cluster Component for Mapbox GL JS
Stars: ✭ 27 (-50.91%)
Mutual labels:  mapbox-gl, maps
Osm Liberty
A free Mapbox GL basemap style for everyone
Stars: ✭ 231 (+320%)
Mutual labels:  mapbox-gl, maps
Mapdeck
R interface to Deck.gl and Mapbox
Stars: ✭ 296 (+438.18%)
Mutual labels:  mapbox-gl, maps
Osmscout Server
Maps server providing tiles, geocoder, and router
Stars: ✭ 105 (+90.91%)
Mutual labels:  mapbox-gl, maps
Mapbox Gl Native Android
Interactive, thoroughly customizable maps in native Android powered by vector tiles and OpenGL
Stars: ✭ 135 (+145.45%)
Mutual labels:  mapbox-gl, maps
Pure Maps
Maps and navigation
Stars: ✭ 136 (+147.27%)
Mutual labels:  mapbox-gl, maps
deck.gl-time-series-widget
A React Time Slider implementation for DECK.GL - (non)temporal data - by CPU filtering ⌛
Stars: ✭ 19 (-65.45%)
Mutual labels:  mapbox-gl, maps
s60-maps
Yet another maps for Symbian OS
Stars: ✭ 27 (-50.91%)
Mutual labels:  maps
Trilateration
Trilateration system using 3 latitude and longitude points, and 3 radius distances in PHP, C#, Java and Javascript
Stars: ✭ 22 (-60%)
Mutual labels:  maps
leaflet-draw-toolbar
Leaflet.toolbar for Leaflet.draw. Example: https://justinmanley.github.io/leaflet-draw-toolbar/examples/popup.html.
Stars: ✭ 55 (+0%)
Mutual labels:  maps
orange3-geo
🍊 🌍 Orange add-on for dealing with geography and geo-location
Stars: ✭ 22 (-60%)
Mutual labels:  maps
cim-spec
This repository hosts the specification for the Cartographic Information Model
Stars: ✭ 45 (-18.18%)
Mutual labels:  maps
jsfiddle-github
JSFiddle implementation for interactive JavaScript examples.
Stars: ✭ 16 (-70.91%)
Mutual labels:  maps
urlshort
Ex 2 - Create an http.Handler that forwards paths to other URLs
Stars: ✭ 114 (+107.27%)
Mutual labels:  maps
Euclid
Great-circle mathematics helper library for platforms using Swift -
Stars: ✭ 46 (-16.36%)
Mutual labels:  maps
jpn-atlas
TopoJSONフォーマットの日本の国、都道府県、市区町村の境界データ。Japanese municipality and prefecture boundary data in topojson format.
Stars: ✭ 17 (-69.09%)
Mutual labels:  maps

elm-mapbox

Great looking and performant maps in Elm using MapboxGl. Discuss in #maps on the Elm Slack.

High Quality Mapping in Elm

There have been some attempts to make native elm mapping packages. However, Mapbox offers a very complex solution that offers some killer features that are difficult to reproduce:

  • client side high quality cartography
  • high performance with large datasets

The 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.

Sources specify how to get the data that powers the layers. Multiple layers can take in a single source.

This 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).

How does this Work?

This 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.

Getting Started

To get going, install the package and the accompanying npm library:

elm install gampleman/elm-mapbox
npm install --save elm-mapbox

Microsoft Edge needs a polyfill to use custom elements. The polyfill provided by webcomponents.org is known to work https://github.com/webcomponents/custom-elements:

npm install --save @webcomponents/custom-elements

Then include the library into your page. How exactly to do this depends on how you are building your application. We recommend using Parcel, since it is super easy to setup. Then you will want to make your index.js look something like this:

// polyfill for custom elements. Optional, see https://caniuse.com/#feat=custom-elementsv1
import "@webcomponents/custom-elements";

import { registerCustomElement, registerPorts } from "elm-mapbox";

// This brings in mapbox required CSS
import "mapbox-gl/dist/mapbox-gl.css";

// Your Elm application
import { Elm } from "./src/Main.elm";

// A Mapbox API token. Register at https://mapbox.com to get one of these. It's free.
const token =
    "pk.eyJ1Ijovm,vedfg";

// This will add elm-mapbox custom element into the page's registry.
// This **must** happen before your application attempts to render a map.
registerCustomElement({
    token
});

// Initialize your Elm application. There are a few different ways
// to do this, whichever you choose doesn't matter.
var app = Elm.Main.init({ flags: {} });

// Register ports. You only need to do this if you use the port integration.
// I usually keep this commented out until I need it.
registerPorts(app);

Next, optionally, setup a ports module. The best way to do this is to to copy this file 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.

Finally, you will need to setup a base style. You can copy some of the example styles, or you can use the (beta) Style code generator in conjunction with Mapbox Studio.

Example

See Example01 for an example application.

Support

This library is supported in all modern browsers. The elmMapbox library has a supported function that can be injected via flags:

import {supported} from "elm-mapbox";

var app = Elm.MyApp.fullscreen({
  mapboxSupported: supported({
    // If  true , the function will return  false if the performance of
    // Mapbox GL JS would be dramatically worse than expected (e.g. a
    // software WebGL renderer would be used).
    failIfMajorPerformanceCaveat: true
  })
});

Customizing the JS side

The registerCustomElement function accepts an options object that takes the following options:

  • token: the Mapbox token. If you don't pass it here, you will need to use the token Elm attribute.
  • onMount a callback that gives you access to the mapbox instance whenever a map gets instantiated. Mostly useful for registering plugins.

Furthermore, 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).

The registerPorts function accepts an option object that takes the following options:

  • 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.

License

(c) Jakub Hampl 2018, 2019

MIT License

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].