我嘗試開發一個應用程序,以顯示單張地圖服務:地圖小冊子標記
是否有可能根據「屬性」 GeoJSON的屬性有不同的標誌?
{ "type": "FeatureCollection", "features": [ { "type": "Feature", "geometry": { "type": "Point", "coordinates": [ 6.1200622,46.2106091 ] }, "properties": { "nom":"Cfffff Genève", "rue":"Route des F", "num":"11", "npa":1203, "localite":"Genève", "canton":"GE", "tel":"033 345 17 57", "url":"www.formation-cemea.ch", "domaine":"société " }},
這裏是我的地圖腳本: 我想,當你點擊一個按鈕的頂部顯示它對應的屬性(用另一種顏色)只標記? 謝謝大家的幫助SO MUCH)
<div class="btn-group">
<button type="button" id="allbus" class="btn btn-success">All</button>
<button type="button" id="others" class="btn btn-primary">Sexualité</button>
<button type="button" id="cafes" class="btn btn-danger">Mal-être</button>
<button type="button" id="cafes" class="btn btn-secondary">Santé</button>
<button type="button" id="cafes" class="btn btn-info">Drogues</button>
<button type="button" class="btn btn-warning">Société</button>
<button type="button" class="btn btn-outline-success">Internet</button>
</div>
<body>
<div id="map"></div>
<script type="text/javascript">
var map = L.map('map');
var terrainTiles = L.tileLayer('http://{s}.tiles.wmflabs.org/bw-mapnik/{z}/{x}/{y}.png', {
maxZoom: 18,
attribution: '© <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>'
});
terrainTiles.addTo(map);
map.setView([46.5160000, 6.6328200], 10);
L.control.locate(location).addTo(map);
L.easyButton('<strong>BE</strong>', function(){
//zoomTo.setView([55, -2], 4);
map.setView([46.95, 6.85], 12);
}).addTo(map);
L.easyButton('<strong>FR</strong>', function(){
//zoomTo.setView([55, -2], 4);
map.setView([46.95, 6.85], 12);
}).addTo(map);
L.easyButton('<strong>GE</strong>', function(){
//zoomTo.setView([55, -2], 4);
map.setView([46.95, 6.85], 12);
}).addTo(map)
L.easyButton('<strong>JU</strong>', function(){
//zoomTo.setView([55, -2], 4);
map.setView([46.95, 6.85], 12);
}).addTo(map);
L.easyButton('<strong>NE</strong>', function(){
//zoomTo.setView([55, -2], 4);
map.setView([46.95, 6.85], 12);
}).addTo(map);
L.easyButton('<strong>VS</strong>', function(){
//zoomTo.setView([55, -2], 4);
map.setView([46.95, 6.85], 12);
}).addTo(map);
L.easyButton('<strong>VD</strong>', function(){
//zoomTo.setView([55, -2], 4);
map.setView([46.95, 6.85], 12);
}).addTo(map);
function addDataToMap(data, map) {
var dataLayer = L.geoJson(data, {
onEachFeature: function(feature, layer) {
var popupText = "<b>" + feature.properties.nom
+ "<br>"
+ "<small>" + feature.properties.localite
+ "<br>Rue: " + feature.properties.rue + + feature.properties.num
+ "<br>Téléphone: " + feature.properties.tel
+ "<br><a href= '" + feature.properties.url + "'>Internet</a>";
layer.bindPopup(popupText); }
});
dataLayer.addTo(map);
}
$.getJSON("data.geojson", function(data) { addDataToMap(data, map); });
</script>
</body>
</html>