2011-08-04 23 views
0

私は最初のjQueryプラグインを作ろうとしています。基本的にはgoMapマップへのラッパーのようなもので、誰かがGoogleマップ上でマーカーを動かすたびに緯度と経度のテキストフィールドを更新します。別のjQueryプラグインを使用するjQueryプラグインの作成方法は?

は、私はそれがこのように設定している(私は質問を書いて、これはとても不足しているセミコロンを無視するか、私はcoffeescriptでそれを書いたので、かなりラフ見に行くされており、単に翻訳しています何でもしてください!):

(function($) { 
    $.fn.correctionMap = function(options) { 
    defaults = { 
     latFieldSelector: "#listing_latitude" 
     longFieldSelector: "#listing_longitude" 
     resetLinkSelector: "#reset_marker_link" 
     marker_id: 'listing_marker' 
    } 

    options = $.extend(defaults, options); 

    // grab the text field elements 
    latField = $(options.latFieldSelector) 
    longField = $(options.longFieldSelector) 

    // inialise the map go-ordinates from the 
    // values in the text fields 
    initialLat = Number(latField.val()) 
    initialLong = Number(longField.val()) 

    // build the options object for the goMap plugin 
    map_options = { 
     longitude: initialLong 
     latitude: initialLat 
     zoom: 16 
     maptype: 'ROADMAP' 

     markers: [{ 
     longitude: initialLong 
     latitude: initialLat 
     draggable: true 
     id: options.marker_id 
     }] 
    }; 

    // add the map to the div 
    return this.goMap(map_options) 
)(jQuery) 

私が$("#correction_map").correctionMap()と呼ぶと、何もしないようです。ただし、プラグインの中から私がconsole.log this.goMap(map_options)の場合は、初期化されているようです(大まかな点検)。私は間違った返事をしていますか?

+0

私にとっては、他のプラグインへの呼び出しからトレースしてみましたか?何かエラーがありますか?あなたが渡しているデータに何か問題があるかもしれません。 –

+0

笑私はそれを修正した。 javascriptは完璧だった、私は地図divに高さと幅を与えるのを忘れてしまった!とにかく見てくれてありがとう。 –

答えて

0

goMapを使用するときに、マップのターゲットであるdivにCSSで高さと幅を指定する必要があります。私の質問のJavascriptは問題ありません。おっとっと!

関連する問題