[OpenLayers-Users] How To Properly Use The "addFeatures" Function

Jim Hoff me at jimhoff.com
Mon Jun 3 06:25:23 PDT 2013


Help! I'm trying to add features to a vector layer from a string variable
containing a KML image. I can successfully load the KML data at the time
that I define the vector layer like this:

map.addLayer(Zones_Layer = new OpenLayers.Layer.Vector('Zones',
{  strategies: [new OpenLayers.Strategy.Fixed()],
   protocol: new OpenLayers.Protocol.HTTP
   ({ url: "Zones/A.kml",
      format: new OpenLayers.Format.KML
         ({  extractStyles:
true,
            extractAttributes:
true,
            maxDepth:
2
         })
   })
}));

but that only allows me to add one KML file to the vector layer. Instead, I
am trying to use the "addFeatures" function (of which I find no examples) to
add the features to the vector layer after it has already been defined, like
this:

map.addLayer(Zones_Layer = new OpenLayers.Layer.Vector('Zones'));
var FeatureArray1 = new OpenLayers.Format.KML({extractStyles: true,
extractAttributes: true, maxDepth: 2}).read(xmlhttp_responseText);
Zones_Layer.addFeatures(FeatureArray1);
var FeatureArray2 = Zones_Layer.features;

When I inspect the variables "FeatureArray1" and "FeatureArray2" in FireBug,
both correctly contain the feature data, but I see that the features in the
vector layer are being held in an array called "unrenderedFeatures".

So my question is: *Why are the features properly rendered when I load them
the first way, but not the second, and how can I fix this?*

By the way, the KML file (attached  A.kml
<http://osgeo-org.1560.x6.nabble.com/file/n5057472/A.kml>  ) was created in
Google Maps, using their "My places"/"CREATE MAP" feature.

Thanks in advance for your help!




--
View this message in context: http://osgeo-org.1560.x6.nabble.com/How-To-Properly-Use-The-addFeatures-Function-tp5057472.html
Sent from the OpenLayers Users mailing list archive at Nabble.com.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/openlayers-users/attachments/20130603/c37697c7/attachment.html>


More information about the Users mailing list