GithubHelp home page GithubHelp logo

mapbox / mapbox-gl-draw Goto Github PK

View Code? Open in Web Editor NEW
899.0 899.0 572.0 4.46 MB

Draw tools for mapbox-gl-js

Home Page: https://www.mapbox.com/mapbox-gl-js/example/mapbox-gl-draw/

License: ISC License

JavaScript 99.15% HTML 0.85%
drawing javascript mapbox-gl mapbox-gl-js

mapbox-gl-draw's Introduction

@mapbox/mapbox-gl-draw

Build Status

Adds support for drawing and editing features on mapbox-gl.js maps. See a live example here

Requires mapbox-gl-js.

If you are developing with mapbox-gl-draw, see API.md for documentation.

Installing

npm install @mapbox/mapbox-gl-draw

Draw ships with CSS, make sure you include it in your build.

Usage in your application

JavaScript

When using modules

import mapboxgl from 'mapbox-gl';
import MapboxDraw from "@mapbox/mapbox-gl-draw";

When using a CDN

<script src='https://api.mapbox.com/mapbox-gl-js/plugins/mapbox-gl-draw/v1.4.3/mapbox-gl-draw.js'></script>

CSS

When using modules

import '@mapbox/mapbox-gl-draw/dist/mapbox-gl-draw.css'

When using CDN

<link rel='stylesheet' href='https://api.mapbox.com/mapbox-gl-js/plugins/mapbox-gl-draw/v1.4.3/mapbox-gl-draw.css' type='text/css' />

Typescript

Typescript definition files are available as part of the DefinitelyTyped package.

npm install @types/mapbox__mapbox-gl-draw

Example usage

mapboxgl.accessToken = 'YOUR_ACCESS_TOKEN';

var map = new mapboxgl.Map({
  container: 'map',
  style: 'mapbox://styles/mapbox/streets-v12',
  center: [40, -74.50],
  zoom: 9
});

var Draw = new MapboxDraw();

// Map#addControl takes an optional second argument to set the position of the control.
// If no position is specified the control defaults to `top-right`. See the docs
// for more details: https://docs.mapbox.com/mapbox-gl-js/api/#map#addcontrol

map.addControl(Draw, 'top-left');

map.on('load', function() {
  // ALL YOUR APPLICATION CODE
});

https://www.mapbox.com/mapbox-gl-js/example/mapbox-gl-draw/

See API.md for complete reference.

Enhancements and New Interactions

For additional functionality check out our list of custom modes.

Mapbox Draw accepts functionality changes after the functionality has been proven out via a custom mode. This lets users experiment and validate their mode before entering a review process, hopefully promoting innovation. When you write a custom mode, please open a PR adding it to our list of custom modes.

Developing and testing

Install dependencies, build the source files and crank up a server via:

git clone [email protected]:mapbox/mapbox-gl-draw.git
yarn install
yarn start & open "http://localhost:9967/debug/?access_token=<token>"

Testing

npm run test

Publishing

To GitHub and NPM:

npm version (major|minor|patch)
git push --tags
git push
npm publish

To CDN:

# make sure you are authenticated for AWS
git checkout v{x.y.z}
yarn install
yarn run prepublish
aws s3 cp --recursive --acl public-read dist s3://mapbox-gl-js/plugins/mapbox-gl-draw/v{x.y.z}

Update the version number in the GL JS example.

Naming actions

We're trying to follow standards when naming things. Here is a collection of links where we look for inspiration.

mapbox-gl-draw's People

Contributors

adrianababakanian avatar andrewharvey avatar ansis avatar averas avatar davidtheclark avatar dependabot[bot] avatar dereklieu avatar drewbo avatar edenh avatar fc avatar ghoshkaj avatar greenkeeper[bot] avatar ilyamilosevic avatar jisaacks avatar karimnaaji avatar kelvinabrokwa avatar kirach avatar kkaefer avatar lukeelmers avatar mayagao avatar mcwhittemore avatar mollymerp avatar mourner avatar samanpwbb avatar scothis avatar stepankuzmin avatar thiagoxvo avatar timiyay avatar tmcw avatar tristen 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  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  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  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  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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

mapbox-gl-draw's Issues

Advanced draw operations for squares

  • Click and dragging with the alt key should draw a shape with fixed width+height with center pinning (i.e. the drawn layer expands in size across the canvas in both directions)
  • Click and dragging with the shift key should draw a shape with fixed width+height with top-left pinning.

Use map.on('click'

Using the built-in on('click' event instead of catching click events on the map container will let gl-draw remove a bunch of code, including the homegrown mousePos utility fn

Remove store & undo/redo

I think that gl-draw should, at its core, only emit events. Undo/redo should be implemented outside of core.

Shape draw operations

  • Click and dragging should draw a shape with variable width+height
  • Click and dragging with the alt key should draw a shape with fixed width+height with center pinning (i.e. the drawn layer expands in size across the canvas in both directions)
  • Click and dragging with the shift key should draw a shape with fixed width+height with top-left pinning.

Better README.md

  • Description
    • Overview
    • Version number
    • Testing badges
    • Link to live site (if applicable)
  • Usage
    • How to use it with code samples
    • Links to documentation (if applicable)
  • Running locally
    • How to run it locally
    • Include dependencies
  • Testing
    • How to test it locally

You should be able to select features

If you click on a feature, it should be restyled and selected.

  • If the feature is a marker, it should be draggable #23
  • If the feature is a polygon, it should be editable

When a person clicks on a marker and then drags the selected marker, the marker should move

The way I see this playing out is:

There are two states: edit & data (drawn or imported data)

  • mousedown emits a function that calls map.featuresAt. This returns the feature under the mouse and removes it from data object and put's it in the edit object.
  • mousedown + drag set's a key that enables mousemove
  • mousemove calculates the coordinates of the markers placement on the map and updates the new coordinates to the edit object.
  • mouseup unsets the key the enables mousemove, removes the feature from the edit object and updates the data object with the new coordinates.

cc @kelvinabrokwa

Shape edit operations

  • Dragging a control point should resize a shape with the top right position pinned.
  • Shift+Dragging a control point should resize a shape without pinning
  • Dragging when a cursor is over a feature + within a variable radius should move a shape across the map.

Perfomance improvements

gl-draw, as is, is virtually unuseable. However, its a great test-case for gl-js on-the-fly rendering capabilities. That being said, there many optimizations in the javascript here that can ameliorate this.

To do:

Upstream:

  • check out zoom and pan implementations in mapbox-gl-js for tips and tricks on animation

Add API.md

Generate this via jsdoc in the codebase.

Avoid using DOM elements

Many of the guides and intermediate drawing UI in gl-draw are constructed using divs and CSS: these should be implemented in GL land instead.

Control candidates

Leaflet Draw has 7 control elements:

  • LineString
  • Freeform polygon
  • Square
  • Circle
  • Marker
  • Edit existing
  • Delete existing

It would ideal to narrow this toolchain.


I'd like to propose:

  • Freeform pen with control interactions
  • Circle
  • Marker

Freeform pen would:

  • Create a perfect square by holding the shift key (or one finger hold on touch)
  • Complete a point by double clicking (likewise on touch) if the end point doesn't connect with the first it's a linestring.

To edit existing: If editing is enabled, touching or selecting an existing feature puts it in edit mode.
To delete existing: selecting an existing feature and hitting the escape key or touch and holding element for delete or edit options on mobile (this might be doable). Having some sort of undo flash display might be nice here too (something similar to the way inbox does it)

Hover styling

It would be nice if on hover, the feature that would be selected if clicked was styled differently.

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.