Javascript 特征。在这种情况下,可以将单个样式指定给向量层。这里有一个例子,它做的比你需要的更多,但应该让你有方向性:数据从哪里来?使一个地区不同于另一个地区的规则是什么?这些规则是在哪里定义的?数据来自一个Shapefile,规则是区域填充,在Shapefile的属

Javascript 特征。在这种情况下,可以将单个样式指定给向量层。这里有一个例子,它做的比你需要的更多,但应该让你有方向性:数据从哪里来?使一个地区不同于另一个地区的规则是什么?这些规则是在哪里定义的?数据来自一个Shapefile,规则是区域填充,在Shapefile的属,javascript,leaflet,openlayers-3,choropleth,Javascript,Leaflet,Openlayers 3,Choropleth,特征。在这种情况下,可以将单个样式指定给向量层。这里有一个例子,它做的比你需要的更多,但应该让你有方向性:数据从哪里来?使一个地区不同于另一个地区的规则是什么?这些规则是在哪里定义的?数据来自一个Shapefile,规则是区域填充,在Shapefile的属性表中定义。到目前为止,我尝试导出GeoJSON、GML和KML格式,结果是一样的:只显示边界(区域轮廓),但我也需要显示颜色。它需要是OpenLayers吗?它可能是像d3.js这样更符合这一点的东西吗?你需要学习如何设计这些特性。在这种情况


特征。在这种情况下,可以将单个样式指定给向量层。这里有一个例子,它做的比你需要的更多,但应该让你有方向性:数据从哪里来?使一个地区不同于另一个地区的规则是什么?这些规则是在哪里定义的?数据来自一个Shapefile,规则是区域填充,在Shapefile的属性表中定义。到目前为止,我尝试导出GeoJSON、GML和KML格式,结果是一样的:只显示边界(区域轮廓),但我也需要显示颜色。它需要是OpenLayers吗?它可能是像d3.js这样更符合这一点的东西吗?你需要学习如何设计这些特性。在这种情况下,可以将单个样式指定给向量层。下面是一个例子,它做的比你需要的多,但应该让你有方向性:
<script src="leaflet.js" type="text/javascript"></script>

<link rel="stylesheet" href="leaflet.css" type="text/css" >
<script type="text/javascript" src="jquery-3.0.0.js" ></script>
<script type="text/javascript">

        // Create a map ('map' is the div id where the map will be displayed)
        var map = L.map('map').setView([-15, -55], 5); // Set the center of the map

        // Select the Basemap
        L.tileLayer('http://stamen-tiles-{s}.a.ssl.fastly.net/toner-lite/{z}/{x}/{y}.png', {
            attribution: '&copy; <a href="http://osm.org/copyright">OpenStreetMap</a> contributors | CRR'
        }).addTo(map);

        // Var to save the GeoJSON opened
        var geojsonObject;

        // Open the GeoJSON with the informations
        // Change 'pop_2015_json.geojson' for your GeoJSON file
        $.getJSON("pop_2015_json.geojson", function(json) {
            geojsonObject = L.geoJson(json, {style: style, onEachFeature: onEachFeature});
            geojsonObject.addTo(map);
        });

        // Function to set the color of each region
        function getColor(p) {
            return p > 2000000  ? '#023858' :
                   p > 600000   ? '#045a8d' :
                   p > 300000   ? '#0570b0' :
                   p > 90000    ? '#3690c0' :
                   p > 20000    ? '#74a9cf' :
                   p > 10000    ? '#a6bddb' :
                                  '#d0d1e6';
        }

        // Function to apply the style
        function style(feature) {
            return {
                // 'pop_2015' is an information from GeoJSON
                fillColor: getColor(feature.properties.pop_2015),
                weight: 1,
                opacity: 0.9,
                color: 'grey',
                dashArray: '3',
                fillOpacity: 0.9
            };
        }

        // Change the style when mouse are hovered
        function highlightFeature(e) {
            var layer = e.target;

            // Change the border style
            layer.setStyle({
                weight: 3,
                color: '#666',
                dashArray: '',
                fillOpacity: 0.7,
                opacity: 1
            });

            if (!L.Browser.ie && !L.Browser.opera && !L.Browser.edge) {
                layer.bringToFront();
            }

            // Update the style of the hovered region
            info.update(layer.feature.properties);
        }

        // Reset the style on mouse over the region
        function resetHighlight(e) {
            geojsonObject.resetStyle(e.target);

            info.update();
        }

        // Zoom to region when clicked
        function zoomToFeature(e) {
            map.fitBounds(e.target.getBounds());
        }

        // Apply for each region
        function onEachFeature(feature, layer) {
            layer.on({
                mouseover: highlightFeature,
                mouseout: resetHighlight,
                click: zoomToFeature
            });
        }

        // Add a field to display the region information
        var info = L.control();

        info.onAdd = function (map) {
            this._div = L.DomUtil.create('div', 'info'); // create a div with a class "info"
            this.update();
            return this._div;
        };

        // Method that we will use to update the control based on feature properties passed
        info.update = function (props) {
            this._div.innerHTML = '<h4>População por Município &nbsp;</h4>' +  (props ?
                '<b>' + props.nome + '</b><br />' + props.pop_2015 + ' habitantes</sup>'
                : ' ');
        };

        info.addTo(map);


        // Lengend of the map
        var legend = L.control({position: 'bottomright'});

        // Create the legend
        legend.onAdd = function (map) {

            var div = L.DomUtil.create('div', 'legend'),
                // with the interval values
                grades = [0, 10000, 20000, 90000, 300000, 600000, 2000000],
                labels = [];

            // loop through our population intervals and generate a label with a colored square for each interval
            for (var i = 0; i < grades.length; i++) {
                div.innerHTML +=
                    '<i class="legenda" style="background:' + getColor(grades[i] + 1) + '"></i> ' +
                    grades[i] + (grades[i + 1] ? ' &ndash; ' + grades[i + 1] + '<br>' : ' +');
            }

            return div;
        };

        legend.addTo(map);

    </script>