I have a point object WKT. Like this: POINT (25.04568 48.221548)
. Also I have an icon in my project folder.
My goal is to show on a map an icon that represents a feature. Can it be just a normal OpenLayers feature (if yes, then how can I define that it should represent and icon) or do I need to create an OpenLayers marker (somehow create LonLat from WKT)?
It is fairly easy to add an icon if you have the point.
Just view the javascript source of this page: OpenLayers example markers page
An important part to remember is that if you use an icon you have to use .clone() on it if you need it to display more than once. Code snippet from above example:
"...
var markers = new OpenLayers.Layer.Markers( "Markers" );
map.addLayer(markers);
var size = new OpenLayers.Size(21,25);
var offset = new OpenLayers.Pixel(-(size.w/2), -size.h);
var icon = new OpenLayers.Icon('http://www.openlayers.org/dev/img/marker.png',size,offset);
markers.addMarker(new OpenLayers.Marker(new OpenLayers.LonLat(0,0),icon));
var halfIcon = icon.clone();
markers.addMarker(new OpenLayers.Marker(new OpenLayers.LonLat(0,45),halfIcon));
marker = new OpenLayers.Marker(new OpenLayers.LonLat(90,10),icon.clone());
..."
Something like this on your point object:
point.transform(
new OpenLayers.Projection("EPSG:900913"), //from
map.getProjectionObject() //to
);
Of course you need to know what your points projection is. There are plenty of examples out there.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.