1

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

asked Jul 3, 2013 at 19:40
2
  • I have tried to fix typos and grammar to make sense of the title and the question but I just could not understand your first parenthetical remark "if yes,...." Could you please edit it to make it meaningful? Commented Jul 3, 2013 at 19:47
  • edited, it is better? Commented Jul 3, 2013 at 19:50

1 Answer 1

1

If you want to change icons for all objects on map, you can change the style. For example:

testLayer = new OpenLayers.Layer.Vector("testLayer", {
 rendererOptions: { zIndexing: true },
 styleMap: new OpenLayers.StyleMap({
 "default": new OpenLayers.Style({
 externalGraphic: "../../pics/icon1.png",
 graphicWidth:32,
 graphicHeight:34,
 graphicXOffset:-10,
 graphicYOffset:-34 ,
 graphicZIndex: 1
 }, 
 OpenLayers.Feature.Vector.style["default"]),
 "select": new OpenLayers.Style({
 externalGraphic: "../../pics/icon2.png",
 graphicWidth:36,
 graphicHeight:38,
 graphicXOffset:-12,
 graphicYOffset:-38,
 graphicZIndex: 1000
 })
 })

If you want to set icon for one object, you can use OpenLayers.Marker. But it is not recommended. For example:

 function addNewMarkers() {
 ...
 var position = map.getLonLatFromPixel(e.xy);
 var size = new OpenLayers.Size(21,25);
 var offset = new OpenLayers.Pixel(-(size.w/2), -size.h);
 var icon = new OpenLayers.Icon('OpenLayers-2.12/img/marker-gold.png', size, offset);
 var markersLayer = map.getLayer('Markers');
 var myTestMarker = new OpenLayers.Marker(position,icon);
 ...
 markersLayer.addMarker(myTestMarker);
 }
answered Jul 4, 2013 at 5:32

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.