From f26fdca1d3d370532174fdda09bfae5b51034509 Mon Sep 17 00:00:00 2001 From: Scott Farley Date: Wed, 2 Oct 2019 07:52:19 -0700 Subject: [PATCH 1/2] real debug --- debug/index.html | 60 ++++++++++++++++++++++++++++++++++++++++++++++++ package.json | 2 +- 2 files changed, 61 insertions(+), 1 deletion(-) create mode 100644 debug/index.html diff --git a/debug/index.html b/debug/index.html new file mode 100644 index 00000000..b1868b08 --- /dev/null +++ b/debug/index.html @@ -0,0 +1,60 @@ + + Mapbox-gl-geocoder + + + + + + + + +
+

Hi

+ + + \ No newline at end of file diff --git a/package.json b/package.json index b0827116..130d6dbe 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,7 @@ "unpkg": "dist/mapbox-gl-geocoder.min.js", "style": "lib/mapbox-gl-geocoder.css", "scripts": { - "start": "budo debug/index.js --live -- -t brfs ", + "start": "budo lib/index.js:bundle.js --open debug --live -- -t brfs --standalone MapboxGeocoder lib/index.js", "prepublish": "NODE_ENV=production && mkdir -p dist && browserify --standalone MapboxGeocoder lib/index.js | uglifyjs -c -m > dist/mapbox-gl-geocoder.min.js && cp lib/mapbox-gl-geocoder.css dist/", "test": "browserify -t envify test/index.js test/events.test.js | smokestack -b firefox | tap-status | tap-color", "docs": "documentation build lib/index.js --format=md > API.md", From 2e55d103bc2f54ba2d2b4bf5b6de74477609abb4 Mon Sep 17 00:00:00 2001 From: Scott Farley Date: Wed, 2 Oct 2019 09:45:45 -0700 Subject: [PATCH 2/2] remove old debug pages --- debug/filter.js | 76 ---------------------------- debug/index.js | 128 ------------------------------------------------ package.json | 2 +- 3 files changed, 1 insertion(+), 205 deletions(-) delete mode 100644 debug/filter.js delete mode 100644 debug/index.js diff --git a/debug/filter.js b/debug/filter.js deleted file mode 100644 index 91ca799e..00000000 --- a/debug/filter.js +++ /dev/null @@ -1,76 +0,0 @@ -'use strict'; -var mapboxgl = require('mapbox-gl'); -var insertCss = require('insert-css'); -var fs = require('fs'); -mapboxgl.accessToken = window.localStorage.getItem('MapboxAccessToken'); - -insertCss(fs.readFileSync('./lib/mapbox-gl-geocoder.css', 'utf8')); -insertCss( - fs.readFileSync('./node_modules/mapbox-gl/dist/mapbox-gl.css', 'utf8') -); - -var MapboxGeocoder = require('../'); - -var mapDiv = document.body.appendChild(document.createElement('div')); -mapDiv.style.position = 'absolute'; -mapDiv.style.top = 0; -mapDiv.style.right = 0; -mapDiv.style.left = 0; -mapDiv.style.bottom = 0; - -var map = new mapboxgl.Map({ - container: mapDiv, - style: 'mapbox://styles/mapbox/streets-v9', - center: [-79.4512, 43.6568], - zoom: 13 -}); - -var geocoder = new MapboxGeocoder({ - accessToken: window.localStorage.getItem('MapboxAccessToken'), - country: 'au', - filter: function(item) { - // returns true if item contains New South Wales region - return item.context - .map(i => { - return i.id.startsWith('region') && i.text == 'New South Wales'; - }) - .reduce((acc, cur) => { - return acc || cur; - }); - } -}); - -window.geocoder = geocoder; - -var button = document.createElement('button'); -button.textContent = 'click me'; - -var removeBtn = document.body.appendChild(document.createElement('button')); -removeBtn.style.position = 'absolute'; -removeBtn.style.zIndex = 10; -removeBtn.style.top = '10px'; -removeBtn.style.left = '10px'; -removeBtn.textContent = 'Remove geocoder control'; - -map - .getContainer() - .querySelector('.mapboxgl-ctrl-bottom-left') - .appendChild(button); -map.addControl(geocoder); - -map.on('load', function() { - button.addEventListener('click', function() { - geocoder.query('Montreal Quebec'); - }); - removeBtn.addEventListener('click', function() { - map.removeControl(geocoder); - }); -}); - -geocoder.on('results', function(e) { - console.log('results: ', e.features); -}); - -geocoder.on('error', function(e) { - console.log('Error is', e.error); -}); diff --git a/debug/index.js b/debug/index.js deleted file mode 100644 index 099d3869..00000000 --- a/debug/index.js +++ /dev/null @@ -1,128 +0,0 @@ -'use strict'; -var mapboxgl = require('mapbox-gl'); -var insertCss = require('insert-css'); -var fs = require('fs'); - -mapboxgl.accessToken = window.localStorage.getItem('MapboxAccessToken'); - - -var meta = document.createElement('meta'); -meta.name = 'viewport'; -meta.content = 'initial-scale=1,maximum-scale=1,user-scalable=no'; -document.getElementsByTagName('head')[0].appendChild(meta); - -insertCss(fs.readFileSync('./lib/mapbox-gl-geocoder.css', 'utf8')); -insertCss( - fs.readFileSync('./node_modules/mapbox-gl/dist/mapbox-gl.css', 'utf8') -); - -var MapboxGeocoder = require('../'); - -var mapDiv = document.body.appendChild(document.createElement('div')); -mapDiv.style.position = 'absolute'; -mapDiv.style.top = 0; -mapDiv.style.right = 0; -mapDiv.style.left = 0; -mapDiv.style.bottom = 0; - -var map = new mapboxgl.Map({ - container: mapDiv, - style: 'mapbox://styles/mapbox/streets-v9', - center: [-79.4512, 43.6568], - zoom: 13 -}); - -var coordinatesGeocoder = function(query) { - var matches = query.match(/^[ ]*(-?\d+\.?\d*)[, ]+(-?\d+\.?\d*)[ ]*$/); - if (!matches) { - return null; - } - function coordinateFeature(lng, lat) { - lng = Number(lng); - lat = Number(lat); - return { - center: [lng, lat], - geometry: { - type: 'Point', - coordinates: [lng, lat] - }, - place_name: 'Lat: ' + lat + ', Lng: ' + lng, - place_type: ['coordinate'], - properties: {}, - type: 'Feature' - }; - } - var coord1 = matches[1]; - var coord2 = matches[2]; - var geocodes = []; - if (coord1 < -90 || coord1 > 90) { - // must be lng, lat - geocodes.push(coordinateFeature(coord1, coord2)); - } - if (coord2 < -90 || coord2 > 90) { - // must be lat, lng - geocodes.push(coordinateFeature(coord2, coord1)); - } - if (geocodes.length == 0) { - // else could be either - geocodes.push(coordinateFeature(coord1, coord2)); - geocodes.push(coordinateFeature(coord2, coord1)); - } - return geocodes; -}; - -var geocoder = new MapboxGeocoder({ - accessToken: mapboxgl.accessToken, - trackProximity: true, - localGeocoder: function(query) { - return coordinatesGeocoder(query); - }, - mapboxgl: mapboxgl -}); - -window.geocoder = geocoder; - -var button = document.createElement('button'); -button.textContent = 'click me'; - -var removeBtn = document.body.appendChild(document.createElement('button')); -removeBtn.style.position = 'absolute'; -removeBtn.style.zIndex = 10; -removeBtn.style.top = '10px'; -removeBtn.style.left = '10px'; -removeBtn.textContent = 'Remove geocoder control'; - -map - .getContainer() - .querySelector('.mapboxgl-ctrl-bottom-left') - .appendChild(button); -map.addControl(geocoder); - -map.on('load', function() { - button.addEventListener('click', function() { - geocoder.query('Montreal Quebec'); - }); - removeBtn.addEventListener('click', function() { - map.removeControl(geocoder); - }); -}); - -geocoder.on('results', function(e) { - console.log('results: ', e.features); -}); - -geocoder.on('result', function(e) { - console.log('result: ', e.result); -}); - -geocoder.on('clear', function(e) { - console.log('clear'); -}); - -geocoder.on('loading', function(e) { - console.log('loading:', e.query); -}); - -geocoder.on('error', function(e) { - console.log('Error is', e.error); -}); diff --git a/package.json b/package.json index 130d6dbe..f5079358 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,7 @@ "unpkg": "dist/mapbox-gl-geocoder.min.js", "style": "lib/mapbox-gl-geocoder.css", "scripts": { - "start": "budo lib/index.js:bundle.js --open debug --live -- -t brfs --standalone MapboxGeocoder lib/index.js", + "start": "budo lib/index.js:bundle.js --live -- -t brfs --standalone MapboxGeocoder lib/index.js", "prepublish": "NODE_ENV=production && mkdir -p dist && browserify --standalone MapboxGeocoder lib/index.js | uglifyjs -c -m > dist/mapbox-gl-geocoder.min.js && cp lib/mapbox-gl-geocoder.css dist/", "test": "browserify -t envify test/index.js test/events.test.js | smokestack -b firefox | tap-status | tap-color", "docs": "documentation build lib/index.js --format=md > API.md",