2
OpenLayers에 서버에서 검색된 KML 파일을 표시하려고합니다. 어떤 이유로이 기능이 작동하지 않습니다. 비슷한 질문을했으나 실제 예제를 찾을 수 없습니다. 내가 한 것은 OpenLayers 배포판의 예제 중 하나를 개선 한 것입니다. kml-track.jsOpenLayers : 원격 kml 표시
내가 발견 한 내용으로 개선했습니다. 이것이 그 모양입니다. 나는 명백한 무엇인가 놓치고있는 것처럼 느낀다.
http://openlayers.org/dev/examples/kml-layer.html
하는 당신이 오류를 얻고있다 : 모든 포인터이 당신에게 도움이 될 OpenLayers에서 KML 계층을 표시하는 방법의 예입니다
var map ;
function init() {
var mercator = new OpenLayers.Projection("EPSG:900913");
var geographic = new OpenLayers.Projection("EPSG:4326");
//note that I have host equal to location// //Math.Random will stop caching//
var mykmlurl = 'http://myserver/kml-track.kml';
map = new OpenLayers.Map({
div: "map",
projection: mercator,
layers: [
new OpenLayers.Layer.OSM(),
//Defiine your KML layer//
new OpenLayers.Layer.Vector("This Is My KML Layer", {
//Set your projection and strategies//
projection: geographic,
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
})
}),
styleMap: new OpenLayers.StyleMap({
"default": new OpenLayers.Style({
graphicName: "circle",
pointRadius: 2,
fillOpacity: 0.5,
fillColor: "#ffcc66",
strokeColor: "#666633",
strokeWidth: 1
})
})
})
],
center: new OpenLayers.LonLat(-93.2735, 44.8349).transform(geographic, mercator),
zoom: 8
});
//function called// //timer// //layer to refresh//
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()} });
}
당신은 그것이 작동하지 않는다고 말합니다. 전혀 표시되지 않습니까? 자바 스크립트 디버깅 콘솔에 체크인하면 KML 파일이 요청됩니까? –