Giter VIP home page Giter VIP logo

bbox's Introduction

bbox.js

A minimal geo-bounding-box helper class implemented in pure Javascript. It comes with minimal tests and one major and two minor features:

  • Create custom format output string
  • Interpolate all 4 box corners
  • Validate absolute coordinates

Tests can be run using node: node bbox.test.js. Missing features:

  • Validate coordinates relative to each other ("is bottomRight corner really the bottom?")

Usage

The major motivation of bbox is to easily generate any type of string representation, specifying:

  • the corners and order of corners printed: corners: ['bottomLeft', 'bottomRight']
  • the coordinates and order of coordinates printed: coords: ['lat', 'lng']
  • the separators for corners and coordinates: cornerSeparator: '; ', coordSeparator: ', '
Bbox = require('./bbox.js');

const corners = {
  bottomLeft: {
    lng: 5.98865807458,
    lat: 47.3024876979,
  },
  topRight: {
    lng: 15.0169958839,
    lat: 54.983104153,
  },
};
const bbox = new Bbox(corners);
// bbox now has: bbox.bottomLeft && bbox.topRight && bbox.bottomRight && bbox.topLeft

let res = bbox.createBboxString({ corners: ['bottomLeft', 'bottomRight'] });
// res is '5.98865807458,47.3024876979;15.0169958839,47.3024876979'

res = bbox.createBboxString({ corners: ['bottomLeft', 'bottomRight','topLeft', 'topRight'] });
// res is '5.98865807458,47.3024876979;15.0169958839,47.3024876979;5.98865807458,54.983104153;15.0169958839,54.983104153'

res = bbox.createBboxString({ corners: ['bottomLeft', 'bottomRight'], coords: ['lng'] });
// res is '5.98865807458;15.0169958839'

res = bbox.createBboxString({ corners: ['bottomLeft', 'bottomRight'], coords: ['lat'] });
// res is '47.3024876979;47.3024876979'

res = bbox.createBboxString({ corners: ['bottomLeft', 'bottomRight'], coords: ['lat', 'lng'] });
// res is '47.3024876979,5.98865807458;47.3024876979,15.0169958839'

res = bbox.createBboxString({
  corners: ['bottomLeft', 'bottomRight'],
  cornerSeparator: ' | ',
  coordSeparator: ' , '
});
// res is '5.98865807458 , 47.3024876979 | 15.0169958839 , 47.3024876979'

bbox's People

Contributors

balint42 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.