OpenStreetMap がデフォルトの「今ココなう!Proxy」のインストール #osmjp

Debian

バイクでどこかに行く時に、よく 今ここなう! で現在位置をツイートさせていただいている。

今ここなう!の地図として、OpenStreetMap が使える ことを知ったので、早速自前で Proxy をインストールしてみることにした。

まずは、 README.txt に従って標準状態でのインストールを進める

事前に準備すること

1. PHPが5.2以降であることを確認してください。

PHP のバージョンを確認する
yasunari@tswxl:~$ dpkg -l | grep -i php
yasunari@tswxl:~$
インストールされてない。
インストールする
yasunari@tswxl:~$ su - root
Password:
tswxl:~# apt-get install php5
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages were automatically installed and are no longer required:
  libshadow-ruby1.8 irb1.8 libnet-ssleay-perl rdoc libruby ruby1.8 ruby facter
  rdoc1.8 host libruby1.8 libopenssl-ruby1.8 libreadline-ruby1.8
  libopenssl-ruby libxmlrpc-ruby libnet-libidn-perl
Use 'apt-get autoremove' to remove them.
The following extra packages will be installed:
  apache2-mpm-prefork apache2.2-common libapache2-mod-php5 libxml2 php5-common
  sgml-base ucf xml-core
Suggested packages:
  www-browser apache2-doc apache2-suexec apache2-suexec-custom php-pear
  sgml-base-doc
The following packages will be REMOVED:
  apache2-mpm-worker
The following NEW packages will be installed:
  apache2-mpm-prefork libapache2-mod-php5 libxml2 php5 php5-common sgml-base
  ucf xml-core
The following packages will be upgraded:
  apache2.2-common
1 upgraded, 8 newly installed, 1 to remove and 10 not upgraded.
Need to get 4740kB of archives.
After this operation, 8311kB of additional disk space will be used.
Do you want to continue [Y/n]? y
Get:1 http://ftp.jp.debian.org lenny/main libxml2 2.6.32.dfsg-5+lenny4 [792kB]
Get:2 http://ftp.jp.debian.org lenny/main ucf 3.0016 [64.4kB]
Get:3 http://ftp.jp.debian.org lenny/main apache2.2-common 2.2.9-10+lenny11 [803kB]
Get:4 http://ftp.jp.debian.org lenny/main apache2-mpm-prefork 2.2.9-10+lenny11 [224kB]
Get:5 http://ftp.jp.debian.org lenny/main php5-common 5.2.6.dfsg.1-1+lenny13 [370kB]
Get:6 http://ftp.jp.debian.org lenny/main libapache2-mod-php5 5.2.6.dfsg.1-1+lenny13 [2452kB]
Get:7 http://ftp.jp.debian.org lenny/main php5 5.2.6.dfsg.1-1+lenny13 [1084B]
Get:8 http://ftp.jp.debian.org lenny/main sgml-base 1.26 [11.7kB]
Get:9 http://ftp.jp.debian.org lenny/main xml-core 0.12 [23.1kB]
Fetched 4740kB in 38s (123kB/s)
Preconfiguring packages ...
dpkg: apache2-mpm-worker: dependency problems, but removing anyway as you request:
 apache2 depends on apache2-mpm-worker (>= 2.2.9-10+lenny9) | apache2-mpm-prefork (>= 2.2.9-10+lenny9) | apache2-mpm-event (>= 2.2.9-10+lenny9); however:
  Package apache2-mpm-worker is to be removed.
  Package apache2-mpm-prefork is not installed.
  Package apache2-mpm-event is not installed.
