Skip to content

sprabowo/s2-helper-wasm

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 

Repository files navigation

S2 helper wasm

simple s2 helper run on browser through wasm to do such s2 cell id calculation given latitude, longitude, level and reverse s2 cell id to coordinates

Modules (vite preferred)

Instal

npm install s2-helper-wasm

Usage

import init, { calculate } from 's2-helper-wasm'

init().then(() => {
  const cellID = calculate(-6.228968465405475, 106.8071658857885, 13) 
  console.log(cellID) // "3344469575738589184"
})

Non modules

Build

wasm-pack build --target no-modules
# copy pkg/s2_helper_wasm.js, pkg/s2_helper_wasm_bg.wasm to public folder
cp pkg/s2_helper_wasm.js public
cp pkg/s2_helper_wasm_bg.wasm public

Usage

<!-- index.html -->
<script src="/s2_helper_wasm.js"></script>
<script>
  const { calculate } = wasm_bindgen

  async function init() {
    await wasm_bindgen()
    const cellID = calculate(-6.228968465405475, 106.8071658857885, 13)
    console.log(cellID) // "3344469575738589184"
  }

  init()
</script>