123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- import { db } from "../database/db";
- import axios from "axios";
- const headers = {
- 'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8',
- 'Nmtoken': '6B905B9C-32E1-4653-8038-FDB54A18DE3F'
- };
- export async function fetchRegion(region) {
- const apiUrl = `https://nomadmania.com/static/geojson/${region}.geojson`
- try {
- const response = await axios.get(apiUrl, {region}, {headers});
- if (response.data) {
- await db.transaction(tx => {
- tx.executeSql(
- 'INSERT INTO regions (region_id, data) VALUES (?, ?);',
- [region, JSON.stringify(response.data)],
- (res) => {},
- (error) => { console.error("Error saving GeoJSON data: ", error); }
- );
- });
- }
- } catch (error) {
- console.error('Error fetching data from API:', error);
- }
- }
- export async function getForRegion(region) {
- const apiUrl = 'https://nomadmania.com/webapi/series/get-for-region';
- try {
- const response = await axios.post(apiUrl, {region}, {headers});
- if (response.data.data) {
- const first100Markers = response.data.data.slice(0, 20);
- first100Markers.forEach(async (marker) => {
- await db.transaction(tx => {
- tx.executeSql(
- 'INSERT INTO markers (a, d, g, i, marker_id, l, m, n, new, s, sid, v) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);',
- [marker.a, marker.d, marker.g, marker.i, marker.marker_id, marker.l, marker.m, marker.n, marker.new, marker.s, marker.sid, marker.v],
- (res) => {},
- (error) => { console.error("Error saving GeoJSON data: ", error); }
- );
- });
- });
- }
- } catch (error) {
- console.error('Error fetching data from API:', error);
- }
- }
|