(Reading database ... 21669 files and directories currently installed.)
Removing apache2-mpm-worker ...
Stopping web server: apache2 ... waiting .
Selecting previously deselected package libxml2.
(Reading database ... 21660 files and directories currently installed.)
Unpacking libxml2 (from .../libxml2_2.6.32.dfsg-5+lenny4_armel.deb) ...
Selecting previously deselected package ucf.
Unpacking ucf (from .../archives/ucf_3.0016_all.deb) ...
Moving old data out of the way
Preparing to replace apache2.2-common 2.2.9-10+lenny9 (using .../apache2.2-common_2.2.9-10+lenny11_armel.deb) ...
Unpacking replacement apache2.2-common ...
Selecting previously deselected package apache2-mpm-prefork.
Unpacking apache2-mpm-prefork (from .../apache2-mpm-prefork_2.2.9-10+lenny11_armel.deb) ...
Selecting previously deselected package php5-common.
Unpacking php5-common (from .../php5-common_5.2.6.dfsg.1-1+lenny13_armel.deb) ...
Selecting previously deselected package libapache2-mod-php5.
Unpacking libapache2-mod-php5 (from .../libapache2-mod-php5_5.2.6.dfsg.1-1+lenny13_armel.deb) ...
Selecting previously deselected package php5.
Unpacking php5 (from .../php5_5.2.6.dfsg.1-1+lenny13_all.deb) ...
Selecting previously deselected package sgml-base.
Unpacking sgml-base (from .../sgml-base_1.26_all.deb) ...
Selecting previously deselected package xml-core.
Unpacking xml-core (from .../archives/xml-core_0.12_all.deb) ...
Processing triggers for man-db ...
Setting up libxml2 (2.6.32.dfsg-5+lenny4) ...
Setting up ucf (3.0016) ...
Setting up apache2.2-common (2.2.9-10+lenny11) ...
Setting up apache2-mpm-prefork (2.2.9-10+lenny11) ...
Starting web server: apache2.
Setting up php5-common (5.2.6.dfsg.1-1+lenny13) ...
Setting up libapache2-mod-php5 (5.2.6.dfsg.1-1+lenny13) ...

Creating config file /etc/php5/apache2/php.ini with new version
Reloading web server config: apache2.
Setting up php5 (5.2.6.dfsg.1-1+lenny13) ...
Setting up sgml-base (1.26) ...
Setting up xml-core (0.12) ...
!tswxl:~#

2. cURLが使用可能であることを確認してください

tswxl:~# apt-get install php5-curl
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages were automatically installed and are no longer required:
  libshadow-ruby1.8 irb1.8 libnet-ssleay-perl rdoc libruby ruby1.8 ruby facter
  rdoc1.8 host libruby1.8 libopenssl-ruby1.8 libreadline-ruby1.8
  libopenssl-ruby libxmlrpc-ruby libnet-libidn-perl
Use 'apt-get autoremove' to remove them.
The following extra packages will be installed:
  ca-certificates libcurl3 libssh2-1
The following NEW packages will be installed:
  ca-certificates libcurl3 libssh2-1 php5-curl
0 upgraded, 4 newly installed, 0 to remove and 10 not upgraded.
Need to get 464kB of archives.
After this operation, 1507kB of additional disk space will be used.
Do you want to continue [Y/n]? y
Get:1 http://ftp.jp.debian.org lenny/main ca-certificates 20080809 [151kB]
Get:2 http://security.debian.org lenny/updates/main libcurl3 7.18.2-8lenny5 [225kB]
Get:3 http://ftp.jp.debian.org lenny/main libssh2-1 0.18-1 [63.7kB]
Get:4 http://ftp.jp.debian.org lenny/main php5-curl 5.2.6.dfsg.1-1+lenny13 [24.4kB]
Fetched 464kB in 4s (104kB/s)
Preconfiguring packages ...
Selecting previously deselected package ca-certificates.
(Reading database ... 21801 files and directories currently installed.)
Unpacking ca-certificates (from .../ca-certificates_20080809_all.deb) ...
Selecting previously deselected package libssh2-1.
Unpacking libssh2-1 (from .../libssh2-1_0.18-1_armel.deb) ...
Selecting previously deselected package libcurl3.
Unpacking libcurl3 (from .../libcurl3_7.18.2-8lenny5_armel.deb) ...
Selecting previously deselected package php5-curl.
Unpacking php5-curl (from .../php5-curl_5.2.6.dfsg.1-1+lenny13_armel.deb) ...
Processing triggers for man-db ...
Setting up ca-certificates (20080809) ...
Updating certificates in /etc/ssl/certs....done.
Running hooks in /etc/ca-certificates/update.d....done.
Setting up libssh2-1 (0.18-1) ...
Setting up libcurl3 (7.18.2-8lenny5) ...
Setting up php5-curl (5.2.6.dfsg.1-1+lenny13) ...
!tswxl:~#

3.Cache_Liteが使用可能であることを確認してください

tswxl:~# pear install Cache_Lite
-su: pear: command not found
tswxl:~# apt-cache search pear
	:
	:
