質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
jQuery

jQueryは、JavaScriptライブラリのひとつです。 簡単な記述で、JavaScriptコードを実行できるように設計されています。 2006年1月に、ジョン・レシグが発表しました。 jQueryは独特の記述法を用いており、機能のほとんどは「$関数」や「jQueryオブジェクト」のメソッドとして定義されています。

Q&A

0回答

2955閲覧

jQueryプラグインのimgViewer2で表示するマーカーを別々の物にしたい

addd123

総合スコア0

jQuery

jQueryは、JavaScriptライブラリのひとつです。 簡単な記述で、JavaScriptコードを実行できるように設計されています。 2006年1月に、ジョン・レシグが発表しました。 jQueryは独特の記述法を用いており、機能のほとんどは「$関数」や「jQueryオブジェクト」のメソッドとして定義されています。

0グッド

0クリップ

投稿2021/01/21 09:43

編集2021/01/21 09:44

前提・実現したいこと

jQueryプラグインのimgViewer2(https://github.com/waynegm/imgViewer2)で表示するマーカーを別々の画像にしたいです。

下記のページには青いマーカーが3つ表示されていますが、
これをそれぞれ別の色(別の画像)のマーカーに設定したいのですが上手くいきません。

https://waynegm.github.io/imgViewer2/basic_note.html

該当のソースコード

<script type="text/javascript"> ;(function($) { /* *Here we extend the imgViewer widget to display markers and notes * * This can be done with a few lines of code because of the capabilities of Leaflet */ $.widget("wgm.imgNotes2", $.wgm.imgViewer2, { options: { /* *Default action for addNote callback */ addNote: function(data) { var map = this.map, loc = this.relposToLatLng(data.x, data.y); var marker = L.marker(loc).addTo(map).bindPopup(data.note+"</br><input type='button' value='Delete' class='marker-delete-button'/>"); marker.on("popupopen", function() { var temp = this; $(".marker-delete-button:visible").click(function () { temp.remove(); }); }); } }, /* *Add notes from a javascript array */ import: function(notes) { if (this.ready) { var self = this; $.each(notes, function() { self.options.addNote.call(self, this); }); } } }); $(document).ready( function() { var $img = $("#map-image").imgNotes2({ onReady: function() { var notes = [ {x: "0.5", y:"0.5", note:"test1"}, {x: "0.7", y:"0.5", note:"test2"}, {x: "0.824", y: "0.593", note: "test3"} ]; this.import(notes); } }); }); })(jQuery); </script>

試したこと

こちらのページに書いてある方法を試したところマーカーを別の画像に変えることはできたのですが、
マーカーを個別に設定するコードの書き方がわからず、全て同じ画像になってしまいます…。

https://github.com/waynegm/imgViewer2/issues/32

初歩的な質問かもしれませんが、解決法があれば回答よろしくお願いします。

<script type="text/javascript"> ;(function($) { /* *Here we extend the imgViewer widget to display markers and notes * * This can be done with a few lines of code because of the capabilities of Leaflet */ $.widget("wgm.imgNotes2", $.wgm.imgViewer2, { options: { /* *Default action for addNote callback */ addNote: function(data) { var map = this.map, loc = this.relposToLatLng(data.x, data.y); var myIcon = L.divIcon({ className: 'my-div-icon', html: data.label}); var marker = L.marker(loc, {icon: myIcon}).addTo(map).bindPopup(data.note+"</br><input type='button' value='Delete' class='marker-delete-button'/>"); marker.on("popupopen", function() { var temp = this; $(".marker-delete-button:visible").click(function () { temp.remove(); }); }); } }, /* *Add notes from a javascript array */ import: function(notes) { if (this.ready) { var self = this; $.each(notes, function() { self.options.addNote.call(self, this); }); } } }); $(document).ready( function() { var $img = $("#map-image").imgNotes2({ onReady: function() { var notes = [ {x: "0.5", y:"0.5", note:"test1"}, {x: "0.7", y:"0.5", note:"test2"}, {x: "0.824", y: "0.593", note: "test3"} ]; this.import(notes); } }); }); })(jQuery); </script>

CSS

1.my-div-icon{ 2background:url(アイコン画像) 3}

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだ回答がついていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問