maptalks snap plugin
maptalks.js version required >= 1.0.0-rc.11
- Support Geometry Edit/Draw
- Impressive performance perf test
- NPM
npm i maptalks
# or
# npm i maptalks-gl
npm i maptalks.snap
- CDN
<script type="text/javascript" src="https://unpkg.com/maptalks/dist/maptalks.min.js"></script>
<script src="https://unpkg.com/maptalks.snap/dist/maptalks.snap.js"></script>
edit Geometry
draw Geometry
custom filtergeometries
filtergeometries from multi layers
perf test
drag point
- map
- options
-
{Number} tolerance
snapTo threshold
-
{Function } filterGeometries
filter geometries for snap collision. If it is empty, all geometries on the layer where the geometry is located will be obtained
-
import {
Snap
} from 'maptalks.snap';
const snap = new Snap(map, {
//snapTo threshold
tolerance: 15,
// filter geometries for snap collision
filterGeometries: function() {
//you can return geometries for snap collision
return layer.geometries().filter(geo => {
return geo instanceof maptalks.Polygon;
})
}
});
snap.on('snap', (e) => {
console.log(e);
})
//if you use cdn,Snap Hanging under maptalks namespace
// const snap = new maptalks.Snap(map, {
// //snapTo threshold
// tolerance: 15,
// // filter geometries for snap collision
// filterGeometries: function() {
// //you can return geometries for snap collision
// return layer.geometries().filter(geo => {
// return geo instanceof maptalks.Polygon;
// })
// }
// });
snap.effectGeometry(polygon);
//update options
snap.config({
tolerance: 18,
//other opiton params
...
})
- effectGeometry(geometry)
effect geometry for snap
snap.effectGeometry(polygon);
snap.effectGeometry(lineString);
- unEffectGeometry(geometry)
remove geometry snap behavior
snap.unEffectGeometry(polygon);
snap.unEffectGeometry(lineString);
- dispose()
dispose Snap
snap.dispose();
- snap
snap.on('snap', (e) => {
console.log(e);
})