[OpenLayers-Users] Re: adding KML file

Arnd Wippermann arnd.wippermann at web.de
Fri Feb 11 13:58:32 EST 2011


Hi,

Below some code to show how you can accomplish your task. You have to use
the projection sphericalMercator, to get your features at the right place. 

Both your kml files are in projection EPSG:4326. OpenLayers is able to
reproject vector data from EPSG:4326 (WGS84) to EPSG:900913
(sphericalMercator) and back without proj4js.

You should also keep in mind, that a web application is not a desktop
program. Loading your page results in downloading a kml file with 1.5 MB. I
had have to wait endlessly until my firefox was willing to act again on
mouse clicks.

Arnd

http://dev.openlayers.org/releases/OpenLayers-2.9.1/doc/apidocs/files/OpenLa
yers/Layer/Google-js.html
http://docs.openlayers.org/library/spherical_mercator.html#spherical-mercato
r

function init()
{
    var P4326   = new OpenLayers.Projection("EPSG:4326");
    var P900913 = new OpenLayers.Projection("EPSG:900913");

    mapOptions = {
        projection: P900913,
        displayProjection: P4326,
        units: "m",
        numZoomLevels: 18,
        maxResolution: 156543.0339,
        maxExtent: new OpenLayers.Bounds(-20037508, -20037508,20037508,
20037508.34)
        //controls : []
    };
    map = new OpenLayers.Map('map', mapOptions);

    var gphy = new OpenLayers.Layer.Google(
        "Google Physical",
        {type: G_PHYSICAL_MAP, sphericalMercator:true}
    );
    var gsat = new OpenLayers.Layer.Google(
        "Google Satellite",
        {type: G_SATELLITE_MAP, numZoomLevels: 22}
    );

    var cykloWGS = new OpenLayers.Layer.GML("cykloWGS",
'/dp/linie/wgs/cyklo2_ln.kml', {
  			format: OpenLayers.Format.KML,
            projection:new OpenLayers.Projection("EPSG:4326"),
  			formatOptions: {
  				'extractStyles': false,
  			}
  			});
    var cykloSphericalMercator = new
OpenLayers.Layer.GML("cykloSphericalMercator",
'/dp/linie/mercator/cyklo2_ln.kml', {
  			format: OpenLayers.Format.KML,
            projection:new OpenLayers.Projection("EPSG:4326"),
  			formatOptions: {
  				'extractStyles': false,
  			}
  			});

    map.addLayers([gphy, gsat, cykloWGS, cykloSphericalMercator]);

    map.addControl(new OpenLayers.Control.LayerSwitcher());

    map.setCenter(new
OpenLayers.LonLat(15.205078122883185,50.86577799589138).transform(P4326,
P900913), 10);
}
 

-----Ursprüngliche Nachricht-----
Von: openlayers-users-bounces at lists.osgeo.org
[mailto:openlayers-users-bounces at lists.osgeo.org] Im Auftrag von vrbikdan
Gesendet: Freitag, 11. Februar 2011 16:26
An: openlayers-users at lists.osgeo.org
Betreff: [OpenLayers-Users] Re: AW: Re: AW: Re: adding KML file

Sarah Schuessler <sarah_flip at ...> writes:

> Hi,if you use a overlay layer with epsg 4326 and base layer(google) 
> with epsg
900913 you have to transform or projection (proj4) client side.You don´t use
spericalMercator: true at the moment.HTHSarah

So I don't use sphericalMercator: true, so I thing that base layer hasn't
projection spherical Mercator. So it could be WGS84. Now, there is kml file
with WGS84 but lines aren't at place, where it should be. Why? I'm using the
same projections, so it should be at right place or not? Ok, I can suppose,
that I'm using bad projection and base layer has spherical mercator even I
haven't written in my code 'sphericalMercator': true. It could be problem,
but I tried fetch kml file with spherical mercator and it looks the same.
Lines doesn't fit on base layer. Even If I use kml file with absolutely
wrong projection like SJTSK (it is for the Czech republic only) it looks the
same.

I tried to use sphericalMercator: true but in that case I have center of map
somewhere in Gulf of Guinea and I can't pan. I don't know, what I should do,
because I thought that if I have kml file with the same projection as base
layer, it will be ok.

_______________________________________________
Users mailing list
Users at lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/openlayers-users



More information about the Users mailing list