Leafletポリゴン(GeoJSON経由でロード)のイベントを手動でトリガーする方法を理解しようとしています。
一言で言えば、私は多数のポリゴンを含むリーフレットマップを持っています。また、マップの外側に通常のハイパーリンクがあり、クリックすると、特定のポリゴンでマウスオーバーイベント(または実際には任意のイベント)がトリガーされます。
ハイパーリンクを特定のポリゴンのイベントにバインドできるように、すべてのポリゴンにIDを割り当てるにはどうすればよいですか?それとも、これを行う最も論理的な方法ですか?
最終的には、各ポリゴンに関連付けられたテキストラベルのHTMLテーブルとともに、多数のポリゴンを含むマップを作成しようとしています。HTMLテーブルのテキストをクリックするときに、マップポリゴンでイベントをトリガーしたい(またはその逆)。各ポリゴンを参照する方法がわかりません。
これが私の非常に単純化されたHTMLです:
<body>
<div id="map" style="height: 550px; width:940px"></div>
<a href="#" id="testlink">Click to trigger a specific polygon mouseover event</a>
</body>
これが私の非常に単純化されたJSです:
$(document).ready(function () {
// build the map and polygon layer
function buildMap(data) {
var map = new L.Map('map');
var cloudmadeUrl = 'http://{s}.tile.cloudmade.com/***yourkeyhere***/66267/256/{z}/{x}/{y}.png',
cloudmadeAttribution = '',
cloudmade = new L.TileLayer(cloudmadeUrl, {maxZoom: 18, attribution: cloudmadeAttribution});
var mapLoc = new L.LatLng(43.675198,-79.383287);
map.setView(mapLoc, 12).addLayer(cloudmade);
var geojsonLayer = new L.GeoJSON(null, {});
geojsonLayer.on("featureparse", function (e){
// apply the polygon style
e.layer.setStyle(polyStyle);
(function(layer, properties) {
layer.on("mouseover", function (e) {
// change the style to the hover version
layer.setStyle(polyHover);
});
});
layer.on("mouseout", function (e) {
// reverting the style back
layer.setStyle(polyStyle);
});
layer.on("click", function (e) {
// do something here like display a popup
console.log(e);
});
})(e.layer, e.properties);
});
map.addLayer(geojsonLayer);
geojsonLayer.addGeoJSON(myPolygons);
}
// bind the hyperlink to trigger event on specific polygon (by polygon ID?)
$('#testlink').click(function(){
// trigger a specific polygon mouseover event here
});
});