1

I have a problem. I would like to set a separate mouseout conditions for one of the geoJson.property value.

The sitoation looks as follows:

I set function for

function style2(feature) {
if (feature.properties.Post_Survey_Home_Count === "")
    return{
    fillColor: '#ffff99',
    fillOpacity: '#ffff99',
    weight: 0.5
    }
    else
return {
    fillColor: getColor2(feature.properties.Type),
    fillOpacity: 1,
    weight: 2,
    opacity: 0.75,
    //color: '#ffffff',
    //dashArray: '3'
};
}

and next in terms of these statements I would like to set a separate mouseout function for this one geoJSON property:

So that I tried:

   layer.on({ 
                mouseover: function (e) {
                    this.setStyle({
                        'fillColor': '#663300',
                        'weight':11
                    });
                },
                mouseout: function (e) {
                    if (feature.properties.Post_Survey_Home_Count === ""){
                    this.setStyle({
                        'fillColor':'#ffff99',
                        'weight': 0.5
                    }) else {
                    this.setStyle({
                        'fillColor': getColor2(feature.properties.Type),
                        'weight': 2
                    });
                }
                }

But my map is gone. Console says about unexpected tokens, when I fixed them the console says: Unepxpected "else". Does it mean, that if statements are not available for the mouseover and mouseout function?

1 - before mouseover 2 - after mouseover - the view back to typical for a whole layer instead of this one property

enter image description here

  • What about adding missing } before else? – TomazicM Nov 15 at 12:20
  • Not working mate, however you are right. Technically it should be there, but tere is still not a result. Even concole doesn't help me here,. as it stands that some tokens are unexpectable or missing, where they should be. – Mariusz Krukar Nov 15 at 13:02
0

I believe, that much more convenient is to use the resetStyle statement. In this event my code looks as follows:

   layer.on({ 
                mouseover: function (e) {
                    this.setStyle({
                        'fillColor': '#663300',
                        'weight':11
                    });
                },
                mouseout: function (e) {
                 job2.resetStyle(this);   //job2 is my GeoJson layer name
                }
            }); //layer.on finish

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.