Further to this, I have removed the featureClass parameter, and included
extractAttributes: true:
var wfs = new OpenLayers.Layer.WFS("API WFS",
"http://10.65.192.1/cgi-bin/apiwfs.exe?",
{typename: 'apiaries_dev', maxfeatures: 100, extractAttributes: true},
{scales: [150000, 10]});
map.addLayers([wms1,wfs]);
I have added:
var options = {
hover: true,
onSelect: function(feature) {
OpenLayers.Util.getElement('apiary').innerHTML =
feature.attributes.apiary_id;
}
};
var select = new OpenLayers.Control.SelectFeature(wfs, options);
map.addControl(select);
//select.handler.stopDown = false;
//select.handler.stopUp = false;
select.activate();
This allows me to hover over each point and select it, however I am struggling
to get at the attributes still. Here is a sample of the GML returned by
Mapserver:
<gml:Point srsName="EPSG:2193">
<gml:coordinates>1824867.377072,5534693.953457</gml:coordinates>
</gml:Point>
</ms:msGeometry>
<ms:apiary_id>88883</ms:apiary_id>
<ms:x_nzmg>2734900</ms:x_nzmg>
<ms:y_nzmg>6096500</ms:y_nzmg>
<ms:beekeeper_reg_no>H0733</ms:beekeeper_reg_no>
<ms:maf_id>7</ms:maf_id>
</ms:apiaries_dev>
</gml:featureMember>
</wfs:FeatureCollection>
There are 5 attributes: apiary_id, x_nzmg, y_nzmg, beekeeper_reg_no, maf_id
However, the onSelect function above returns "undefined" into the apiary div.
How should I reference the attribute fields in each feature?
Many thanks,
Robert Sanson
>>> "Robert Sanson" <[EMAIL PROTECTED]> 21/05/2008 10:07 a.m. >>>
I have a n OpenLayers map that displays point markers for a WFS layer served
from Mapserver. The source data is an OGR Virtual layer reading froma table in
a SQL-server database with x,y fields in a table.
Here is the OL snippet that adds the layer:
var wfs = new OpenLayers.Layer.WFS("API WFS",
"http://10.65.192.1/cgi-bin/apiwfs.exe?",
{typename: 'apiaries_dev', maxfeatures: 100},
{scales: [150000, 10], featureClass: OpenLayers.Feature.WFS});
map.addLayers([wms1,wfs]);
map.setBaseLayer(wms1);
The layer displays fine on top of a base WMS layer.
I want to be able to select a single marker using a CTRL-click, and send the
attributes to a div below the map. Next I want to be able to capture a new
location for the marker using ALT-click, and send the map coordinates to a
separate div. From there, I will formulate a POST to a server to update the
location in the source table.
The code for capturing the coordinates is as follows:
//add various map controls
var control = new OpenLayers.Control();
OpenLayers.Util.extend(control, {
draw: function () {
// this Handler.Point will intercept the ctrl-mousedown
// before Control.MouseDefault gets to see it
this.point = new OpenLayers.Handler.Point( control,
{"done": this.notice},
{keyMask: OpenLayers.Handler.MOD_ALT});
this.point.activate();
},
notice: function (bounds) {
document.getElementById('apiary').innerHTML = bounds;
}
});
map.addControl(control);
This works.
However, I have no idea as to how to select and then get at the attributes of
the WFS layer. Any help appreciated.
Many thanks,
Robert Sanson
------------------------------------------------------------------
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
Click here 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.
------------------------------------------------------------------
_______________________________________________
Users mailing list
[email protected]
http://openlayers.org/mailman/listinfo/users