AW: [OpenLayers-Users] How to display custom labels inside custommarker icon..?

Arnd Wippermann arnd.wippermann at web.de
Thu Mar 17 13:27:55 EDT 2011


Hi,

you should use a vector layer instead of markers layer. Then you have many
ways to style your features.

That's how I do display an externalGraphic with text label:

var template = {
    strokeColor: "#0000FF",
    strokeOpacity: 1,
    strokeWidth: 3,
    fillColor: "#00AAFF",
    fillOpacity: 1,
    pointRadius: 5,
    pointerEvents: "visiblePainted",

    externalGraphic: "marker.png", //externalGraphic url from attribute url
use "${url}"
    graphicXOffset :  0,
    graphicYOffset :  0,
    graphicWidth   : 20,
    graphicHeight  : 20,
    rotation:0,

    label : "${name}", //label from attribute name

    labelXOffset:  10,
    labelYOffset: -10,
    fontColor: "red",
    fontSize: "12px",
    fontFamily: "Arial",
    fontWeight: "bold",
    labelAlign: "lt"
};
var aStyleMap = new OpenLayers.StyleMap(new OpenLayers.Style(template));

var vectorLayer = new OpenLayers.Layer.Vector("Markers", {
    styleMap: aStyleMap
});

// create a point feature
var point = new OpenLayers.Geometry.Point(-111.04, 45.68);
var pointFeature = new OpenLayers.Feature.Vector(point,null,null);

vectorLayer.addFeatures([pointFeature]);

Examples:
http://openlayers.org/dev/examples/vector-features-with-text.html
http://gis.ibbeck.de/OLClient/OLClient.asp?WMC=./data/WMC/ExternalGraphic_an
d_Labels.wmc.xml
 
Arnd 

-----Ursprüngliche Nachricht-----
Von: openlayers-users-bounces at lists.osgeo.org
[mailto:openlayers-users-bounces at lists.osgeo.org] Im Auftrag von dbenedetto
Gesendet: Donnerstag, 17. März 2011 16:04
An: users at openlayers.org
Betreff: [OpenLayers-Users] How to display custom labels inside custommarker
icon..?

Does anyone have an example of a way to display a number (marker ID) inside
a custom marker?

Here's what I have thus far. You will see the '9' text label is hardcoded
atm and is below the marker and to the left. (you will have to create
/images/map_pointer.png to run as is):


    
       
       {% include "header_includes.html" %}
       
       
       
       
    
    
    
Test 9 Example

    

        

    

    



THanks to any that can assist!

--
View this message in context:
http://osgeo-org.1803224.n2.nabble.com/How-to-display-custom-labels-inside-c
ustom-marker-icon-tp6181272p6181272.html
Sent from the OpenLayers Users mailing list archive at Nabble.com.
_______________________________________________
Users mailing list
Users at lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/openlayers-users



More information about the Users mailing list