地图模板制作-发布-gpurl调用

window.open可以直接打开url链接。

saveas可以另存,仅支持ie浏览器

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="viewport" content="width=device-width,user-scalable=no">

<meta name="viewport"
    content="initial-scale=1, maximum-scale=1,user-scalable=no">
<title>Maps Toolbar</title>

<link rel="stylesheet"
    href="https://js.arcgis.com/3.16/dijit/themes/nihilo/nihilo.css">
<link rel="stylesheet"
    href="https://js.arcgis.com/3.16/esri/css/esri.css">
<style>
html,body,#mainWindow {
    font-family: sans-serif;
    height: 100%;
    width: 100%;
}

html,body {
    margin: 0;
    padding: 0;
}

#header {
    height: 80px;
    overflow: auto;
    padding: 0.5em;
}
</style>
<script type="text/javascript" src="../js/jquery.min.js"></script>
<script src="https://js.arcgis.com/3.16/"></script>
<script>
    
      var map, toolbar, symbol, geomTask;
      var app = {};
      require([
        "esri/map",
        "esri/tasks/LegendLayer",
        "esri/layers/ArcGISDynamicMapServiceLayer",
        "esri/tasks/PrintTask",
        "esri/layers/FeatureLayer",
        "esri/tasks/PrintParameters",
         "esri/tasks/PrintTemplate",
             "esri/config",
         "esri/dijit/Print",
        "esri/toolbars/draw",
        "esri/graphic",
        "dojo/dom",
        "esri/symbols/SimpleMarkerSymbol",
        "esri/symbols/SimpleLineSymbol",
        "esri/symbols/SimpleFillSymbol",

"dojo/parser", "dijit/registry",

"dijit/layout/BorderContainer", "dijit/layout/ContentPane",
        "dijit/form/Button", "dijit/WidgetSet", "dojo/domReady!"
      ], function(
        Map,LegendLayer, ArcGISDynamicMapServiceLayer,PrintTask,FeatureLayer,PrintParameters,PrintTemplate,esriConfig,Print, Draw, Graphic,dom,
        SimpleMarkerSymbol, SimpleLineSymbol, SimpleFillSymbol,
        parser, registry
      ) {
        parser.parse();
        //esriConfig.defaults.io.proxyUrl = "/proxy/";

esriConfig.defaults.io.proxyUrl = "http://localhost/java/proxy.jsp" ;
    esriConfig.defaults.io.alwaysUseProxy = true;
        map = new Map("map", {
          basemap: "streets",    
          center: [-15.469, 36.428],
          zoom: 3
        });
        app.map=map;

var layerFeatureAdd=new ArcGISDynamicMapServiceLayer("http://10.12.12.24:6080/arcgis/rest/services/tjszyMap/LouDou/MapServer");
       layerFeatureAdd.id="testlegend";
        map.addLayer(layerFeatureAdd);
        var fbt=new ArcGISDynamicMapServiceLayer("http://10.12.12.24:6080/arcgis/rest/services/tjszyMap/YinHuangShuiLiang/MapServer");
        fbt.id="fbttest";
        map.addLayer(fbt);
        console.log(layerFeatureAdd);
        map.on("load", createToolbar);
         app.printer = new Print({
          map: map,
          url: "http://localhost:6080/arcgis/rest/services/Utilities/PrintingTools/GPServer/Export%20Web%20Map%20Task"
        }, dom.byId("printButton"));
        app.printer.startup();
        var legendtest=new Array();
        var lelayer=new LegendLayer();
        lelayer.layerId="testlegend";
        lelayer.subLayerIds =[1];
         var lelayer2=new LegendLayer();
        lelayer2.layerId="fbttest";
    legendtest.push(lelayer);
    legendtest.push(lelayer2);
     console.log(legendtest);
        var template=new PrintTemplate();
             template.exportOptions={
                  width: 1920,
                  height: 1080,
                  dpi: 96
                };
           template.format="jpg";
           var OtherInfo={};
           OtherInfo.authormm="徐茂景";
           OtherInfo.ttt="122221";
         template.label="label+testLAble";  
             template.layout="A4 Landscape_copy";
               template.layoutOptions={titleText:"titleText测试",legendLayers:legendtest,authorText:"authorText测试",copyrightText:"copyrightText测试",scalebarUnit:"Kilometers",customTextElements:OtherInfo};  
             template.preserveScale =false;
             template.showAttribution =false;
       var printpara=new PrintParameters();
       printpara.map=map;
       printpara.template=template;
       var printTask=new PrintTask("http://localhost:6080/arcgis/rest/services/GP/ExportWebMap/GPServer/Export%20Web%20Map",printpara);
        // loop through all dijits, connect onClick event
        // listeners for buttons to activate drawing tools
        registry.forEach(function(d) {
          // d is a reference to a dijit
          // could be a layout container or a button
          if ( d.declaredClass === "dijit.form.Button" ) {
            d.on("click", activateTool);
          }
        });
       document.getElementById('testPrint').onclick = function(e){
         printTask.execute(printpara, printResult);
         function printResult(e){
         
        // window.open(e.url)
        SaveAs5(e.url);
         console.log(e.url);
         }
       
       }
       
       function SaveAs5(imgURL)
{
var oPop = window.open(imgURL,"","width=1, height=1, top=5000, left=5000");
for(; oPop.document.readyState != "complete"; )
{
if (oPop.document.readyState == "complete")break;
}
oPop.document.execCommand("SaveAs");
oPop.close();
}
        function activateTool() {
        alert("tesr");
          var tool = this.label.toUpperCase().replace(/ /g, "_");
          console.log(tool);
          toolbar.activate(Draw[tool]);
        //  map.hideZoomSlider();
        }
        
        function createToolbar(themap) {
          toolbar = new Draw(map);
          toolbar.on("draw-end", addToMap);
        }

function addToMap(evt) {
          var symbol;
          toolbar.deactivate();
          map.showZoomSlider();
          switch (evt.geometry.type) {
            case "point":
            case "multipoint":
              symbol = new SimpleMarkerSymbol();
              break;
            case "polyline":
              symbol = new SimpleLineSymbol();
              break;
            default:
              symbol = new SimpleFillSymbol();
              break;
          }
          var graphic = new Graphic(evt.geometry, symbol);
          map.graphics.add(graphic);
        }
      });
    </script>
