Skip to content

Instantly share code, notes, and snippets.

@amarinelli
Created November 4, 2014 00:09
Show Gist options
  • Save amarinelli/e953f9ad93c64c6a8420 to your computer and use it in GitHub Desktop.
Save amarinelli/e953f9ad93c64c6a8420 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<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>Create Map and add a dynamic layer</title>
<link rel="stylesheet" href="http://js.arcgis.com/3.11/esri/css/esri.css"/>
<style>
html, body, #mapDiv{
padding: 0;
margin: 0;
height: 100%;
}
</style>
<script src="http://js.arcgis.com/3.11/"></script>
<script>
var map;
var dynamicMapServiceLayer;
var dynamicMapServiceLayer2;
var infoTemplates;
var infoTemplates2;
require([
"esri/map",
"esri/layers/ArcGISDynamicMapServiceLayer",
"esri/InfoTemplate",
"esri/layers/FeatureLayer",
"esri/graphic",
"esri/layers/ImageParameters",
"dojo/domReady!"
], function (
Map, ArcGISDynamicMapServiceLayer, InfoTemplate, FeatureLayer, Graphic, ImageParameters) {
map = new Map("mapDiv", {
sliderOrientation : "horizontal",
});
var imageParameters = new ImageParameters();
imageParameters.format = "jpeg"; //set the image type to PNG24, note default is PNG8.
infoTemplates = {
0: {
infoTemplate: new InfoTemplate(
"Attributes", "<tr>Name: <td>${NAME} <tr></td><br><tr>Area:<td>${SHAPE_Area}</tr></td><br>" +
"<a id='moreInfo' href='javascript:void(0);' onclick=moreInfoClick()>More Information</a>"
),
layerUrl: null
}
};
infoTemplates2 = {
0: {
infoTemplate: new InfoTemplate(
"Attributes", "<tr>Name: <td>${NAME} <tr></td><br><tr>Area:<td>${SHAPE_Area}</tr></td><br>"
),
layerUrl: null
}
}
//Takes a URL to a non cached map service.
dynamicMapServiceLayer = new ArcGISDynamicMapServiceLayer("http://cutsp62:6080/arcgis/rest/services/canada_json/MapServer", {
"opacity" : 0.5,
"id" : "testlayer",
"imageParameters" : imageParameters
});
dynamicMapServiceLayer2 = new ArcGISDynamicMapServiceLayer("http://cutsp62:6080/arcgis/rest/services/canada_json_2/MapServer", {
"opacity" : 0.5,
"id" : "testlayer2",
"imageParameters" : imageParameters
});
dynamicMapServiceLayer.setInfoTemplates(infoTemplates);
map.addLayer(dynamicMapServiceLayer);
});
function moreInfoClick() {
console.log("click");
map.removeLayer(dynamicMapServiceLayer);
addNewLayer();
};
function addNewLayer() {
console.log("click2");
dynamicMapServiceLayer2.setInfoTemplates(infoTemplates2);
map.addLayer(dynamicMapServiceLayer2);
}
</script>
</head>
<body>
<div id="mapDiv"></div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment