Security News
PyPI Introduces Digital Attestations to Strengthen Python Package Security
PyPI now supports digital attestations, enhancing security and trust by allowing package maintainers to verify the authenticity of Python packages.
@mapbox/mapbox-gl-draw
Advanced tools
@mapbox/mapbox-gl-draw is a plugin for Mapbox GL JS that adds support for drawing and editing features on a map. It allows users to draw points, lines, and polygons, and provides a user-friendly interface for manipulating these shapes.
Drawing Points
This feature allows users to draw points on the map. The code initializes the MapboxDraw control and adds it to the map. When a point is created, an event is triggered, and the created point's features are logged to the console.
const draw = new MapboxDraw();
map.addControl(draw);
map.on('draw.create', function(e) {
const features = e.features;
console.log('Point created:', features);
});
Drawing Lines
This feature allows users to draw lines on the map. Similar to drawing points, the MapboxDraw control is added to the map, and an event is triggered when a line is created, logging the line's features to the console.
const draw = new MapboxDraw();
map.addControl(draw);
map.on('draw.create', function(e) {
const features = e.features;
console.log('Line created:', features);
});
Drawing Polygons
This feature allows users to draw polygons on the map. The MapboxDraw control is added to the map, and an event is triggered when a polygon is created, logging the polygon's features to the console.
const draw = new MapboxDraw();
map.addControl(draw);
map.on('draw.create', function(e) {
const features = e.features;
console.log('Polygon created:', features);
});
Editing Features
This feature allows users to edit existing features on the map. The MapboxDraw control is added to the map, and an event is triggered when a feature is updated, logging the updated feature's details to the console.
const draw = new MapboxDraw();
map.addControl(draw);
map.on('draw.update', function(e) {
const features = e.features;
console.log('Feature updated:', features);
});
Deleting Features
This feature allows users to delete features from the map. The MapboxDraw control is added to the map, and an event is triggered when a feature is deleted, logging the deleted feature's details to the console.
const draw = new MapboxDraw();
map.addControl(draw);
map.on('draw.delete', function(e) {
const features = e.features;
console.log('Feature deleted:', features);
});
leaflet-draw is a plugin for the Leaflet library that provides similar drawing and editing functionalities for maps. It allows users to draw points, lines, and polygons, and offers a user-friendly interface for manipulating these shapes. Compared to @mapbox/mapbox-gl-draw, leaflet-draw is designed specifically for the Leaflet ecosystem.
Turf is a JavaScript library for spatial analysis that includes some drawing and editing functionalities. It allows users to create and manipulate geometries, perform spatial operations, and analyze geospatial data. While Turf is more focused on spatial analysis, it can be used in conjunction with other libraries to provide drawing capabilities similar to @mapbox/mapbox-gl-draw.
Adds support for drawing and editing features on mapbox-gl.js maps.
Requires mapbox-gl-js. Compatible versions are documented in the package.json
On NPM this package has recently moved from mapbox-gl-draw
to @mapbox/mapbox-gl-draw
npm install @mapbox/mapbox-gl-draw
Draw ships with CSS, make sure you include it in your build. It can be found on our CDN or at require('mapbox-gl-draw/dist/mapbox-gl-draw.css')
.
<link rel='stylesheet' href='https://api.mapbox.com/mapbox-gl-js/plugins/mapbox-gl-draw/v0.17.4/mapbox-gl-draw.css' type='text/css' />
When using modules
var mapboxgl = require('mapbox-gl');
var MapboxDraw = require('@mapbox/mapbox-gl-draw');
When using a CDN
<script src='https://api.mapbox.com/mapbox-gl-js/plugins/mapbox-gl-draw/v0.17.4/mapbox-gl-draw.js'></script>
Example setup
mapboxgl.accessToken = 'YOUR_ACCESS_TOKEN';
var map = new mapboxgl.Map({
container: 'map',
style: 'mapbox://styles/mapbox/streets-v8',
center: [40, -74.50],
zoom: 9
});
var Draw = new MapboxDraw();
map.addControl(Draw)
Install dependencies, build the source files and crank up a server via:
git clone git@github.com:mapbox/mapbox-gl-draw.git
npm install
npm start & open http://localhost:9966/debug/?access_token=<token>
npm run test
To github and npm
npm version (major|minor|patch)
git push --tags
git push
npm publish
Update the version number in the GL JS example.
We're trying to follow standards when naming things. Here is a collection of links where we look for inspriation.
FAQs
A drawing component for Mapbox GL JS
We found that @mapbox/mapbox-gl-draw demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 28 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
PyPI now supports digital attestations, enhancing security and trust by allowing package maintainers to verify the authenticity of Python packages.
Security News
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.