[OpenLayers-Users] GeoJSON layer and modifyFeature control

Adorian Ardelean mynature at gmail.com
Fri Dec 5 04:28:02 EST 2008


Hi Eric,

I've already passed through something like this. At least the code looks
similar to me. Code is below:

var mycontext =  {
    getColor: function(feature)
    {
    var jsonvalue = feature.attributes["fillcolor"];
    return  jsonvalue;
    }
};
var contexttemplate = {
    fillOpacity: 0.6,
    fillColor: "${getColor}",
    strokeColor:"orange",
    strokeWidth:"1"
    };

var contextStyle = new OpenLayers.Style(contexttemplate,mycontext);
var myStyleMap = new OpenLayers.StyleMap({"default":contextStyle});

var rules = [new OpenLayers.Rule({
symbolizer: contexttemplate,
context: mycontext,
elseFilter: true
})];
myStyleMap.styles["default"].addRules(rules);
myStyleMap.styles["select"].addRules(rules); (w/ or w/o this line does not
work)

var regions = new OpenLayers.Layer.Vector("regions",{extractAttributes:true,
format: OpenLayers.Format.GeoJSON, projection: new
OpenLayers.Projection("EPSG:4326"), styleMap: myStyleMap});


The fill color is not changed accordingly to color I have in GeoJSON file
under attribute fillcolor. All other properties in template are applied. The
edit function does not work.
If I remove {"default":contextStyle} from OpenLayers.StyleMap(
{"default":contextStyle});  and we remain only with
var myStyleMap = new OpenLayers.StyleMap();  and all rest of code the same,
the edit function works. But still no fillcolor context is applied.

I have also oversimplified the code in a separate page, but result is
identical.

All the best,
Adorian


> I added the code below to the modify-feature.html example and it
> worked for me (code is based on Alexandre's):
>
>            var tpl = {
>                 pointRadius: "${radius}",
>                fillOpacity: 0.4,
>                strokeColor: "#000000",
>                strokeWidth: 2
>             };
>            var ctx = {
>                context: {
>                    radius: function(feature) {
>                        return 10;
>                    }
>                }
>            };
>
>            var oStyle = new OpenLayers.Style(tpl, ctx);
>
>            var oStyleMap = new OpenLayers.StyleMap({
>                "default": oStyle,
>                 // works w/ or w/o the following
>                 "select": new OpenLayers.Style({
>                    fillColor: "#66ccff",
>                    fillOpacity: 0.2,
>                    strokeColor: "#3399ff"
>                })
>            });
>
>            var aoTypeColor = {
>                '1': {fillColor:"blue"},
>                '2': {fillColor:"red"},
>                '3': {fillColor:"yellow"},
>                '4': {fillColor:"white"}
>            };
>
>            oStyleMap.addUniqueValueRules("default", "Type", aoTypeColor);
>            oStyleMap.addUniqueValueRules("select", "Type", aoTypeColor);
>
>             var rules = [
>                new OpenLayers.Rule({
>                     symbolizer: tpl,
>                    context: ctx,
>                    elseFilter: true
>                })
>            ];
>            oStyleMap.styles["default"].addRules(rules);
>            oStyleMap.styles["select"].addRules(rules);
>
>
>
> --
> Eric
>



-- 
Dr. Adorian Ardelean
coordinator of myNature Project

http://mybiosis.info/nature/portal.php?pagename=firstpage [a Romanian
biodiversity-database]
http://mybiosis.info/nature/portal.php?pagename=adorian [CV]
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/openlayers-users/attachments/20081205/e9b7a0ef/attachment.html


More information about the Users mailing list