久しぶりにRailsを使ってフロント開発です。Google Maps APIを使用した地図上に会社の位置を表示する内容です。
コントローラのコードは1行だけで
class MyController < ApplicationController
def map
@companies = Company.all
end
end
モデルも今回は大して触りません。
あとはひたすらテンプレートとJavaScriptの編集作業です。
Google Maps APIはバージョン3になってかなりできることの範囲が広がったようで、特にRails用のプラグインなど使用しなくても大きな幅でカスタマイズが可能です。ただコマーシャルユースの場合はライセンスが必要で、社内利用のサイトだとサービスに問い合わせると、USD$11,000 for 250,000 page views per yearという返事が返ってきました。安くはありませんね。
Google Mapsは独自の google.maps.event.addListener などのメソッドを提供していて、その挙動と一つづつ試しながらなので、一進一退のゆっくり作業です。ちょっと面倒…。jQueryと組み合わせてゆっくりゆっくり開発です。
マーカーのDOMを取得できないという質問がウェブにあり、これは大変そうだなと思ったのですが、
marker = new google.maps.Marker({
position: m_position,
id: "8iu3afluh"
});
google.maps.event.addListener(marker, "click", function() {
alert(this.id);
});
などとすれば設定したマーカーの id: 8iu3afluh が返って来るので、とにかくこれで問題無さそうです。
Showing posts with label JavaScript. Show all posts
Showing posts with label JavaScript. Show all posts
Tuesday, 18 September 2012
Tuesday, 28 June 2011
Objective JavaScript
Some say that not many uses JavaScript as an objective language.
In my experience objective JS is useful in producing modular architecture, and later customising functions, etc. However, my impression is that if ones who are not familiar with objective programming deal with objective JS, it is very easy to loose the control of borders of objects. This is chiefly because variables have no concept of focus, they can be referred from anywhere.
Anyways, it is delightful to see JS from different perspective.
Object can be created for instance:
Then constructor is something like this;
In my experience objective JS is useful in producing modular architecture, and later customising functions, etc. However, my impression is that if ones who are not familiar with objective programming deal with objective JS, it is very easy to loose the control of borders of objects. This is chiefly because variables have no concept of focus, they can be referred from anywhere.
Anyways, it is delightful to see JS from different perspective.
Object can be created for instance:
if(!window.obj){ function Obj(){}; }
Then constructor is something like this;
function Obj(){ this.var1 = a; this.var2 = 1; }
Then object can be inherited with .prototype method:
SomeObj.prototype = new Obj();
Methods can be implemented by
SomeObj.prototype.method1 = function (){ statement1; statement2; }
Instancing can be realised by
obj1 = new SomeObj();
If somebody found errors, better ideas, etc.etc., You are welcome to share your comments on the wall!
Subscribe to:
Posts (Atom)