[OpenLayers-Users] Virtual Earth Layers vector layer projection issue

BillyZ313 billyz at iagt.org
Tue Jun 7 13:43:51 EDT 2011


I am new to OpenLayers and I have an issue that seems like it should be
pretty straight forward and easy to fix.  I am simply trying to put a kml
layer and a vector layer both with selectable features on a virtual earth
base layer map.  If I do not specify the sphericalMercator or maxExtent and
don't use a projection it seems to look correct at first but of course when
u zoom, pan or resize there are issues and clearly the projection is needed. 
However when i add those properties I receive errors and the marker (from
the vector layer) doesn't show up.  The code in the init function is as
follows:

function initOpenLayers()
        {
        /*******Size the div to full browser***********/
            resize();
             /*******Create Projection***********/                  
            proj = new OpenLayers.Projection("EPSG:4326");
            /*******Create map Options***********/
            var options = {
                        controls: [new OpenLayers.Control.MouseDefaults()],
                        projection: proj
                        };
            /*******Create Map***********/                        
            map_OL = new OpenLayers.Map('map_canvas_GoogleMaps1', options);
            /*******VE Street Map***********/  
            var street = new OpenLayers.Layer.VirtualEarth( "Street", {type:
VEMapStyle.Street, 
                                                                           
isBaseLayer:true,
                                                                           
sphericalMercator: true,
                                                                           
maxExtent: new
OpenLayers.Bounds(-20037508.34,-20037508.34,20037508.34,20037508.34)
                                                                           
});   
            /*******VE Hybrid Map***********/                                                                                      
            var hybrid = new OpenLayers.Layer.VirtualEarth("Hybrid", {type:
VEMapStyle.Hybrid, isBaseLayer:true,
                                                                           
sphericalMercator: true,
                                                                           
maxExtent: new
OpenLayers.Bounds(-20037508.34,-20037508.34,20037508.34,20037508.34)
                                                                           
});   
            /*******VE Aerial Map***********/                                                                                      
            var aerial = new OpenLayers.Layer.VirtualEarth("Aerial", {type:
VEMapStyle.Aerial, isBaseLayer:true,
                                                                           
sphericalMercator: true,
                                                                           
maxExtent: new
OpenLayers.Bounds(-20037508.34,-20037508.34,20037508.34,20037508.34)
                                                                           
});
            /*******VE Shaded Map***********/                                                                              
            var shaded = new OpenLayers.Layer.VirtualEarth("Shaded", {type:
VEMapStyle.Shaded, isBaseLayer:true,
                                                                           
sphericalMercator: true,
                                                                           
maxExtent: new
OpenLayers.Bounds(-20037508.34,-20037508.34,20037508.34,20037508.34)
                                                                           
});
            /*******Add Layers***********/  
            map_OL.addLayers([ street,aerial,hybrid, shaded]);
           /*******Create KML Layer***********/ 
            var pts_areas_reportadas = new
OpenLayers.Layer.GML("pts_areas_reportadas", 
                                                               
'http://arcserver1.iagt.org//fllowpaadmin/attachmentUploads/pts_areas_reportadas.kml', 
                                                                {
                                                                    format:
OpenLayers.Format.KML, 
                                                                   
formatOptions: { 
                                                                               
extractStyles: true, 
                                                                               
extractAttributes: true 
                                                                               
}, 
                                                                   
projection: map_OL.displayProjection
                                                                });
               

            /*******Add KML Layer***********/ 
            map_OL.addLayer(pts_areas_reportadas);
            /*******Create Style Map for the Vector Layer Points***********/    
            var styleMap = new OpenLayers.StyleMap({pointRadius: 10,
                                                    externalGraphic:
"images/VLocation.png"
                                                    });
            /*******Create array for Features***********/                                                       
            var myFeature = [];
            /*******Create a feature point***********/ 
            var point = new OpenLayers.LonLat(-90.601111, 14.380833);
            var point2 = new OpenLayers.LonLat(-90.601111, 14.380833);
            /*******Transform the point ***********/ 
            var transPoint = point.transform(proj,
map_OL.getProjectionObject());
            /*******Create marker from point***********/ 
            marker1 = new OpenLayers.Feature.Vector(point2);
            /*******Add attributes***********/ 
            marker1.attributes.name = "Pacaya Volcano";
            marker1.attributes.description = "Explosive eruptions shook two
huge volcanos in Central and South America on Friday, forcing thousands of
people to flee their homes and disrupting air traffic as ash drifted over
wide regions.  Guatemala's Pacaya volcano started erupting lava and rocks on
Thursday afternoon, blanketing the country's capital with ash and forcing
the closure of the international airport. President Alvaro Colom declared a
\"state of calamity.\"";
              // var geoMarker = marker1.geometry.clone()
              // geoMarker.transform(proj, map_OL.getProjectionObject());
              // myFeature[0] = geoMarker;
            /*******Add Marker to feature collection***********/               
            myFeature[0] = marker1;
            /*******Create Layer for the markers***********/ 
            mylayer = new OpenLayers.Layer.Vector('Points', 
                                                   {
                                                        styleMap: styleMap 
                                                    });
            /*******Add feature collection to layer***********/ 
            mylayer.addFeatures(myFeature);  
           
            /*******Add layer to the map***********/
            try
            {
                map_OL.addLayer(mylayer);
            }
            catch(e)
            {
                    alert(e.message);
            }                                           
            /*******Set map center***********/ 
            try
            {
                map_OL.setCenter(transPoint, 9);
            }
            catch(e3)
            {alert(e3.message);}
            /*******Add both layers to the SelectFeature control***********/
            select = new
OpenLayers.Control.SelectFeature([pts_areas_reportadas, mylayer], {onSelect:
onFeatureSelect, onUnselect: onFeatureUnselect});
            /*******Add control to the map***********/ 
            map_OL.addControl(select);
            /*******Activate select control***********/ 
            select.activate(); 
           
            
        }

If you see where I went wrong please let me know, I'll keep poking at it as
well...
Thanx,
~~~BillyZ

--
View this message in context: http://osgeo-org.1803224.n2.nabble.com/Virtual-Earth-Layers-vector-layer-projection-issue-tp6450691p6450691.html
Sent from the OpenLayers Users mailing list archive at Nabble.com.


More information about the Users mailing list