Created
March 28, 2014 13:58
-
-
Save jameyquinn/9833439 to your computer and use it in GitHub Desktop.
Model:Polygon
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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