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

mapplz

v1.0.2

Published

Simple geodata and mapmaking

Downloads

24

Readme

MapPLZ-Node

Greenkeeper badge

MapPLZ is a framework to make mapping quick and easy in your favorite language.

Getting started

MapPLZ consumes many many types of geodata. It can process data for a script or dump it into a database.

Adding some data:

var MapPLZ = require('mapplz').MapPLZ;
var mapstore = new MapPLZ();


// add points
mapstore.add(40, -70);
mapstore.add([40, -70);
mapstore.add({ lat: 40, lng: -70 });

// assure items are added using callbacks
mapstore.add(40, -70, function(err, pt) {    });
mapstore.add([40, -70], function(err, pt) {    });

// add lines
mapstore.add([[40, -70], [33, -110]]);

// add polygons
mapstore.add([[[40, -70], [33, -110], [22, -90], [40, -70]]]);

// GeoJSON objects or strings
mapstore.add({ "type": "Feature", "geometry": { "type": "Point", "coordinates": [-70, 40] } });
mapstore.add('{ "type": "Feature", "geometry": { "type": "Point", "coordinates": [-70, 40] } }');

// add properties
mapstore.add({ "type": "Feature", "geometry": { "type": "Point", "coordinates": [-70, 40] }, "properties": { "color": "#0f0" }},
  function(err, pt) {
    pt.properties.color == "#0f0";
  });

mapstore.add({ lat: 40, lng: -70, color: "blue" }, function(err, pt2) {
  mapstore.add(40, -70, { color: "blue" }, function(err, pt3) {  
  });
});

// also: WKT, CSV strings, and MapPLZ code
mapstore.add('POINT(-70 40)');
mapstore.add('color,geo\nred,\'{"type":"Feature","geometry":{"type":"Point","coordinates":[-70,40]}}\'');

mapcode =  "map\n";
mapcode += "  marker\n";
mapcode += "    [40, -70]\n";
mapcode += "  plz\n";
mapcode += "plz\n";
mapstore.add(mapcode);

Each feature is returned as a MapItem, which is easy to retrieve data from.

mapstore.add(40, -70, function(err, pt) {
  mapstore.add([[40, -70], [50, 20]], { "color": "red" }), function(err, line) {
    UsePtAndLine(pt, line);
  });
});

function UsePtAndLine(pt, line) {
  pt.lat == 40
  pt.toGeoJson() == '{ "type": "Feature", "geometry": { "type": "Point", "coordinates": [-70, 40] }}'

  line.type == "line"
  line.path == [[40, -70], [50, 20]]
  line.properties.color == "red"

  pt.delete();
  line.delete(function(err){
    // line is now deleted
  });
}

Queries

You don't need a database to query data with MapPLZ, but you're able to use Postgres/PostGIS or MongoDB for faster, more accurate queries. As of version 1, this library no longer supports RethinkDB.

MapPLZ simplifies geodata management and queries:

mapstore.count("", function(err, count) {
  // count all, return integer
});
mapstore.query("", function(err, all_mapitems) {
  // query all, return [ MapItem ]
});
mapstore.near([lat, lng], 5, function(err, nearest) {
  // five nearest
  // can also send GeoJSON, { lat: Number, lng: Number }, or MapItem
});
mapstore.within([[[40, -70], [50, -80], [30, -80], [40, -70]]], function(err, within) {
  // all points within this polygon
  // can also send GeoJSON, { path: [[[]]] }, or MapItem
});

// with PostGIS
mapstore.count("color = 'blue'", function(err, count) {
  // count == 1
});
mapstore.query("color = 'blue'", function(err, blue_mapitems) {
  // blue_mapitems == [ MapItem ];
});

// with any setup other than PostGIS
mapstore.count({ color: "blue" }, function(err, count) {
  // count == 1
});
mapstore.query({ color: "blue" }, function(err, blue_mapitems) {
  // blue_mapitems == [ MapItem ];
});

Setting up PostGIS

const pg = require('pg');
const MapPLZ = require('mapplz');

var mapstore = new MapPLZ.MapPLZ();
var connString = "postgres://postgres:@localhost/travis_postgis";

var client = new pg.Client(connString);
client.connect(connString, function(err, client, done) {
  if(!err) {
    mapstore.database = new MapPLZ.PostGIS();
    mapstore.database.client = client;
  }
});

Setting up MongoDB

var MongoClient = require('mongodb').MongoClient;
var MapPLZ = require('mapplz');

var mapstore = new MapPLZ.MapPLZ();
var connString = "mongodb://localhost:27017/sample";

MongoClient.connect(connString, function(err, db) {
  db.collection('mapplz', function(err, collection) {
    mapstore.database = new MapPLZ.MongoDB();
    mapstore.database.collection = collection;
  });
});

Interactive Maps

Export as an interactive HTML/JS map

mapstore.add({lat: 40, lng: -70, label: "Popup text"}, function(err, pt) {
  // the map embed
  mapstore.embed_html(function(content){
  });

  // a whole page (including embed)
  mapstore.render_html(function(content){
  });
});

Dependencies

All are installed when you run npm install mapplz

  • coffee-script (MIT license)
  • geolib (MIT license)
  • node-postgres (BSD license)
  • node-mongodb-native (Apache license)
  • fast-csv (MIT license)

License

Free BSD License