[OpenLayers-Users] GeoJSON and SelectFeature control

Adorian Ardelean mynature at gmail.com
Tue Nov 4 01:43:23 EST 2008


Hi Robert,

Thank you for your reply! I have a very similar way to load the geoJSON file
and handle the controls outside map div. Except that I put part of code for
loading geoJSON in a function: I want only one GeoJSON layer in which I
load/switch an indeterminate number of GeoJSON files. This part is working
well.

In this project I have actually two vector layers: One which is used just
for drawing things on map (temporarily) and the other one which is the
GeoJSON layer. For both vector layers I've declared distinct SelectFeature
controls with intention of calling a "featureinfo" function. Beside this I
include a draw polygon and delete feature control (the last one is again a
SelectFeature control actually). It seems that functionality was affected by
the way I have declared the controls, and one of the controls "did not like"
going with the others.

In the end I found a "solution" and the thing is working now. I currently
have no idea why it did not work and why is now working. But I am happy with
the result.
See below two code versions of how I declare controls:

example 1 :
controls = {
            polygon: new
OpenLayers.Control.DrawFeature(vectors,OpenLayers.Handler.Polygon),
            polygoninfo: new OpenLayers.Control.SelectFeature(vectors,
{hover: true, onSelect: serialize}),
            deletepolygon: new OpenLayers.Control.SelectFeature(vectors,
{callbacks: {'click': deleteFeature}}),
            regioninfo: new OpenLayers.Control.SelectFeature(regions,
{callbacks: {'click': serialize}})
            };

example 1 is not working: delete and select functions do not work for both
vector layers (vectors and regions). only draw polygon works corectly.

example 2:
controls = {
            polygon: new
OpenLayers.Control.DrawFeature(vectors,OpenLayers.Handler.Polygon),
            };

var polygoninfo = new OpenLayers.Control.SelectFeature(vectors, {hover:
true, onSelect: serialize});
var deletepolygon = new OpenLayers.Control.SelectFeature(vectors,
{callbacks: {'click': deleteFeature}});
var regioninfo = new OpenLayers.Control.SelectFeature(regions, {callbacks:
{'click': serialize}});

map.addControl(polygoninfo);
polygoninfo.activate();
map.addControl(deletepolygon);
deletepolygon.activate();
map.addControl(regioninfo);
regioninfo.activate();

example 2 is working only partially. All controls work except regioninfo.

example 3:
controls = {
            polygon: new
OpenLayers.Control.DrawFeature(vectors,OpenLayers.Handler.Polygon),
            polygoninfo: new OpenLayers.Control.SelectFeature(vectors,
{hover: true, onSelect: serialize}),
            regioninfo: new OpenLayers.Control.SelectFeature(regions,
{callbacks: {'click': serialize}})
            };

var deletepolygon = new OpenLayers.Control.SelectFeature(vectors,
{callbacks: {'click': deleteFeature}});
map.addControl(deletepolygon);
deletepolygon.activate();

example 3 is working well. all functions are doing what they are supposed to
do. Personally I would prefer version 1 of code. However, since version 3
does the job I am glad that I could pass this point. It must be something I
do wrong when I declare callbacks or...I don't know....

Thank you again for your input,
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]
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/openlayers-users/attachments/20081104/f0b8ce0b/attachment.html


More information about the Users mailing list