Skip to content

Instantly share code, notes, and snippets.

@jameyquinn
Created March 28, 2014 13:58
Show Gist options
  • Select an option

  • Save jameyquinn/9833439 to your computer and use it in GitHub Desktop.

Select an option

Save jameyquinn/9833439 to your computer and use it in GitHub Desktop.
Model:Polygon
rk.waitFor(
'Model:Base'
).then(function(ModelBase, app){
app.polygon = app.polygon || {};
var PolygonModel = app.polygon.PolygonModel = ModelBase.extend({
/**
* Location model used primarily for autofill results (but can be used
* anywhere.
*
* @class Model:Location
* @constructor
* @module rk
*/
idAttribute: 'id',
defaults: {
resourceType: 'polygons'
},
urlRoot: '/airports',
initialize: function(options){
if(!options.vertices){
throw new Error('Model:Polygon expects vertices object');
}
this.vertices = options.vertices;
},
url: function() {
var id = this.serializeCoordinates(
this.vertices,
'|',
','
);
return this.get('resourceType') + "/" + id;
},
joinNested: function(arr, char) {
return [].concat.apply([], arr).join(char);
},
serializeCoordinates: function (arr, mainChar, subChar) {
return _.map(arr, function (point) {
return String(point.lat) + subChar + String(point.lng);
}).join(mainChar);
}
});
rk.load('Model:Polygon', PolygonModel);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment