[OpenLayers-Users] Re: marker can be created from feature?
IvanBell
Ivan.Bell at CCA.com
Wed Jun 8 09:30:39 EDT 2011
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.
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.
I now define a marker layer, which has a style map that defines the marker's
style.
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 }
}
);
I also define a method to add a marker to the map. This is called from a
click event in my map.
/**
* 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();
}
All of this code was derived directly from the
http://dev.openlayers.org/releases/OpenLayers-2.10/examples/ OpenLayers
examples .
Sincerely,
Ivan
-----
Up the Irons!!!
--
View this message in context: http://osgeo-org.1803224.n2.nabble.com/marker-can-be-created-from-feature-tp6451665p6453624.html
Sent from the OpenLayers Users mailing list archive at Nabble.com.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/openlayers-users/attachments/20110608/e3703d21/attachment.html
More information about the Users
mailing list