tswxl:~# apt-cache search pear | grep pear
egroupware-egw-pear - modified PEAR modules for eGroupWare
gnome-color-chooser - GTK+/GNOME desktop appearance customization tool
lxappearance - a new feature-rich GTK+ theme switcher
php-xml-util - a XML utility for php-pear
php-pear - PEAR - PHP Extension and Application Repository
pysycache-dblclick-appleandpear - Apple and pear images for double click activities for PySyCache
tswxl:~#
先に php-pear をインストールする
tswxl:~# apt-get install php-pear
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages were automatically installed and are no longer required:
  libshadow-ruby1.8 irb1.8 libnet-ssleay-perl rdoc libruby ruby1.8 ruby facter
  rdoc1.8 host libruby1.8 libopenssl-ruby1.8 libreadline-ruby1.8
  libopenssl-ruby libxmlrpc-ruby libnet-libidn-perl
Use 'apt-get autoremove' to remove them.
The following extra packages will be installed:
  php5-cli
Suggested packages:
  php5-dev php4-dev
The following NEW packages will be installed:
  php-pear php5-cli
0 upgraded, 2 newly installed, 0 to remove and 10 not upgraded.
Need to get 2779kB of archives.
After this operation, 7475kB of additional disk space will be used.
Do you want to continue [Y/n]? y
Get:1 http://ftp.jp.debian.org lenny/main php5-cli 5.2.6.dfsg.1-1+lenny13 [2444kB]
Get:2 http://ftp.jp.debian.org lenny/main php-pear 5.2.6.dfsg.1-1+lenny13 [335kB]
Fetched 2779kB in 22s (125kB/s)
Selecting previously deselected package php5-cli.
(Reading database ... 21989 files and directories currently installed.)
Unpacking php5-cli (from .../php5-cli_5.2.6.dfsg.1-1+lenny13_armel.deb) ...
Selecting previously deselected package php-pear.
Unpacking php-pear (from .../php-pear_5.2.6.dfsg.1-1+lenny13_all.deb) ...
Processing triggers for man-db ...
Setting up php5-cli (5.2.6.dfsg.1-1+lenny13) ...

Creating config file /etc/php5/cli/php.ini with new version
Setting up php-pear (5.2.6.dfsg.1-1+lenny13) ...
!tswxl:~#
これで、pear が使えるようになったか??
tswxl:~# pear install Cache_Lite
WARNING: channel "pear.php.net" has updated its protocols, use "channel-update pear.php.net" to update
downloading Cache_Lite-1.7.12.tgz ...
Starting to download Cache_Lite-1.7.12.tgz (30,469 bytes)
.....done: 30,469 bytes
install ok: channel://pear.php.net/Cache_Lite-1.7.12
tswxl:~#

4./tmpがapahceの実行ユーザーで書き込み可能であることを確認してください

tswxl:~# ls -ld /tmp
drwxrwxrwt 6 root root 4096 Oct 30 03:22 /tmp
tswxl:~#
問題なし

apache の再起動

README.txt にはないが、念のため再起動
tswxl:~# /etc/init.d/apache2 restart
Restarting web server: apache2 ... waiting .
tswxl:~#

5. GoogleMaps API キーを取得してください。

今回は、OpenStreetMap を使うので、要らないはず

配置

proxy-1.5.zip のダウンロード

yasunari@tswxl:~$ cd /tmp
yasunari@tswxl:/tmp$ wget http://www.fujita-lab.com/imakoko/proxy-1.5.zip
--2011-10-30 03:32:58--  http://www.fujita-lab.com/imakoko/proxy-1.5.zip
Resolving www.fujita-lab.com... 49.212.16.214
Connecting to www.fujita-lab.com|49.212.16.214|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 860212 (840K) [application/zip]
Saving to: `proxy-1.5.zip'

100%[======================================>] 860,212      143K/s   in 5.9s

2011-10-30 03:33:04 (143 KB/s) - `proxy-1.5.zip' saved [860212/860212]

yasunari@tswxl:/tmp$ unzip -l proxy-1.5.zip
Archive:  proxy-1.5.zip
  Length     Date   Time    Name
 --------    ----   ----    ----
        0  11-22-09 16:19   proxy/
        0  11-22-09 16:19   proxy/api/
	:
	:
     1494  07-05-09 02:23   proxy/view.html
     7096  11-22-09 16:20   README.txt
 --------                   -------
   845160                   389 files
