33 lines
1.2 KiB
JavaScript
33 lines
1.2 KiB
JavaScript
'use strict';
|
|
|
|
const mongoose = require('mongoose'),
|
|
Schema = mongoose.Schema,
|
|
UserTypes = require('../helpers/constants').UserTypes;
|
|
|
|
const schema = new Schema({
|
|
properties: {
|
|
name: { type: String },
|
|
type: { type: Number, default: 0 },
|
|
color: { type: String },
|
|
area: { type: Number, default: 0 },
|
|
crop: { type: Schema.Types.ObjectId, ref: 'Crop', required: false },
|
|
radius: { type: Number, required: false }, // in meters, store the original radius of the pivot area
|
|
},
|
|
geometry: {
|
|
type: {
|
|
type: String,
|
|
required: true,
|
|
enum: ['Polygon'],
|
|
default: 'Polygon'
|
|
},
|
|
coordinates: { type: [[[Number]]], required: true }
|
|
},
|
|
client: { type: Schema.Types.ObjectId, ref: UserTypes.CLIENT, index: true, required: true }, // The client's Id
|
|
});
|
|
|
|
// NOTE: Enabling 2dsphere indexed for the benefits of powerfull geo queries for these types of data will REQUIRE standardized polygon (CCW for boundaries, CW for holes or xcls) compliant to GeoJSON.
|
|
// and also no connected multi-polygons. These are required to ensure the data is valid for the 2dsphere index. LATER.
|
|
schema.index({ geometry: '2dsphere' });
|
|
|
|
module.exports = mongoose.model('Area', schema);
|