Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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}
                )
share|improve this question
    
Sounds like the same problem I had: gis.stackexchange.com/questions/8621/… –  underdark Feb 18 '12 at 18:56

2 Answers 2

up vote 3 down vote accepted

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

share|improve this answer
    
I edited my code but all other layers except google earth went red :( –  kinkajou Feb 16 '12 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 Feb 16 '12 at 10:55
    
pastebin.com/PVttcr2u and setting 'sphericalMercator': true would make everything empty –  kinkajou Feb 17 '12 at 9:58
    
See pastebin.com/adB1nq8S –  unicoletti Feb 18 '12 at 17:43
    
I changed the code to setcenter but I could not make other base layer except google's appear. –  kinkajou Feb 20 '12 at 4:27

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 .

share|improve this answer
    
yes I know that but I thought geoserver will reproject it for me. any idea? –  kinkajou Feb 14 '12 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 Feb 16 '12 at 23:32

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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