[OpenLayers-Users] (no subject)

julien minet juminet at gmail.com
Mon Jan 25 15:20:39 EST 2010


Hi Harish,

If you remove the line "map.addLayer(layer);" in your script, then it works.


You should also put your map options to Spherical Mercator (EPSG: 900913):

    var options = {
        projection: new OpenLayers.Projection("EPSG:900913"),
        displayProjection: new OpenLayers.Projection("EPSG:4326"),
        units: "m",
        numZoomLevels: 18,
        maxResolution: 156543.0339,
        maxExtent: new OpenLayers.Bounds(-20037508, -20037508, 20037508,
20037508.34)
        };


and put your google layers to sphericalMercator:true:

var gphy = new OpenLayers.Layer.Google( "Google Physical", {type:
G_PHYSICAL_MAP,'sphericalMercator': true} );


and then translate your coordinates in WGS84 (EPSG:4326) in EPSG:900913 like
you have already done by:

center.transform(proj, map.getProjectionObject());

It is better to work in SphericalMercator (EPSG: 900913) with Google layers.




Julien


On Fri, Jan 22, 2010 at 8:57 PM, Harish Chandran <harishchandran19 at gmail.com
> wrote:

> Hello everyone. This is my first post and its about a problem I can't
> figure out. I wanted to make a google map based interface with a marker
> pointing specific locations. It all went well till I loaded the page. I can
> see my map.but I can't see the marker. It is supposed to point at the map
> center.Here is the code:
>
> ##############################
>
> ###################################################################################################################
>
> <html xmlns="http://www.w3.org/1999/xhtml">
> <head>
> <title>User Interface</title>
>
> <link rel="stylesheet"
> href="file:///C:/Documents%20and%20Settings/N-compass/Desktop/UI/basicstyle.css"
> />
>
> <link rel="stylesheet"
> href="file:///C:/Documents%20and%20Settings/N-compass/Desktop/UI/google.css"
> type="text/css" />
>
> <link rel="stylesheet"
> href="file:///C:/Documents%20and%20Settings/N-compass/Desktop/UI/style.css"
> type="text/css" />
>
> <script src='
> http://maps.google.com/maps?file=api&amp;v=2&amp;key=ABQIAAAAjpkAC9ePGem0lIq5XcMiuhR_wWLPFku8Ix9i2SXYRVK3e45q1BQUd_beF8dtzKET_EteAjPdGDwqpQ<http://maps.google.com/maps?file=api&v=2&key=ABQIAAAAjpkAC9ePGem0lIq5XcMiuhR_wWLPFku8Ix9i2SXYRVK3e45q1BQUd_beF8dtzKET_EteAjPdGDwqpQ>
> '></script>
> <script src="http://openlayers.org/dev/OpenLayers.js"></script>
>
> <script type="text/javascript">
>
>     var map;
>     var size, icon;
>
>     function init(){
>
>         map = new OpenLayers.Map('map');
>
>
>         var gphy = new OpenLayers.Layer.Google(
>             "Google Physical",
>             {type: G_PHYSICAL_MAP}
>         );
>         var gmap = new OpenLayers.Layer.Google(
>             "Google Streets", // the default
>             {numZoomLevels: 20}
>         );
>         var ghyb = new OpenLayers.Layer.Google(
>             "Google Hybrid",
>             {type: G_HYBRID_MAP, numZoomLevels: 20}
>         );
>         var gsat = new OpenLayers.Layer.Google(
>             "Google Satellite",
>             {type: G_SATELLITE_MAP, numZoomLevels: 20}
>         );
>
>         map.addLayers([gphy, gmap, ghyb, gsat]);
>
>
>
>     var proj = new OpenLayers.Projection("EPSG:4326");
>     var center = new OpenLayers.LonLat(72.856178,19.017656);
>     center.transform(proj, map.getProjectionObject());
>
>     map.setCenter(center,11);
>
>     map.addLayer(layer);
>     var markers = new OpenLayers.Layer.Markers( "Markers" );
>     map.addLayer(markers);
>
>     size = new OpenLayers.Size(15,15);
>     calculateOffset = function(size) {return new
> OpenLayers.Pixel(-(size.w/2), -size.h);};
>     icon = new
> OpenLayers.Icon('file:///C:/Documents%20and%20Settings/N-compass/Desktop/UI/marker.png',size,
> null, calculateOffset);
>
>     markers.addMarker(new OpenLayers.Marker(center,icon));
>
>     map.addControl(new OpenLayers.Control.LayerSwitcher());
>
>     }
>
> </script>
> </head>
>
>     <body onload="init()">
>         <h1 id="title">User Interface</h1>
>
>         <div id="tags">
>         </div>
>
>         <p id="shortdesc">
>             This project is still not over
>         </p>
>
>         <a style="float:right" href="" id="permalink">Permalink</a>
>
>         <div id="map" class="smallmap" onclick="co-ordinate()"></div>
>
>         <div id="docs"></div>
>     </body>
> </html>
>
> ########################################################################################################################################
> The path to css and icon files have been changed to point to files in my
> local directory. But they are the same files used in the openlayers
> examples.
>
> I know I am missing something very silly, can't figure it out. Any ideas?
>
> _______________________________________________
> Users mailing list
> Users at openlayers.org
> http://openlayers.org/mailman/listinfo/users
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/openlayers-users/attachments/20100125/8432c7ec/attachment.html


More information about the Users mailing list