如何缩小和改变传单中的颜色

时间:2017-03-14 11:59:37

标签: leaflet mapbox

我正在使用传单和leaflet-fusesearch。这是我在搜索传单中绘制的一行时弹出框的代码:

var map = L.map('map').setView([1.3096622448984000, 103.7689017333800], 12);

    L.tileLayer('https://api.tiles.mapbox.com/v4/{id}/{z}/{x}/{y}.png?access_token=token', {
        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: 'mapbox.streets'
    }).addTo(map);
    map.doubleClickZoom.disable();
    var info = L.control();

    var options = {
            position: 'topleft',
            title: 'Search',
            placeholder: 'enter link id ',
            maxResultLength: 15,
            threshold: 0.5,
            showInvisibleFeatures: true,
            showResultFct: function(feature, container) {
                props = feature.properties;
                var name = L.DomUtil.create('b', null, container);
                name.innerHTML = props.id;

                container.appendChild(L.DomUtil.create('br', null, container));

                var cat = props.id
                    info = '' + cat + ', ' + 'th link';
                container.appendChild(document.createTextNode(info));
            }
        };

    var searchCtrl = L.control.fuseSearch(options);

    searchCtrl.addTo(map);




    var geojson;

    function getColor(d) {
        return  d > 2000 ? '#006400' :
            d > 1500  ? '#6fdc6f' :
            d > 1000  ? '#6fdc6f' :
            d > 500  ? '#6fdc6f' :
            d > 50   ? '#FF0000' :
            d > 20   ? '#c8ff58' :
            d > 10   ? '#6fdc6f' :
                       '#fafafa';


    }


    function style(feature) {
        return {
            weight: 2,
            opacity: 1,
            color: '#ff0000',
            fillOpacity: 0.7,

        };
    }


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

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


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

    info.update(layer.feature.properties);

    }
function resetHighlight(e) {
    geojson.resetStyle(e.target);
     info.update();
}
function zoomToFeature(e) {
    map.fitBounds(e.target.getBounds());
    map.doubleClickZoom.disable();
}


info.update = function (props) {
    this._div.innerHTML = '<h4><b>August 2016: <b></h4>' +  (props ?
        '<b>Link ' + props.id + '</b><br />'  
        : 'Hover over a link');


};


function onEachFeature(feature, layer) {
     feature.layer = layer;

    layer.on({
        mouseover: highlightFeature,
        mouseout: resetHighlight,


    });
    var popupContent = 
      '<b>Link ' + feature.properties.id + '</b>';

    layer.bindPopup(popupContent);          
    feature.layer = layer;

}






geojson = L.geoJson(zones, {
    style: style,
    onEachFeature: onEachFeature
}).addTo(map);


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




searchCtrl.indexFeatures(zones.features, ['id']);
info.addTo(map);

但是当我加载页面时,高亮显示功能正常工作,当我搜索一行时,弹出窗口也能正常工作。但是在搜索后,高亮显示功能不起作用,我也想放大并更改颜色地图中的一行。感谢任何帮助。

1 个答案:

答案 0 :(得分:0)

遇到同样的问题并深入研究leaflet-fusesearch代码,我想我们必须修改createResultItem函数:

https://github.com/naomap/leaflet-fusesearch/blob/master/src/leaflet.fusesearch.js#L286

似乎该函数只允许openPoup / panAndpopup作为事件,在此步骤中添加其他事件或传递个人函数会很有用