NOTICE: help.openstreetmap.org is no longer in use from 1st March 2024. Please use the OpenStreetMap Community Forum

I've got a complexion with this JavaScript. I've done several research but yet to succeed. Anyone?

<script type="text/javascript">
var map;

function init() {
// Create the map object
map = new OpenLayers.Map({
        allOverlays: true,
        controls: [
            new OpenLayers.Control.Navigation(),
            new OpenLayers.Control.PanZoom(),
        ]
    });
    var osm_layer = new OpenLayers.Layer.OSM();
    map.addLayer(osm_layer);

map.setCenter(
            new OpenLayers.LonLat(mylon,mylat).transform(
                new OpenLayers.Projection("EPSG:4326"),
                map.getProjectionObject()
            ), 12
        ); */        
}

var KMLURL = 'myfile.kml?' + Math.random();

var MyKmlLayer= new OpenLayers.Layer.Vector("This Is My KML Layer", {
        //Set your projection and strategies//
        projection: new OpenLayers.Projection("EPSG:4326"),
        strategies: [new OpenLayers.Strategy.Fixed()],
        //set the protocol with a url//
        protocol: new OpenLayers.Protocol.HTTP({
            //set the url to your variable//
            url: KMLURL,
            //format this layer as KML//
            format: new OpenLayers.Format.KML({
                //maxDepth is how deep it will follow network links//
                maxDepth: 1,
                //extract styles from the KML Layer//
                extractStyles: true,
                //extract attributes from the KML Layer//
                extractAttributes: true
            })
        })
    });

window.setInterval(UpdateKmlLayer, 5000, MyKmlLayer);

function UpdateKmlLayer(layer) {
        //setting loaded to false unloads the layer//
        layer.loaded = false;
        //setting visibility to true forces a reload of the layer//
        layer.setVisibility(true);
        //the refresh will force it to get the new KML data//
        layer.refresh({ force: true, params: { 'key': Math.random()} });
    }
}
</script>

Thank you in advance.

asked 05 Aug '11, 08:46

zearth's gravatar image

zearth
21335
accept rate: 0%

closed 05 Aug '11, 09:41

Jonathan%20Bennett's gravatar image

Jonathan Ben...
8.3k1785108

2

First, this isn't really an OpenStreetMap question, but an OpenLayers one (or even just a JavaScript one) -- you may get an answer by asking in a forum for OpenLayers.

Even then you should try to come up with a better worded question, rather than simply dumping your code and expecting everyone to find the problem. State what you've tried that didn't work, and what results you got instead.

(05 Aug '11, 09:45) Jonathan Ben...

The question has been closed for the following reason "Question is off-topic or not relevant" by Jonathan Bennett 05 Aug '11, 09:41

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×362
×60
×49

question asked: 05 Aug '11, 08:46

question was seen: 5,683 times

last updated: 05 Aug '11, 09:45

NOTICE: help.openstreetmap.org is no longer in use from 1st March 2024. Please use the OpenStreetMap Community Forum