4
<meta charset="UTF-8" />
5
<title>NBMap Basic Example</title>
6
<link href="https://maps-gl.nextbillion.io/maps/api/css" rel="stylesheet" />
23
#remove-snap-to-road {
34
<button id="req-snap-to-road">Request Snap To Roads</button>
35
<button id="remove-snap-to-road">Remove Snap To Roads</button>
37
<script src="https://maps-gl.nextbillion.io/maps/api/js"></script>
40
nextbillion.setApiKey('your-api-key')
42
nextbillion.setApiHost('your-api-endpoint')
43
var map = new nextbillion.maps.Map(document.getElementById('map'), {
45
center: { lat: 28.6139, lng: 77.209 },
48
const pathBeforeSnaped = [
49
{ lng: 77.21114158630371, lat: 28.604850536014702 },
50
{ lng: 77.21084117889404, lat: 28.605199049558387 },
51
{ lng: 77.21077680587769, lat: 28.605604077359384 },
52
{ lng: 77.21049785614014, lat: 28.606037361185322 },
53
{ lng: 77.21032619476318, lat: 28.606159810638356 },
54
{ lng: 77.21013307571411, lat: 28.60661193045945 },
55
{ lng: 77.21003651618958, lat: 28.60696043816028 },
56
{ lng: 77.20970392227173, lat: 28.60726184929353 },
57
{ lng: 77.20960736274719, lat: 28.607563259562024 },
58
{ lng: 77.20940351486206, lat: 28.608053049403924 },
59
{ lng: 77.20922112464905, lat: 28.608401552324047 },
60
{ lng: 77.20897436141968, lat: 28.608702959322628 },
61
{ lng: 77.20867395401001, lat: 28.608740635136623 },
62
{ lng: 77.20829844474792, lat: 28.608693540367003 },
63
{ lng: 77.20811605453491, lat: 28.608844243555513 },
64
{ lng: 77.20770835876465, lat: 28.608740635136623 },
65
{ lng: 77.20752596855164, lat: 28.608571093867152 },
66
{ lng: 77.20718264579773, lat: 28.60846748517888 },
67
{ lng: 77.20661401748656, lat: 28.608250848500468 },
68
{ lng: 77.20619559288025, lat: 28.607958859227068 },
69
{ lng: 77.20587372779846, lat: 28.6077516405407 },
72
let snapToRoadsShapes = null
73
document.getElementById('req-snap-to-road').onclick = async function () {
74
const resp = await nextbillion.api.SnapToRoads({
75
path: pathBeforeSnaped,
81
snapToRoadsShapes = map.renderSnapToRoads(resp, pathBeforeSnaped)
84
document.getElementById('remove-snap-to-road').onclick = function () {
85
if (!snapToRoadsShapes) {
88
map.removeSnapToRoads(snapToRoadsShapes)
89
snapToRoadsShapes = null