GithubHelp home page GithubHelp logo

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
npm ci
npm 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}
npm ci
npm 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

mcwhittemore avatar kelvinabrokwa avatar dependabot[bot] avatar samanpwbb avatar tristen avatar drewbo avatar greenkeeper[bot] avatar stepankuzmin avatar kkaefer avatar scothis avatar davidtheclark avatar mourner avatar ansis avatar underoot avatar andrewharvey avatar tmcw avatar ghoshkaj avatar averas avatar jisaacks avatar edenh avatar lukeelmers avatar mayagao avatar timiyay avatar fc avatar adrianababakanian avatar ilyamilosevic avatar varna avatar kirach avatar dereklieu avatar neodescis avatar

Stargazers

Gabriel Dantas avatar Daniel Moreira avatar Osama Alawna avatar Sean Wright avatar Arpad Gabor avatar Jean Ricardo Monteiro avatar Rafael Coimbra avatar Nilick avatar hojat avatar Thomas Rosen avatar Stanislav (Stanley) Modrak avatar KORAY OZDOGU avatar Carl Gleisner avatar Mustafa Murat avatar Thomas Schmidt avatar  avatar Julien avatar Sergio Cózar avatar Anthony DeLeon avatar Davide avatar Farhanunnasih avatar sucls avatar  avatar iceahh avatar CAFFEINE avatar  avatar Min avatar  avatar Chris Dalke avatar Sourabh Soni avatar  avatar  avatar WhaleFall avatar AceCodePt avatar  avatar RizkLee avatar  avatar  avatar pedoc avatar  avatar  avatar  avatar  avatar Marcelo Augusto Escaioni Migotto avatar lemon avatar Abdur-Rahman avatar  avatar  avatar Brady Swann avatar Captain Code avatar Jhoan Vergara Arocutipa avatar  avatar  avatar /dev/null avatar Kristof avatar Arman Shahinyan avatar Daniel Thoma avatar Austin Chick avatar Dennis Jensen avatar Dan Jian avatar N Reed Miller avatar Brodie Gallinger avatar Bankn8II©$A avatar MEKXH avatar Muny Roth avatar Awais Ali avatar princewck avatar  avatar Jimmy Briggs avatar guoqing22 avatar Sachin Kanishka avatar Alessandro avatar Guillem avatar  avatar Nikhil Peri avatar Baptiste Mahé avatar Edu Nauta avatar Mattias Hemmingsson avatar Mark Kirchen avatar Fuyi avatar lauro.o.m avatar  avatar Cherno avatar James Goldie avatar Alireza Sahabi avatar Nicholas Haley avatar pb avatar David Higginbotham avatar  avatar xiaobc avatar simon avatar Shahab Movahhedi avatar  avatar  avatar Alan Gordie avatar  avatar Pham Tinh avatar 七秒记忆 avatar Maksymilian Lach avatar Ryan avatar

Watchers

 avatar Leon Sorokin avatar Matthew Perryman avatar Mike Gionfriddo avatar  avatar  avatar Ivo van Dongen avatar Alex Barth avatar Siarhei Fedartsou avatar Maning Sambale avatar Mike Ringrose avatar Jorge Zapata avatar Yanpeng Lin avatar Mathias avatar Brad Leege avatar Minh Nguyễn avatar  avatar  avatar Roman avatar Pavel avatar Thomas Moenicke avatar Doug Chuchro avatar macroshen avatar  avatar Yury Khrol avatar HOU Bo avatar Denis Tikhomirov avatar Jeff Hurlock avatar SanD avatar Isaac Besora Vilardaga avatar Fabian Guerra Soto avatar Tatiana Van Campenhout avatar Connor Brown avatar  avatar Akira Murao avatar Shravan Shah avatar Oleksandr avatar Blythe Sheldon avatar  avatar  avatar Lizz S avatar Yury Zakreuski avatar Abimael Riveros avatar Virginia Yung (Ng) avatar Oana Badiu avatar Peter Liu avatar Alex Granin avatar  avatar Himanshu Adlakha avatar Ben Pleasanton avatar Shawn avatar Uladzislava Pratashchyk avatar  avatar Miro Kokkonen avatar Nicki Dlugash avatar Lindsay Young avatar Edith Yesenia Quispe Pérez avatar Paavan Sirigiri avatar Luis Alanya  avatar Chetan Gowda avatar  avatar NotImplemented avatar Dmitry Kormulev avatar  avatar  avatar Aliaksei Labachou avatar Jake Dickinson avatar Danny  Katherin Aiquipa Pacheco avatar Richman avatar Sivaram Ramachandran avatar  avatar Yury Kanetski avatar Lorn avatar Jakub Borowski avatar liuweiguang avatar Ilkka Kellokoski avatar Mathias Fröjdman avatar Ildar SALAKHIEV avatar Kara avatar Ruth Maben avatar César A. avatar Dzmitry Nikulin avatar Denis avatar  avatar Karito Tenorio Palomino avatar GALIA avatar Naib Baghirov avatar Pratik avatar Nikita Slavin avatar Yauhen Zhurko avatar Abhishek Saikia avatar  avatar linghuam avatar Kelvin avatar Artsiom Radkevich avatar  avatar Jaime Chen avatar Valentín avatar  avatar Pavel Zhuchkov avatar

mapbox-gl-draw's Issues

Hover styling

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

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.

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

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)

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.

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

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.

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.

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

Add API.md

Generate this via jsdoc in the codebase.

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.

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.

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