0

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)?

geocodezip
  • 158,664
  • 13
  • 220
  • 245

1 Answers1

0

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

OpenLayers examples 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.

Projections and OpenLayers.Geometry.Point in openlayers

Spherical Mercator - OpenLayers Library Documentation

Community
  • 1
  • 1
aws
  • 26
  • 3
  • OK, but I do not have LonLat, only WKT. How can I create a LonLat? –  Jul 03 '13 at 20:28
  • Well you might have to transform the point from one projection to another and then use var point.x and point.y as lonlat. – aws Jul 03 '13 at 21:42