[OpenLayers-Users] GeoJSON layer and modifyFeature control

Robert Sanson SansonR at asurequality.com
Thu Dec 4 15:11:34 EST 2008


This works for me:
 
var crop_style = OpenLayers.Util.extend({}, OpenLayers.Feature.Vector.style['default']);
                crop_style.strokeWidth = 3;
                crop_style.strokeColor = "#ff0000";
                crop_style.fillOpacity = 0.25; 
                crop_style.pointRadius = 2;
 
var geojson_format = new OpenLayers.Format.GeoJSON();
 
var crops = new OpenLayers.Layer.Vector("Crop areas",
                  {isBaseLayer: false,
                   style: crop_style, 
                   extractAttributes: true }); 
                   crops.addFeatures(geojson_format.read(cropsresponse.responseText));
                 map.addLayer(crops);

controls = {
                select: new OpenLayers.Control.SelectFeature(crops, {callbacks: {'over':feature_info}}),
                dpolygon: new OpenLayers.Control.DrawFeature(crops,OpenLayers.Handler.Polygon),
                modify: new OpenLayers.Control.ModifyFeature(crops),
                delf: new OpenLayers.Control.SelectFeature(crops, {onSelect: function(feature) {crops.destroyFeatures([feature])}})
                   };
              for(var key in controls) {
                map.addControl(controls[key]);
              }
            }
Hope this helps,
 
Robert Sanson

>>> "Adorian Ardelean" <mynature at gmail.com> 5/12/2008 7:53 a.m. >>>
Hi Eric,

No...it is not working yet. There is some improvement indeed: I can see now the selection style, but vertexes are still not editable.

I have tried to adapt the suggestion in post I have mentioned earlier. 

var styleMap = new OpenLayers.StyleMap(); 

var rules = [new OpenLayers.Rule({
symbolizer: template, 
elseFilter: true
})];
styleMap.styles["default"].addRules(rules); 

Using this the edit polygon works!!!. However, I did not figured out how to include "context" within this. Select style is also not visible (but I do not mind this, I can most probably find a work around for selection style).

Initially I have used:
var mystyle = new OpenLayers.Style(template, {context: context}); 
var styleMap = new OpenLayers.StyleMap(mystyle); 
And context worked fine.

Any hints on how to include context with rules?

Thank you,
Adorian



On Thu, Dec 4, 2008 at 5:58 PM, Eric Lemoine <eric.c2c at gmail.com> wrote:


Hello

Try:

new OpenLayers.StyleMap({
   "default": yourStyle
});

Hope this helps,

Eric

2008/12/4, Adorian Ardelean <mynature at gmail.com>:
> Hi again,
>
> I have eliminated also the context for style as a source of problem for the
> modifyFeature control not working. So it seems that just by specifying a
> styleMap as option when declaring the vector layer makes the modifyFeature
> control not functional.
>
> var template = {
>     fillOpacity: 0.6,
>     fillColor: "red",
>     strokeColor:"orange",
>     strokeWidth:"1"
>     };
>
> var mystyle = new OpenLayers.Style(template);
>
> var regions = new OpenLayers.Layer.Vector("regions",{extractAttributes:true,
> format: OpenLayers.Format.GeoJSON, projection: new
> OpenLayers.Projection("EPSG:4326"), styleMap: new
> OpenLayers.StyleMap(mystyle)});
>
>
> I think the solution might be somewhere in the post:
> StyleMap and ModifyFeatures aren't compatible ?I will give it a try.
>
> All the best,
> Adorian
>
>
> 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]
>




-- 
Dr. Adorian Ardelean
coordinator of myNature Project

proiectul myNature
str. Rascoala din 1907 nr 12
Timisoara 300523
Romania

http://mybiosis.info/nature/portal.php?pagename=firstpage [a Romanian biodiversity-database]
http://mybiosis.info/nature/portal.php?pagename=adorian [CV]


Projects in which I was involved:
http://hercules.kgs.ku.edu/Hexacoral/Anemone2/ [Hexacorallians of the World]
http://www.ubio.org [uBio Project]
http://portal.ubio.org [uBio Portal]
http://microscope.mbl.edu [micro*scope Project]
http://starcentral.mbl.edu/biopedia [BioPedia]
http://starcentral.mbl.edu/custar [CU*STAR]
http://planktonnet.awi.de/index.php [planktonNet]

Yahoo messenger: transylvaniasan



Click here ( https://www.mailcontrol.com/sr/wQw0zmjPoHdJTZGyOCrrhg== ) to report this email as spam.
------------------------------------------------------------------
The contents of this email are confidential to AsureQuality. If you have received this communication in error please notify the sender immediately and delete the message and any attachments. The opinions expressed in this email are not necessarily those of AsureQuality. This message has been scanned for known viruses before delivery. AsureQuality supports the Unsolicited Electronic Messages Act 2007. If you do not wish to receive similar communications in future, please notify the sender of this message.
------------------------------------------------------------------


This message has been scanned for malware by SurfControl plc. www.surfcontrol.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/openlayers-users/attachments/20081205/7af66951/attachment.html


More information about the Users mailing list