简体   繁体   English

使用动态值的小叶脉络图

[英]leaflet choropleth map using dynamic value

I am doing a choropleth map using leaflet and JSON data. 我正在使用传单和JSON数据来制作Choropleth映射 I got a clean tutorial in leaflet site. 我在传单网站上得到了一个干净的教程。 In that tutorial the used us-states.js JSON file where the choropleth was based on the feature.properties.density feature of the JSON if I am not wrong. 在该教程中,使用的us-states.js JSON文件(如果我没弄错的话)的基础是JSON的feature.properties.density功能。 If we see the JS file we can found there is a field called "ID" which is state id. 如果我们看到JS文件,则可以找到一个名为“ ID”的字段,它是状态ID。 I have a database where I have 5 different categories of data based on state ID. 我有一个数据库,其中有基于状态ID的5种不同类别的数据。 Categories are population, density, male_population, female_population, literacy_rate. 类别是人口,密度,男性人口,女性人口,识字率。 I am calling those data through ajax and get a GeoJSON data state-wise as follows (Its a dummy data). 我通过ajax调用这些数据,并按如下方式按状态获取GeoJSON数据(它是虚拟数据)。

[{"state_id":"01","population":"123456","density":"1234","male_pop":"65432","female_pop":"57421","literacy_rate":"98"}]
...
[{"state_id":"50","population":"123456","density":"1234","male_pop":"65432","female_pop":"57421","literacy_rate":"98"}]

I want to integrate this data as choropleth value. 我想将此数据集成为choropleth值。 when I call on literacy function the variation of color will be based on literacy_rate data. 当我调用扫盲功能时,颜色的变化将基于literacy_rate数据。 I can make the changes in getcolor function category wise. 我可以明智地在getcolor函数类别中进行更改。

Thanks 谢谢

I would recommend using Leaflet Data Visualization Framework (DVF) plugin, located here . 我建议使用位于此处的 Leaflet Data Visualization Framework(DVF)插件。 This plugin contains a set of Layers, (such as a Choropleth layer) and a set of functions to help color-code your data. 该插件包含一组图层(例如Choropleth图层)和一组用于对数据进行颜色编码的功能。

The example located here will demonstrate the DVF Choropleth Data layer. 此处的示例将演示DVF Choropleth数据层。

Using DVF, you can create a color function to create your scaling color values. 使用DVF,您可以创建颜色函数来创建缩放颜色值。 For example, this function will generate a function from yellow to red. 例如,此函数将生成一个从黄色到红色的函数。 The point values contain the range of values, and the HSL Hue. 点值包含值的范围和HSL色相。

var yellowToRed = new L.HSLHueFunction(new L.Point(50, 60), new L.Point(100, 0));

DVF contains a L.ChoroplethDataLayer layer that will accept your GeoJSON, and your color function, and will generate the layer for you. DVF包含一个L.ChoroplethDataLayer图层,该图层将接受您的GeoJSON和您的颜色函数,并将为您生成该图层。

var layer = new L.ChoroplethDataLayer(geoJSON, {
    // For the full options, see the documentation
    displayOptions: {
        // The display will be colored by your 'density' property in your GeoJSON. This accesses the feature object directory, so the 'properties' prefix is required if you're going to access a GeoJSON property on your data.
        'properties.density': {
            // A legend will automatically be generated for you. You can add this as a control. This displayName property will be the title for this layer's legend.
            displayName: 'Density',
            color: yellowToRed
        }
    };
});

This is just a simple example. 这只是一个简单的例子。 For your data, it might look slightly different. 对于您的数据,它可能看起来略有不同。 Go through the DVF documentation and samples and you'll find what's right for you. 查看DVF文档和样本,您将找到适合自己的东西。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM