<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=iso-8859-15">
<META content="MSHTML 6.00.2900.3243" name=GENERATOR></HEAD>
<BODY>
<DIV>Hi Adorian</DIV>
<DIV> </DIV>
<DIV>I have some code that does this:</DIV>
<DIV> </DIV>
<DIV>//First I specify the format</DIV>
<DIV>var geojson_format = new OpenLayers.Format.GeoJSON();</DIV>
<DIV> </DIV>
<DIV>//Then I load some geoJSON from another Web page:</DIV>
<DIV>var cropsurl = 'http://web-cf8dev.agriquality.co.nz/wstest/scid_ajax.cfm?mode=getFeatures&Farm_id=' + farmid;<BR>OpenLayers.loadURL(cropsurl, '', this, cropsreturn);</DIV>
<DIV> </DIV>
<DIV>//Then it is serialised into a Vector layer</DIV>
<DIV>crops = new OpenLayers.Layer.Vector("Crop areas",<BR> {isBaseLayer: false,<BR> style: crop_style, <BR> extractAttributes: true }); <BR> crops.addFeatures(geojson_format.read(cropsresponse.responseText));<BR> map.addLayer(crops);</DIV>
<DIV> </DIV>
<DIV>//My select feature control is set up along with a group of other controls:</DIV>
<DIV>controls = {<BR> select: new OpenLayers.Control.SelectFeature(crops, {callbacks: {'over':feature_info}}),<BR> dpolygon: new OpenLayers.Control.DrawFeature(crops,OpenLayers.Handler.Polygon),<BR> modify: new OpenLayers.Control.ModifyFeature(crops),<BR> delf: new OpenLayers.Control.SelectFeature(crops, {onSelect: function(feature) {crops.destroyFeatures([feature])}})<BR> };<BR> for(var key in controls) {<BR> map.addControl(controls[key]);<BR> }</DIV>
<DIV>//I toggle which controls are active by a set of radio buttons outside the map div</DIV>
<DIV>for(key in controls) {<BR> var control = controls[key];<BR> if(element.value == key && element.checked) {<BR> control.activate();<BR> } else {<BR> control.deactivate();<BR> }<BR> }</DIV>
<DIV> </DIV>
<DIV>Hope that helps.</DIV>
<DIV> </DIV>
<DIV>Cheers,</DIV>
<DIV> </DIV>
<DIV>Robert Sanson</DIV>
<DIV><BR>>>> "Adorian Ardelean" <mynature@gmail.com> 1/11/2008 6:14 a.m. >>><BR>Hi, <BR><BR>I am trying to link a SelectFeature control to a dynamically loaded GeoJSON layer. I would like to serialize features drawn in this layer, but it seems that SelectFeature control does not work for me. Hover effect does not show either. Features from JSON layer are polygons. <BR><BR>I would like to know if it is possible to use SelectFeature control with a GeoJSON layer. <BR><BR>All the best, <BR>Adorian <BR><BR><BR>If helpful for reply, here are bits of code I use. For control: <BR>var regioninfo = new OpenLayers.Control.SelectFeature(regions, {hover: true, onSelect: getregioninfo}); <BR>map.addControl(regioninfo); <BR>regioninfo.activate(); <BR><BR>where regions is GeoJSON layer and getregioninfo is the function that will serialize the feature. <BR><BR>For creating and reloading the layer GeoJSON I use: <BR>var regions = new OpenLayers.Layer.Vector("regions",{format: OpenLayers.Format.GeoJSON}); <BR>OpenLayers.loadURL(url, {}, null, onloadjson, onloadfailedjson);<BR clear=all><BR>-- <BR>Dr. Adorian Ardelean<BR>coordinator of myNature Project<BR><BR><A href="http://mybiosis.info/nature/portal.php?pagename=firstpage">http://mybiosis.info/nature/portal.php?pagename=firstpage</A> [a Romanian biodiversity-database]<BR><BR><BR><BR><BR><BR></DIV><FONT style="BACKGROUND-COLOR: #ffffff">
<P align=center><FONT style="BACKGROUND-COLOR: #ffffff">Click <A href="https://www.mailcontrol.com/sr/wQw0zmjPoHdJTZGyOCrrhg==">here</A> to report this email as spam.</FONT></P></FONT><br><br><table bgcolor=white style="color:black"><tr><td><br>------------------------------------------------------------------<br>
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.<br>
------------------------------------------------------------------</td></tr></table><br><br>
<P align=center><FONT style="BACKGROUND-COLOR: #ffffff">This message has been scanned for malware by SurfControl plc. </FONT><A href="http://www.surfcontrol.com/"><FONT style="BACKGROUND-COLOR: #ffffff" color=#000000>www.surfcontrol.com</FONT></A></P>
</body></HTML>