openlayers5之加载KML数据
目录
openlayers5之加载KML数据
功能说明
openlayers加载KML格式数据
//矢量图层,数据源为kml文件;
var vetorLayer=new ol.layer.Vector({
source:new ol.source.Vector({
url: 'data/kml/2012-02-10.kml',
format:new ol.format.KML()
});
})
//与其他矢量图层一样进行查询操作。
var displayFeatureInfo = function(pixel) {
var features = [];
map.forEachFeatureAtPixel(pixel, function(feature) {
features.push(feature);
});
if (features.length > 0) {
var info = [];
var i, ii;
for (i = 0, ii = features.length; i < ii; ++i) {
info.push(features[i].get('name'));
}
document.getElementById('info').innerHTML = info.join(', ') || '(unknown)';
map.getTarget().style.cursor = 'pointer';
} else {
document.getElementById('info').innerHTML = ' ';
map.getTarget().style.cursor = '';
}
};
map.on('pointermove', function(evt) {
if (evt.dragging) {
return;
}
var pixel = map.getEventPixel(evt.originalEvent);
displayFeatureInfo(pixel);
});
map.on('click', function(evt) {
displayFeatureInfo(evt.pixel);
});