All Projects → NYCPlanning → labs-maputnik-dev-server

NYCPlanning / labs-maputnik-dev-server

Licence: other
An express.js server that allows for quickly loading mapboxGL styles from any project into the Maputnik Style Editor

Programming Languages

javascript
184084 projects - #8 most used programming language
shell
77523 projects

Labels

Projects that are alternatives of or similar to labs-maputnik-dev-server

Ubunter
An automated tool to turn your ubuntu machine into a hacking lab
Stars: ✭ 17 (-45.16%)
Mutual labels:  labs
Academiccontent
Free tech resources for faculty, students, researchers, life-long learners, and academic community builders for use in tech based courses, workshops, and hackathons.
Stars: ✭ 2,196 (+6983.87%)
Mutual labels:  labs
awesome-mobile-robotics
Useful links of different content related to AI, Computer Vision, and Robotics.
Stars: ✭ 243 (+683.87%)
Mutual labels:  labs
LAB
MIT IT Lab Repository
Stars: ✭ 23 (-25.81%)
Mutual labels:  labs
labs-zap-search
Search application for the DCP Zoning Application Search
Stars: ✭ 13 (-58.06%)
Mutual labels:  labs
DZ-Pharma-Data
Medications data for +4800 drugs sold in Algeria and their labs
Stars: ✭ 23 (-25.81%)
Mutual labels:  labs
athnlp-labs
Athens NLP Summer School Labs
Stars: ✭ 41 (+32.26%)
Mutual labels:  labs
labs-migration-viz
A single-page interactive visualization of historic U.S. Census migration data for New York City
Stars: ✭ 18 (-41.94%)
Mutual labels:  labs
Cobol Programming Course
Training materials and labs for a "Getting Started" level course on COBOL
Stars: ✭ 1,963 (+6232.26%)
Mutual labels:  labs
advanced-istio-service-mesh-workshop
Advanced Istio Service Mesh Workshop
Stars: ✭ 28 (-9.68%)
Mutual labels:  labs
USTC-CS-Resources
USTC计算机学院 个人学习资料分享
Stars: ✭ 86 (+177.42%)
Mutual labels:  labs
iot-curriculum
Hands on labs and content for students and educators to learn and teach the Internet of Things at schools, universities, coding clubs, community colleges and bootcamps
Stars: ✭ 110 (+254.84%)
Mutual labels:  labs
bring-your-own-data-labs
Bring your own data Labs: Build a serverless data pipeline based on your own data
Stars: ✭ 40 (+29.03%)
Mutual labels:  labs
CSUS-CPE-CSC-EEE-Materials
Homework, labs, tests for a variety of classes. Feel free to share. California State University, Sacramento
Stars: ✭ 38 (+22.58%)
Mutual labels:  labs
hackthebox
Notes Taken for HTB Machines & InfoSec Community.
Stars: ✭ 286 (+822.58%)
Mutual labels:  labs
containers-101-workshop
Docker Linux Containers 101 Workshop
Stars: ✭ 18 (-41.94%)
Mutual labels:  labs
Container.training
Slides and code samples for training, tutorials, and workshops about Docker, containers, and Kubernetes.
Stars: ✭ 2,377 (+7567.74%)
Mutual labels:  labs
robo-chart-web
📊 Transform Google sheets to pretty charts!
Stars: ✭ 28 (-9.68%)
Mutual labels:  labs
database labs
initial set of databases labs
Stars: ✭ 19 (-38.71%)
Mutual labels:  labs
Labtainers
Labtainers: A Docker-based cyber lab framework
Stars: ✭ 226 (+629.03%)
Mutual labels:  labs

Maputnik Dev Server

This Express.js server allows you to quickly load Mapbox GL styles from any project into the Maputnik Style Editor.

