GeoJSONを使って多数のマーカーを地図で高速に表示出来るので、GoogleMapのAPIで使ってましたが、課金が多くなって来るので、Leafletへの代替中で調べて試したところ、下のようなので出来ました。
< コード例 >
// ローカルのGeoJSONを読込 //
const fnm = "GeoJSON/" + this.geojsonnm + ".json";
// -- featuresを走査 -- //
$.getJSON(fnm, function (data) {
let popuphtml = "";
let icn;
let geojson = L.geoJson(data, {
onEachFeature: function (feature, layer) {
// ポップアップのHTML //
popuphtml = feature.properties.name + "<br>" +
feature.properties.zip + "<br>" +
feature.properties.addr + "<br>" +
feature.properties.tel;
// HTMLをレイヤーにバインドする //
layer.bindPopup(popuphtml);
// PCの場合、マウスオーバーでポップアップさせる //
if (!IS_TABLETUSER) {
layer.on('mouseover', function (e) {
this.openPopup();
});
layer.on('mouseout', function (e) {
this.closePopup();
});
}
}
// マーカーをプロパティで記述したアイコンに変更 //
, pointToLayer: function (feature, latlng) {
if (feature.properties.icon !== "") {
icn = L.icon({
iconUrl: feature.properties.icon,
//shadowUrl: 'leaf-shadow.png',
iconSize: [20, 20]
});
}
return L.marker(latlng, {icon: icn});
}
});
// マップに追加 //
geojson.addTo(lmap);
});
< GeoJSON例 >
{
"features": [
{
"type": "Feature",
"properties": {
"zip": "162-0845",
"addr_e": "",
"icon": "Img/lmapicon/targetplace.png",
"name": "防衛省本庁",
"unlo": "",
"tel": "",
"id": "28741",
"tp": "",
"addr": "新宿区市谷本村町5-1",
"name_e": "",
"url": ""
},
"geometry": {
"coordinates": [
139.7288,
35.6928
],
"type": "Point"
}
},
{
"type": "Feature",
"properties": {
"zip": "239-0811",
"addr_e": "",
"icon": "Img/lmapicon/targetplace.png",
"name": "防衛大学校",
"unlo": "",
"tel": "",
"id": "28742",
"tp": "",
"addr": "横須賀市走水1-10-20",
"name_e": "",
"url": ""
},
"geometry": {
"coordinates": [
139.72196,
35.25767
],
"type": "Point"
}
},
{
"type": "Feature",
"properties": {
"zip": "359-0042",
"addr_e": "",
"icon": "Img/lmapicon/targetplace.png",
"name": "防衛医科大学校",
"unlo": "",
"tel": "",
"id": "28743",
"tp": "",
"addr": "所沢市並木3-2",
"name_e": "",
"url": ""
},
"geometry": {
"coordinates": [
139.46762,
35.80379
],
"type": "Point"
}
},
< 地図表示例>

|
|
|
|
|
|
