diff options
Diffstat (limited to 'src/refactor.js')
-rw-r--r-- | src/refactor.js | 43 |
1 files changed, 28 insertions, 15 deletions
diff --git a/src/refactor.js b/src/refactor.js index d4e50a7..e68d2d9 100644 --- a/src/refactor.js +++ b/src/refactor.js @@ -43,10 +43,15 @@ const dataController = (function () { geoParam = { insideBoundingBox: [bounds], }; - } else { + } else if (shape === 'polygon') { geoParam = { insidePolygon: [bounds], }; + } else { + geoParam = { + aroundLatLng: bounds, + // aroundRadius: 1000, + }; } const res = await client.searchSingleIndex({ @@ -74,14 +79,16 @@ const interfaceController = (function () { selectRect: '.select--rectangle', selectPoly: '.select--polygon', ip: '.select--ip', + ipLoader: '.ip-loader', hits: '#hits', searchBar: '#searchbar', }; - const generateMap = async function (bounds, position, maxSpace, initialPolygonBounds, currentShape) { + const generateMap = async function (bounds, position, maxSpace, initialPolygonBounds, currentShape, zoom = 12) { + console.log(bounds, position, maxSpace, initialPolygonBounds, currentShape, zoom); const { Map, Polygon, Rectangle } = await google.maps.importLibrary('maps'); map = new Map(document.getElementById('map'), { - zoom: 9, + zoom, center: position, mapId: 'pub_map', restriction: { @@ -96,7 +103,8 @@ const interfaceController = (function () { editable: true, draggable: true, }); - } else { + shape.setMap(map); + } else if (currentShape === 'polygon') { shape = new Polygon({ paths: initialPolygonBounds, strokeColor: '#FF0000', @@ -108,8 +116,8 @@ const interfaceController = (function () { draggable: true, geodesic: true, }); + shape.setMap(map); } - shape.setMap(map); }; return { @@ -198,7 +206,7 @@ const controller = (function (dataCTRL, uiCTRL) { const initialPolygonBounds = dataCTRL.initialPolygonBounds; // Polygon bound const initialSetup = async function () { - await uiCTRL.initMap(rectBounds, centralPoint, mapBounds, initialPolygonBounds, 'rectangle'); + await uiCTRL.initMap(rectBounds, centralPoint, mapBounds, initialPolygonBounds, 'rectangle', 12); const searchResults = await dataCTRL.getSearchResults('', 'rectangle', [ rectBounds.north, @@ -258,7 +266,7 @@ const controller = (function (dataCTRL, uiCTRL) { const setupShapeSelectListeners = async function () { $(DOM.selectRect).addEventListener('click', async () => { - await uiCTRL.initMap(rectBounds, centralPoint, mapBounds, initialPolygonBounds, 'rectangle'); + await uiCTRL.initMap(rectBounds, centralPoint, mapBounds, initialPolygonBounds, 'rectangle', 12); const searchResults = await dataCTRL.getSearchResults(dataCTRL.getCurrentQuery(), 'rectangle', [ rectBounds.north, rectBounds.east, @@ -271,7 +279,7 @@ const controller = (function (dataCTRL, uiCTRL) { }); $(DOM.selectPoly).addEventListener('click', async () => { - await uiCTRL.initMap(rectBounds, centralPoint, mapBounds, initialPolygonBounds, 'polygon'); + await uiCTRL.initMap(rectBounds, centralPoint, mapBounds, initialPolygonBounds, 'polygon', 12); const translatedPolyBounds = initialPolygonBounds.flatMap(({ lat, lng }) => [lat, lng]); const searchResults = await dataCTRL.getSearchResults( dataCTRL.getCurrentQuery(), @@ -284,14 +292,19 @@ const controller = (function (dataCTRL, uiCTRL) { }); $(DOM.ip).addEventListener('click', async () => { - const res = await client.searchSingleIndex({ - indexName: INDEX_NAME, - searchParams: { - aroundLatLngViaIP: true, - aroundRadius: 1000, - }, + $(DOM.ipLoader).classList.replace('hidden', 'inline-block'); + navigator.geolocation.getCurrentPosition(async (pos) => { + const position = { lat: pos.coords.latitude, lng: pos.coords.longitude }; + await uiCTRL.initMap('', position, rectBounds, '', 'ip', 10); + const searchResults = await dataCTRL.getSearchResults( + dataCTRL.getCurrentQuery(), + 'ip', + `${pos.coords.latitude}, ${pos.coords.longitude}` + ); + await uiCTRL.embedSearchResults(searchResults.hits); + uiCTRL.updateHitsList(searchResults.hits); + $(DOM.ipLoader).classList.replace('inline-block', 'hidden'); }); - console.log(res); }), $(DOM.searchBar).addEventListener('input', async (e) => { const q = dataCTRL.getCurrentQuery(); |