[OpenLayers-Users] popup with wfs marker layer...

John Cole john.cole at uai.com
Tue Mar 13 19:35:53 EDT 2007


Christopher,
  I've made it a little further...  I've subclassed Feature.WFS into
Feature.WFS.Marker, and I'm parsing the GML to get the 'gid' and creating
the feature with that ID and gid.  But I'm having problems getting back to
that gid from the evt object.

Here is my class (and debug routine) so far.  Any suggestions?  I was
expecting the evt object to have the gid, or an object attached to the evt
object to have it.

function DumpResult(source, result)
{
var s = "<plaintext>";
s = s + source + " " + "\n";
for (var x in result) {
	s = s + x + "=" + result[x] + "\n";
}

if (result.get_stackTrace) s = s + result.get_stackTrace() + "\n";
s = s + "</pre>";

document.getElementById("DebugDiv").innerHTML = s;
}

OpenLayers.Feature.WFS.Marker = OpenLayers.Class.create();
OpenLayers.Feature.WFS.Marker.prototype = 
OpenLayers.Class.inherit( OpenLayers.Feature.WFS, {
  
/** 
 * @constructor
 * 
 * @param {OpenLayers.Layer} layer
 * @param {XMLNode} xmlNode
 */
initialize: function(layer, xmlNode) {
	var newArguments = arguments;
	var data = this.processXMLNode(xmlNode);
	newArguments = new Array(layer, data.lonlat, data)
	OpenLayers.Feature.prototype.initialize.apply(this, newArguments);
	DumpResult("initialize", this);
	this.createMarker();
	this.marker.events.register('click', this, this.markerClick); 
	this.layer.addMarker(this.marker);
},

/**
 * @param {XMLNode} xmlNode
 * 
 * @returns Data Object with 'id', 'lonlat', and private properties set
 * @type Object
 */
processXMLNode: function(xmlNode) {
	//this should be overridden by subclasses
	// must return an Object with 'id' and 'lonlat' values set
	var point = OpenLayers.Ajax.getElementsByTagNameNS(xmlNode,
"http://www.opengis.net/gml", "gml", "Point");
	var text  =
OpenLayers.Util.getXmlNodeValue(OpenLayers.Ajax.getElementsByTagNameNS(point
[0], "http://www.opengis.net/gml","gml", "coordinates")[0]);
	var floats = text.split(",");
	var gid =
OpenLayers.Util.getXmlNodeValue(OpenLayers.Ajax.getElementsByTagNameNS(xmlNo
de, "http://mapserver.gis.umn.edu/mapserver", "ms", "gid")[0]);
	
	//DumpResult("processXMLNode", text);
	//document.getElementById("DebugDiv").innerHTML = gid;
	return {lonlat: new OpenLayers.LonLat(parseFloat(floats[0]),
	
parseFloat(floats[1])),
			id: gid, gid: gid};

},

/**
 * @param {Event} evt
 */
markerClick: function(evt) {
	
	DumpResult("markerClick", evt);
	OpenLayers.Event.stop(evt);
},
	
/** @final @type String */
CLASS_NAME: "OpenLayers.Feature.WFS.Marker"
});

Thanks,

John

-----Original Message-----
From: Christopher Schmidt [mailto:crschmidt at metacarta.com] 
Sent: Sunday, March 11, 2007 11:18 AM
To: John Cole
Cc: 'users at openlayers.org'
Subject: Re: [OpenLayers-Users] popup with wfs marker layer...

On Sun, Mar 11, 2007 at 09:19:53AM -0600, John Cole wrote:
> Christopher,
>   I'm not married to the markers, but it seems to fit the bill for this
> application.  Will the new WFS allow points to be rendered with a bitmap
as
> well as a vector symbol?
> 
>   In either case, it would be very nice to have an option to attach a
> feature level event to vector layers, to handle selection/info/editing of
> WFS features.
> 
>   To make sure I understand how to do what I want with the 2.3 WFS
markers,
> I need to create a new class, inherit from OpenLayers.Layer.WFS and
override
> the function that populates the markers array, attaching my event handler
as
> the markers are created.  That seems ok, but I can't seem to find the
> function that actually loads the markers, could you provide a hint as to
> it's location? :-)

Hm, that's not the way I had intended it to work. Instead, what you
should be able to do is pass a different featureClass option to the
layer. In the default WFS example, it has:  

{ featureClass: OpenLayers.Feature.WFS}

You should subclass OpenLayers.Feature.WFS: It has:

        this.createMarker();
        this.layer.addMarker(this.marker);

in the initialize function: you should probably change this to something
like:
this.marker.events.register('click', this, this.markerClick);
this.layer.addMarker(marker);

and then define a 'markerClick' event on the feature similar to the
Layer.Text.

The more I think about it, the more I feel we probably need to keep the
non-vector WFS layer. Which is a shame, cause I really don't like the
code :) Thanks for the feedback -- let me know if this doesn't help.

Regards, 
-- 
Christopher Schmidt
MetaCarta

-- 
No virus found in this incoming message.
Checked by AVG Free Edition.
Version: 7.5.446 / Virus Database: 268.18.8/718 - Release Date: 3/11/2007
9:27 AM
 

-- 
No virus found in this outgoing message.
Checked by AVG Free Edition.
Version: 7.5.446 / Virus Database: 268.18.10/720 - Release Date: 3/12/2007
7:19 PM
 
This email and any files transmitted with it are confidential and intended solely for the use of the individual or entity to whom they are addressed. If you have received this email in error please notify the sender. This message contains confidential information and is intended only for the individual named. If you are not the named addressee you should not disseminate, distribute or copy this e-mail.



More information about the Users mailing list