GEDCOM
The FamilyTree2.convertGedcomToFamilyMembers() method allows you to import GEDCOM file data directly into Family Tree JS 2 and display it as a family tree.
javascript
FamilyTree2.convertGedcomToFamilyMembers(text, fieldBinding)textis the raw GEDCOM file content as a string.fieldBindingis an object that maps GEDCOM tag names to your family tree node property names.
javascript
{
NAME: 'name',
BIRT_DATE: 'dateOfBirth'
}NAME maps the GEDCOM NAME tag to the node name property.
BIRT_DATE maps the GEDCOM 1 BIRT 2 DATE tag to the node dateOfBirth property.
Load GEDCOM Data
Here is an example workflow for loading GEDCOM data:
- Open a GEDCOM file with the File System Access API.
- Convert the file content into family members.
- Load the converted data into the tree.
1. Open a GEDCOM File
Use showOpenFilePicker() to let the user choose a .ged file, then read the file as text.
2. Convert GEDCOM to Family Members
javascript
let familyMembers = FamilyTree2.convertGedcomToFamilyMembers(text, fieldBinding);3. Load into the Family Tree
javascript
familyTree.addFamilyMembers(familyMembers).draw(familyMembers[0].id);Full Code Example
Load GEDCOM Data in Family Tree JS 2
This example demonstrates:
- Opening a
.gedfile. - Mapping GEDCOM fields with
fieldBinding. - Converting the data with
convertGedcomToFamilyMembers(). - Displaying the converted data in a family tree.