yasunari@tswxl:/tmp$

proxy-1.5.zip の展開

yasunari@tswxl:/home/httpd/html$ mkdir imakoko
yasunari@tswxl:/home/httpd/html$ cd !$
cd imakoko
yasunari@tswxl:/home/httpd/html/imakoko$ unzip /tmp/proxy-1.5.zip
Archive:  /tmp/proxy-1.5.zip
   creating: proxy/
   creating: proxy/api/
	:
	:
  inflating: proxy/view.html
  inflating: README.txt
yasunari@tswxl:/home/httpd/html/imakoko$ ls
README.txt  proxy
yasunari@tswxl:/home/httpd/html/imakoko$

ファイルの修正

1. proxy/static/script.jsの修正

yasunari@tswxl:/home/httpd/html/imakoko$ cd proxy/static/
yasunari@tswxl:/home/httpd/html/imakoko/proxy/static$ mv script.js{,.orig}
yasunari@tswxl:/home/httpd/html/imakoko/proxy/static$ cp script.js{.orig,}
yasunari@tswxl:/home/httpd/html/imakoko/proxy/static$ vi script.js
	:
	:
yasunari@tswxl:/home/httpd/html/imakoko/proxy/static$ !cp:s/cp/diff -u/
diff -u script.js{.orig,}
--- script.js.orig      2009-11-22 16:16:44.000000000 +0900
+++ script.js   2011-10-30 03:43:27.378056591 +0900
@@ -74,9 +74,11 @@
 var prev_trace = "";
 var levels0 = encodeNumber(numLevels);

-var static_file_site = 'http://your.site.com/img';
+//var static_file_site = 'http://your.site.com/img';
+var static_file_site = 'http://www.yamasita.jp/imakoko/proxy/img';
 var screen_name_site = 'http://www.fujita-lab.com/imakoko';
-var subdirectory = "";
+//var subdirectory = "";
+var subdirectory = "/imakoko/proxy";
 var extension = '.php';

 var apiview = 0;
yasunari@tswxl:/home/httpd/html/imakoko/proxy/static$

2. HTMLファイルの修正

yasunari@tswxl:/home/httpd/html/imakoko/proxy/static$ ls
script.js  script.js.orig
yasunari@tswxl:/home/httpd/html/imakoko/proxy/static$ cd ..
yasunari@tswxl:/home/httpd/html/imakoko/proxy$ ls
api  css  img  index.php  static  view.html
yasunari@tswxl:/home/httpd/html/imakoko/proxy$ mv view.html{,.orig}
yasunari@tswxl:/home/httpd/html/imakoko/proxy$ cp view.html{.orig,}
yasunari@tswxl:/home/httpd/html/imakoko/proxy$ vi view.html
	:
	:
yasunari@tswxl:/home/httpd/html/imakoko/proxy$ diff -u view.html{.orig,}|nkf -e
--- view.html.orig      2009-07-05 02:23:50.000000000 +0900
+++ view.html   2011-10-30 03:47:24.119839667 +0900
@@ -4,7 +4,7 @@
 <head>
   <meta http-equiv="content-type" content="text/html; charset=utf-8">
   <meta name="author" content="Fujitalon" />
-  <link rel="stylesheet" type="text/css" href="/css/simple.css">
+  <link rel="stylesheet" type="text/css" href="/imakoko/proxy/css/simple.css">
   <script src="http://maps.google.com/maps?file=api&v=2&key=" type="text/javascript"></script>
   <script type="text/javascript">
   <!--//--><![CDATA[//><!--
@@ -20,7 +20,7 @@

   //--><!]]>
   </script>
-  <script src="/static/script.js" type="text/javascript"></script>
+  <script src="/imakoko/proxy/static/script.js" type="text/javascript"></script>
   <title>今ココなう!(β):全体地図モード</title>

 </head>
yasunari@tswxl:/home/httpd/html/imakoko/proxy$

確認

http://www.yamasita.jp/imakoko/proxy にアクセスすると、
なんか、index.php をダウンロードするんですが、、、

アクセス

http://www.yamasita.jp/imakoko/proxy/view.html にアクセスすると、 無事今ここなう!が表示された。
右肩の [Mapnik] ボタンを押すと、、見慣れた OpenStreetMap が表示された。

