Wednesday 20 February 2019

KML file seems to load in Openlayers without error but doesn't show vectors


I'm trying to load a KML file into an Openlayers map. It seems to successfully run but I am not seeing anything show up on the map.


Vectors should show up in an area of New Mexico if it's working correctly.


Here is my code (here is a link to the KML file )


var map;


var baseMaps = [];
var sensors = [];

//create map and center over location
var init = function () {
// create map

map = new OpenLayers.Map({
div: "map",

theme: null,
projection:new OpenLayers.Projection("EPSG: 4326"),
controls: [
new OpenLayers.Control.Attribution(),
new OpenLayers.Control.TouchNavigation({
dragPanOptions: {
enableKinetic: true
}
}),
new OpenLayers.Control.Zoom()

],
layers: [
new OpenLayers.Layer.OSM()
]
});

map.setCenter(new OpenLayers.LonLat(-106.7653, 32.3197).transform(new OpenLayers.Projection("EPSG:4326"), map.getProjectionObject()),9);
};

//show kmlFile

var showSensor = function(sensorVO)
{
if(sensorVO.selected == true)
{
var kmllayer = new OpenLayers.Layer.Vector("KML", {
strategies: [new OpenLayers.Strategy.Fixed()],
protocol: new OpenLayers.Protocol.HTTP({
url: sensorVO.url,
format: new OpenLayers.Format.KML({
extractStyles: true,

extractAttributes: true,
maxDepth: 2
})
})
});

map.addLayer(kmllayer);
var select = new OpenLayers.Control.SelectFeature(kmllayer);
map.addControl(select);
select.activate();


map.setCenter(new OpenLayers.LonLat(-106.639261,32.649908).transform(new OpenLayers.Projection("EPSG:4326"), map.getProjectionObject()),10);

var obj = {"vo":sensorVO, "kmlLayer":kmllayer};
sensors.push(obj);
}

else
{


for (var i = 0; i < sensors.length; i++)
{
var vo = sensors[i].vo;
if(vo.id == sensorVO.id)
{
map.removeLayer(vo.kmlLayer);
sensors.splice(i, 1);
}

}


}

}

init();

setTimeout(function(){
var obj = {"id":1, "selected":true, "url":"kml-files/1858-Vegitation-Map.kml"};


showSensor(obj);
}, 1000);


No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...