<div dir="ltr"><p style="margin:0px 0px 1em;padding:0px;border:0px;font-size:14px;vertical-align:baseline;clear:both;color:rgb(51,51,51);font-family:'Helvetica Neue',Helvetica,Arial,sans-serif;line-height:18px;background-color:rgba(248,248,248,0.6)">Hello everybody,</p><p style="margin:0px 0px 1em;padding:0px;border:0px;font-size:14px;vertical-align:baseline;clear:both;color:rgb(51,51,51);font-family:'Helvetica Neue',Helvetica,Arial,sans-serif;line-height:18px;background-color:rgba(248,248,248,0.6)">I am trying dynamical give a color to some points read by a GeoJSON file. I am taking inspiration by this post<br></p><p style="margin:0px 0px 1em;padding:0px;border:0px;font-size:14px;vertical-align:baseline;clear:both;color:rgb(51,51,51);font-family:'Helvetica Neue',Helvetica,Arial,sans-serif;line-height:18px;background-color:rgba(248,248,248,0.6)"><a href="http://gis.stackexchange.com/questions/42401/how-can-i-add-an-infowindow-to-an-openlayers-geojson-layer" style="margin:0px;padding:0px;border:0px;vertical-align:baseline;text-decoration:none;color:rgb(53,141,170)">How can I add an infowindow to an OpenLayers GeoJSON layer?</a></p><p style="margin:0px 0px 1em;padding:0px;border:0px;font-size:14px;vertical-align:baseline;clear:both;color:rgb(51,51,51);font-family:'Helvetica Neue',Helvetica,Arial,sans-serif;line-height:18px;background-color:rgba(248,248,248,0.6)">but I can't get what is wrong in my code:</p><pre style="margin-top:0px;margin-bottom:10px;padding:5px;border:0px;font-size:12px;vertical-align:baseline;overflow:auto;width:auto;max-height:600px;font-family:Consolas,Menlo,Monaco,'Lucida Console','Liberation Mono','DejaVu Sans Mono','Bitstream Vera Sans Mono','Courier New',monospace,serif;background-color:rgb(238,238,238);word-wrap:normal;color:rgb(51,51,51);line-height:18px"><code style="margin:0px;padding:0px;border:0px;vertical-align:baseline;font-family:Consolas,Menlo,Monaco,'Lucida Console','Liberation Mono','DejaVu Sans Mono','Bitstream Vera Sans Mono','Courier New',monospace,serif;color:rgb(34,34,34);white-space:inherit">    <script type="text/javascript">


        var map;
        function initMap() {
            map = new OpenLayers.Map("info");
            var mapnik = new OpenLayers.Layer.OSM();
            map.addLayer(mapnik);

            map.addControl(new OpenLayers.Control.ScaleLine());
            map.addControl(new OpenLayers.Control.OverviewMap());
            map.addControl(new OpenLayers.Control.MousePosition());
            map.addControl(new OpenLayers.Control.LayerSwitcher());


             var myStyles = new OpenLayers.StyleMap({
                    "default": new OpenLayers.Style({
                        fillColor: "${getColor}",
                        strokeWidth: 1,        
                        strokeColor: "#000",
                        fillOpacity: 0.8,
                        graphicZIndex: 5 

                    },
                    {
                    context: {
                       getColor : function (feature) {
                          return feature.attributes.colore > 2 ? '#ffc000' :
                                 feature.attributes.colore > 1 ? '#00317c' :
                                                                 '#FFEDA0' ;
                         }
                       } 
                  })
              }); 

            var geojson_layer = new OpenLayers.Layer.Vector("GeoJSON", { 
                    styleMap: myStyles, 
                    projection: new OpenLayers.Projection("EPSG:4326"),
                    strategies: [
                        new OpenLayers.Strategy.Fixed()], 
                    protocol: new OpenLayers.Protocol.HTTP({ 
                        url: "colori.json", 
                    format: new OpenLayers.Format.GeoJSON() 
                }) 
            });

            map.addLayer(geojson_layer);

            map.setCenter(
                new OpenLayers.LonLat(8.692, 49.412).transform(
                    new OpenLayers.Projection("EPSG:4326"),
                    map.getProjectionObject()
                ), 10
            );

        }

    </script>
</code></pre><p style="margin:0px 0px 1em;padding:0px;border:0px;font-size:14px;vertical-align:baseline;clear:both;color:rgb(51,51,51);font-family:'Helvetica Neue',Helvetica,Arial,sans-serif;line-height:18px;background-color:rgba(248,248,248,0.6)">and here is the GeoJSON file colori.json I am trying to use:</p><pre style="margin-top:0px;margin-bottom:10px;padding:5px;border:0px;font-size:12px;vertical-align:baseline;overflow:auto;width:auto;max-height:600px;font-family:Consolas,Menlo,Monaco,'Lucida Console','Liberation Mono','DejaVu Sans Mono','Bitstream Vera Sans Mono','Courier New',monospace,serif;background-color:rgb(238,238,238);word-wrap:normal;color:rgb(51,51,51);line-height:18px"><code style="margin:0px;padding:0px;border:0px;vertical-align:baseline;font-family:Consolas,Menlo,Monaco,'Lucida Console','Liberation Mono','DejaVu Sans Mono','Bitstream Vera Sans Mono','Courier New',monospace,serif;color:rgb(34,34,34);white-space:inherit">{"type":"FeatureCollection",
    "features":[
        {"type":"Feature",
            "properties":{
                "colore": 7
            },
            "geometry":{
                "type":"Point",
                "coordinates":[8.692, 49.412]
            }
        }
    ]
}</code></pre><div>Thanks for your help!</div><div><br></div><div>Niccolò</div><div><br></div><div><br></div>-- <br>Niccolò Dal Santo<div>+39 342 15 70 842</div><div><a href="mailto:ncl.dalsanto@gmail.com" target="_blank">ncl.dalsanto@gmail.com</a></div>
</div>