</head>
<body class="nihilo">

<div id="mainWindow" data-dojo-type="dijit/layout/BorderContainer"
        data-dojo-props="design:'headline'">
        <div id="header" data-dojo-type="dijit/layout/ContentPane"
            data-dojo-props="region:'top'">
            <span>Draw:<br /> </span>
            <button data-dojo-type="dijit/form/Button">Point</button>
            <button data-dojo-type="dijit/form/Button">Multi Point</button>
            <button data-dojo-type="dijit/form/Button">Line</button>
            <button data-dojo-type="dijit/form/Button">Polyline</button>
            <button data-dojo-type="dijit/form/Button">Polygon</button>
            <button data-dojo-type="dijit/form/Button">Freehand Polyline</button>
            <button data-dojo-type="dijit/form/Button">Freehand Polygon</button>

<button data-dojo-type="dijit/form/Button">Arrow</button>
            <button data-dojo-type="dijit/form/Button">Triangle</button>
            <button data-dojo-type="dijit/form/Button">Circle</button>
            <button data-dojo-type="dijit/form/Button">Ellipse</button>
            <button id="testPrint">打印</button>
            <div id="printButton" onclick="clickTestPrint()"></div>
        </div>
        <div id="map" data-dojo-type="dijit/layout/ContentPane"
            data-dojo-props="region:'center'"></div>
    </div>

</body>
</html>

