[OpenLayers-Users] GeoJSON and SelectFeature control
Robert Sanson
SansonR at asurequality.com
Sun Nov 2 15:20:21 EST 2008
Hi Adorian
I have some code that does this:
//First I specify the format
var geojson_format = new OpenLayers.Format.GeoJSON();
//Then I load some geoJSON from another Web page:
var cropsurl = 'http://web-cf8dev.agriquality.co.nz/wstest/scid_ajax.cfm?mode=getFeatures&Farm_id=' + farmid;
OpenLayers.loadURL(cropsurl, '', this, cropsreturn);
//Then it is serialised into a Vector layer
crops = new OpenLayers.Layer.Vector("Crop areas",
{isBaseLayer: false,
style: crop_style,
extractAttributes: true });
crops.addFeatures(geojson_format.read(cropsresponse.responseText));
map.addLayer(crops);
//My select feature control is set up along with a group of other controls:
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]);
}
//I toggle which controls are active by a set of radio buttons outside the map div
for(key in controls) {
var control = controls[key];
if(element.value == key && element.checked) {
control.activate();
} else {
control.deactivate();
}
}
Hope that helps.
Cheers,
Robert Sanson
>>> "Adorian Ardelean" <mynature at gmail.com> 1/11/2008 6:14 a.m. >>>
Hi,
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.
I would like to know if it is possible to use SelectFeature control with a GeoJSON layer.
All the best,
Adorian
If helpful for reply, here are bits of code I use. For control:
var regioninfo = new OpenLayers.Control.SelectFeature(regions, {hover: true, onSelect: getregioninfo});
map.addControl(regioninfo);
regioninfo.activate();
where regions is GeoJSON layer and getregioninfo is the function that will serialize the feature.
For creating and reloading the layer GeoJSON I use:
var regions = new OpenLayers.Layer.Vector("regions",{format: OpenLayers.Format.GeoJSON});
OpenLayers.loadURL(url, {}, null, onloadjson, onloadfailedjson);
--
Dr. Adorian Ardelean
coordinator of myNature Project
http://mybiosis.info/nature/portal.php?pagename=firstpage [a Romanian biodiversity-database]
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/20081103/c3f64182/attachment.html
More information about the Users
mailing list