답변:
내가 이것에 대한 정보를 찾기에 충분히 어렵다고 생각되는 나는 이것을 추가 할 것이다.
1)
KML 레이어를 만듭니다.
//Define your KML layer
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: mykmlurl,
//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
})
})
});
2)
KML 레이어의 URL을 설정하십시오.
//note that I have host equal to location// //Math.Random will stop caching//
var mykmlurl= 'http://' + host + '/KML?key=' + Math.random();
삼)
레이어를 새로 고치는 간격을 설정하십시오.
//function called// //timer// //layer to refresh//
window.setInterval(UpdateKmlLayer, 5000, MyKmlLayer);
4)
레이어를 업데이트하는 기능 :
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()} });
//- <3 from Thqr -//
}
이것이 다른 사람들이 더 쉽게 할 수 있기를 바랍니다. 행운을 빕니다.
나는 이것으로 아무 소용이 없었습니다. 누군가 내 코드를 살펴보고 내가 뭘 잘못하고 있는지 말해 줄 수 있습니까? 감사합니다!
<html>
<head>
<title>Test</title>
<link rel="stylesheet" href="http://openlayers.org/api/theme/default/style.css" type="text/css" />
<link rel="stylesheet" href="http://openlayers.org/dev/examples/style.css" type="text/css" />
<script src='http://maps.google.com/maps?file=api&v=2&key=ABQIAAAAl9RMqSzhPUXAfeBCXOussRTQDbvAygy0cfGJr8dEMAYKf3RWNBQqP9mjKIsqTfmAlz5LOJ3Xpy5s4w'></script>
<script src="http://openlayers.org/api/OpenLayers.js"></script>
<script type="text/javascript">
var map;
function init() {
// Create the map object
map = new OpenLayers.Map('map');
// Create a Google layer
var gmap = new OpenLayers.Layer.Google(
"Google Streets", // the default
{numZoomLevels: 20}
);
// Add layer to map
map.addLayer(gmap);
map.setCenter(new OpenLayers.LonLat(-112.1161, 33.6636), 13);
}
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: C:/Users/person/desktop/test.kml,
//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
})
})
});
var proposedanchorpositionurl = 'http://' + host + '/KML?key=' + Math.random();
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()} });
//- <3 from Thqr -//
}
</script>
</head>
<body onload="init()">
<h1 id="title">test</h1>
<div id="map" class=""></div>
</body>
</html>
죄송합니다. 불완전한 코드를 수정해야했습니다. 이번에는 실행해야합니다.
Refresh 전략을보고 싶을 수도 있습니다. http://dev.openlayers.org/releases/OpenLayers-2.11/doc/apidocs/files/OpenLayers/Strategy/Refresh-js.html
테스트되지 않았지만 이와 같은 것?
<script src="http://openlayers.org/api/OpenLayers.js"></script>
<script type="text/javascript">
var map;
function init() {
// Create the map object
map = new OpenLayers.Map('map');
// Create a Google layer
var gmap = new OpenLayers.Layer.Google(
"Google Streets", // the default
{numZoomLevels: 20}
);
// Add layer to map
map.addLayer(gmap);
map.setCenter(new OpenLayers.LonLat(-112.1161, 33.6636), 13);
var KMLURL = 'C:/Users/person/desktop/test.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()} });
//- <3 from Thqr -//
}
}
</script>