YDF(YOLP Data Format)は、YOLP(Yahoo! Open Local Platform)の標準データフォーマットです。
地図を表示するAPIと、拠点データを出力するWeb APIとの間の入出力をスムーズにするため、シンプルなデータ構造に統一します。

Yahoo!デベロッパーネットワーク - 地図 - YDF

こんな感じのメソッドを作ってみてYDFを生成。


#!/usr/bin/env ruby
$KCODE='u'
 
require "rexml/document"
 
def create_ydf(id, name, description, coordinates)
 
  out = REXML::Document.new()
  out.add(REXML::XMLDecl.new(version="1.0", encoding="UTF-8"))
 
  out_ydf = REXML::Element.new("YDF")
  out_ydf.add_attributes({
    "firstResultPosition" => "1",
    "totalResultsAvailable" => "1",
    "totalResultsReturned" => "1",
    "xmlns" => "http://olp.yahooapis.jp/ydf/1.0"
  })
  out.add_element(out_ydf)
 
  out_feature = REXML::Element.new("Feature", out_ydf)
 
  REXML::Element.new("Id", out_feature).add_text(id)
  REXML::Element.new("Name", out_feature).add_text(name)
  REXML::Element.new("Description", out_feature).add_text(description)
 
  out_geometry = REXML::Element.new("Geometry", out_feature)
  REXML::Element.new("Type", out_geometry).add_text("linestring")
  REXML::Element.new("Coordinates", out_geometry).add_text(coordinates)
 
  out_style = REXML::Element.new("Style", out_feature)
  REXML::Element.new("Type", out_style).add_text("line")
  REXML::Element.new("Size", out_style).add_text("3")
  REXML::Element.new("Opacity", out_style).add_text("50")
  REXML::Element.new("Color", out_style).add_text("0000ff")
  REXML::Element.new("EndLine", out_style).add_text("arrow")
  REXML::Element.new("StartLine", out_style).add_text("arrow")
 
  str = ""
  out.write(str, -1, false, true)
  
  str
end

やすらぎ居酒屋 月天 - ルートラボ - LatLongLab のルートデータを試しにYDFにしてみた。
routelab_HgT5K.ydf

Yahoo!デベロッパーネットワーク - 地図 - スタティックマップのAPIでYDFファイルを読み込ませて地図の画像を作ってみる。
http://map.olp.yahooapis.jp/OpenLocalPlatform/V1/static?appid=nilabinfo&width=500&height=500&output=png&url=http%3A%2F%2Fwww.nilab.info%2Flab%2F0%2Froutelab_HgT5K.ydf

tags: Ruby YahooJapanMapsAPI zurazure

Posted by NI-Lab. (@nilab)