Writing Mapbox GL styles by hand is a pain, and Maputnik makes it easy to experiment with different styles via a GUI. However, manually loading sources and layers into Maputnik is cumbersome. Since Maputnik takes a style query param, it's possible to pass in a complete Mapbox GL style. maputnik-dev-server provides a simple way to load the current style from a Mapbox GL map in a development environment into Maputnik.

maputnik-dev-server

Why not use maputnik-cli?

Maputnik CLI wants a file on the local filesystem as an input. If you're doing a lot of addSource() and addLayer() in your project and have your configs spread out, you may not have a consolidated style JSON to pass into maputnik-cli. Our approach grabs the current style from an already loaded map, and doesn't concern itself with how the map was initialized.

Workflow

The Express server hosts the Maputnik editor at localhost:4000/maputnik, as well as a simple API for receiving and serving a Mapbox GL style JSON. The indended workflow is as follows:

  1. In your development project, use map.getStyle() to get the current style JSON.

  2. Add id and metadata properties to the style JSON to make them compatible with Maputnik. (You will need metadata.maputnik:mapbox_access_token if you are using mapbox-hosted sources and sprites.)

  3. POST the style JSON to http://localhost:4000/style

  4. Open a new browser tab with http://localhost:4000/maputnik?style=http://localhost:4000/style#${zoom}/${lat}/${lng}. maputnik-dev-server will be serving the same style JSON that was just posted at /style, where the maputnik UI can pick it up.

  5. Your style will be loaded into Maputnik! Try out changes to individual layer styles, and copy and paste their JSON back into your project.

Steps 1-4 can be achieved with the click of a button with a few lines of code in your project. This can be wired up to a button you can use during development, or even run in the javascript console if the map object is available. It's up to you how to trigger the POST and new tab.

openMaputnik() {
  const style = map.getStyle();
  const zoom = map.getZoom();
  const { lng, lat } = map.getCenter();

  fetch('http://localhost:4000/style', {
    method: 'POST',
    headers: {
      Accept: 'application/json',
      'Content-Type': 'application/json',
    },
    body: JSON.stringify(style),
  })
    .then(() => {
      window.open(`http://localhost:4000/?style=http://localhost:4000/style#${zoom}/${lat}/${lng}`, '_blank');
    });
},

It is also possible to send the current map JSON to maputnik-dev-server from the JavaScript console, as long as the map object is available globally. See step 4 below.

How to Use

  1. Clone this repo & install dependencies:
git clone [email protected]:NYCPlanning/labs-maputnik-dev-server.git
cd labs-maputnik-dev-server
npm install
  1. Download and Build Maputnik into /public (runs scripts/build-maputnik.sh):
npm run build-maputnik
  1. Start the server:
npm run start
  1. Paste the following command in to the JavaScript console:
fetch('http://localhost:4000/style',{method:'POST',headers:{Accept:'application/json','Content-Type': 'application/json'},body: JSON.stringify(map.getStyle())}).then(()=>{window.open(`http://localhost:4000/?style=http://localhost:4000/style#${map.getZoom()}/${map.getCenter().lat}/${map.getCenter().lng}`,'_blank');});
  1. Style layers in Maputnik, copy and paste the resulting layer configs into your code.

The valid JSON throws off our linter, so we like using [linter-eslint](https://atom.io/packages/linter-eslint) to format everything once we paste the JSON into our code.

Routes

  • POST /style - submit a style JSON that will be immediately available using GET /style
  • GET /style - 'GET' the last style that was POSTed

How you can help

In the spirit of free software, everyone is encouraged to help improve this project. Here are some ways you can contribute.

  • Comment on or clarify [issues](link to issues)
  • Report [bugs](link to bugs)
  • Suggest new features
  • Write or edit documentation
  • Write code (no patch is too small)
    • Fix typos
    • Add comments
    • Clean up code
    • Add new features

Read more about contributing.

Contact us

You can find us on Twitter at @nycplanninglabs, or comment on issues and we'll follow up as soon as we can. If you'd like to send an email, use [email protected]

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