export const convertWKTPointToLatLng = (wktString: string) => { if ( !wktString || typeof wktString !== 'string' || !wktString.startsWith('POINT') ) { return null; } const matched = wktString.match(/POINT\s*\(([-\d.]+)\s+([-\d.]+)\)/); if (!matched) return null; const lng = parseFloat(matched[1]); const lat = parseFloat(matched[2]); return [lng, lat]; // [longitude, latitude] }; export const convertWKTLineStringToLatLngArray = (wktString: string) => { if ( !wktString || typeof wktString !== 'string' || !wktString.startsWith('LINESTRING') ) { return []; } const matched = wktString.match(/LINESTRING\s*\((.*)\)/); if (!matched) return []; const coordinates = matched[1].split(',').map((coordStr) => { const [x, y] = coordStr.trim().split(' ').map(Number); return [x, y]; // [lng, lat] }); return coordinates; }; export const convertWKTtoLatLngString = (wktString: string) => { if ( !wktString || typeof wktString !== 'string' || !wktString.startsWith('MULTIPOLYGON') ) { return []; } const matched = wktString.match(/MULTIPOLYGON\s*\(\(\((.*)\)\)\)/); if (!matched) return []; const polygons = matched[1] .split(')),((') // chia các polygon .map((polygonStr) => polygonStr .trim() .split(',') .map((coordStr) => { const [x, y] = coordStr.trim().split(' ').map(Number); return [x, y]; }), ); return polygons; }; export const getBanzoneNameByType = (type: number) => { switch (type) { case 1: return 'Cấm đánh bắt'; case 2: return 'Cấm di chuyển'; case 3: return 'Vùng an toàn'; default: return 'Chưa có'; } };