单击时突出显示geojson对象 - Leaflet

时间:2018-02-06 15:17:30

标签: javascript leaflet

我一直试图通过点击突出显示所选功能,但我可以找到方法,我尝试使用onEachFeature样式选项,但不起作用:这就是我所拥有的; < / p>

function onEachFeature(feature, layer) {

        style: function highL(feature){
            return{fillColor:'rgb(1,1,1)'};
        }

        layer.on({
            click: infoJ
         });
     }

function infoJ(e) {
    document.getElementById('obrr').innerHTML =       e.target.feature.properties.OBRA;
    document.getElementById('nomm').innerHTML =  e.target.feature.properties.NOMBRE;
    document.getElementById('dominn').innerHTML =  e.target.feature.properties.DOMINIO;
    document.getElementById('dirr').innerHTML =  e.target.feature.properties.DIRECC;
    document.getElementById('montt').innerHTML =  e.target.feature.properties.MONTO;
    document.getElementById('fondd').innerHTML =  e.target.feature.properties.FINANCIAM;
    document.getElementById('inicc').innerHTML =  e.target.feature.properties.FECH_INI;
}

var lay1 = L.geoJson(json_Obras,{
        pointToLayer: function (feature, latlng) {

        var markerStyle = { 
            fillColor: getColor(feature.properties.OBRA),
            color: "#FFF",
            fillOpacity: 1,
            opacity: 1,
            weight: 1,
            radius: 8
        };

        return L.circleMarker(latlng, markerStyle)
    },
        onEachFeature: onEachFeature,
    }).addTo(map);


function getColor(status) {
return  status == "Construccion Cancha"     ? 'rgba(182,220,86,1.0)' :
        status == "Construccion Sede Social"    ? 'rgba(233,95,194,1.0)' :
        status == "Mejoramiento Multicancha"  ? 'rgba(162,59,225,1.0)' :
        status == "Construcción"  ? 'rgba(214,112,117,1.0)' :
        status == "Remodelacion Sede Social"       ? 'rgba(211,124,192,1.0)' :
        status == "Instalacion Pasto Sintetico"  ? 'rgba(106,240,191,1.0)' :
        status == "Reconstruccion Techo"  ? 'rgba(117,195,226,1.0)' :
        status == "Construccion Balsa"       ? 'rgba(24,214,17,1.0)' :
        status == "Arreglo Sede social centro de madres"       ?    'rgba(110,231,138,1.0)' :
        status == "Mejoramiento Sede Social"       ? 'rgba(104,110,228,1.0)' :
                                   '#353942';
}

它是一个geojson对象,按属性加载颜色,HTML div中的值,我的ifdea是当页面上出现信息时突出显示所选功能,谢谢!!

0 个答案:

没有答案