<div dir="ltr">This is expected behavior. Canvas works like a drawing board. Elements drawn to the canvas do not have a DOM representation. Why don't you use in your vector layer's features array to see if your feature was fetched?<div>
<br></div><div style>Andreas.</div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Sat, Jun 1, 2013 at 8:34 AM, Ivan Sipka <span dir="ltr"><<a href="mailto:frkator@gmail.com" target="_blank">frkator@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Hello,<div><br></div><div>this is my scenario: a map with one baselayer and one overlay vector layer with one point feature in it. I want to obtain the feature DOM node via <a href="https://developer.mozilla.org/en-US/docs/Web/API/document.getElementById" target="_blank">document.getElementById</a>. Feature gets drawn on screen in both cases.</div>

<div><br></div><div>If I use canvas renderer the element gets drawn on map but:</div><div><br></div><div>1) document.getElementById(<a href="http://feature.geometry.id" target="_blank">feature.geometry.id</a>) returns null</div>

<div>2) DOM tree inspection via chrome debugger shows no elements in canvas</div><div><br></div><div><div>If I use SVG renderer, I can see it in the DOM tree and document.getElementById(<a href="http://feature.geometry.id" target="_blank">feature.geometry.id</a>) returns it.</div>

</div><div><br></div><div>Example code:</div><div>
        
        
    
    
        <div></div>
        
        
    
    
        <div></div>
        
        
    
    
        <div></div>
        
        
    
    
        <div></div><div><br></div><div><!DOCTYPE html></div><div><html></div><div>    <head></div><div>        <script src="<a href="http://openlayers.org/api/2.12/OpenLayers.js" target="_blank">http://openlayers.org/api/2.12/OpenLayers.js</a>"></script></div>

<div>       <!--<script src="<a href="http://openlayers.org/dev/OpenLayers.js" target="_blank">http://openlayers.org/dev/OpenLayers.js</a>"></script>--><br></div><div>        <script type="text/javascript"></div>

<div>            </div><div>            var map,vectors,feature;</div><div><br></div><div>            function init() {</div><div>                var x = 659688.852138;</div><div>                var y = 5710701.2962197;</div>

<div>                </div><div>                map = new OpenLayers.Map({</div><div>                    div: "map",</div><div>                    projection: "EPSG:900913",</div><div>                    controls: [</div>

<div>                        new OpenLayers.Control.Navigation(),</div><div>                        new OpenLayers.Control.PanZoomBar()</div><div>                    ]</div><div>                });</div><div>                </div>

<div>                var renderer = OpenLayers.Util.getParameters(window.location.href).renderer;</div><div>                </div><div>                renderer = typeof(renderer) == 'undefined' ? 'Canvas' : renderer;</div>

<div><br></div><div>                vectors = new OpenLayers.Layer.Vector('vectors', {</div><div>                                    renderers: [renderer]</div><div>                                }); </div><div>
                                </div>
<div>                feature = new OpenLayers.Feature.Vector(new OpenLayers.Geometry.Point(x,y));</div><div><br></div><div>                map.addLayers([new OpenLayers.Layer.OSM(),vectors]);</div><div><br></div><div>                map.setCenter(new OpenLayers.LonLat(x,y), 18);</div>

<div>                vectors.addFeatures(feature);</div><div>                </div><div>                var fetched = document.getElementById(<a href="http://feature.geometry.id" target="_blank">feature.geometry.id</a>);</div>
<div>                </div>
<div>                alert('obtaining feature via document.getElementById has '+ (fetched == null ? 'failed':'suceeded'));</div><div>            }</div><div>        </script></div><div>        <style></div>

<div>            #map {</div><div>                width: 600px;</div><div>                height: 400px;</div><div>            }</div><div>        </style></div><div>    </head></div><div>    <body onload="init();"></div>

<div>        <div id="map"></div></div><div>    </body></div><div></html></div><div><br></div><div>Default renderer is Canvas if you want to test it you can give the canvas implementation as a URL parameter like this:</div>

<div><br></div><div>example.html</div><div>example.html?renderer=Canvas</div><div><br></div><div>or</div><div><br></div><div>example.html?renderer=SVG<br></div><div><br></div>
<div>Judging by the <a href="http://openlayers.org/dev/examples/canvas.html" target="_blank">canvas example</a> I'm doing it right. I tried to alternate OL versions from 2.12 to 2.13dev but it didn't help.</div><div>
<br>
</div><div>Why is this happening?  Is there any clever workaround?</div><div><br></div><div>thanks for your time</div><div>linski</div></div></div>
<br>_______________________________________________<br>
Dev mailing list<br>
<a href="mailto:Dev@lists.osgeo.org">Dev@lists.osgeo.org</a><br>
<a href="http://lists.osgeo.org/mailman/listinfo/openlayers-dev" target="_blank">http://lists.osgeo.org/mailman/listinfo/openlayers-dev</a><br>
<br></blockquote></div><br><br clear="all"><div><br></div>-- <br>Andreas Hocevar<br>OpenGeo - <a href="http://opengeo.org/">http://opengeo.org/</a><br>Expert service straight from the developers.<br>
</div>