6

How do I dynamically check whether a layer object belongs to the OpenLayers.Layer.Vector class?

6

Simply test the javascript instanceof operator against OpenLayers.Layer.Vector or Vector

1

better way: layer.CLASS_NAME == 'OpenLayers.Layer.Vector'

0

A quick example to describe how the instanceof function works in this case:

map.getLayers().item(1) instanceof ol.layer.Vector

this code yields true in my case as item(1) is a vector layer

map.getLayers().item(2) instanceof ol.layer.Vector

this yields false in my case as item(2) is an Image layer

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.