arcgis api for javascipt 输出图片的更多相关文章

  1. arcgis api for javascipt 加载天地图、百度地图

    写在前面的话: 1.百度地图是自己定义的坐标系统,wkid=102100.百度地图数据是加密的产物.下文将附上百度坐标与WGS84,谷歌等坐标系统转换方法(地理-地理),此方法并未亲测,据说准 2.百 ...

  2. ArcGIS API for Silverlight之配准JPG图片地图文字倾斜解决方案

    原文:ArcGIS API for Silverlight之配准JPG图片地图文字倾斜解决方案 根据实际JPG图片进行配准后,发布的地图,利用ArcGIS API for Silverlight在网页 ...

  3. arcgis api for javascript 学习(七) 调用发布地图信息,并将地图属性信息输出到Excel表格---进阶版

    我们在arcgis api for javascript 学习(三)已经学习到了关于调用地图信息进行属性输出的问题,不过通过代码我们实现后会发现还是有一些小瑕疵的,比如我们只能单个数据属性的输出,如果 ...

  4. arcgis api 4.x for js 自定义叠加图片图层实现地图叠加图片展示(附源码下载)

    前言 关于本篇功能实现用到的 api 涉及类看不懂的,请参照 esri 官网的 arcgis api 4.x for js:esri 官网 api,里面详细的介绍 arcgis api 4.x 各个类 ...

  5. arcgis api for javascript 学习(三) 调用发布地图信息,并将地图属性信息输出到Excel表中

    吐血推荐:网上搜了很久关于webgis地图属性表输出到Excel表,并没能找到相关有价值的信息,在小白面前,这就是一脸懵x啊!网上要么是关于前端如何在页面上直接导出excel,和webgis半毛钱关系 ...

  6. ArcGIS API for Silverlight 点沿着线流动

    原文:ArcGIS API for Silverlight 点沿着线流动 概述 前段时间做了一个项目,要求是有一些电力输送线,电力输送线或者石油管道都是有流动方向的,用户想做一个动态效果来模拟电力的输 ...

  7. ArcGIS API for Silverlight开发入门

    你用上3G手机了吗?你可能会说,我就是喜欢用nokia1100,ABCDEFG跟我 都没关系.但你不能否认3G是一种趋势,最终我们每个人都会被包裹在3G网络中.1100也不是一成不变,没准哪天为了打击 ...

  8. arcgis api for js入门开发系列二十打印地图的那些事

    前面我写过关于利用arcgis api for js打印地图的,但是打印地图服务都是基于arcgis server发布的,arcgis api加载在线地图,比如天地图.百度地图.高德地图等,底图都是打 ...

  9. arcgis api for javascript 学习(六) 地图打印

    1.本文应用arcgis api for javascript对发布的动态地图进行打印,打印的为PDF格式,打印出来如图: 2.需要特别注意的是:我们在运行代码前,需要打开PrintingTools, ...

随机推荐

  1. Kylin-2.6.2集群部署

    1. 集群节点规划与说明 rzx1 all rzx2 query rzx3 query 说明: Kylin节点角色有三种: all: 包含query和job query: 查询节点 job: 工作节点 ...

  2. go垃圾回收

    go垃圾回收 当创建一些变量时,变量有一个确定的生命周期.例如函数中定义的局部变量,当函数退出时变量就不存在了.另外在其他情况下,至少对于编译器来说,这不是那么的明显.例如,某个被函数返回的变量的生命 ...

  3. SaaS上云工具包为企业应用构筑上云之梯

    导语:本文中,阿里云资深技术专家郑刚将聚焦SaaS上云工具包如何帮助企业上云,包括产品上云.商品上市.服务上心,讲述了SaaS上云工具包为客户和伙伴提供的价值.在SaaS上云工具包整体解决方案的帮助下 ...

  4. Service7

    在真机上,利用clone-vm7新建一台虚拟机,名字:PXE-Server     1.设置防火墙为trusted   2.当前及永久关闭SELinux   3.配置IP地址:192.168.4.16 ...

  5. docker核心组件(6)

    Docker 的核心组件包括: Docker 客户端 - Client Docker 服务器 - Docker daemon Docker 镜像 - Image Registry Docker 容器 ...

  6. css选择器的分类及优先级计算方法总结

    首先声明一下CSS三大特性—— 继承. 优先级和层叠.继承即子类元素继承父类的样式;优先级是指不同类别样式的权重比较;层叠是说当数量相同时,通过层叠(后者覆盖前者)的样式. css选择符分类 首先来看 ...

  7. ORM-Dapper:Dapper列表

    ylbtech-ORM-Dapper:Dapper列表 1.返回顶部 1.1. https://dapper-tutorial.net/ 1.2. 2.1. https://www.nuget.org ...

  8. 内存Zone中的pageset成员分析

    1: struct per_cpu_pageset __percpu *pageset; 首先,分析一个函数,__free_pages,这个函数是Buddy System提供的API接口函数,用于翻译 ...

  9. (转载) 深入理解ES6箭头函数的this以及各类this面试题总结

    声明:本文转载自 https://blog.csdn.net/yangbingbinga/article/details/61424363 ES6中新增了箭头函数这种语法,箭头函数以其简洁性和方便获取 ...

  10. drf中间件流程图