1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113
| <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <title>地图打印</title> <link rel="stylesheet" href="https://js.arcgis.com/3.28/esri/css/esri.css" /> <script src="https://js.arcgis.com/3.28/"></script> <script src="https://code.jquery.com/jquery-1.12.4.js"></script> <style type="text/css"> .MapClass{ width:100%; height:500px; border:1px solid #000; } </style> <script type="text/javascript">
require(["esri/map", "dojo/dom","dojo/on","dojo/query", "esri/layers/ArcGISDynamicMapServiceLayer", "esri/symbols/SimpleMarkerSymbol", "esri/symbols/SimpleLineSymbol", "esri/symbols/SimpleFillSymbol", "esri/toolbars/draw", "esri/graphic", "esri/tasks/PrintTask", "esri/tasks/PrintTemplate", "esri/tasks/PrintParameters", "dojo/colors", "dojo/domReady!"], function (Map,dom,on,query, ArcGISDynamicMapServiceLayer, SimpleMarkerSymbol, SimpleLineSymbol, SimpleFillSymbol, Draw, Graphic, PrintTask,PrintTemplate,PrintParameters, Color) { var map = new esri.Map("mapDiv"); var layer = new esri.layers.ArcGISDynamicMapServiceLayer ("http://localhost:6080/arcgis/rest/services/ecology/beijing_2012_3/MapServer"); map.addLayer(layer); var toolBar = new Draw(map); lineSymbol = new SimpleLineSymbol(SimpleLineSymbol.STYLE_DASH, new Color([255, 0, 0]), 3); polygonSymbol = new SimpleFillSymbol(SimpleFillSymbol.STYLE_SOLID, lineSymbol, new Color([255, 0, 0, 0.25])); query(".pbtn").on("click",function(event){ toolBar.activate(Draw.POLYGON, { showTooltips:true }) }) on(toolBar,"draw-end",function(result){ var geometry=result.geometry; var graphicpoint= new Graphic(geometry, polygonSymbol); map.graphics.add(graphicpoint); toolBar.deactivate(); }) on(dom.byId("Btn"),"click",function(){ var printMap = new PrintTask("http://localhost:6080/arcgis/rest/services/Utilities/PrintingTools/GPServer/Export%20Web%20Map%20Task"); var template = new PrintTemplate(); var params = new PrintParameters(); printMap.outSpatialReference = map.SpatialReference template.exportOptions = { width: 850, height: 650, dpi: 96 }; template.format = "PDF"; template.layout = "MAP_ONLY"; PrintTemplate params.map = map; params.template = template; printMap.execute(params, function(result){ if (result != null) { window.open(result.url); } }) }) }); </script> </head> <body> <div id="mapDiv" class="MapClass"></div> <button class="pbtn" >画多边形</button> <input id="Btn" type="button" value="地图打印" /> </body> </html>
|