Coder Social home page Coder Social logo

labs-mapboxgl-print-service's Introduction

labs-mapboxgl-print-service

Print Layout Service for MapboxGL Web Maps

Requirements

You will need the following things properly installed on your computer.

Local development

  • Clone this repo: git clone [email protected]:NYCPlanning/labs-mapboxgl-print-service.git
  • Navigate to the directory: cd labs-mapboxgl-print-service
  • Install dependencies: npm install
  • Start the server: npm run start
  • Visit your app at http://localhost:3000.

How to Use

The service consists of a single page react frontend served at /, and an API for POSTing and GETing configurations.

Endpoints

POST /config - receives a JSON config object and stores it in a session. If invalid, returns a JSON error message

GET /config - gets the JSON config object associated with this session. If none exist, returns a JSON encoded error message.

Example

To create a landscape print map from the js console, assuming map exists as a global variable, POST to the /config endpoint. On success, open / in a new tab:

fetch('http://localhost:3000/config', {
  method: 'POST',
  credentials: 'include',
  headers: {
    Accept: 'application/json',
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    mapConfig: {
      style: map.getStyle(),
      center: map.getCenter(),
      zoom: map.getZoom(),
      bearing: map.getBearing(),
      pitch: map.getPitch(),
    },
    logo: 'https://raw.githubusercontent.com/NYCPlanning/logo/master/dcp_logo_772.png',
    title: 'This is a test title',
    subtitle: 'This is a test subtitle',
    content: 'This is a test string for the content field',
  }),
})
  .then(res => res.json())
  .then((res) => {
    console.log(res)
    if (res.status === 'success') {
      window.open('http://localhost:3000','_blank');
    }
  })

labs-mapboxgl-print-service's People

Contributors

dhochbaum-dcp avatar andycochran avatar allthesignals avatar tangoyankee avatar

Stargazers

Dan Majka avatar Nick Lempesis avatar dev-guf avatar  avatar Jessica McInchak avatar Ian Shiland avatar Erick Otenyo avatar Connor Montgomery avatar Erdong avatar Ilya Radchenko avatar  avatar Andrew Burnes avatar

Watchers

James Cloos avatar Godfrey Yeung avatar py avatar Tyler Matteo avatar Horatio avatar  avatar

labs-mapboxgl-print-service's Issues

Needs better README

Much has changed since the REAME was originally written.

  • How do I run this locally?
  • How do I make a POST (test.html)?

Don't show empty items

image

If the POST does not have a source or content (e.g.) do not show an empty source/content boxes. There are a couple ways to do this:

  • If POST does not contain a particular element, the app does not use the component for that element and the user cannot add it to the map.
  • If POST does not contain a particular element, the visibility of that element is false and the user must add an empty one for it to appear.

๐Ÿ˜– Foiled by Popup Blocker

When clicking the print button in e.g. ZoLa, it is not immediately noticeable when a popup blocker prevents the print service from opening.

Popup blockers typically only allow window.open if used during the processing of a user event (like a click). If window.open is called later, the popup blocker catches it.

A few possible solutions:

https://stackoverflow.com/questions/2587677/avoid-browser-popup-blockers/2587692#2587692

https://stackoverflow.com/questions/9514698/bypass-popup-blocker-on-window-open-when-jquery-event-preventdefault-is-set/9514875#9514875

https://stackoverflow.com/questions/4602964/how-do-i-prevent-google-chrome-from-blocking-my-popup/4603026#4603026

Optional Subtitle

If the POST does not contain a subtitle, but the title is editable (titleEditable:false), the user should be able to add a subtitle.

This could be done simply by changing this:

{subtitle &&

to this:

{(subtitle || (titleEditable !== false)) &&

However, since subtitleVisible defaults to true, the print would start off with an empty subtitle. Instead it would be nice if subtitleVisible was set to true if a subtitle exists.

Archivable?

@rtblair @godfreyyeung any idea if this code is still in use anywhere? I know we "print" maps in applicantmaps but I couldn't find any direct references to this repo using code search.

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.