2

I know that many have this problem,but none of the answers helped me so i suppose it's a different problem.This is my code:

    <!DOCTYPE html>
<html>
    <head>
        <title>Lesson Javascript-OpenLayers-WMS</title>
        <script src="http://maps.google.com/maps/api/js?v=3&amp;sensor=false"></script>
        <script src="http://openlayers.org/api/OpenLayers.js"></script> 

        <script>
                    var map;
            var lat_x=23.5552407
            var long_y=41.0746029


            function arxiki() {

                map = new OpenLayers.Map('map');
                map.addControl(new OpenLayers.Control.LayerSwitcher());
            map.events.register("mousemove", map, function(e) {
                            var position = this.events.getMousePosition(e);
                            OpenLayers.Util.getElement("coords").innerHTML = position;
                        });

                // the SATELLITE layer has all 22 zoom level, so we add it first to
                // become the internal base layer that determines the zoom levels of the
                // map.
                var gsat = new OpenLayers.Layer.Google(
                    "Google Satellite",
                    {type: google.maps.MapTypeId.SATELLITE, numZoomLevels: 22,visibility: false}
                );
                var gphy = new OpenLayers.Layer.Google(
                    "Google Physical",
                    {type: google.maps.MapTypeId.TERRAIN, visibility: false}
                );
                var gmap = new OpenLayers.Layer.Google(
                    "Google Streets", // the default
                    {numZoomLevels: 20, visibility: false}
                );
                var ghyb = new OpenLayers.Layer.Google(
                    "Google Hybrid",
                    {type: google.maps.MapTypeId.HYBRID, numZoomLevels: 22,visibility: true}
                );

            /////////////kml layers
                var kml =  new OpenLayers.Layer.Vector("KML", {
                        strategies: [new OpenLayers.Strategy.Fixed()],
                        protocol: new OpenLayers.Protocol.HTTP({
                            url: "oikismoiKilkis.kml",
                            projection: new OpenLayers.Projection("EPSG:4326"),
                            format: new OpenLayers.Format.KML({
                                extractStyles: true, 
                                extractAttributes: true,
                                maxDepth: 2
                            })
                        })
                    });

                    map.addLayers([gsat, gphy, gmap, ghyb,kml]);
                // Google.v3 uses EPSG:900913 as projection, so we have to
                // transform our coordinates
                map.setCenter(new OpenLayers.LonLat(lat_x,long_y).transform(
                    new OpenLayers.Projection("EPSG:4326"),
                    map.getProjectionObject()
                ), 7);

                //map.zoomToMaxExtent();  
            }
        </script>

        <!--<script src="google-v3-alloverlays.js"></script>-->
    </head>
    <body onload="arxiki()">

        <div id="map" onmousemove="GetCoords();" style="width:500px;height:300px;outline:1px solid black"></div>
        <label id="coords"></label>

    </body>
</html>

Here everything works fine instead of the KML loading part. I have tried running the html from a localhost (IIS 7),running different types of projection (2100,4326),running KML files that others suggested that they work, uploading the KML (GoogleDrive,DropBox) and load it from online, even different loaders like the GML Loader using as format .KML .

What am I doing wrong and as an extra question is the conversion from different types of projection system happening automatically like in Google Earth?

closed as off-topic by PolyGeo Sep 2 at 20:06

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This problem cannot or can no longer be reproduced. Changes to the system or to the asker's circumstances may have rendered the question obsolete, or the question does not include a procedure to enable potential answerers to reproduce the same symptoms. Such questions are off-topic as they are unlikely to help future readers, but editing them to include more details can lead to re-opening." – PolyGeo
If this question can be reworded to fit the rules in the help center, please edit the question.

  • I don't see any projection definition for the map object. It should be EPSG:900913 or EPSG:3857. – AndreJ Dec 8 '14 at 9:47
  • Thanks for response AndreJ.. I have changed the the map definition to map = new OpenLayers.Map('map', {projection: new OpenLayers.Projection("EPSG:900913"),displayProjection: new OpenLayers.Projection("EPSG: 4326")}); but still no result.Did you manage to make it work somehow? I have been searching the hole night.. :/ – prieston Dec 8 '14 at 9:57
  • I have just converted one of my GPX files to kml with QGIS, put it in the same local folder and it gets displayed. Maybe your kml file references to something that does not exist. Can you insert the dropbox link? – AndreJ Dec 8 '14 at 10:36
  • soory for the delay..was searching. THAT'S GREAT NEWS :D! here's the link . What coord system did you use to export? and did you change the map definition? – prieston Dec 8 '14 at 11:06
  • Downloaded to disk it works for me too in Firefox, except that it does not align with anything. I used EPSG:4326 (as all GPX data uses it). Openlayers does not like much other CRS than 4326 and 900913. I took the unchanged html from your question. – AndreJ Dec 8 '14 at 11:26

Browse other questions tagged or ask your own question.