如何在传单中缩放和更改颜色 [英] How to zoom and change color in leaflet

查看:76
本文介绍了如何在传单中缩放和更改颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am using leaflet and leaflet-fusesearch. This is my code for pop up a box when searching for a line plotted in leaflet:

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);

但是当我加载页面时,突出显示功能可以正常工作,当我搜索一行时,弹出窗口也可以正常工作,但是在搜索之后突出显示功能不起作用,我还想放大并更改其颜色地图上的线.感谢您的帮助.

But when I load the page the highlight feature works fine and when I search for a line the pop up also works fine.But after the search the highlight feature does not work and I also want to zoom in and change the color of the line in the map.Any help is appreciated.

推荐答案

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

Having the same problem and digging into the leaflet-fusesearch code I guess we have to modify the createResultItem function :

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

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

It seems the function allows only openPoup / panAndpopup as event, it would be usefull to add other events or pass personnal function at this step

这篇关于如何在传单中缩放和更改颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