<bdo id='iYb6v'></bdo><ul id='iYb6v'></ul>

    <small id='iYb6v'></small><noframes id='iYb6v'>

    <legend id='iYb6v'><style id='iYb6v'><dir id='iYb6v'><q id='iYb6v'></q></dir></style></legend>

      <i id='iYb6v'><tr id='iYb6v'><dt id='iYb6v'><q id='iYb6v'><span id='iYb6v'><b id='iYb6v'><form id='iYb6v'><ins id='iYb6v'></ins><ul id='iYb6v'></ul><sub id='iYb6v'></sub></form><legend id='iYb6v'></legend><bdo id='iYb6v'><pre id='iYb6v'><center id='iYb6v'></center></pre></bdo></b><th id='iYb6v'></th></span></q></dt></tr></i><div id='iYb6v'><tfoot id='iYb6v'></tfoot><dl id='iYb6v'><fieldset id='iYb6v'></fieldset></dl></div>
    1. <tfoot id='iYb6v'></tfoot>

      传单地图,通过按钮获取geojson文件的具体数据

      时间:2023-08-08
      <tfoot id='0ypuS'></tfoot>

          <i id='0ypuS'><tr id='0ypuS'><dt id='0ypuS'><q id='0ypuS'><span id='0ypuS'><b id='0ypuS'><form id='0ypuS'><ins id='0ypuS'></ins><ul id='0ypuS'></ul><sub id='0ypuS'></sub></form><legend id='0ypuS'></legend><bdo id='0ypuS'><pre id='0ypuS'><center id='0ypuS'></center></pre></bdo></b><th id='0ypuS'></th></span></q></dt></tr></i><div id='0ypuS'><tfoot id='0ypuS'></tfoot><dl id='0ypuS'><fieldset id='0ypuS'></fieldset></dl></div>
            • <bdo id='0ypuS'></bdo><ul id='0ypuS'></ul>

                <legend id='0ypuS'><style id='0ypuS'><dir id='0ypuS'><q id='0ypuS'></q></dir></style></legend>
              • <small id='0ypuS'></small><noframes id='0ypuS'>

                  <tbody id='0ypuS'></tbody>
                本文介绍了传单地图,通过按钮获取geojson文件的具体数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                问题描述

                我正在尝试使用按钮在我的 geojson 文件的地图特定值 (data.geojson) 上显示.(例如绘制只有值domaine"的地图:violences")

                I'm triying to display on my map specific value ( data.geojson) of my geojson file with buttons. (for exemple to plot a map with only value "domaine":"violences ")

                我正在寻找一种方法,通过我的地图上的按钮来依赖我的数据(domaine":violences"或其他)?

                I am loocking for a way to rely my data ("domaine":"violences" or other)with a buttons on my map ?

                非常感谢您抽出宝贵时间.我的js:

                Thanks so much in advance for your time. my js:

                <script type="text/javascript">
                var map = L.map('map');
                var terrainTiles = L.tileLayer('http://stamen-tiles-{s}.a.ssl.fastly.net/toner-lite/{z}/{x}/{y}.{ext}', {
                    attribution: 'Map tiles by <a href="http://stamen.com">Stamen Design</a>, <a href="http://creativecommons.org/licenses/by/3.0">CC BY 3.0</a> &mdash; Map data &copy; <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>',
                    subdomains: 'abcd',
                    minZoom: 0,
                    maxZoom: 20,
                    ext: 'png'
                });
                
                
                
                terrainTiles.addTo(map);
                map.setView([46.5160000, 6.6328200], 10);
                
                
                
                
                L.control.locate(location).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>

                data.geojson

                the data.geojson

                {
                "type": "FeatureCollection",
                "features": [
                {
                "type": "Feature",
                "geometry": {
                   "type": "Point",
                   "coordinates":  [ 6.1200622,46.2106091 ]
                },
                "properties": {
                  "nom":"Centre d'entraînement aux méthodes d'éducation active - Genève",
                  "rue":"Route des Franchises",
                  "num":"11",
                  "npa":1203,
                  "localite":"Genève",
                  "canton":"GE",
                  "tel":"022 940 17 57",
                  "url":"www.formation-cemea.ch",
                  "domaine":"formation   "
                }
                  },
                
                  {
                "type": "Feature",
                "geometry": {
                   "type": "Point",
                   "coordinates":  [ 6.1243056,46.2120426 ]
                  },
                "properties": {
                  "nom":"VIRES",
                  "rue":"Rue Ernest-Pictet ",
                  "num":"10",
                  "npa":1203,
                  "localite":"Genève",
                  "canton":"GE",
                  "tel":"022 328 44 33",
                  "url":"www.vires.ch",
                  "domaine":"violences   "
                  }
                }
                

                推荐答案

                至于打开/关闭你的类别,你可以使用 Leaflet Layers Control L.control.layers.

                As for toggling ON / OFF your categories, you could use Leaflet Layers Control L.control.layers.

                至于按类别(在您的情况下为域")对功能进行分组,请参阅我在评论中链接的帖子:传单:如何从单个集合中切换 GeoJSON 功能属性?

                As for grouping your features by category ("domaine" in your case), see the post I linked in my comment: Leaflet: How to toggle GeoJSON feature properties from a single collection?

                您甚至可以通过直接使用图层组来稍微简化它L.layerGroup 而不是使用中间数组.

                You could even slightly simplify it by directly using Layer Groups L.layerGroup instead of using intermediate arrays.

                var categories = {},
                    category;
                
                var layersControl = L.control.layers(null, null).addTo(map);
                
                function addDataToMap(data, map) {
                  L.geoJson(data, {
                    onEachFeature: function(feature, layer) {
                      category = feature.properties.domaine;
                      // Initialize the category layer group if not already set.
                      if (typeof categories[category] === "undefined") {
                        categories[category] = L.layerGroup().addTo(map);
                        layersControl.addOverlay(categories[category], category);
                      }
                      categories[category].addLayer(layer);
                    }
                  });
                  //dataLayer.addTo(map); // no longer add the GeoJSON layer group to the map.
                }
                
                $.getJSON("data.geojson", function(data) {
                  addDataToMap(data, map);
                });
                

                演示:https://plnkr.co/edit/H6E6q0vKwb3RPOZBWs27?p=preview

                这篇关于传单地图,通过按钮获取geojson文件的具体数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                上一篇:如何在 react-leaflet 中调用 fitBounds 和 getBounds? 下一篇:Web 上的等距矩形地图

                相关文章

                最新文章

                <small id='YbgG5'></small><noframes id='YbgG5'>

                  <bdo id='YbgG5'></bdo><ul id='YbgG5'></ul>
                <i id='YbgG5'><tr id='YbgG5'><dt id='YbgG5'><q id='YbgG5'><span id='YbgG5'><b id='YbgG5'><form id='YbgG5'><ins id='YbgG5'></ins><ul id='YbgG5'></ul><sub id='YbgG5'></sub></form><legend id='YbgG5'></legend><bdo id='YbgG5'><pre id='YbgG5'><center id='YbgG5'></center></pre></bdo></b><th id='YbgG5'></th></span></q></dt></tr></i><div id='YbgG5'><tfoot id='YbgG5'></tfoot><dl id='YbgG5'><fieldset id='YbgG5'></fieldset></dl></div>
              • <legend id='YbgG5'><style id='YbgG5'><dir id='YbgG5'><q id='YbgG5'></q></dir></style></legend>

                  1. <tfoot id='YbgG5'></tfoot>