OpenLayers.Map object exposes a method call getLayersByClass. How do I use this method to retrieve all of the Vector layers from the map?

I tried map.getLayersByClass("Vector") but this returned an empty array.

1 Answer 1


The class should be OpenLayers.Layer.Vector not Vector. So your code should be:

  • You're welcome :) Good luck.
    – R.K.
    Nov 11, 2012 at 2:50
  • What is the OpenLayers 3 equivalent for this? May 15, 2017 at 7:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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