npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-codegrid

v0.0.3

Published

React and React Native Javascript function to query country code from coordinates

Downloads

46

Readme

react-codegrid - Javascript function to query country code

react-codegrid is a simple javascript library for efficiently retrieving country code from lat-lng coordinates of a point. The data is encoded in a set of compressed utf-grid json files.

Features

  • No application server needed (other than static web serving for browser use). No dependencies on external geocoding services.

  • Compact data size - under present configuration, country code is resolved at grain level of zoom 17 tiles (several hundred meters). JSON files covering the planet take up 13M, and <1.3M after compression by gzip.

  • JS code has no external dependencies for browser use (native JSON assumed).

  • Flexibility - sub-country divisions can be incorporated by custom geojson files.

Usage

npm use

npm install react-codegrid

yarn use

yarn add react-codegrid

In Javascript:

const codegrid = require('react-codegrid');

codegrid.getCode(lat, lng, callback);

Example

const codegrid = require('react-codegrid');

codegrid.getCode(2.811371, -74.43708, (error, code) => {
  if (!error) {
    //return a country code
  }
});

Data structure

Concept -

  • Similar to UTF Grid : https://github.com/mapbox/utfgrid-spec (Note: The json files used are grouped and compressed, and do not meet the specifications)

Under the present schema -

  • At the top level, the world is coded into a 512*512 utf-grid, providing a resolution at zoom level 9 (z9) tiles.

  • When and only when there is ambiguity (2 or more countries in the same z9 tile), the next level grid (resolution at z13) is generated.

  • Similarly, a further level at zoom level 17 is generated. Tiles with ambiguity are set to the country at the center point.

  • To save space, in case one country takes up only part of a tile, and the rest of it is open sea, the entire tile is set to the country.

  • A number of tiles contain highly repetitive data (same country in a grid row, or repeating patterns). While gzip could save much of the network bandwidth during transit, tiles without compression would still take up much memory when loaded. The utf grids are therefore compressed in JSON representation, cutting down roughly 80% in size.

  • utf-grid tile data derived from Openstreetmap data with some manual fixes, separately using a set of Python scripts - http://github.com/hlaw/codegrid

License

  • Country Code Data in the tiles directory produced from Openstreetmap (http://www.openstreetmap.org). Data under Openstreetmap are available under ODbL.

  • JS code and demo: WTFPL (http://en.wikipedia.org/wiki/WTFPL)

Github page

  • http://github.com/hlaw/codegrid-js
  • https://github.com/QuinsZouls/react-codegrid

Author

  • hlaw
  • QuinsZouls