1

I have an openlayers vector layer with features added from a text file. I am now trying to access these features via their attributes (if layer.features.attributes.some_attribute equals to something hide the specific feature). However, I don't seem to be able to access the features at all. I cannot even count them. I think I need some basic advice on how this accessing is done.

My original question is Hiding specific icons/markers on text generated vector layer, and I'm trying to accomplish something like Openlayers - Vector Layer - Combining hide/show features using style property.

I thought I had all the clues I needed but must be making some basic coding error...

0

1 Answer 1

0

You are encapsulating your pois in a function using var, hence it's not possible to access it directly (search JavaScript scope on a search engine)

You can always access at your demo page the pois features indirectly because map is global and layers are attached to map with map.layers[1].features

Clearly, it's not safe to use an indice [1] as it may change with your application evolution. Learn JavaScript more to change your code: my solution is more a hack due to your code than a "good" solution. You can take a look at this online book to improve your JavaScript skills.

2
  • 1
    You are correct that my JavaScript skills are weak. I will try to improve. However, this is only a part of the whole project, which is coded in php, asp and sql. So forgive me for trying to cut some corners as to learning yet another code language. Still, thanks for pointing out the major error! Commented Nov 4, 2014 at 21:12
  • Ok, I finally solved it. First, I had to make the pois layer a global variable to access it from an external function (thanks Thomas!). Second, it turns out I was trying to access what I thought was an attribute, when in fact it was an externalGrahics link. Once I figured that out, the rest worked as I wanted. I have added the solution to the original question. Commented Nov 5, 2014 at 22:45

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.