Git Product home page Git Product logo

mapbox-gl-rs's Introduction

mapbox-gl-rs

Unofficial Rust binding for mapbox-gl-js

Crates.io Docs.rs GithubActions

What's this?

mapbox-gl-js is an open source library for rendering a beautiful vector-based maps in web browser, built with Mapbox and OSS community. The goal of this project is to create a rust binding for mapbox-gl-js via WebAssembly so that Rustacean can build webapps with beautiful Mapbox maps only in Rust.

NOTE: mapbox-gl-rs is in super-duper infant stage. Most of the features are WIP. Please bear with that if you're interested! Also, any contributions e.g. bug reports, feature requests, sending a patch are appreciated.

How does it work?

wasm-bindgen provides a Rust library and tool to compile Rust code into WebAssembly, which allows Rust based application e.g. egui and RustPython to run on web browsers. Most of the people don't know that wasm-bindgen also allows to invoke JavaScript code from Rust. This project leverages this feature to provide a Rust binding for mapbox-gl-js.

Usage

Add mapboxgl to your Cargo.toml

mapboxgl = "0.4"

Add the following CSS and JavaScript snippet in html, so that mapboxgl JavaScript module is loaded.

<link href='https://api.mapbox.com/mapbox-gl-js/v2.10.0/mapbox-gl.css' rel='stylesheet' />
<script src="https://api.mapbox.com/mapbox-gl-js/v2.10.0/mapbox-gl.js"></script>

Build and run your app. If you are a Yew user, the following command will build and start a web server automatically

trunk serve

Supported features

Examples

License

This project is licensed under the MIT license.

mapbox-gl-rs's People

Contributors

dependabot[bot] avatar gregoryraymond avatar griffobeid avatar jryio avatar rmstorm avatar shimatar0 avatar wa1aric avatar wayeast avatar yukinarit avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

mapbox-gl-rs's Issues

The requested module './snippets/mapboxgl-89106e6563064742/mapbox-gl.js' does not provide an export named 'Map'

Hi, I am trying to display a map in a perseus app. I have copied the mapbox-gl.js into my project and mapped it to ./snippets/mapboxgl-89106e6563064742/mapbox-gl.js.

When I visit the page with the map on it I get the following error.

Uncaught SyntaxError: The requested module './snippets/mapboxgl-89106e6563064742/mapbox-gl.js' does not provide an export named 'Map' (at bundle.js:1:10)

The pages setup is as follows.

When the page loads I run the following code (only in browser not SSR)

let map_state = state.map_state.get().as_ref().to_owned();
let options = MapOptions::new(
    "pk.eyJ1IjoibGlhbTczNyIsImEiOiJjbDZpdzh1cGgweDc2M2RvMndja2xlOHFzIn0.b9nPCIMzEkN6qWYsSQMoog".into(),
    "map".into(),
).center(LatLng {
    lat: map_state.lat,
    lng: map_state.lng,
}).zoom(map_state.zoom);
let mut map = MapFactory::new(options).unwrap();
map.set_listener(MapListener);

And add the following html to the page

<div id="map" class="w-screen h-screen"></div>

In the head I added the Mapbox css with the following

<link rel = "stylesheet" href = "https://api.mapbox.com/mapbox-gl-js/v2.10.0/mapbox-gl.css" />

Currently the map listener is empty, issue still occurs without a listener

struct MapListener;
impl MapEventListner for MapListener { }

When I visit the page, the page is blank and I get this in the dev tools

image

And when I open bundle.js in the dev tools I see the following

image

I'm not sure what to do now so if someone could help me fix this it would be greatly appreciated

Heatmaps

This project is open to accept contributions to enable support for using heatmaps ? It is not included on this roadmap but is quite useful.

The requirements for heatmaps would be to extend the Paint structure to allow some additional properties that could me set by default as none to not affect the existing base of dependent crates.

I'm glad to build the necessary wasm-bindgen but I need the confirmation that there is interest to send the pull request

Implement PartialEq for Map or MapFactory

When using mapboxgl inside of a Yew app, it would be helpful to pass around MapFactory or Map as props to other components so they can manipulate the map in different ways. Yew requires that props implement Properties and PartialEq.

Additionally, in order to take a map instance and pass it into a Yew context provider like use_context, the type must implement ParitalEq (docs for use_context).

Global state management crates for Yew like bounce also require that the shared value be ParitalEq.

This will allow the mapbox gl instance to be used outside of the context where it was initialized.

MapLibre support?

Hi, this seems like a very cool project! Do you think it would be possible to add MapLibre support as well? MapLibre is an open source fork of the sadly-no-longer-open-but-still-loved MapBox code. Thanks!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.