Podtxt
Podtxt

Reputation: 35

Openlayers Feature.Vector only uses default style

I'm changing from markers to vector layer and I can't make my site to use any sort of non-default icon, whatever I put in externalGraphic style attribute doesnt have effect on map. I just see orange circles. To be exact, no matter what I put in Openlayers.Style to style my point features, I get default look of icons. It should be easy, but I try for days and can't make it work, so I came here for help. When warstwa_ikon was markers layer everything was fine, but I need extra functionality.

Thats my styling code:

var StylIkony = new OpenLayers.Style({
    externalGraphic : '${symbol}',
    graphicWidth    : 15,
    graphicHeight   : 15,
    cursor          : 'pointer' 
});

var StylWarstwyIkon = new OpenLayers.StyleMap ({
    default: StylIkony,
    delete: StylIkony,
    select: StylIkony,
    temporary: StylIkony 
});

warstwa_ikon = new OpenLayers.Layer.Vector("Ikony Lokali",{ eventListeners: { "featureselected": WywolajRamke }});
warstwa_ikon.StyleMap = StylWarstwyIkon;
map.addLayer(warstwa_ikon);

Thats already executed code from generating Features:

WspolrzedneIkony = new OpenLayers.Geometry.Point(2279231, 7127620);
Ikona = new OpenLayers.Feature.Vector(WspolrzedneIkony, 
        { "symbol": "../GRAFIKI/IkonyLokali/10.png", "idLokalu": 1 });
warstwa_ikon.addFeatures([Ikona]);
WspolrzedneIkony = new OpenLayers.Geometry.Point(2279245, 7127630);
Ikona = newOpenLayers.Feature.Vector(WspolrzedneIkony,
        { "symbol": "../GRAFIKI/IkonyLokali/6.png", "idLokalu": 2 });
warstwa_ikon.addFeatures([Ikona]);

Thats DOM of my vector layers (warstwa_ikon) StyleMap:

http://s24.postimg.org/hwfjakg0l/stylemap.png

Thats DOM of my vector layer first Feature, which should be styled:

http://s9.postimg.org/oxlocyku7/feature.png

Sorry, I can't include normal images yet. I should add that this is not a problem with accessing icon image file, I can't get layer to use any sort of images, even from internet links.

Upvotes: 0

Views: 423

Answers (1)

xamamano -jorix-
xamamano -jorix-

Reputation: 401

Declares StyleMap on layer creation as:

 warstwa_ikon = new OpenLayers.Layer.Vector("Ikony Lokali", {
     styleMap: StylWarstwyIkon,
     eventListeners: ...
 });

and removes:

 warstwa_ikon.StyleMap = StylWarstwyIkon;

Upvotes: 1

Related Questions