Skip to content

Instantly share code, notes, and snippets.

@tomwayson
Last active August 17, 2017 06:48
Show Gist options
  • Save tomwayson/8727474 to your computer and use it in GitHub Desktop.
Save tomwayson/8727474 to your computer and use it in GitHub Desktop.
Custom ArcGISDynamicMapServiceLayer
<!DOCTYPE html>
<html>
<!--
Example of how to extend the ArcGISDynamicMapService layer to send custom parameters to exportMap.
Adapted from the Dynamic Map Service Example:
https://developers.arcgis.com/javascript/jssamples/map_dynamic.html
-->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<!--The viewport meta tag is used to improve the presentation and behavior of the samples
on iOS devices-->
<meta name="viewport" content="initial-scale=1, maximum-scale=1,user-scalable=no">
<title>Custom dynamic layer</title>
<link rel="stylesheet" href="http://js.arcgis.com/3.8/js/esri/css/esri.css"/>
<style>
html, body, #mapDiv{
padding: 0;
margin: 0;
height: 100%;
}
</style>
<script src="http://js.arcgis.com/3.8/"></script>
<script>
var map;
require([
"esri/map",
"esri/layers/ArcGISDynamicMapServiceLayer",
"esri/layers/ImageParameters",
// additional dependencies to extend the class
'dojo/_base/declare',
'dojo/io-query'
], function (
Map, ArcGISDynamicMapServiceLayer, ImageParameters, declare, ioQuery) {
// custom class extending ArcGISDynamicMapServiceLayer
var CustomArcGISDynamicMapServiceLayer = declare([ArcGISDynamicMapServiceLayer], {
// override get image url to send parameters to service
// example:
// http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Demographics/ESRI_Population_World/MapServer/export?dpi=96&transparent=true&format=jpeg&bbox=-150.11384396396352%2C-60.90690208135621%2C38.98689434289862%2C36.62926820323585&bboxSR=4326&imageSR=4326&size=950%2C490&f=image&myParam=custom
getImageUrl: function(extent,width,height,callback) {
console.log(arguments);
// TODO: get hardcoded vals from the base class, and/or args above
var params = {
dpi:96,
transparent:true,
format:"jpeg",
bbox:extent.xmin + "," + extent.ymin + "," + extent.xmax + "," + extent.ymax,
bboxSR:4326,
imageSR:4326,
size:width+","+height,
// width:width,
// height:height,
f:"image",
// NOTE: custom parameters go here
myParam:"custom"
};
callback(this._url.path + "/export?" + ioQuery.objectToQuery(params));
}
});
// NOTE: from this point on the sample code is the same
map = new Map("mapDiv", {
sliderOrientation : "horizontal"
});
var imageParameters = new ImageParameters();
imageParameters.format = "jpeg"; //set the image type to PNG24, note default is PNG8.
//Takes a URL to a non cached map service.
var dynamicMapServiceLayer = new CustomArcGISDynamicMapServiceLayer("http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Demographics/ESRI_Population_World/MapServer", {
"opacity" : 0.5,
"imageParameters" : imageParameters
});
map.addLayer(dynamicMapServiceLayer);
});
</script>
</head>
<body>
<div id="mapDiv"></div>
</body>
</html>
@hhzhaoheng
Copy link

good

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment