This NodeJS+MongoDB application demonstrates how to create simple RESTful JSON-based API that operates with GeoSpatial data.
It shows implementation approaches to basic CRUD operations and demonstrates methods of getting and grouping (clusterization)
of large amount of GeoSpatial data on server side. Data is provided in GeoJSON format.
As a frontend part it uses highly efficient RemoteObjectManager module from Yandex.Maps API.
-
Fork your own copy of this git repository and clone it.
-
Install NodeJS, npm and MongoDB
-
Install all dependencies
npm install
-
Write your config overrides in config/local.json
-
Run server.js
node server.js
- Run tests
mocha test
Use Feature model to upload geospatial data to MongoDB on server side.
Test helper saveFeatures method shows an example how to do it.
var helper = require('./test/helper');
// Upload 1 million Features to MongoDB
helper.saveFeatures(1000000)
.then(function (res) {
console.log(res);
}, function (err) {
console.log(err);
}, function (stat) {
console.log(stat);
});
API operates with GeoSpatial data using GeoJSON format
Use POST type of request and send GeoJSON Feature object Currently only "Point" type of geometry supported and long-lat coordinates order Provide special "properties" data fields as "balloonContent", "hintContent", "iconContent". You are able to use own Feature identificator "id" or it will be assigned by Server.
POST /api/v1/features
{
"id": "1",
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [ 37.5, 55.7 ]
},
"properties": {
"balloonContent": "The quick brown fox jumps over the lazy dog",
"hintContent": "The quick brown fox jumps over the lazy dog"
}
}
Server will reply with 201 status and return stored Feature data.
Use PUT type of request to update existed Feature data using featureId on the end of request URL Send the fields you want to update.
PUT /api/v1/features/1
{
"properties": {
"balloonContent": "New content of Placemark Balloon"
}
}
Server will reply with 204 status.
Use DELETE type of request to remove existed Feature using featureId on the end of request URL
DELETE /api/v1/features/1
Server will reply with 204 status.
Use GET type of request to get existed Feature data using featureId on the end of request URL
GET /api/v1/features/1
Server will reply with 204 status and return Feature data.
Use GET type of request to search Features using URL path according to type of search. Provide additional arguments from GeoJSON Feature schema to filter only necessary Features.
For getting Features within certain tile numbers provide bbox argument describes requested tiles area, zoom, and necessity in clusterization. GET /api/v1/features/within/tiles?bbox=0,0,2,2?clusterize=1&zoom=5
Server will reply with 200 status and return found Features as FeatureColection