[OpenLayers-Users] id of a marker

Puneet Kishor punk.kish at gmail.com
Tue Dec 27 16:51:56 EST 2011


On Dec 27, 2011, at 3:41 PM, Cúmar Cueva wrote:

> Maybe there's something wrong, but is necessary show the way how you're
> creating the markers and getting the id in your code. Do you have a simple
> case?
> 



    var markerLayer = new OpenLayers.Layer.Markers( "Markers" );
    map.addLayer(markerLayer);
    
    var size = new OpenLayers.Size(21, 25);
    var offset = new OpenLayers.Pixel(-(size.w / 2), -size.h);
    var icon = new OpenLayers.Icon('http://path/to/marker.png', size, offset);
    
    var marker = new OpenLayers.Marker(
        new OpenLayers.LonLat(x, y).transform(
            proj.latlng,
            proj.google
        ), 
        icon
    );
    
    marker.id = "my_custom_id";
    markerLayer.addMarker(marker);
    
    
The above code does set a marker attribute called "id" to "my_custom_id", but I can't use it to get that DOM element. For example, the following doesn't work

    var elem = document.getElementById(marker.id);
    do something with 'elem'



> 2011/12/27 Puneet Kishor <punk.kish at gmail.com>
> 
>> 
>> On Dec 27, 2011, at 3:02 PM, Cúmar Cueva wrote:
>> 
>>> I don't remember if by default a maker has an 'id',
>> 
>> When I create a marker, it gets a programmatically generated id, for
>> example, id="OL_Icon_207"
>> 
>>> but if you have created
>>> a maker with a explicit 'id' as:
>>> 
>>>   var marker = new OpenLayers.Marker(LatLon, Icon);
>>>   marker.id = 'myId001';
>>> 
>>> then, you can get this value using the simple way:
>>> 
>>>  marker.id
>> 
>> 
>> Using the technique above does nothing. I don't think it sets the DOM id
>> of the marker element.
>> 
>> 
>> 
>>> 
>>> 
>>> 
>>> 2011/12/27 Puneet Kishor <punk.kish at gmail.com>
>>> 
>>>> I am wondering if I can get the id of a marker that I just created.
>>>> Unfortunately, `marker.id` is not a property. Suggestions?
>>>> 
>>>> --
>>>> Puneet Kishor
>> _______________________________________________
>> Users mailing list
>> Users at lists.osgeo.org
>> http://lists.osgeo.org/mailman/listinfo/openlayers-users
>> 
> 
> 
> 
> -- 
> Atte,
> 
> Cúmar Cueva



More information about the Users mailing list