Skip to content

Commit

Permalink
Merge pull request #159 from Esri/basemodel-updates
Browse files Browse the repository at this point in the history
Basemodel updates for Geohash and Local cache service fixes
  • Loading branch information
ungoldman committed Apr 30, 2015
2 parents 2022fba + 1aa69f0 commit ff0c866
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 9 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@
All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](http://semver.org/).

## [2.1.5] - 2015-04-30
### Added
* method for getting geohash grids if the installed cache supports it
* saveFile method in lib/BaseModel to give providers that ability to save file centrally

### Changed
* Fixed registration of services in the lib/Local.js cache

## [2.1.4] - 2015-04-28
### Changed
* fixed an issue with export shapefiles from datasets with exactly 5k features
Expand Down Expand Up @@ -214,6 +222,7 @@ Koop is now just a node module that exposes an express middleware app with hooks
- koop-server is no more; all central code is in the koop project
- to use Koop you must use it as middleware in an app that boots up an http server

[2.1.5]: https://github.com/Esri/koop/compare/v2.1.4...v2.1.5
[2.1.4]: https://github.com/Esri/koop/compare/v2.1.3...v2.1.4
[2.1.3]: https://github.com/Esri/koop/compare/v2.1.2...v2.1.3
[2.1.2]: https://github.com/Esri/koop/compare/v2.1.1...v2.1.2
Expand Down
25 changes: 23 additions & 2 deletions lib/BaseModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,26 @@ var BaseModel = function( koop ){
}
}

return {
function getGeoHash (key, options, callback) {
if (!koop.Cache.db.geoHashAgg){
callback('The installed cache doesnt support geohash aggregation', null);
} else {
var limit = options.limit || 100000,
precision = options.precision || 8;
koop.Cache.db.geoHashAgg(key, limit, precision, options, callback);
}
}

function saveFile (path, file, data, callback) {
koop.files.write( path, file, data, function( err ){
if (err){
return callback(err);
}
return callback();
});
};

return {
log: log,
files: files,
cacheDir: cacheDir,
Expand All @@ -127,7 +146,9 @@ var BaseModel = function( koop ){
tileGet: tileGet,
generateThumbnail: generateThumbnail,
getImageServiceTile: getImageServiceTile,
getServiceTile: getServiceTile
getServiceTile: getServiceTile,
getGeoHash: getGeoHash,
saveFile: saveFile
};

};
Expand Down
22 changes: 16 additions & 6 deletions lib/Local.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,22 +50,32 @@ module.exports = {
callback(null, true);
},

serviceRegister: function( type, key, info, callback ){
this.store.services[type + ':' + info.id] = info;
serviceRegister: function( type, info, callback ){
if (!this.store.services[type]){
this.store.services[type] = {};
}
this.store.services[type][info.id] = info;
callback(null, true);
},

serviceCount:function(type, callback){
callback(null, Object.keys(this.store.services).length);
var services = this.store.services[type] || {};
callback(null, Object.keys(services).length);
},

serviceRemove: function( key, id, callback){
this.store.services[ key+':'+id ] = null;
serviceRemove: function( type, id, callback){
if (this.store.services[type] && this.store.services[type][id]){
this.store.services[type][id] = null;
}
callback(null, true);
},

serviceGet: function( type, id, callback){
callback(null, this.store.services[type+':'+id] || {});
if (!id){
callback(null, this.store.services[type] || {});
} else {
callback(null, this.store.services[type][id]);
}
},

remove: function( key, callback){
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "koop",
"version": "2.1.4",
"version": "2.1.5",
"description": "A node module/express middleware for converting GeoJSON to Esri Feature Services.",
"main": "index.js",
"scripts": {
Expand Down

0 comments on commit ff0c866

Please sign in to comment.