// If the history has been loaded and a timestamp is known
if (history != null && date != null) {
// Lookup for the primitive version at the specified timestamp
HistoryOsmPrimitive hp = history.getByDate(date);
if (hp != null) {
PrimitiveData data = null;
switch (p.getType()) {
case NODE:
data = new NodeData();
((NodeData)data).setCoor(((HistoryNode)hp).getCoords());
break;
case WAY:
data = new WayData();
List<Long> nodeIds = ((HistoryWay)hp).getNodes();
((WayData)data).setNodes(nodeIds);
// Find incomplete nodes to load at next run
for (Long nodeId : nodeIds) {
if (p.getDataSet().getPrimitiveById(nodeId, OsmPrimitiveType.NODE) == null) {
Node n = new Node(nodeId);
p.getDataSet().addPrimitive(n);
toLoadNext.put(n, date);
}
}
break;
case RELATION:
data = new RelationData();
List<RelationMemberData> members = ((HistoryRelation)hp).getMembers();
((RelationData)data).setMembers(members);
break;
default: throw new AssertionError("Unknown primitive type");
}
data.setUser(hp.getUser());
try {
data.setVisible(hp.isVisible());
} catch (IllegalStateException e) {
Main.error("Cannot change visibility for "+p+": "+e.getMessage());
}
data.setTimestamp(hp.getTimestamp());
data.setKeys(hp.getTags());
data.setOsmId(hp.getId(), (int) hp.getVersion());
// Load the history data
try {
p.load(data);
// Forget this primitive