[OpenLayers-Users] BING and OpenLayers

Roger André randre at gmail.com
Fri Mar 19 19:13:36 EDT 2010


Hi Eric,

I appreciate the link to documentation, and have tried to apply the
information it contains.  The best I can do with it is below.  It
looks ok, until you start to pan the map, at which point the WMS layer
slides right off.

<html>
<head>
  <title>OpenLayers Example</title>
    <script src='http://dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=6.1'></script>
    <script src="http://openlayers.org/api/OpenLayers.js"></script>
    </head>
    <body>
      <div style="width:80%; height:80%" id="map"></div>
      <script defer='defer' type='text/javascript'>

// Code goes here
var options = {
  projection: new OpenLayers.Projection("EPSG:900913"),
  units: "m",
  maxResolution: 156543.0339,
  maxExtent: new OpenLayers.Bounds(-20037508.34, -20037508.34,
20037508.34, 20037508.34)
};

map = new OpenLayers.Map('map', options);

// create Virtual Earth layer
var vemap = new OpenLayers.Layer.VirtualEarth("Virtual Earth",
 {
     sphericalMercator: true,
     maxExtent: new
OpenLayers.Bounds(-20037508.34,-20037508.34,20037508.34,20037508.34)
 });


// create WMS layer
var wms = new OpenLayers.Layer.WMS(
    "World Map",
    "http://labs.metacarta.com/wms/vmap0",
    {'layers': 'basic', 'transparent': true}
);

map.addLayers([vemap, wms]);
map.zoomToMaxExtent();
      </script>
    </body>
</html>


---------------------------------

On Sat, Mar 13, 2010 at 12:07 AM, Eric Lemoine
<eric.lemoine at camptocamp.com> wrote:
>
> On Saturday, March 13, 2010, Roger André <randre at gmail.com> wrote:
> > Hi All,I'm trying to resolve some strange behavior in my OpenLayers map.  I am using a BING maps base layer, and a GeoJson feature collection layer.  Both layers display in the map, but the GeoJson layer "acts funny".  For one thing, it is slightly offset from where it should be located, and for another, it doesn't move with the BING base layer when I pan the map.
> > I am trying to follow the instructions at http://docs.openlayers.org/library/spherical_mercator.html#spherical-mercator, which seem to be very well written, but may be slightly out of date?  For example, the doc says to instantiate a new VirtualEarth layer by doing this:
> >
> > var layer = new OpenLayers.Layer.VirtualEarth("Virtual Earth",
> >  {     sphericalMercator: true,
> >      maxExtent: new OpenLayers.Bounds(-20037508.34,-20037508.34,20037508.34,20037508.34)
> >  });
> >
> >
> > But the current examples show using this syntax:
> >
> >             var roads = new OpenLayers.Layer.VirtualEarth("Road Map",
> >                  {  type: VEMapStyle.Shaded,                    numZoomLevels: 21  }
> >             );
> >
> >
> > In any case, I can't seem to figure out how to apply the projection instructions that are on the doc.  Also, I'm not sure if a projection mismatch is causing the problem I'm seeing, but I figure it's a place to start.
> >
> > Would appreciate some advice regarding how to troubleshoot this.
>
> Hi
>
> <http://trac.openlayers.org/wiki/FrequentlyAskedQuestions#WhydontmyvectorfeaturesworkoverGoogleYahooVirtualEarthetc.>
>
> (this a link to the old FAQ, as the new one is currently out of order.)
>
> You should use the EPSG:900913 projection in your map and set
> "sphericalMercator" to true in your VirtualEarch layer. See the
> spherical-mercator.html example. Also, the vector data (GeoJSON)
> should be in EPSG:900913, unless you reproject it client side. If you
> use either the fixed or BBOX strategy set "projection" to the your
> data projection (e.g. new OpenLayers.Projection("EPSG:4326")) in the
> layer to havr OpenLayers reproject the data to the map projection
> before adding it to the layer.
>
> Cheers,
>
> --
> Eric Lemoine
>
> Camptocamp France SAS
> Savoie Technolac, BP 352
> 73377 Le Bourget du Lac, Cedex
>
> Tel : 00 33 4 79 44 44 96
> Mail : eric.lemoine at camptocamp.com
> http://www.camptocamp.com



More information about the Users mailing list