Use the print widget or the print task. Here's a simple sample showing how to use the print dijit.
createPrinter: function () { var transformers = {}; return { register: function (transformName, transform) { transformers[transformName] = transform; }, print: function (options) { var self = this, map, output, features; map = dojo.byId(options.map); output = dojo.byId(options.target) || dojo.create("div"); features = dojo.filter(options.features, function (f) { return transformers.hasOwnProperty(f); }); dojo.forEach(features, function (f) { self.render(output, transformers(map, options)); }); return output; }, render: function (div, imagery) { var images = imagery.images; if (images) { images = dojo.map(images, function (item) { var img = dojo.create("img", { src: item.src }); dojo.style(img, { position: "absolute", left: item.x + "px", top: item.y + "px", opacity: item.opacity || 1, zIndex: item.zIndex || 99 }); if (item.w) { dojo.style(img, { width: item.w + "px", height: item.h + "px" }); } return img; }); } dojo.forEach(images, function (img) { div.appendChild(img); }); if (imagery.polylines) { // render vector data } } }; },
print: function (node) { var printer; printer = createPrinter(acme.gis.mapdrawer.render.createPrinter()); var div = printer.print({ map: agsMap, features: ["layers", "markers"], target: node }); dojo.style(div, { position: "relative", overflow: "hidden", width: $.todo("960px", "move to frame?"), height: $.todo("600px", "move to frame?") }); return div; }, function createPrinter(print) { print.register("markers", function (map) { var images = []; dojo.forEach(map.graphicsLayerIds, function (id) { var layer = map.getLayer(id); dojo.forEach(layer.graphics, function (graphic) { var geom, symbol, point; geom = graphic.geometry; symbol = graphic.symbol; if (geom.type === "point" && symbol.url) { point = map.toScreen(geom); images.push({ src: symbol.url, x: point.x, y: point.y, zIndex: 10 }); } }); }); return { images: images }; }); print.register("layers", function (map) { var images = dojo.query(".layersDiv div img", map.root); var root = dojo.position(map.root); images = dojo.map(images, function (img) { var pos; pos = dojo.position(img); return { src: img.src, x: pos.x - root.x, y: pos.y - root.y, opacity: dojo.style(img, "opacity"), zIndex: dojo.style(img, "zIndex") }; }); return { images: images }; }); return print; }
Hi Mostafa, thank you for the response. Is there any way to do this after the map load, instead of user saving the map.
The only client-side solution I am aware of is querying all the the imagery URLs and relevant styling information in each layer of interest and generating the HTML for a new window containing those URLs and then printing that window. Of course ArcGIS 10.1 has a print service.
i think a good way to do that will be implementing getting a screen shot and opening the SaveAs diagram to save it as a .jpg or .png...you can create your own custom menu via javascript, let's say onRightClick you open your custom menu with saveAs button, and the saveAs button includes getting a screen shot as mentioned above.grtz,mostafa.
Aangemelde leden kunnen berichten plaatsen, updates volgen en meer. Nieuw hier? Registreer een gratis account.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.