[OpenLayers-Users] styling vector data from kml file

Bill Schoolfield bill at billmax.com
Thu Dec 20 15:50:23 PST 2012


The code below fails to render the layer's points. If I comment out 
styleMap in the OpenLayers.Layer.Vector constructor I can see the layer 
(not styled of course). What is wrong?


         var styleMap = new OpenLayers.StyleMap({
                 fillOpacity: 1,
                 pointRadius: 10
         });

         var lookup = {
                 0: {externalGraphic: "images/modem.png", pointRadius: 10},
                 1: {externalGraphic: "images/radio-waves-md.png", 
pointRadius: 100},
         };

         styleMap.addUniqueValueRules("default", "type", lookup);

         var l =  new OpenLayers.Layer.Vector("BillMax", {
             styleMap: styleMap,
             strategies: [new OpenLayers.Strategy.Fixed()],
             protocol: new OpenLayers.Protocol.HTTP({
                 url: "test.kml",
                 format: new OpenLayers.Format.KML({
                 extractStyles: true,
                 extractAttributes: true,
                 projection: "EPSG:4236",
                 'internalProjection': new 
OpenLayers.Projection("EPSG:900913"),
                 'externalProjection': new 
OpenLayers.Projection("EPSG:3857")
                 })
             })
         });

The kml looks like:

<?xml version="1.0"?>
<kml xmlns="http://www.opengis.net/kml/2.2" encoding="UTF-8">
   <Document>
     <Placemark>
       <name>Troy Beasley</name>
       <address>305 Vaughn St.</address>
       <Point>
         <coordinates>-97.14879049, 32.89119839, 0.</coordinates>
         <type>0</type>
       </Point>
     </Placemark>
     <Placemark>
       <name>Shari Acosta</name>
       <address>6815 Manhattan Blvd</address>
       <Point>
         <coordinates>-97.21082905, 32.77544398, 0.</coordinates>
         <type>1</type>
       </Point>
     </Placemark>
...


More information about the Users mailing list