# maptalks.autoadsorb

> Adsorb vertux/border/both of geos on layer When drawing or editing

Latest version **1.0.0-beta.1** (published 2022-07-22) · MIT license · 0 weekly downloads

## Install

```sh
npm install maptalks.autoadsorb
pnpm add maptalks.autoadsorb
yarn add maptalks.autoadsorb
bun add maptalks.autoadsorb
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0-beta.1 |
| Published | 2022-07-22 |
| First published | 2018-07-10 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 11 |
| Unpacked size | 772.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | cXiaof |
| Maintainers | cxiaof |
| Keywords | maptalks, autoadsorb, adsorb, snap, snapto |

## Links

- npm: https://www.npmjs.com/package/maptalks.autoadsorb
- Repository: https://github.com/cXiaof/maptalks.autoadsorb
- Issues: https://github.com/cXiaof/maptalks.autoadsorb/issues
- npm.io page: https://npm.io/package/maptalks.autoadsorb

## Dependencies (11)

- [@turf/combine](https://npm.io/package/@turf/combine.md) ^6.5.0
- [@turf/explode](https://npm.io/package/@turf/explode.md) ^6.5.0
- [@turf/flatten](https://npm.io/package/@turf/flatten.md) ^6.5.0
- [geojson-rbush](https://npm.io/package/geojson-rbush.md) ^3.2.0
- [lodash.isequal](https://npm.io/package/lodash.isequal.md) ^4.5.0
- [lodash.findindex](https://npm.io/package/lodash.findindex.md) ^4.6.0
- [lodash.difference](https://npm.io/package/lodash.difference.md) ^4.5.0
- [@turf/nearest-point](https://npm.io/package/@turf/nearest-point.md) ^6.5.0
- [@turf/polygon-to-line](https://npm.io/package/@turf/polygon-to-line.md) ^6.5.0
- [lodash.differencewith](https://npm.io/package/lodash.differencewith.md) ^4.5.0
- [@turf/nearest-point-on-line](https://npm.io/package/@turf/nearest-point-on-line.md) ^6.5.0

## Recent versions

- 1.0.0-beta.1 (latest) — 2022-07-22
- 1.0.0-alpha.3 — 2022-05-18
- 1.0.0-alpha.2 — 2022-05-18
- 1.0.0-alpha.1 — 2022-05-18
- 0.4.0 — 2022-05-12
- 0.3.0 — 2022-05-12
- 0.2.0 — 2021-03-26
- 0.1.0 — 2019-05-05
- 0.1.0-beta.5 — 2018-07-19
- 0.1.0-beta.4 — 2018-07-18
- 0.1.0-beta.3 — 2018-07-17
- 0.1.0-beta.2 — 2018-07-17
- 0.1.0-beta.1 — 2018-07-10

## README

# maptalks.autoadsorb

Adsorb vertux/border/both of geos on layer When drawing or editing,inspired on [maptalks.snapto](https://github.com/liubgithub/maptalks.snapto/wiki)

## Examples

### [DEMO](https://cxiaof.github.io/maptalks.autoadsorb/demo/index.html)

## Install

- Install with npm: `npm install maptalks.autoadsorb`.
- Install with yarn: `yarn add maptalks.autoadsorb`.
- Download from [dist directory](https://github.com/cXiaof/maptalks.autoadsorb/tree/master/dist).
- Use unpkg CDN: `https://cdn.jsdelivr.net/npm/maptalks.autoadsorb/dist/maptalks.autoadsorb.min.js`

## Usage

As a plugin, `maptalks.autoadsorb` must be loaded after `maptalks.js` in browsers. You can also use `'import { Autoadsorb } from "maptalks.autoadsorb"` when developing with webpack.

```html
<!-- ... -->
<script src="https://cdn.jsdelivr.net/npm/maptalks.autoadsorb/dist/maptalks.autoadsorb.min.js"></script>
<!-- ... -->
```

```javascript
// new Autoadsorb, option layers is necessary.
const autoAdsorb = new maptalks.Autoadsorb({ layers: [layer] })

// or you can update some options later
autoAdsorb.setMode('vertux')
autoAdsorb.setDistance(20)

// Use when drawing with DrawTool.
autoAdsorb.bindDrawTool(drawTool)

// Use when editing geometry.
autoAdsorb.bindGeometry(geometry)

// Forced refresh of adsorption geometries.Usually used after drawend or editend.
autoAdsorb.refreshTargets()
```

## API Reference

```javascript
new maptalks.Autoadsorb(options)
```

- options **Object** options
  - layers **Array** Get layer array or layerID array of the adsorption target.
  - mode **String** there are three modes, auto/vertux/border, auto by default.
  - distance **Number** the distance in pixel from mouse to the snap point, 10 by default.
  - shellPoints **Number** number of shell points in Circle and Ellipse, 60 by default.The larger the number, the smoother the experience when adsorption Circle and Ellipse.
  - needCtrl **Boolean** do adsorb only with Ctrl, default is false.

`bindDrawTool(drawtool)` bind a drawtool on map.

`bindGeometry(geometry)` bind a geometry on map which need edited.

`refreshTargets()` forced refresh of adsorption geometries.

`isEnable()` get enable status

`setMode()` adsorb mode, 'vertux' will only adsorb Point ,'border' will only adsorb Line, and 'auto' will find both but may find Point only if Point and Line at very close

`getMode()` get mode now

`setDistance()` adsorb distance, used to set how far to find geometries around

`getDistance()` get distance now

`remove()` clear private object

## Contributing

We welcome any kind of contributions including issue reportings, pull requests, documentation corrections, feature requests and any other helps.

## Develop

The only source file is `index.js`.

It is written in ES6, transpiled by [babel](https://babeljs.io/) and tested with [mocha](https://mochajs.org) and [expect.js](https://github.com/Automattic/expect.js).

### Scripts

- Install dependencies

```shell
$ npm install
```

- Watch source changes and generate runnable bundle repeatedly

```shell
$ gulp watch
```

- Package and generate minified bundles to dist directory

```shell
$ gulp minify
```

- Lint

```shell
$ npm run lint
```

## More Things

- [maptalks.autoadsorb](https://github.com/cXiaof/maptalks.autoadsorb/issues)
- [maptalks.multisuite](https://github.com/cXiaof/maptalks.multisuite/issues)
- [maptalks.geosplit](https://github.com/cXiaof/maptalks.geosplit/issues)
- [maptalks.polygonbool](https://github.com/cXiaof/maptalks.polygonbool/issues)
- [maptalks.geo2img](https://github.com/cXiaof/maptalks.geo2img/issues)
- [maptalks.control.compass](https://github.com/cXiaof/maptalks.control.compass/issues)
- [maptalks.autogradual](https://github.com/cXiaof/maptalks.autogradual/issues)

---
_Source: https://npm.io/package/maptalks.autoadsorb · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
