简体   繁体   English

与传单故障的交互式等值线图

[英]Interactive Choropleth Map with Leaflet trouble

edit** Here is a link to my website . 编辑**这是我网站的链接。 The Leaflet test one page is what works so far and the leaflet test page 2 is when I try to add interactive features. Leaflet测试一页到目前为止是有效的,传单测试第2页是我尝试添加交互功能的时候。

I'm having a hard time getting my interactive map to actually be interactive. 我很难让我的交互式地图实际上是互动的。 I'm making a map of number of wells in PA counties. 我正在绘制PA县的井数量图。 I've been following the instructions on 我一直在按照说明进行操作

http://leafletjs.com/examples/choropleth.html#interactive-choropleth-map http://leafletjs.com/examples/choropleth.html#interactive-choropleth-map

I've managed to find/create a GeoJSON file with all the info I need and I can display it with colors corresponding to attribute data but when I try to make it interactive (county borders highlight when hovering over), it does't work. 我已经设法找到/创建一个GeoJSON文件,其中包含我需要的所有信息,我可以使用与属性数据相对应的颜色显示它,但是当我尝试使其交互时(悬停在县边界时突出显示),它不起作用。

    var map = L.map('map').setView([40.6473, -99.84375], 5);

        L.tileLayer('https://{s}.tiles.mapbox.com/v3/{id}/{z}/{x}/{y}.png', {
            maxZoom: 18,
            attribution: 'Map data &copy; <a href="http://openstreetmap.org">OpenStreetMap</a> contributors, ' +
                '<a href="http://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>, ' +
                'Imagery © <a href="http://mapbox.com">Mapbox</a>',
            id: 'examples.map-i875mjb7'
        }).addTo(map);

// start GeoJson

function base (feature,layer){

    layer.bindPopup("<h1 class='info'> Hi, I'm a box</h1><p class='info2'>" + feature.properties.count_ + "</p>  <p class='info2'>" + feature.properties.name + "</p>");    
};



function getColor(d) {
    return d > 1000 ? '#800026' :
           d > 500  ? '#BD0026' :
           d > 200  ? '#E31A1C' :
           d > 100  ? '#FC4E2A' :
           d > 50   ? '#FD8D3C' :
           d > 20   ? '#FEB24C' :
           d > 10   ? '#FED976' :
                      '#FFEDA0';
}

function style(feature) {
    return {
        fillColor: getColor(feature.properties.count_),
        weight: 2,
        opacity: 1,
        color: 'white',
        dashArray: '3',
        fillOpacity: 0.7
    };
}

L.geoJson(wcc, {style: style}).addTo(map);

//good up to here

When I try to add the next block of code that deals with the interactive features, the map doesn't load. 当我尝试添加处理交互式功能的下一个代码块时,地图不会加载。

    function highlightFeature(e) {
    var layer = e.target;

    layer.setStyle({
        weight: 5,
        color: '#666',
        dashArray: '',
        fillOpacity: 0.7
    });

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

function resetHighlight(e) {
    geojson.resetStyle(e.target);
}

I'm new to all of this so hopefully it is something simple. 我是所有这一切的新手所以希望这很简单。 I don't really understand what the e.target is doing. 我真的不明白e.target在做什么。 I've been stuck on this for a while. 我已经坚持了一段时间。 Any ideas are appreciated! 任何想法都表示赞赏!

I figured it out..There was a statement where I forgot to include my geojson variable. 我想通了......有一个声明,我忘了包含我的geojson变量。

I had 我有

var geojson;
// ... our listeners
geojson = L.geoJson(...);

and I needed to include my geojson var name 我需要包含我的geojson var名称

var geojson;
// ... our listeners
geojson = L.geoJson(wcc);

(I could have sworn I tried that earlier but it's working now!) (我本来可以发誓我早些时候试过了,但它现在正在工作!)

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

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