如何打印ArcGis地图的特定范围?
我正在尝试使用JSAPI(而不是显示的扩展)在Arcgis地图上打印特定区域 我没有找到任何方法或选项来执行此操作,因此我尝试更改扩展,然后打印地图:如何打印ArcGis地图的特定范围?,gis,arcgis,esri,arcgis-js-api,Gis,Arcgis,Esri,Arcgis Js Api,我正在尝试使用JSAPI(而不是显示的扩展)在Arcgis地图上打印特定区域 我没有找到任何方法或选项来执行此操作,因此我尝试更改扩展,然后打印地图: var extent = new esri.geometry.Extent( -620526.0922336339, 5993991.149960931, 108988.90572005256, 6293624.300838808, myMap.spatialReference ); myMap.
var extent = new esri.geometry.Extent(
-620526.0922336339,
5993991.149960931,
108988.90572005256,
6293624.300838808,
myMap.spatialReference
);
myMap.setExtent(extent, true).then(function() {
console.log('setExtend is finished');
var template = new esri.tasks.PrintTemplate();
template.exportOptions = {
width : 500,
height : 500
};
template.format = 'jpg';
template.layout = 'MAP_ONLY';
var params = new esri.tasks.PrintParameters();
params.map = myMap;
params.template = template;
var printTask = new esri.tasks.PrintTask(urlToThePrintServer);
printTask.execute(params);
});
由于setExtent是异步的,并且返回延迟的,所以我必须使用“then”方法
我可以看到地图在移动,但延迟的似乎不起作用。。。(我没有看到console.log()
- 是否有其他方法打印地图的特定延伸
- 如果不是,为什么从未调用“then”方法
(我使用的是3.12 JS API)我觉得你的代码不错,不过很明显你没有发布所有的JavaScript或HTML。也许你不需要你需要的模块。或者您的代码试图在加载映射之前运行,尽管这不太可能,因为正如您所说,映射确实在移动。或者是别的什么地方出了问题 我在这里举了一个完整的工作示例。希望您可以将其与您正在做的事情进行比较,并找出代码中的错误。为方便起见,以下是相同的代码:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="viewport" content="initial-scale=1, maximum-scale=1,user-scalable=no"/>
<title>Simple Map</title>
<link rel="stylesheet" href="http://js.arcgis.com/3.13/esri/css/esri.css">
<style>
html, body, #map {
height: 100%;
width: 100%;
margin: 0;
padding: 0;
}
body {
background-color: #FFF;
overflow: hidden;
font-family: "Trebuchet MS";
}
</style>
<script src="http://js.arcgis.com/3.13/"></script>
<script>
var myMap;
var urlToThePrintServer = "http://sampleserver6.arcgisonline.com/arcgis/rest/services/Utilities/PrintingTools/GPServer/Export%20Web%20Map%20Task";
require(["esri/map", "dojo/domReady!"], function(Map) {
myMap = new Map("map", {
basemap: "topo", //For full list of pre-defined basemaps, navigate to http://arcg.is/1JVo6Wd
center: [-122.45, 37.75], // longitude, latitude
zoom: 13
});
myMap.on("load", function(map) {
var extent = new esri.geometry.Extent(
-620526.0922336339,
5993991.149960931,
108988.90572005256,
6293624.300838808,
myMap.spatialReference
);
myMap.setExtent(extent, true).then(function() {
console.log('setExtend is finished');
require([
"esri/tasks/PrintTemplate",
"esri/tasks/PrintParameters",
"esri/tasks/PrintTask"
], function(
PrintTemplate,
PrintParameters,
PrintTask
) {
var template = new PrintTemplate();
template.exportOptions = {
width : 500,
height : 500
};
template.format = 'jpg';
template.layout = 'MAP_ONLY';
var params = new PrintParameters();
params.map = myMap;
params.template = template;
var printTask = new PrintTask(urlToThePrintServer);
printTask.execute(params, function(response) {
console.log("The printed document is at " + response.url);
window.open(response.url);
});
});
});
});
});
</script>
</head>
<body>
<div id="map"></div>
</body>
</html>
简单地图
html,body,#map{
身高:100%;
宽度:100%;
保证金:0;
填充:0;
}
身体{
背景色:#FFF;
溢出:隐藏;
字体系列:“投石机MS”;
}
var-myMap;
var urlToThePrintServer=”http://sampleserver6.arcgisonline.com/arcgis/rest/services/Utilities/PrintingTools/GPServer/Export%20Web%20Map%20Task";
要求([“esri/map”、“dojo/domReady!”),函数(map){
myMap=新地图(“地图”{
basemap:“topo”,//有关预定义的basemap的完整列表,请导航到http://arcg.is/1JVo6Wd
中心:[-122.45,37.75],//经度,纬度
缩放:13
});
myMap.on(“加载”,函数(map){
var区段=新esri.GEOMETY.区段(
-620526.0922336339,
5993991.149960931,
108988.90572005256,
6293624.300838808,
myMap.spatialReference
);
setExtent(extent,true).then(function(){
log('setExtend已完成');
要求([
“esri/tasks/PrintTemplate”,
“esri/任务/打印参数”,
“esri/任务/打印任务”
],功能(
打印模板,
打印参数,
打印任务
) {
var template=新的PrintTemplate();
template.exportOptions={
宽度:500,
身高:500
};
template.format='jpg';
template.layout='MAP_ONLY';
var params=新的打印参数();
params.map=myMap;
params.template=模板;
var printTask=新的printTask(urlToThePrintServer);
printTask.execute(参数、函数(响应){
log(“打印的文档位于”+response.url);
window.open(response.url);
});
});
});
});
});
除了您使用的是不推荐使用的非AMD样式之外,外观看起来还不错。您是否尝试在该函数中设置断点?是的,我还添加了一个try/catch。没有错误,但从未调用“then”部分。您的代码和我的代码之间的唯一区别是,当我单击按钮时,所有代码都被调用,并且我的地图有几个层……我替换了dojo.addOnLoad()根据您在示例中所做的要求,删除了我的所有层,现在它可以工作了……您的fiddle代码帮了大忙。在我的应用程序中,我创建了一个用于打印的地图,并将其隐藏,以便打印输出独立于可视地图范围。