使用 Openlayers 加载 ImageServer 数据
Loading ImageServer data with Openlayers
所以我正在尝试使用 openlayers 5.2 加载 ArcGOS ImageServer,但我真的很难让任何东西正常工作。我编写的代码基于此示例 http://openlayers.org/en/latest/examples/vector-esri.html. Here is my modified version for ImageServer instead of FeatureServer. The url that i generate is valid,但我不确定如何根据需要将图像添加到源中。
如果有人有任何想法请告诉我。
var imageUrl = 'https://sampleserver3.arcgisonline.com/ArcGIS/rest/services/Portland/Aerial/ImageServer';
var xyzGrid = new ol.tilegrid.createXYZ({
tileSize: 512
});
var featureSource = new ol.source.Vector({
loader: function(extent, resolution, projection) {
var url = imageUrl + '/exportImage?bbox=' + extent.join(",") +
'&imageSR=102100' +
'&bboxSR=102100' +
'&pixelType=U8' +
'&f=pjson' +
'&size=512%2C512';
$.ajax({
url: url,
dataType: 'jsonp',
success: function(response) {
console.log(response)
if (response.error) {
console.log(response.error.message + '\n' + response.error.details.join('\n'));
} else {
var source = new ol.source.Image({
url: response.href,
projection: projection,
imageExtent: extent
});
featureSource.addFeatures(source);
}
}});
},
strategy: new ol.loadingstrategy.tile(xyzGrid)
});
var featureService = new ol.layer.Vector({
title: 'ImageServer',
source: featureSource,
});
layers.push(featureService);
没关系,TileArcGISRest 工作正常,但我只需要
params: {
'FORMAT': 'png'
}
因为我的测试服务器不支持默认的 "PNG32" 格式。
所以我正在尝试使用 openlayers 5.2 加载 ArcGOS ImageServer,但我真的很难让任何东西正常工作。我编写的代码基于此示例 http://openlayers.org/en/latest/examples/vector-esri.html. Here is my modified version for ImageServer instead of FeatureServer. The url that i generate is valid,但我不确定如何根据需要将图像添加到源中。
如果有人有任何想法请告诉我。
var imageUrl = 'https://sampleserver3.arcgisonline.com/ArcGIS/rest/services/Portland/Aerial/ImageServer';
var xyzGrid = new ol.tilegrid.createXYZ({
tileSize: 512
});
var featureSource = new ol.source.Vector({
loader: function(extent, resolution, projection) {
var url = imageUrl + '/exportImage?bbox=' + extent.join(",") +
'&imageSR=102100' +
'&bboxSR=102100' +
'&pixelType=U8' +
'&f=pjson' +
'&size=512%2C512';
$.ajax({
url: url,
dataType: 'jsonp',
success: function(response) {
console.log(response)
if (response.error) {
console.log(response.error.message + '\n' + response.error.details.join('\n'));
} else {
var source = new ol.source.Image({
url: response.href,
projection: projection,
imageExtent: extent
});
featureSource.addFeatures(source);
}
}});
},
strategy: new ol.loadingstrategy.tile(xyzGrid)
});
var featureService = new ol.layer.Vector({
title: 'ImageServer',
source: featureSource,
});
layers.push(featureService);
没关系,TileArcGISRest 工作正常,但我只需要
params: {
'FORMAT': 'png'
}
因为我的测试服务器不支持默认的 "PNG32" 格式。