isoxml
Version:
JavaScript library to parse and generate ISOXML (ISO11783-10) files
91 lines (90 loc) • 2.32 kB
JavaScript
import { TAGS } from './constants';
import { registerEntityClass } from '../classRegistry';
import { fromXML, toXML } from '../utils';
const ATTRIBUTES = {
A: {
name: 'PartfieldId',
type: 'xs:ID',
isPrimaryId: true,
isOptional: false,
isOnlyV4: false,
},
B: {
name: 'PartfieldCode',
type: 'xs:string',
isPrimaryId: false,
isOptional: true,
isOnlyV4: false,
},
C: {
name: 'PartfieldDesignator',
type: 'xs:string',
isPrimaryId: false,
isOptional: false,
isOnlyV4: false,
},
D: {
name: 'PartfieldArea',
type: 'xs:unsignedLong',
isPrimaryId: false,
isOptional: false,
isOnlyV4: false,
minValue: 0,
maxValue: 4294967294,
},
E: {
name: 'CustomerIdRef',
type: 'xs:IDREF',
isPrimaryId: false,
isOptional: true,
isOnlyV4: false,
},
F: {
name: 'FarmIdRef',
type: 'xs:IDREF',
isPrimaryId: false,
isOptional: true,
isOnlyV4: false,
},
G: {
name: 'CropTypeIdRef',
type: 'xs:IDREF',
isPrimaryId: false,
isOptional: true,
isOnlyV4: false,
},
H: {
name: 'CropVarietyIdRef',
type: 'xs:IDREF',
isPrimaryId: false,
isOptional: true,
isOnlyV4: false,
},
I: {
name: 'FieldIdRef',
type: 'xs:IDREF',
isPrimaryId: false,
isOptional: true,
isOnlyV4: false,
},
};
const CHILD_TAGS = {
PLN: { name: 'PolygonnonTreatmentZoneonly', isOnlyV4: false },
LSG: { name: 'LineString', isOnlyV4: false },
PNT: { name: 'Point', isOnlyV4: false },
GGP: { name: 'GuidanceGroup', isOnlyV4: true },
};
export class Partfield {
constructor(attributes, isoxmlManager) {
this.attributes = attributes;
this.isoxmlManager = isoxmlManager;
this.tag = TAGS.Partfield;
}
static fromXML(xml, isoxmlManager, internalId, targetClass = Partfield) {
return fromXML(xml, isoxmlManager, targetClass, ATTRIBUTES, CHILD_TAGS, internalId);
}
toXML() {
return toXML(this, ATTRIBUTES, CHILD_TAGS);
}
}
registerEntityClass('main', TAGS.Partfield, Partfield);