Log.log(work)

いろんな作業メモ

openstreetmap + Leaflet.js memo

openstreetmap
https://openstreetmap.jp/

API
http://leafletjs.com/reference.html

レイヤーについて
http://leafletjs.com/examples/layers-control/

プラグイン紹介
http://qiita.com/pokohide/items/6329f1f92253ced23599

経路検索
http://wiki.openstreetmap.org/wiki/JA:OpenRouteService#.E7.9B.B4.E6.8E.A5.E7.B5.8C.E8.B7.AF.E6.A4.9C.E7.B4.A2.E3.83.AA.E3.82.AF.E3.82.A8.E3.82.B9.E3.83.88.EF.BC.88GET_.E3.82.92.E4.BD.BF.E7.94.A8.EF.BC.89

ルートの描画
https://github.com/leaflet/Leaflet.Draw#readme
https://leaflet.github.io/Leaflet.draw/docs/leaflet-draw-latest.html#l-draw

上のサンプル
https://leaflet.github.io/Leaflet.draw/docs/examples/snapping.html

Using GeoJSON with Leaflet(つかうかな?
http://leafletjs.com/examples/geojson/
http://s.kitazaki.name/docs/geojson-spec-ja.html

カスタマイズ
http://qiita.com/ShingoOikawa/items/41a522c1361e33c3c3dd

CentOS7にzipが入っていなかった件

環境 VM上のCentOS7 ※ホストOSはWindows

検証用のCentOSにzipコマンドが含まれているスクリプトを動かしたら

zip: コマンドが見つかりません

え?入ってないんかい。

$ yum list installed | grep zip
bzip2-libs.x86_64                     1.0.6-13.el7                     @anaconda
gzip.x86_64                           1.5-8.el7                        @anaconda

ほんとに入ってなかった。

yumでインストールできるかinfoオプションをつけて確認。

$ sudo yum --enablerepo=epel,remi,rpmforge info zip
読み込んだプラグイン:fastestmirror
Loading mirror speeds from cached hostfile
 * base: ftp.iij.ad.jp
 * epel: ae.mirror.rasanegar.com
 * extras: ftp.iij.ad.jp
 * updates: centos.usonyx.net
利用可能なパッケージ
名前                : zip
アーキテクチャー    : x86_64
バージョン          : 3.0
リリース            : 11.el7
容量                : 260 k
リポジトリー        : base/7/x86_64
要約                : A file compression and packaging utility compatible with
                    : PKZIP
URL                 : http://www.info-zip.org/Zip.html
ライセンス          : BSD
説明                : The zip program is a compression and file packaging
                    : utility.  Zip is analogous to a combination of the UNIX
                    : tar and compress commands and is compatible with PKZIP (a
                    : compression and file packaging utility for MS-DOS
                    : systems).
                    :
                    : Install the zip package if you need to compress files
                    : using the zip program.

お、あるある。

じゃあインストール。

$ sudo yum install zip
読み込んだプラグイン:fastestmirror
base                                                     | 3.6 kB     00:00
extras                                                   | 3.4 kB     00:00
updates                                                  | 3.4 kB     00:00
updates/7/x86_64/primary_db                                | 2.2 MB   00:00
Loading mirror speeds from cached hostfile
 * base: ftp.iij.ad.jp
 * extras: ftp.iij.ad.jp
 * updates: centos.usonyx.net
依存性の解決をしています
--> トランザクションの確認を実行しています。
---> パッケージ zip.x86_64 0:3.0-11.el7 を インストール
--> 依存性解決を終了しました。

依存性を解決しました

================================================================================
 Package        アーキテクチャー  バージョン              リポジトリー     容量
================================================================================
インストール中:
 zip            x86_64            3.0-11.el7              base            260 k

トランザクションの要約
================================================================================
インストール  1 パッケージ

総ダウンロード容量: 260 k
インストール容量: 796 k
Is this ok [y/d/N]: y
Downloading packages:
zip-3.0-11.el7.x86_64.rpm                                  | 260 kB   00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  インストール中          : zip-3.0-11.el7.x86_64                           1/1
  検証中                  : zip-3.0-11.el7.x86_64                           1/1

インストール:
  zip.x86_64 0:3.0-11.el7

完了しました!

p.s. unzipも入ってなかった。。。

作業メモ - node.js/webpack

windows7(64bit)でnode.jsとwebpackを使うことになったのでめも。


何かのタイミングでwindowsマシンにnode.jsが入っていたのでついでにnpmも入ってた。
ラッキー。
※--versionで確認
※たぶんインストーラーでいれたような気もする
Node.js



webpackはnpmでインストールする。

github.com



と思ったら案の定proxyでエラー。

環境変数にセットしておくか、npm の configにセットする。
セット後、リトライしたら問題なく行った。

npm config set proxy http://proxy.example.com:8080

insertBeforeで躓いた件

テーブル内の要素を上へもしくは下へ入れ替えが出来る画面を造っていたときにはまった。

入れ替えにはinsertBeforeで出来ると聞いて。

やり方はいろいろあれど、楽そうだったのでinsertBefore を使ってノードに挿入する手段を考えてみた。

参考サイト:
DOM Node チラ裏 - latest log

作ってみたらうまく動かない。

単純なテーブルで書いてみたら動くときと動かないときがある。

<tbody id="tbody1">
  <tr>
    <td>
    <input type="text" value="1" />
    <i onclick="up(this);" class="fa fa-chevron-up"></i>
    <i onclick="down(this);" class="fa fa-chevron-down"></i>
    </td>
  </tr>
  <tr>
    <td>
    <input type="text" value="2" />
    <i onclick="up(this);" class="fa fa-chevron-up"></i>
    <i onclick="down(this);" class="fa fa-chevron-down"></i>
    </td>
  </tr>
  <tr>
    <td>
    <input type="text" value="3" />
    <i onclick="up(this);" class="fa fa-chevron-up"></i>
    <i onclick="down(this);" class="fa fa-chevron-down"></i>
    </td>
  </tr>
</tbody>


上に移動する処理(下へは省略)

function up(obj) {

  var tbody = document.getElementById("tbody1");
  var tr = obj.parentNode.parentNode;

  if(tr.previousSibling != null & tr.previousSibling.nodeName === "TR") {
    // 「tr」を上に挿入
    tbody.insertBefore(tr, tr.previousSibling);
  }

}
事象

tr.previousSiblingが#textだったりtrだったりする。

前の要素が#textになっているのはなぜ?と不思議に思い、
console.log(tr.previousSibling.nodeValue);
で値を出したら空白が表示されてた。

空白?


原因

htmlにtbody以下は空白は入れてはいけない。
見栄えよくするために空白を入れているとその空白も要素だと勘違いされるっぽい??
とりあえず改行なし・空白なしで修正してみたら思ったとおりに動いた。