Ok, I actually was able to figure out how to use a vector layer to
create markers (points). It was a lot easier that what I was making it
out to be, once I figured out what to do. My problem now lies with
passing a value to the popup creator so I can display point-specific
info. My code looks like so (cribbed from the vector layer examples web
page) --
var vectorLayer = new OpenLayers.Layer.Vector("Vector Layer",
{"style": layer_style});
selectControl = new OpenLayers.Control.SelectFeature(
vectorLayer,
{"onSelect": onFeatureSelect, "onUnselect": onFeatureUnselect}
);
map.addControl(selectControl);
selectControl.activate();
var features = [];
for (var i = 0; i < points.length; i++) {
var point = new OpenLayers.Geometry.Point(points[i].lo,
points[i].la).transform(
new OpenLayers.Projection("EPSG:4326"),
map.getProjectionObject()
);
var pointFeature = new OpenLayers.Feature.Vector(point, {"pid":
i}, style_blue);
features.push(pointFeature);
}
vectorLayer.addFeatures(features);
map.addLayer(vectorLayer);
},
"onPopupClose": function(evt) {
selectControl.unselect(selectedFeature);
},
"onFeatureSelect": function(feature) {
selectedFeature = feature;
var pid = feature.pid; // this was set in the loop above
var str = getInfoOnFeature(pid); // this is where I retrieve info
var popup = new OpenLayers.Popup.FramedCloud(
"chicken",
feature.geometry.getBounds().getCenterLonLat(),
null,
"<div style='font-size:.8em'>" +
"Point ID: " + feature.pid + "<br />" +
"<br />Info: " + str +
"</div>",
null,
true,
onPopupClose
);
feature.popup = popup;
map.addPopup(popup);
}
As shown above, when a feature is selected, I would like to be able to
access its "pid" and use it to retrieve information about that feature
that I can then display in the popup. The OpenLayers.Feature docs say
that I can specify arbitrary, serializable attributes in the
constructor. For now, I get "undefined" for feature.pid. What am I doing
wrong, and how do I correct this?
--
Puneet Kishor
_______________________________________________
Users mailing list
[email protected]
http://lists.osgeo.org/mailman/listinfo/openlayers-users