0

I have used vector point from database and also polygon country vectors from database.Points appear with in this country vectors but as I switch to google earth map as base layer the points at smaller zoom level would appear outside boundary where as at other zoom level it would appear inside. I have tried to add projection too but in vain.Do I need to reproject google earth's base layer and How?

map = new OpenLayers.Map('map', {
                    controls: [
                        new OpenLayers.Control.Navigation(),
                        new OpenLayers.Control.PanZoomBar(),
                        new OpenLayers.Control.LayerSwitcher({'ascending':false}),                       
                        new OpenLayers.Control.ScaleLine(),
                        new OpenLayers.Control.MousePosition(),
                        new OpenLayers.Control.OverviewMap(),
                        new OpenLayers.Control.KeyboardDefaults()
                    ],                 
             projection: new OpenLayers.Projection("EPSG:900913"),
             displayProjection: new OpenLayers.Projection("EPSG:4326"),
             numZoomLevels: 21,
             maxExtent: new OpenLayers.Bounds(-20037508, -20037508,20037508, 20037508.34)

                });           

                var border = new OpenLayers.Layer.WMS( "Border",
                url, 
                {layers: 'GisData:BORDER'}
            );

                var dsBand = new OpenLayers.Layer.WMS( "District Band",
                url, 
                {layers: 'GisData:BND'}
            );                  


                var Site1 = new OpenLayers.Layer.WMS( "Site 1",
                url, 
                {layers: 'GisData:sites', transparent: "true",format: "image/png"}             
            );
                dwnSite3G.setIsBaseLayer(false);

                var Site2 = new OpenLayers.Layer.WMS( "Site 2",
                url, 
                {layers: 'GisData:sites2', transparent: "true",format: "image/png"}             
            );


                var g_pmap = new OpenLayers.Layer.Google(
                "Google Physical",
                {type: G_PHYSICAL_MAP}
                );

                var gmap_gs = new OpenLayers.Layer.Google(
                    "Google Streets" // the default

                );

                var gmap_ghy  = new OpenLayers.Layer.Google(
                    "Google Hybrid",
                    {type: G_HYBRID_MAP}
                );

                var gmap_gsat = new OpenLayers.Layer.Google(
                    "Google Satellite",
                    {type: G_SATELLITE_MAP}
                )
1

2 Answers 2

3

Your map options are not correct. To use Google as a base layer you have to pass the following options:

var options = {
   projection: new OpenLayers.Projection("EPSG:900913"),
   displayProjection: new OpenLayers.Projection("EPSG:4326"),
   numZoomLevels: 21,
   maxExtent: new OpenLayers.Bounds(-20037508, -20037508,20037508, 20037508.34)
};
var map = new OpenLayers.Map(options);

and set

var googleStreets = new OpenLayers.Layer.Google(
            "Google Streets",
            {'sphericalMercator': true}
        );

on the Google Layers.

Documentation for using OpenLayers with a Spherical Mercator projection:

http://docs.openlayers.org/library/spherical_mercator.html

5
  • I edited my code but all other layers except google earth went red :(
    – kinkajou
    Commented Feb 16, 2012 at 9:47
  • 1
    Have you set Google layers option 'sphericalMercator': true ? Try to create fiddle at jsfiddle.net so that I can see your code
    – unicoletti
    Commented Feb 16, 2012 at 10:55
  • pastebin.com/PVttcr2u and setting 'sphericalMercator': true would make everything empty
    – kinkajou
    Commented Feb 17, 2012 at 9:58
  • See pastebin.com/adB1nq8S
    – unicoletti
    Commented Feb 18, 2012 at 17:43
  • I changed the code to setcenter but I could not make other base layer except google's appear.
    – kinkajou
    Commented Feb 20, 2012 at 4:27
0

The projection for your layers is EPSG4326 and the one used by google is google mercator ESPG:900913. This might be leading to the changes in the projection system .

2
  • yes I know that but I thought geoserver will reproject it for me. any idea?
    – kinkajou
    Commented Feb 14, 2012 at 6:47
  • 1
    It'll only reproject it if you ask it to, by defining the projections for all of your layers, and if GeoServer can reproject that data type - raster might not work.
    – tmcw
    Commented Feb 16, 2012 at 23:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.