[Users] Need help with inefficient code to plot vector, points with no legend in tree.
Andrew Parker
andrew at source3.com
Tue Mar 1 13:34:09 CET 2011
> The link doesn't work for me.
Sorry, mistyped the link. Should of been "saturn" -
http://saturn.nmt.edu/tests/test.html
> Here's what I would do if I were you :
>
> 1) Outside your markTarget method, create you vector layer with its own
> styleMap object (doing like you do with an array of rules is fine)
> 2) in you markTarget method, do :
> a) pvector.removeAllFeatures();
> b) create and add your feature to your vector layer (var yourNewFeature
> = new OpenLayers.Feature.Vector(...) ). The "addFeature" method will
> take care of drawing the feature.
Here is the new code for the if..else. ggLayer and ggfeatures are
global variables. "gg" stands for google geocoder is you are wondering.
...
if (ggLayer) {
ggLayer.removeAllFeatures();
ggLayer.setVisibility(true);
}
else {
ggLayer = new OpenLayers.Layer.Vector('Site Marker', {
styleMap: new OpenLayers.StyleMap(
new OpenLayers.Style({}, {rules: rules})
),
group: "Searched Location"
});
map1.addLayer(ggLayer);
};
ggLayer.addFeatures(ggfeatures);
...
> That should do the trick. BTW, you don't need to create an Array(1) when
> you only have one feature.
I discovered this while playing around with the code. I then looked up
arrays Definitive Guide To JavaScript for better understanding.
> To me, it looks like lots of copy/pasted code
> without understanding it.
You are absolutely correct. I finally gave in trying to learn,
understands, and write the code myself. I have hired a programmer (who
also contributes a lot to the geospaital community) to help me
understand and write code.
> Here's a bunch of samples and doc pages that
> could help :
>
> http://docs.openlayers.org/library/feature_styling.html
> http://dev.openlayers.org/releases/OpenLayers-2.10/examples/vector-features.html
> http://dev.openlayers.org/releases/OpenLayers-2.10/examples/stylemap.html
>
> Alexandre
>
Thanks for the feedback Alexandre.
--
Andrew Parker
Source3 Computing, LLC
www.source3.com
skype: source3computing
505-350-5535
More information about the Users
mailing list