# turns a spherical mercator coord into a tile coord
def self.tile_from_merc(point, zoom)
# turns a spherical mercator coord into a tile coord
def self.tile_from_merc(point, zoom)
# we put all the nodes into the hash, as it doesn't matter whether the node was
# added, deleted or modified - the tile will need updating anyway.
# we put all the nodes into the hash, as it doesn't matter whether the node was
# added, deleted or modified - the tile will need updating anyway.
- doc.find('//node').each do |node|
- lat = node['lat'].to_f
- if lat < -85
- lat = -85
- end
- if lat > 85
- lat = 85
- end
- point = Proj4::Point.new(Math::PI * node['lon'].to_f / 180,
+ doc.find("//node").each do |node|
+ lat = node["lat"].to_f
+ lat = -85 if lat < -85
+ lat = 85 if lat > 85
+ point = Proj4::Point.new(Math::PI * node["lon"].to_f / 180,
# itself deleted and the coverage of the point set isn't enough to encompass the
# change.
node_cache = NodeCache.new(NODE_CACHE_FILE)
# itself deleted and the coverage of the point set isn't enough to encompass the
# change.
node_cache = NodeCache.new(NODE_CACHE_FILE)
next if nodes.include? node_id
# this is a node referenced but not added, modified or deleted, so it should
# still be in the node cache.
next if nodes.include? node_id
# this is a node referenced but not added, modified or deleted, so it should
# still be in the node cache.
point = Proj4::Point.new(entry.lon, entry.lat)
nodes[node_id] = tile_from_merc(point, max_zoom)
end
end
point = Proj4::Point.new(entry.lon, entry.lat)
nodes[node_id] = tile_from_merc(point, max_zoom)
end
end
# create a set of all the tiles at the maximum zoom level which are touched by
# any of the nodes we've collected. we'll create the tiles at other zoom levels
# create a set of all the tiles at the maximum zoom level which are touched by
# any of the nodes we've collected. we'll create the tiles at other zoom levels
- @cache = Mmap.new(filename)
+ @cache = File.new(filename, "r")
+
+ throw "Unexpected format" unless @cache.sysread(4).unpack("l").first == 1
+ throw "Unexpected ID size" unless @cache.sysread(4).unpack("l").first == 8
- if lon != -2147483648 && lat != -2147483648
- node = Node.new(lon, lat)
- end
+ lon, lat = @cache.sysread(8).unpack("ll")
+
+ node = Node.new(lon, lat) if lon != -2147483648 && lat != -2147483648