マップをリーフレットと統合し、マーカーを ajax で更新したいと考えています。
私のマップは次のように作成されます:
<script type="text/javascript">
var cloudmadeUrl = "http://{s}.tile.cloudmade.com/BC9A493B41014CAABB98F0471D759707/997/256/{z}/{x}/{y}.png",
cloudmadeAttribution = "Adrien",
cloudmade = new L.TileLayer(cloudmadeUrl, {maxZoom: 17, attribution: cloudmadeAttribution}),
latlng = new L.LatLng( 43.73357176247478,7.428388595581055);
var map = new L.Map("map", {center: latlng, zoom: 11, layers: [cloudmade]});
var geoJsonData = {
"type": "FeatureCollection",
"features": [
{ "type": "Feature", "id":"1", "properties": { "address": "2" }, "geometry": { "type": "Point", "coordinates": [7.428388595581055,43.73357176247478 ] } },
{ "type": "Feature", "id":"2", "properties": { "address": "151" }, "geometry": { "type": "Point", "coordinates": [7.358388595581055,43.73357176247478 ] } },
{ "type": "Feature", "id":"3", "properties": { "address": "21" }, "geometry": { "type": "Point", "coordinates": [7.398388595581055,43.78357176247478 ] } },
{ "type": "Feature", "id":"4", "properties": { "address": "14" }, "geometry": { "type": "Point", "coordinates": [175.2240856667,-37.8216963 ] } },
{ "type": "Feature", "id":"5", "properties": { "address": "38B" }, "geometry": { "type": "Point", "coordinates": [175.2196982333,-37.8188702167 ] } },
{ "type": "Feature", "id":"6", "properties": { "address": "38" }, "geometry": { "type": "Point", "coordinates": [175.2209942 ,-37.8192782833 ] } }
]
};
var markers = new L.MarkerClusterGroup();
var geoJsonLayer = L.geoJson(geoJsonData, {
onEachFeature: function (feature, layer) {
layer.bindPopup(feature.properties.address);
}
});
markers.addLayer(geoJsonLayer);
map.addLayer(markers);
document.getElementById("doit").onclick = function () {
var m = markerList[Math.floor(Math.random() * markerList.length)];
markers.zoomToShowLayer(m, function () {
m.openPopup();
});
};
}
</script>
次のように見える geojson.php という名前のphpファイルを使用したい:
$geodata='{
"type": "FeatureCollection",
"features": [
{ "type": "Feature", "id":"1", "properties": { "address": "2" }, "geometry": { "type": "Point", "coordinates": [7.428388595581055,43.73357176247478 ] } },
{ "type": "Feature", "id":"2", "properties": { "address": "151" }, "geometry": { "type": "Point", "coordinates": [7.358388595581055,43.73357176247478 ] } },
{ "type": "Feature", "id":"3", "properties": { "address": "21" }, "geometry": { "type": "Point", "coordinates": [7.398388595581055,43.78357176247478 ] } },
{ "type": "Feature", "id":"4", "properties": { "address": "14" }, "geometry": { "type": "Point", "coordinates": [175.2240856667,-37.8216963 ] } },
{ "type": "Feature", "id":"5", "properties": { "address": "38B" }, "geometry": { "type": "Point", "coordinates": [175.2196982333,-37.8188702167 ] } },
{ "type": "Feature", "id":"6", "properties": { "address": "38" }, "geometry": { "type": "Point", "coordinates": [175.2209942 ,-37.8192782833 ] } }
]
};';
echo $geodata ;
?>
https://github.com/calvinmetcalf/leaflet-ajaxを使用すると無効な geojson 形式になりますが、http://geojsonlint.com/ でテストすると正しいようです。ボタンをクリックして表示する特別なアイテムを選択するときに、php ファイルからマーカーを更新するというアイデアはありますか。
よろしくエイドリアン