Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

am not sure whether this is a stupid question or not.. but I am wondering how to dynamically check whether a layer object belongs to OpenLayers.Layer.Vector class.

Thanks for any replies!

share|improve this question
up vote 6 down vote accepted

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

share|improve this answer

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

share|improve this answer

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

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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