Skip to content

Commit 5830a8b

Browse files
author
Scott Farley
committed
new debug page for working without a map
1 parent a6d0e70 commit 5830a8b

File tree

2 files changed

+93
-33
lines changed

2 files changed

+93
-33
lines changed

debug/index.js

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@ insertCss(
1818

1919
var MapboxGeocoder = require('../');
2020

21-
// var mapDiv = document.body.appendChild(document.createElement('div'));
22-
// mapDiv.style.position = 'absolute';
23-
// mapDiv.style.top = 0;
24-
// mapDiv.style.right = 0;
25-
// mapDiv.style.left = 0;
26-
// mapDiv.style.bottom = 0;
21+
var mapDiv = document.body.appendChild(document.createElement('div'));
22+
mapDiv.style.position = 'absolute';
23+
mapDiv.style.top = 0;
24+
mapDiv.style.right = 0;
25+
mapDiv.style.left = 0;
26+
mapDiv.style.bottom = 0;
2727

2828
var notMapDiv = document.body.appendChild(document.createElement('div'));
2929
notMapDiv.style.position = 'absolute';
@@ -35,12 +35,12 @@ notMapDiv.style.backgroundColor = 'red';
3535

3636
notMapDiv.classList.add("notAMap");
3737

38-
// var map = new mapboxgl.Map({
39-
// container: mapDiv,
40-
// style: 'mapbox://styles/mapbox/streets-v9',
41-
// center: [-79.4512, 43.6568],
42-
// zoom: 13
43-
// });
38+
var map = new mapboxgl.Map({
39+
container: mapDiv,
40+
style: 'mapbox://styles/mapbox/streets-v9',
41+
center: [-79.4512, 43.6568],
42+
zoom: 13
43+
});
4444

4545
var coordinatesGeocoder = function(query) {
4646
var matches = query.match(/^[ ]*(-?\d+\.?\d*)[, ]+(-?\d+\.?\d*)[ ]*$/);
@@ -97,27 +97,27 @@ window.geocoder = geocoder;
9797
var button = document.createElement('button');
9898
button.textContent = 'click me';
9999

100-
// var removeBtn = document.body.appendChild(document.createElement('button'));
101-
// removeBtn.style.position = 'absolute';
102-
// removeBtn.style.zIndex = 10;
103-
// removeBtn.style.top = '10px';
104-
// removeBtn.style.left = '10px';
105-
// removeBtn.textContent = 'Remove geocoder control';
106-
107-
// map
108-
// .getContainer()
109-
// .querySelector('.mapboxgl-ctrl-bottom-left')
110-
// .appendChild(button);
111-
// // map.addControl(geocoder);
112-
113-
// map.on('load', function() {
114-
// button.addEventListener('click', function() {
115-
// geocoder.query('Montreal Quebec');
116-
// });
117-
// removeBtn.addEventListener('click', function() {
118-
// map.removeControl(geocoder);
119-
// });
120-
// });
100+
var removeBtn = document.body.appendChild(document.createElement('button'));
101+
removeBtn.style.position = 'absolute';
102+
removeBtn.style.zIndex = 10;
103+
removeBtn.style.top = '10px';
104+
removeBtn.style.left = '10px';
105+
removeBtn.textContent = 'Remove geocoder control';
106+
107+
map
108+
.getContainer()
109+
.querySelector('.mapboxgl-ctrl-bottom-left')
110+
.appendChild(button);
111+
// map.addControl(geocoder);
112+
113+
map.on('load', function() {
114+
button.addEventListener('click', function() {
115+
geocoder.query('Montreal Quebec');
116+
});
117+
removeBtn.addEventListener('click', function() {
118+
map.removeControl(geocoder);
119+
});
120+
});
121121

122122
geocoder.on('results', function(e) {
123123
console.log('results: ', e.features);

debug/nomap.js

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
'use strict';
2+
var mapboxgl = require('mapbox-gl');
3+
var insertCss = require('insert-css');
4+
var fs = require('fs');
5+
6+
mapboxgl.accessToken = window.localStorage.getItem('MapboxAccessToken');
7+
8+
9+
var meta = document.createElement('meta');
10+
meta.name = 'viewport';
11+
meta.content = 'initial-scale=1,maximum-scale=1,user-scalable=no';
12+
document.getElementsByTagName('head')[0].appendChild(meta);
13+
14+
insertCss(fs.readFileSync('./lib/mapbox-gl-geocoder.css', 'utf8'));
15+
insertCss(
16+
fs.readFileSync('./node_modules/mapbox-gl/dist/mapbox-gl.css', 'utf8')
17+
);
18+
19+
var MapboxGeocoder = require('../');
20+
21+
var notMapDiv = document.body.appendChild(document.createElement('div'));
22+
notMapDiv.style.position = 'absolute';
23+
notMapDiv.style.top = 0;
24+
notMapDiv.style.right = 0;
25+
notMapDiv.style.left = 0;
26+
notMapDiv.style.bottom = 0;
27+
notMapDiv.style.backgroundColor = 'darkcyan';
28+
29+
notMapDiv.classList.add("notAMap");
30+
31+
var geocoder = new MapboxGeocoder({
32+
accessToken: mapboxgl.accessToken,
33+
trackProximity: true
34+
});
35+
36+
geocoder.addTo('.notAMap')
37+
38+
window.geocoder = geocoder;
39+
40+
41+
geocoder.on('results', function(e) {
42+
console.log('results: ', e.features);
43+
});
44+
45+
geocoder.on('result', function(e) {
46+
console.log('result: ', e.result);
47+
});
48+
49+
geocoder.on('clear', function(e) {
50+
console.log(e)
51+
console.log('clear');
52+
});
53+
54+
geocoder.on('loading', function(e) {
55+
console.log('loading:', e.query);
56+
});
57+
58+
geocoder.on('error', function(e) {
59+
console.log('Error is', e.error);
60+
});

0 commit comments

Comments
 (0)