Commit simplified Feature class. Features in the main OpenLayers parlance will not be the behemoth that they were in past versions, doing data parsing and everything on their own. Instead, a feature will be a minimal container for point-based data, to which other methods can be added: Feature.WFS might parse data out of XML, while Feature.Text might parse it out of CSV.
git-svn-id: http://svn.openlayers.org/trunk/openlayers@208 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
+11
-187
@@ -1,101 +1,24 @@
|
|||||||
|
|
||||||
|
|
||||||
/** Parse a feature from an XML node
|
|
||||||
* MC specific at the moment
|
|
||||||
*/
|
|
||||||
OpenLayers.Feature = Class.create();
|
OpenLayers.Feature = Class.create();
|
||||||
OpenLayers.Feature.prototype= {
|
OpenLayers.Feature.prototype= {
|
||||||
|
|
||||||
|
// events object
|
||||||
|
events:null,
|
||||||
|
|
||||||
|
// ol.LonLat
|
||||||
|
lonlat:null,
|
||||||
|
|
||||||
// Object
|
// Object
|
||||||
listeners:null,
|
data:null,
|
||||||
|
|
||||||
// ol.Size
|
initialize: function(lonlat, data) {
|
||||||
size:null,
|
this.lonlat = lonlat;
|
||||||
|
this.data = data;
|
||||||
// ol.LatLon
|
|
||||||
_latlon:null,
|
|
||||||
|
|
||||||
// str
|
|
||||||
id:"",
|
|
||||||
fid:null,
|
|
||||||
srsName:null,
|
|
||||||
title:null,
|
|
||||||
location:null,
|
|
||||||
docurl:null,
|
|
||||||
extract:null,
|
|
||||||
geoExtract:null,
|
|
||||||
relevance:null,
|
|
||||||
geoRelevance:null,
|
|
||||||
markerImage:null,
|
|
||||||
|
|
||||||
initialize: function(fNode) {
|
|
||||||
this.listeners = new Object();
|
|
||||||
|
|
||||||
var docpt = OpenLayers.getNodes(fNode, "docpoint")[0];
|
|
||||||
this.fid = docpt.getAttribute('fid');
|
|
||||||
this.id = this.fid;
|
|
||||||
|
|
||||||
var node = OpenLayers.getNodes(docpt, "position")[0];
|
|
||||||
node = OpenLayers.getNodes(node, "gml:Point")[0];
|
|
||||||
this.srsName = node.getAttribute('srsName');
|
|
||||||
var temp = OpenLayers.getTagText(node, "gml:coordinates");
|
|
||||||
this._latlon = ol.LatLon.fromString(temp);
|
|
||||||
|
|
||||||
this.title = OpenLayers.getTagText(docpt, "title");
|
|
||||||
this.location = OpenLayers.getTagText(docpt, "locationName");
|
|
||||||
this.docurl = OpenLayers.getTagText(docpt, "documentUrl");
|
|
||||||
this.extract = OpenLayers.getTagText(docpt, "extract");
|
|
||||||
this.geoExtract = OpenLayers.getTagText(docpt, "geoextract");
|
|
||||||
this.relevance = OpenLayers.getTagText(docpt, "relevance");
|
|
||||||
this.geoRelevance = OpenLayers.getTagText(docpt, "georelevance");
|
|
||||||
|
|
||||||
this.markerImage = OpenLayers.getTagText(docpt, "markerImage");
|
|
||||||
this.size = new ol.Size(20, 25); // TODO: Fix this hard coded value.
|
|
||||||
},
|
},
|
||||||
|
|
||||||
destroy: function() {
|
destroy: function() {
|
||||||
this.listeners = null;
|
|
||||||
this.fid = null;
|
|
||||||
this.id = null;
|
|
||||||
this.srsName = null;
|
|
||||||
this._latlon = null;
|
|
||||||
this.title = null;
|
|
||||||
this.location = null;
|
|
||||||
this.docurl = null;
|
|
||||||
this.extract = null;
|
|
||||||
this.geoExtract = null;
|
|
||||||
this.relevance = null;
|
|
||||||
this.geoRelevance = null;
|
|
||||||
this.markerImage = null;
|
|
||||||
this.size = null;
|
|
||||||
},
|
},
|
||||||
|
|
||||||
toString:function() {
|
|
||||||
var s = this.title + " relevance:" + this.relevance +
|
|
||||||
" [" + this.geoRelevance + "]";
|
|
||||||
s += " Fid [" + this.fid + "] @ " + this._latlon.toString();
|
|
||||||
s += " Location [" + this.geoExtract + "]";
|
|
||||||
return s;
|
|
||||||
},
|
|
||||||
|
|
||||||
/* MARKER DATA INTERFACE FUNCTIONS:
|
|
||||||
*
|
|
||||||
* getLatLon(), getImage()
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* ret(ol.Point)
|
|
||||||
*/
|
|
||||||
getLatLon:function() { return this._latlon.copyOf(); },
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* ret(ol.Point)
|
|
||||||
*/
|
|
||||||
getImage:function() { return this.markerImage; },
|
|
||||||
|
|
||||||
|
|
||||||
/** html content based on feature information
|
/** html content based on feature information
|
||||||
*
|
*
|
||||||
* ret(str):
|
* ret(str):
|
||||||
@@ -108,115 +31,16 @@ OpenLayers.Feature.prototype= {
|
|||||||
|
|
||||||
contentHTML += "<div style='height: 1.5em; overflow: hidden'>"
|
contentHTML += "<div style='height: 1.5em; overflow: hidden'>"
|
||||||
contentHTML += "<span style='font-size: 1.2em; font-weight: bold'>"
|
contentHTML += "<span style='font-size: 1.2em; font-weight: bold'>"
|
||||||
contentHTML += this.title;
|
contentHTML += this.data['title'];
|
||||||
contentHTML += "</span>"
|
contentHTML += "</span>"
|
||||||
contentHTML += "</div>"
|
contentHTML += "</div>"
|
||||||
contentHTML += "<br/>"
|
|
||||||
|
|
||||||
|
|
||||||
contentHTML += "<span style='font-size: 0.7em;'>"
|
|
||||||
contentHTML += "<b>Location:</b>";
|
|
||||||
contentHTML += this.location;
|
|
||||||
contentHTML += " (" + this.geoRelevance + ")";
|
|
||||||
contentHTML += "</span>"
|
|
||||||
contentHTML += "<br>";
|
|
||||||
contentHTML += "<br/>"
|
|
||||||
|
|
||||||
contentHTML += "<span style='font-size: 0.7em; align:center'>"
|
|
||||||
contentHTML += "<b>Extract:</b>";
|
|
||||||
contentHTML += "</span>"
|
|
||||||
contentHTML += "<br>";
|
|
||||||
contentHTML += "<span style='font-size: 0.7em; align:center'>"
|
|
||||||
contentHTML += this.extract;
|
|
||||||
contentHTML += "</span>"
|
|
||||||
|
|
||||||
contentHTML += "</div>"
|
contentHTML += "</div>"
|
||||||
|
|
||||||
return contentHTML;
|
return contentHTML;
|
||||||
},
|
},
|
||||||
|
|
||||||
/** html content based on feature information
|
|
||||||
*
|
|
||||||
* ret(str):
|
|
||||||
*/
|
|
||||||
getDivListHTML:function() {
|
|
||||||
|
|
||||||
var divHTML = '';
|
|
||||||
|
|
||||||
divHTML += '<div id="' + this.fid + '">';
|
|
||||||
divHTML += '<a href="' + this.docurl + '">';
|
|
||||||
divHTML += this.title;
|
|
||||||
divHTML += '</a><div>';
|
|
||||||
divHTML += this.extract;
|
|
||||||
divHTML += '</div></div>';
|
|
||||||
|
|
||||||
return divHTML;
|
|
||||||
},
|
|
||||||
|
|
||||||
/////////////////////////////////
|
/////////////////////////////////
|
||||||
who:function(){return ("Feature.js");} //last
|
who:function(){return ("Feature.js");} //last
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
|
||||||
* @param {Array} nodes
|
|
||||||
* @param {str} tagName
|
|
||||||
*
|
|
||||||
* @return {Array}
|
|
||||||
*/
|
|
||||||
OpenLayers._getNodes=function(nodes, tagName) {
|
|
||||||
var retArray = new Array();
|
|
||||||
for (var i=0;i<nodes.length;i++) {
|
|
||||||
if (nodes[i].nodeName==tagName) {
|
|
||||||
retArray.push(nodes[i]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return retArray;
|
|
||||||
};
|
|
||||||
|
|
||||||
/** These could/should be made namespace aware?
|
|
||||||
*
|
|
||||||
* @param {} p
|
|
||||||
* @param {str} tagName
|
|
||||||
*
|
|
||||||
* @return {Array}
|
|
||||||
*/
|
|
||||||
OpenLayers.getNodes=function(p, tagName) {
|
|
||||||
var nodes = Try.these(
|
|
||||||
function () {
|
|
||||||
return OpenLayers._getNodes(p.documentElement.childNodes,
|
|
||||||
tagName);
|
|
||||||
},
|
|
||||||
function () {
|
|
||||||
return OpenLayers._getNodes(p.childNodes, tagName);
|
|
||||||
}
|
|
||||||
);
|
|
||||||
return nodes;
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param {} parent
|
|
||||||
* @param {str} item
|
|
||||||
* @param {int} index
|
|
||||||
*
|
|
||||||
* @return {str}
|
|
||||||
*/
|
|
||||||
OpenLayers.getTagText = function (parent, item, index) {
|
|
||||||
var result = OpenLayers.getNodes(parent, item);
|
|
||||||
if (result && (result.length > 0))
|
|
||||||
{
|
|
||||||
if (!index) {
|
|
||||||
index=0;
|
|
||||||
}
|
|
||||||
if (result[index].childNodes.length > 1) {
|
|
||||||
return result.childNodes[1].nodeValue;
|
|
||||||
}
|
|
||||||
else if (result[index].childNodes.length == 1) {
|
|
||||||
return result[index].firstChild.nodeValue;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user