カスタマイズ

標準状態でインストールできたので、カスタマイズをすすめる

デフォルトを Mapnik にしたい

myMapTypes.push する順番を変えてみた。
yasunari@tswxl:/home/httpd/html/imakoko/proxy$ diff -u static/script.js{.orig,}|nkf -e
--- static/script.js.orig       2009-11-22 16:16:44.000000000 +0900
+++ static/script.js    2011-10-30 05:03:15.133614983 +0900
@@ -74,9 +74,11 @@
 var prev_trace = "";
 var levels0 = encodeNumber(numLevels);

-var static_file_site = 'http://your.site.com/img';
+//var static_file_site = 'http://your.site.com/img';
+var static_file_site = 'http://www.yamasita.jp/imakoko/proxy/img';
 var screen_name_site = 'http://www.fujita-lab.com/imakoko';
-var subdirectory = "";
+//var subdirectory = "";
+var subdirectory = "/imakoko/proxy";
 var extension = '.php';

 var apiview = 0;
@@ -1173,10 +1175,10 @@

                // 地図レイヤーの種類
                var myMapTypes = [];
-               myMapTypes.push(G_NORMAL_MAP);
-               myMapTypes.push(G_SATELLITE_MAP);
-               myMapTypes.push(G_HYBRID_MAP);
-               myMapTypes.push(G_PHYSICAL_MAP);
+//             myMapTypes.push(G_NORMAL_MAP);
+//             myMapTypes.push(G_SATELLITE_MAP);
+//             myMapTypes.push(G_HYBRID_MAP);
+//             myMapTypes.push(G_PHYSICAL_MAP);

                // OpenStreetMapレイヤーを使うかどうか
                if (isDefined('use_osm') && use_osm) {
@@ -1192,6 +1194,11 @@
                        myMapTypes.push(mapOsmarender);
                }

+               myMapTypes.push(G_NORMAL_MAP);
+               myMapTypes.push(G_SATELLITE_MAP);
+               myMapTypes.push(G_HYBRID_MAP);
+               myMapTypes.push(G_PHYSICAL_MAP);
+
                // 地図オブジェクトの作成
                map = new GMap2(document.getElementById("map"), { mapTypes: myMapTypes });

yasunari@tswxl:/home/httpd/html/imakoko/proxy$

デフォルトの表示位置を向日市にしたい

map_region を設定する。
設定方法がよくわからなかったが、、てきとーに向日市の四隅を設定してみた。
yasunari@tswxl:/home/httpd/html/imakoko/proxy$ diff -u view.html{.orig,} | nkf -e
--- view.html.orig      2009-07-05 02:23:50.000000000 +0900
+++ view.html   2011-10-30 05:13:07.257993738 +0900
@@ -4,7 +4,7 @@
 <head>
   <meta http-equiv="content-type" content="text/html; charset=utf-8">
   <meta name="author" content="Fujitalon" />
-  <link rel="stylesheet" type="text/css" href="/css/simple.css">
+  <link rel="stylesheet" type="text/css" href="/imakoko/proxy/css/simple.css">
   <script src="http://maps.google.com/maps?file=api&v=2&key=" type="text/javascript"></script>
   <script type="text/javascript">
   <!--//--><![CDATA[//><!--
@@ -18,9 +18,14 @@
        var map_maximize = 1;
        var use_osm = 1;

+       var map_region = [  { 'lat':34.96923, 'lon':135.68318 },
+                               { 'lat':34.9625, 'lon':135.70996 },
+                               { 'lat':34.92927, 'lon':135.70024 },
+                               { 'lat':34.929081, 'lon':135.714584 }
+                       ];
   //--><!]]>
   </script>
-  <script src="/static/script.js" type="text/javascript"></script>
+  <script src="/imakoko/proxy/static/script.js" type="text/javascript"></script>
   <title>今ココなう!(β):全体地図モード</title>

 </head>
yasunari@tswxl:/home/httpd/html/imakoko/proxy$
向日市ではなく、京都府ぐらいの縮尺でも良かったかな???



クラッシュした HDD に xfs_repair
ハックの記録
LinkStation/玄箱 をハックしよう

標準ファームのアップデート

Copyright (C) 2003-2011 Yasunari Yamashita. All Rights Reserved.
yasunari @ yamasita.jp 山下康成@京都府向日市