- if (m[0] == "node")
- n = Node.find(:first, :conditions => ["id = ?", m[1]])
- unless n and n.visible
- return false
- end
- if nodes[m[1]]
- return false
- else
- nodes[m[1]] = true
- end
- elsif (m[0] == "way")
- w = Way.find(:first, :conditions => ["id = ?", m[1]])
- unless w and w.visible and w.preconditions_ok?
- return false
- end
- if ways[m[1]]
- return false
- else
- ways[m[1]] = true
- end
- elsif (m[0] == "relation")
- e = Relation.find(:first, :conditions => ["id = ?", m[1]])
- unless e and e.visible and e.preconditions_ok?
- return false
- end
- if relations[m[1]]
+ # find the hash for the element type or die
+ hash = elements[m[0].to_sym] or return false
+
+ # unless its in the cache already
+ unless hash.key? m[1]
+ # use reflection to look up the appropriate class
+ model = Kernel.const_get(m[0].capitalize)
+
+ # get the element with that ID
+ element = model.find(m[1])
+
+ # and check that it is OK to use.
+ unless element and element.visible? and element.preconditions_ok?