<P>I am not sure of the "right way", as I am still learning best practices. However, the following is how I add a marker to my maps.</P>
<P>I first tried creating a new marker feature (e.g., new OpenLayers.Feature(layer,lonlat)) and calling the addMarker() method on the layer. However, I could not get that to work. It appears that the addMarker() method is not supported on a vector layer.</P>
<P>I now define a marker layer, which has a style map that defines the marker's style.</P>
<PRE>
<BLOCKQUOTE>
m_oMarkerLayer = new OpenLayers.Layer.Vector(
"Marker Layer",
{
styleMap: new OpenLayers.StyleMap({
//
// Shift graphic up 25 pixels
//
graphicYOffset: -21,
//
// This will put a label beneath the icon. If the icon cannot be found, or does
// not exist, then only the label will be displayed.
//
// label: "Some Label",
//
// Set the external graphic and background graphic images.
//
externalGraphic: "http://localhost:8081/geoserver/openlayers/img/marker.png",
backgroundGraphic: "http://localhost:8081/geoserver/openlayers/img/marker_shadow.png",
//
// Makes sure the background graphic is placed correctly relative
// to the external graphic.
//
backgroundXOffset: 0,
backgroundYOffset: -16,
//
// Set the z-indexes of both graphics to make sure the background
// graphics stay in the background (shadows on top of markers looks
// odd; let's not do that).
//
graphicZIndex: MARKER_Z_INDEX,
backgroundGraphicZIndex: SHADOW_Z_INDEX,
pointRadius: 10
}),
displayInLayerSwitcher: false,
isBaseLayer: false,
rendererOptions: { yOrdering: true }
}
);
</BLOCKQUOTE>
</PRE>
<P>I also define a method to add a marker to the map. This is called from a click event in my map.</P>
<PRE>
<BLOCKQUOTE>
/**
* Create marker.
*/
function addMarker( p_oLongitudeLatitude ) {
//
// converts the LonLat coordinates to Pixel format
//
var oPixelPoint = m_oMap.getPixelFromLonLat( p_oLongitudeLatitude );
//
// Add the marker to the markers layer.
//
arrFeatures = [];
oMarker = new OpenLayers.Feature.Vector( new OpenLayers.Geometry.Point( p_oLongitudeLatitude.lon, p_oLongitudeLatitude.lat ) );
arrFeatures.push( oMarker );
m_oMarkerLayer.addFeatures( arrFeatures );
m_oMarkerLayer.redraw();
}
</BLOCKQUOTE>
</PRE>
<P>All of this code was derived directly from the <A HREF="http://dev.openlayers.org/releases/OpenLayers-2.10/examples/" target="_top" rel="nofollow" link="external">OpenLayers examples</A>.</P>
<P>Sincerely,<BR>
Ivan</P>
        <div class="signature">Up the Irons!!!</div>
<br/><hr align="left" width="300" />
View this message in context: <a href="http://osgeo-org.1803224.n2.nabble.com/marker-can-be-created-from-feature-tp6451665p6453624.html">Re: marker can be created from feature?</a><br/>
Sent from the <a href="http://osgeo-org.1803224.n2.nabble.com/OpenLayers-Users-f1822463.html">OpenLayers Users mailing list archive</a> at Nabble.com.<br/>