1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- import { db } from "./database/db";
- import * as FileSystem from 'expo-file-system';
- export async function downloadTile(url, z, x, y) {
- try {
- const fileUri = FileSystem.cacheDirectory + `tiles/${z}/${x}/${y}.png`;
- if (!FileSystem.getInfoAsync(FileSystem.cacheDirectory + `tiles/${z}/${x}`).exists) {
- await FileSystem.makeDirectoryAsync(FileSystem.cacheDirectory + `tiles/${z}/${x}`, { intermediates: true });
- }
- if (FileSystem.getInfoAsync(FileSystem.cacheDirectory + `tiles/${z}/${x}/${y}.png`).exists) {
- console.log('File already exists');
- } else {
- const downloadResult = await FileSystem.downloadAsync(url, fileUri);
- if (downloadResult.status !== 200) {
- throw new Error('Failed to download the tile');
- }
- }
- } catch (error) {
- console.error("Error downloading tile:", error);
- }
- }
- export async function loadGeoJSONData(region) {
- const selectQuery = `SELECT data FROM regions WHERE region_id = ${region};`;
- return new Promise((resolve, reject) => {
- db.transaction(tx => {
- tx.executeSql(
- selectQuery,
- [],
- (_, { rows }) => {
- if (rows.length > 0) {
- resolve(JSON.parse(rows._array[0].data));
- } else {
- resolve(null);
- }
- },
- (_, error) => {
- reject(error);
- }
- );
- });
- });
- }
- export async function loadMarkersData() {
- const selectQuery = `SELECT marker_id, l, g, i, n, d FROM markers;`;
- return new Promise((resolve, reject) => {
- db.transaction(tx => {
- tx.executeSql(
- selectQuery,
- [],
- (_, { rows }) => {
- if (rows.length > 0) {
- resolve(rows._array.slice(0, 20));
- } else {
- resolve(null);
- }
- },
- (_, error) => {
- reject(error);
- }
- );
- });
- });
- }
|