Created
September 2, 2014 21:05
-
-
Save phpmaps/c5697092ea5750470755 to your computer and use it in GitHub Desktop.
SVG Map Symbol Print
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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>SVG PictureMarkerSymbol</title> | |
<link rel="stylesheet" type="text/css" href="//js.arcgis.com/3.9/js/esri/css/esri.css"/> | |
<link href="http://js.arcgis.com/3.9/js/dojo/dijit/themes/claro/claro.css" rel="stylesheet"> | |
<style> | |
html, body, #map { | |
padding:0; margin:0; width:100%; height:100%; | |
} | |
.feedback-box { | |
background: #eee; | |
color: #444; | |
background-color: rgba(200, 200, 200, 0.5); | |
position: absolute; | |
font-family: arial; | |
height: 80px; | |
right: 30px; | |
margin: 5px; | |
padding: 20px; | |
top: 30px; | |
width: 80px; | |
z-index: 50; | |
} | |
.feedback { | |
background-color: rgba(255, 255, 255, 1); | |
color: #444; | |
position: absolute; | |
font-family: arial; | |
border: 2px; | |
height: 160px; | |
left: 30px; | |
margin: 5px; | |
padding: 10px; | |
top: 30px; | |
width: 500px; | |
z-index: 50; | |
} | |
</style> | |
<script type="text/javascript" src="//js.arcgis.com/3.9/"></script> | |
<script> | |
require([ | |
"esri/config", | |
"dojo/_base/array", | |
"dojo/dom", | |
"esri/dijit/Print", | |
"esri/tasks/PrintTemplate", | |
"esri/request", | |
"esri/symbols/PictureMarkerSymbol", | |
"esri/renderers/SimpleRenderer", | |
"esri/map", | |
"esri/layers/FeatureLayer", | |
"dojo/parser", | |
"dojo/ready" | |
], function (esriConfig, arrayUtils, dom, Print, PrintTemplate, esriRequest, PictureMarkerSymbol, SimpleRenderer, Map, FeatureLayer, parser, ready) { | |
parser.parse(); | |
var map; | |
ready(function () { | |
esriConfig.defaults.io.proxyUrl = "http://localhost/work/dev/proxy-test-1-1/PHP/proxy.php"; | |
map = new Map("map", { | |
basemap:"gray", | |
center:[-98.5795, 39.828175], | |
zoom:4 | |
}); | |
var svgSymbol = new PictureMarkerSymbol({ //PictureMarkerSymbols have direct support for SVG graphics | |
"angle": 0, | |
"xoffset": 0, | |
"yoffset": 0, | |
"type": "esriPMS", | |
"url": "https://photos-2.dropbox.com/t/0/AAC7vn008UGHD6uNLuVEOfeEjEEM_T-n6hQnY5QeuRiaMg/12/77164369/png/1024x768/3/1409695200/0/2/dot.svg/e0iqk6M9-JIszhUBfsjvgj1UjKBibH3g1sz7OOthfOA", //Set the path to SVG graphic | |
"contentType": "image/svg+xml", | |
"width": 10, | |
"height": 10 | |
}); | |
var svgRenderer = new SimpleRenderer(svgSymbol); | |
var featureLayer = new FeatureLayer("http://sampleserver6.arcgisonline.com/arcgis/rest/services/USA/MapServer/0", { | |
id:"featureLayer", | |
outFields: ["*"], | |
mode: FeatureLayer.MODE_ONDEMAND | |
}); | |
featureLayer.setRenderer(svgRenderer); | |
map.addLayer(featureLayer); | |
//Print Stuff | |
var printInfo = esriRequest({ | |
"url": "http://sampleserver6.arcgisonline.com/arcgis/rest/services/Utilities/PrintingTools/GPServer/Export%20Web%20Map%20Task", | |
"content": { "f": "json" } | |
}); | |
printInfo.then(handlePrintInfo, handleError); | |
function handlePrintInfo(resp) { | |
var layoutTemplate, templateNames, mapOnlyIndex, templates; | |
layoutTemplate = arrayUtils.filter(resp.parameters, function(param, idx) { | |
return param.name === "Layout_Template"; | |
}); | |
if ( layoutTemplate.length == 0 ) { | |
console.log("print service parameters name for templates must be \"Layout_Template\""); | |
return; | |
} | |
templateNames = layoutTemplate[0].choiceList; | |
// remove the MAP_ONLY template then add it to the end of the list of templates | |
mapOnlyIndex = arrayUtils.indexOf(templateNames, "MAP_ONLY"); | |
if ( mapOnlyIndex > -1 ) { | |
var mapOnly = templateNames.splice(mapOnlyIndex, mapOnlyIndex + 1)[0]; | |
templateNames.push(mapOnly); | |
} | |
// create a print template for each choice | |
templates = arrayUtils.map(templateNames, function(ch) { | |
var plate = new PrintTemplate(); | |
plate.layout = plate.label = ch; | |
plate.format = "PDF"; | |
return plate; | |
}); | |
// create the print dijit | |
var printer = new Print({ | |
"map": map, | |
"templates": templates, | |
url: "http://sampleserver6.arcgisonline.com/arcgis/rest/services/Utilities/PrintingTools/GPServer/Export%20Web%20Map%20Task" | |
}, dom.byId("print_button")); | |
printer.startup(); | |
} | |
function handleError(err) { | |
console.log("Something broke: ", err); | |
} | |
}); | |
}); | |
</script> | |
</head> | |
<body class="claro"> | |
<div id="map"> | |
<div class="feedback-box shadow rounded"><div id="print_button"></div></div> | |
</div> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I don't think you can print a svg using esriPMS. It fails throwing an error unable to complete the operation.