gpt4 book ai didi

javascript - map 传单标记

转载 作者:行者123 更新时间:2023-11-30 15:15:03 27 4
gpt4 key购买 nike

我尝试开发一个应用程序来在传单 map 上显示服务:

是否可以根据“properties”geojson属性有不同的标记?


{
“类型”:“特征集合”,
“特征”: [
{
“类型”:“特征”,
“几何学”: {
“类型”:“点”,
“坐标”:[ 6.1200622,46.2106091 ]
},
“特性”: {
"nom":"Cfffff 日内瓦",
"rue":"Route des F",
“数字”:“11”,
“国家安全局”:1203,
"localite":"日内瓦",
“广州”:“GE”,
“电话”:“033 345 17 57”,
“网址”:“www.formation-cemea.ch”,
“酒庄”:“société”
}},
这是我的 map 脚本:enter image description here 我希望当您单击顶部的按钮时,它只显示与属性对应的标记(另一种颜色)?非常感谢大家的帮助 ;)

  <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: '&copy; <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>

最佳答案

您可以在onEachFeature 方法中使用图层实例,检查它是否是一个标记并设置它的图标:

new L.GeoJSON(null ,{
onEachFeature: function (feature, layer) {
if (layer instanceof L.Marker) {
layer.setIcon(new L.Icon(...));
}
}
})

引用:http://leafletjs.com/reference-1.0.3.html#icon

示例:http://leafletjs.com/examples/custom-icons/

关于javascript - map 传单标记,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44593514/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com