view fujix/check.rb @ 2944:b1cb17ea7605

merge
author ARAKI Tsuyohito <c113007@e.koeki-u.ac.jp>
date Tue, 08 Dec 2015 19:36:05 +0900
parents 2cf2d4e4604e
children
line wrap: on
line source

#!/usr/bin/env ruby
#coding:utf-8

print"Content-type: text/html charset=UTF-8\n\n"

require'sqlite3'
require'cgi'
c = CGI.new(:accept_charaset => "UTF-8")
db = SQLite3::Database.new("sql/test.sq3")
db.results_as_hash = true

data = Hash.new

begin
  db.execute("select * from main");
rescue
  db.execute("create table main(id INTEGER PRIMARY KEY AUTOINCREMENT,name,lon,lat)");
  db.execute("insert into main(name,lon,lat) values('#{name}','#{lon}','#{lat}')");
end

db.execute("select * from main") do |load|
  data[load['id']] = [load['name'],load['lon'],load['lat'],load['sta']]
end

lon = 38.89420
lat = 139.8187
redirect = "check.rb"
image = ["","face","angry","sad"]

if ARGV[1] != nil
  lon = ARGV[0].to_f
  lat = ARGV[1].to_f
  redirect += "?" + lon.to_s + "+" + lat.to_s
end

printf(<<_EOS_,redirect,lon.to_f,lat.to_f)
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="leaflet/leaflet.css"/>
<script src="leaflet/leaflet.js"></script>
<style>
 html,body,#map{
    height: 100%
 }
 body{
    padding: 0;
    margin: 0;
 }
</style>
<title>閲覧用ページ</title>
<!-- <meta http-equiv="refresh" content="20;%s"> -->
</head>
<body>
<div id="map"></div>
<script type="text/javascript">
  var hmap = L.map('map',{
     center: [%f,%f],
     zoom: 16 //1~18
  });
  L.tileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',{
    attribution: '&copy; OpenStreetMap contributors'
  }).addTo(hmap);
_EOS_
  
  for id in data.keys
    if data[id][1] == "LON"
      next
    else
      num = data[id][3]
      printf(<<_EOS_,data[id][1].to_f,data[id][2].to_f,image[num],data[id][0])
  L.marker([%f,%f],{
           clickable:true,
           draggable:true,
           icon:L.icon({
                         iconUrl: 'leaflet/images/%s.png',
                         iconAnchor: [0,0],
                         popupAnchor: [10,5]
                       })
  })
  .bindPopup('%s')
  .addTo(hmap);
_EOS_
    end
  end
  
  print"
</script>
</body>
</html>\n"

yatex.org