spring-roolegend-propertiesgvnix

How to change fillColor due a field value


I have a map with some features, but I want to shoe them depending on al field.

May be

if [fieldname] = 0 --> color = RED else --> color = blue

Could anyone give a clue where to start?

Searching at leaflet documentation I managed to program

function getColor(d) {
    return d = 0 ? '#3182bd' :
           d = 1 ? '#31a354' :
                    '#FFEDA0';
}

function style(feature) {
return {
        fillColor: getColor(feature.properties.*fieldname*),
    };

}

But I'm not sure how to integer it, if I'm on the way or there's something easier with gvnix

Thanks all Javier


Solution

  • In your gvNIX view you can customize the symbol used to draw a geometry using the attribute fnAjustRender of entity-field tagx. Using this method you must declare a script in .jspx page and register it in the attribute.

    By example, in show.jspx entity fied definition you should change:

    ....
    <layer:entity-field clusterize="false" 
            fnAjustRender="myJSFunction"   .... z="user-managed"/>
    ....
    

    Then create a myJSFunction in jspx like this:

    <script>
      function myJSFunction(gvmap, layerId, fieldName, 
           featurePk, leafletLayer, featureData, isSelected) {
    
          var iconColor = "white";
          if (featureData.propName == 1) {
            iconColor = "red";
          } else {
            iconColor = "blue";
          }
          var iconMarker = L.AwesomeMarkers.icon({
                    "icon" : icon,
                    "prefix" : prefix,
                    "markerColor" : markerColor,
                    "iconColor" : iconColor
                });
           leafletLayer.setIcon(iconMarker);
           return leafletLayer;
      }
    
    </script>
    

    Warning: no tested code

    Good luck!