POST
|
In this case, the script in question doesn't run until map is loaded (there's a handler with map creation). The lat long prints out fine, so I'm pretty sure the inputPoint is defined. How does the line for transformation work? I'd tried defining the geographic datum directly on the input point (see my response to Dan Patterson), but still getting undefined.
... View more
12-14-2016
10:37 AM
|
0
|
0
|
1752
|
POST
|
Okay, I see what you mean. Defining the point with WGS GCS 1984 in the following way still leaves me with undefined however... var lat = window.myMap.extent.getCenter().getLatitude().toFixed(2); var long = window.myMap.extent.getCenter().getLongitude().toFixed(2); var latLong = "Latitude : " + lat + " - Longitude : " + long; var X; var Y; var rgpfSixSudSR = new SpatialReference ({ wkid : 3297 }); var wgsGCSEightFourSR = new SpatialReference ({ wkid : 4326 }); var geometryService = new GeometryService("http://192.168.1.209:6080/arcgis/rest/services/Utilities/Geometry/GeometryServer"); var inputPoint = new Point(lat, long, wgsGCSEightFourSR); var prjParams = new ProjectParameters (); prjParams.geometries = [inputPoint]; prjParams.outSR = rgpfSixSudSR; geometryService.project(prjParams, function (outputpoint) { console.log('Conversion completed'); X = outputpoint[0].x; Y = outputpoint[0].y; }); var center = "X : " + X + " - Y : " + Y; console.log(latLong); console.log(center); Dan Patterson a écrit: Just to clarify.... longitude latitude comes in different datums, so the numbers themselves need a spatial reference defined (such as GCS WGS84 or GCS NAD83) to begin with. You need a defined spatial reference before data can be projected to another spatial reference, whether the units are the same or different.
... View more
12-14-2016
10:33 AM
|
0
|
0
|
1752
|
POST
|
I'm trying to project some lat long coordinates into another spatial reference. No errors are thrown, but I printing the result to the console gives "undefined". Anyone see where I'm going wrong? var lat = window.myMap.extent.getCenter().getLatitude().toFixed(2);
var long = window.myMap.extent.getCenter().getLongitude().toFixed(2);
var latLong = "Latitude : " + lat + " - Longitude : " + long;
var X;
var Y;
var rgpfSixSudSR = new SpatialReference ({
wkid : 3297
});
var geometryService = new GeometryService("http://ourserver/arcgis/rest/services/Utilities/Geometry/GeometryServer");
var inputPoint = new Point(lat, long, rgpfSixSudSR);
var prjParams = new ProjectParameters ();
prjParams.geometries = [inputPoint];
prjParams.outSR = rgpfSixSudSR;
geometryService.project(prjParams, function (outputpoint) {
console.log('Conversion completed');
X = outputpoint[0].x;
Y = outputpoint[0].y;
});
var center = "X : " + X + " - Y : " + Y;
console.log(latLong);
console.log(center);
... View more
12-13-2016
05:33 PM
|
0
|
11
|
6976
|
POST
|
Hi David, Did you ever figure how to get the output url? I'm trying to avoid taking on the print task if possible, as the print dijit basically gets me where I need except for this detail..
... View more
12-09-2016
01:21 PM
|
0
|
0
|
324
|
POST
|
Hi Ryan, Were you able to get the print output url from the print dijit or print task? I'm trying to access the same thing to get the print output to open automatically instead of just showing the link.
... View more
12-09-2016
01:16 PM
|
0
|
0
|
716
|
POST
|
I'm working on setting custom text elements via the template layout options for a print task to be used in a print widget. I am trying to get the custom text to display the lat long coordinates of the current map extent. I followed this sample to get the widget up and going. However, it sets up the template layouts and starts up the print widget when the app is loaded. This means that my "current" map extent for the layout is the initial map extent. Any suggestions on how to get the template custom text element to update to the current map extent? For the moment, I'm thinking that I have to set up and start up the print widget every time the extent changes... Here is what I have so far: require([
"esri/layers/FeatureLayer",
"esri/dijit/Print",
"esri/tasks/PrintTemplate",
"esri/request",
"esri/config",
"dojo/_base/array",
"dojo/dom",
], function(
FeatureLayer,
Print, PrintTemplate,
esriRequest, esriConfig,
arrayUtils, dom
) {
//var printUrl = "http://sampleserver6.arcgisonline.com/arcgis/rest/services/Utilities/PrintingTools/GPServer/Export%20Web%20Map%20Task";
var printUrl = "http://ourserver/arcgis/rest/services/Our_Tools/Our_Print_Tool/GPServer/Exporter%20une%20carte%20Web";
esriConfig.defaults.io.proxyUrl = "http://ourserver/Java/proxy.jsp";
dojo.connect(window.myMap, "onExtentChange", showExtent);
// get print templates from the export web map task
var printInfo = esriRequest({
"url": printUrl,
"content": {
"f": "json"
}
});
printInfo.then(handlePrintInfo, handleError);
var center = "";
var latLong = "";
function handlePrintInfo(resp) {
var layoutTemplate, templateNames, mapOnlyIndex, templates;
showExtent(window.myMap.extent)
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";
plate.layoutOptions = {
customTextElements : [
{
centerLatLong: latLong,
centerXY: center
}
]
};
return plate;
});
// create the print dijit
printer = new Print({
"map": window.myMap,
"templates": templates,
url: printUrl
}, dom.byId("print_button"));
printer.startup();
}
function showExtent(extent) {
var lat = window.myMap.extent.getCenter().getLatitude().toFixed(2);
var long = window.myMap.extent.getCenter().getLongitude().toFixed(2);
latLong = "Latitude : " + lat + " - Longitude : " + long;
var X = window.myMap.extent.getCenter().x.toFixed(2);
var Y = window.myMap.extent.getCenter().y.toFixed(2);
center = "X : " + X + " - Y : " + Y;
console.log(latlong);
console.log(center);
}
function handleError(err) {
console.log("Something broke: ", err);
}
});
... View more
11-25-2016
01:59 PM
|
0
|
12
|
3082
|
POST
|
Okay figured it out--have to create the legend and start it up directly instead of doing it this way: map.on("layers-add-result", function (evt) {}
... View more
11-22-2016
12:19 PM
|
0
|
0
|
938
|
POST
|
Oups--I had forgotten to mention that I did make that change to reflect my package location.
... View more
11-21-2016
05:31 PM
|
0
|
2
|
938
|
POST
|
Okay, I responded too quickly. I found the reason why Identify doesn't work. It's because the width and height of identifyParams still refers to var map and not window.myMap. That being said, identify now works, search works, print works....now the legend won't populate...! Setting a breakpoint at toc.startup(), but it is never reached. Just giving you an update in case you see anything flagrant that may be causing this. On a big picture scale, though, I will accept your answer.
... View more
11-21-2016
05:24 PM
|
0
|
4
|
938
|
POST
|
Hi Robert, Thank you for taking an in depth look at my app. I can see that you have restructured a lot of things, like you said, notably related to the way the scripts are called. This is extremely helpful. To deploy your version of the app I made two changes: -updated the proxy url to our local url, as I think the sample proxy I had included originally is now expired. -updated the identification task url to use our own service instead of the sample, because it was giving me an error related to CORS. This service has been used for identification task before with success. The app was mainly tested using Chrome. Testing the app on Firefox produces the same results, but not the same errors messages. When testing this your version, I sometimes had a couple of issues. I say sometimes, because emptying the cache and refreshing sometimes succeeded in loading the content pane (first issue on list still exists) : - While the search now works, identification no longer works. Clicking on the map produces an error: Error processing 'imageDisplay' for identify operation. - the right pane doesn't load (including the legend, an print button--when the right pane does load the print widget seems to work fine and the legend is properly populated). I can't tell if it's related to this error on line 26 of Identify.js: Uncaught TypeError: Cannot read property 'domNode' of undefined(...) (using Chrome). The line it refers to is this: window.myMap.infoWindow.setContent(registry.byId("tabs").domNode); I wonder if this thread is similar to my issue--however, moving the "tabs" div within the "content" div did not seem to remove this error. I have also tried to integrate your changes into my application--the source code is here if you think looking at the updated app would help you help me : D. The issues in terms of app functionality are the same as mentioned above. As far as I can tell (by checking the sources tab in Google Chrome developers tools), all the js files were loaded. Mahalo!
... View more
11-21-2016
01:25 PM
|
0
|
5
|
938
|
POST
|
I am attempting to implement a few widgets in my app: search, identify, print, and third-party TOC widget. Each widget works individually, but when bringing it all together, the search widget does not work intermittently (sometimes it works, sometimes it doesn't). The request for the feature returns a result, but the map does not zoom to the feature. I realized that when the Search doesn't work, the Search.js file does not load at all. A breakpoint on line 35 of Search.js is only reached when the widget works..this is not surprising. However, I cannot see what is keeping us from getting there. var sources = search.get("sources"); UPDATE: This is particularly confusing, as setting enableInfoWindow and showInfoWindowOnSelect to true succeeds in finding the feature and opening the infoWindow for the search. Clicking on the default zoom link succeeds in zooming to the window. However, my app doesn't enable infoWindows for the search, as certain Identify elements are signaled by the opening of infoWindows. var search = new Search({
enableButtonMode: true, //this enables the search widget to display as a single button
enableLabel: false,
enableInfoWindow: true,
showInfoWindowOnSelect: true,
map: map
}, "search"); The source code is in a public github repository. When everything works: When Search does not work--but map loads, print works, and identify works: The code is also below, if you are willing to take a look: index.html: <!DOCTYPE html>
<html dir="ltr">
<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>A title</title>
<link rel="stylesheet" href="http://js.arcgis.com/3.17/dijit/themes/claro/claro.css">
<link rel="stylesheet" href="http://js.arcgis.com/3.17/esri/css/esri.css">
<link rel="stylesheet" href="http://js.arcgis.com/3.18/dojox/layout/resources/ExpandoPane.css">
<link rel="stylesheet" href="css/widget_styles.css">
<script>
var dojoConfig = {
//parseOnLoad: true,
packages: [
{
name: "agsjs",
//location: location.pathname.replace(/\/[^/]+$/, "") + '../../agsjs'
"location": '/SPE_SIG/agsjs' // for xdomain load
}]
};
</script>
<script src="http://js.arcgis.com/3.17/"></script>
<script type="text/javascript">
dojo.require("dojox.layout.ExpandoPane");
</script>
<script src="js/Map.js"></script>
<script src="js/Legend.js"></script>
<script src="js/Search.js"></script>
<script src="js/Print.js"></script>
<script src="js/Identify.js"></script>
</head>
<body class="claro">
<div id="content"
data-dojo-type="dijit/layout/BorderContainer"
data-dojo-props="design:'headline', gutters:true"
style="width: 100%; height: 100%; margin: 0;">
<div id="rightPane"
data-dojo-type="dojox/layout/ExpandoPane"
data-dojo-props="region:'right',title:'Outils',startExpanded:false">
<div data-dojo-type="dijit/layout/AccordionContainer">
<div data-dojo-type="dijit/layout/ContentPane" id="legendPane"
data-dojo-props="title:'Légende', selected:true">
<div id="legendDiv"></div>
</div>
<div data-dojo-type="dijit/layout/ContentPane"
data-dojo-props="title:'Impressions'">
<div id="print_button"></div>
</div>
</div>
</div>
<div id="map"
data-dojo-type="dijit/layout/ContentPane"
data-dojo-props="region:'center'"
style="overflow: hidden;width: 100%; height: 100%; margin: 0;">
</div>
<div id="tabs" dojoType="dijit/layout/TabContainer" style="width:385px; height:150px;">
<div id="eCompteTab" dojoType="dijit/layout/ContentPane" title="E_COMPTE"></div>
<div id="eTroncoTab" dojoType="dijit/layout/ContentPane" title="E_TRONCO"></div>
</div>
<div id="search"></div>
</div>
</body>
</html> css:
html, body {
height: 97%;
width: 98%;
margin: 1%;
}
#search {
display: block;
position: absolute;
z-index: 2;
top: 20px;
left: 74px;
}
#rightPane {
width: 20%;
}
#map {
width: 75%;
}
#legendPane {
border: solid #97DCF2 1px;
}
h3 { margin: 0 0 5px 0; border-bottom: 1px solid #444; padding: 0 0 5px 0; text-align: center; }
.shadow {
-moz-box-shadow: 0 0 5px #888;
-webkit-box-shadow: 0 0 5px #888;
box-shadow: 0 0 5px #888;
}
#feedback {
background: #fff;
color: #000;
position: absolute;
font-family: arial;
height: auto;
right: 20px;
margin: 5px;
padding: 10px;
top: 20px;
width: 300px;
z-index: 40;
}
#feedback a {
border-bottom: 1px solid #888;
color: #444;
text-decoration: none;
}
#feedback a:hover, #feedback a:active, #feedback a:visited {
border: none;
color: #444;
text-decoration: none;
}
#note { font-size: 80%; font-weight: 700; padding: 0 0 10px 0; }
#info { padding: 10px 0 0 0; }
Identify.js:
var eCompteResults
var eTroncoResults
require([
"esri/map",
"esri/layers/ArcGISDynamicMapServiceLayer",
"esri/layers/FeatureLayer",
"esri/symbols/SimpleFillSymbol",
"esri/symbols/SimpleLineSymbol",
"esri/symbols/SimpleMarkerSymbol",
"esri/tasks/IdentifyTask",
"esri/tasks/IdentifyParameters",
"dojo/on",
"dojo/parser",
"esri/Color",
"dijit/registry",
"dijit/form/Button",
"dijit/layout/ContentPane",
"dijit/layout/TabContainer",
"dojo/domReady!"
],
function (
Map, ArcGISDynamicMapServiceLayer, FeatureLayer, SimpleFillSymbol, SimpleLineSymbol, SimpleMarkerSymbol,
IdentifyTask, IdentifyParameters, on, parser, Color, registry
) {
parser.parse();
var identifyTask, identifyParams;
// map = new Map("mapDiv", {
// basemap: "streets",
// center: [-83.275, 42.573],
// zoom: 18
// });
//map.on("layers-add-result", initFunctionality);
initFunctionality();
// var landBaseLayer = new ArcGISDynamicMapServiceLayer("https://sampleserver3.arcgisonline.com/ArcGIS/rest/services/BloomfieldHillsMichigan/Parcels/MapServer", {
// opacity: 0.2
// });
map.infoWindow.on("show", function () {
registry.byId("tabs").resize();
});
//map.addLayer(landBaseLayer);
function initFunctionality () {
map.on("click", doIdentify);
identifyTask = new IdentifyTask("https://sampleserver3.arcgisonline.com/ArcGIS/rest/services/BloomfieldHillsMichigan/Parcels/MapServer");
identifyParams = new IdentifyParameters();
identifyParams.tolerance = 3;
identifyParams.returnGeometry = true;
//identifyParams.layerIds = [1, 15];
identifyParams.layerIds = [0, 2];
identifyParams.layerOption = IdentifyParameters.LAYER_OPTION_ALL;
identifyParams.width = map.width;
identifyParams.height = map.height;
map.infoWindow.resize(415, 200);
map.infoWindow.setContent(registry.byId("tabs").domNode);
map.infoWindow.setTitle("Identify Results");
// symbol = new SimpleFillSymbol(SimpleFillSymbol.STYLE_SOLID,
// new SimpleLineSymbol(SimpleLineSymbol.STYLE_SOLID,
// new Color([255, 0, 0]), 2),
// new Color([255, 255, 0, 0.25]));
}
function doIdentify (event) {
map.graphics.clear();
identifyParams.geometry = event.mapPoint;
identifyParams.mapExtent = map.extent;
identifyTask.execute(identifyParams, function (idResults) {
addToMap(idResults, event);
});
}
function addToMap (idResults, event) {
eCompteResults = { displayFieldName: null, features: [] };
eTroncoResults = { displayFieldName: null, features: [] };
for (var i = 0, il = idResults.length; i < il; i++) {
var idResult = idResults;
if (idResult.layerId === 1) {
symbol = new SimpleMarkerSymbol(SimpleFillSymbol.STYLE_SQUARE,
new SimpleLineSymbol(SimpleLineSymbol.STYLE_SOLID,
new Color([255, 0, 0]), 2),
new Color([255, 255, 0, 0.25]));
if (!eCompteResults.displayFieldName) { eCompteResults.displayFieldName = idResult.displayFieldName; }
eCompteResults.features.push(idResult.feature);
}
else if (idResult.layerId === 15) {
symbol = new SimpleLineSymbol(SimpleLineSymbol.STYLE_SOLID,
new Color([255, 0, 0]), 2);
if (!eTroncoResults.displayFieldName) { eTroncoResults.displayFieldName = idResult.displayFieldName; }
eTroncoResults.features.push(idResult.feature);
}
}
registry.byId("eCompteTab").set("content", eCompteResultTabContent(eCompteResults));
registry.byId("eTroncoTab").set("content", eTroncoResultTabContent(eTroncoResults));
map.infoWindow.show(event.screenPoint,
map.getInfoWindowAnchor(event.screenPoint));
}
function eCompteResultTabContent (results) {
var template = "";
var features = results.features;
template += "<i>Nombre d'entités trouvées: " + features.length + "</i>";
template += "<table border='1'>";
template += "<tr><th>NUMERO</th><th>DIAMETRE</th><th>DATE DE POSE</th><th>UD</th></tr>";
var numeroCPTPPT;
var diametreCPTPPT;
for (var i = 0, il = features.length; i < il; i++) {
numeroECOMPTEPPT = features.attributes['NUMERO'];
diametreECOMPTEPPT = features.attributes['DIAMETRE'];
dateposeECOMPTEPPT = features.attributes['DATEPOSE'];
udECOMPTEPPT = features.attributes['UD'];
template += "<tr>";
template += "<td>" + numeroECOMPTEPPT + " <a href='#' onclick='showFeature(eCompteResults.features[" + i + "]); return false;'>(afficher)</a></td>";
template += "<td>" + diametreECOMPTEPPT + "</td>";
template += "<td>" + dateposeECOMPTEPPT + "</td>";
template += "<td>" + udECOMPTEPPT + "</td>";
template += "</tr>";
}
template += "</table>";
return template;
}
function eTroncoResultTabContent (results) {
var template = "";
var features = results.features;
template = "<i>Nombre d'entités trouvées: " + features.length + "</i>";
template += "<table border='1'>";
template += "<tr><th>DIAMETRE</th><th>MATERIAU</th><th>DATE DE POSE</th><th>LONGUEUR</th><th>PROFONDEUR</th><th>SECTO</th><th>UD</th></tr>";
var diametreETRONCOPPT;
var materiauETRONCOPPT;
var dateposeETRONCOPPT;
var longueurETRONCOPPT;
var profondETRONCOPPT;
var sectoETRONCOPPT;
var udETRONCOPPT;
for (var i = 0, il = features.length; i < il; i++) {
diametreETRONCOPPT = features.attributes['DIAMETRE'];
materiauETRONCOPPT = features.attributes['MATERIAU'];
dateposeETRONCOPPT = features.attributes['DATEPOSE'];
longueurETRONCOPPT = features.attributes['LONGCALC'];
profondETRONCOPPT = features.attributes['PROFOND'];
sectoETRONCOPPT = features.attributes['SECTO'];
udETRONCOPPT = features.attributes['UD'];
template += "<tr>";
template += "<td>" + diametreETRONCOPPT + " <a href='#' onclick='showFeature(eTroncoResults.features[" + i + "]); return false;'>(afficher)</a></td>";
template += "<td>" + materiauETRONCOPPT + "</td>";
template += "<td>" + dateposeETRONCOPPT + "</td>";
template += "<td>" + longueurETRONCOPPT + "</td>";
template += "<td>" + profondETRONCOPPT + "</td>";
template += "<td>" + sectoETRONCOPPT + "</td>";
template += "<td>" + udETRONCOPPT + "</td>";
template += "</tr>";
}
template += "</table>";
return template;
}
});
function showFeature (feature) {
map.graphics.clear();
feature.setSymbol(symbol);
map.graphics.add(feature);
}
Legend.js:
var toc, layerInfo;
require([
"esri/map", "esri/layers/ArcGISDynamicMapServiceLayer",
"dojo/_base/array", "dojo/parser", "agsjs/dijit/TOC",
"dijit/layout/BorderContainer", "dijit/layout/ContentPane",
"dijit/layout/AccordionContainer", "dojo/domReady!"
], function (
Map, ArcGISDynamicMapServiceLayer,
arrayUtils, parser, TOC
) {
parser.parse();
map.on("layers-add-result", function (evt) {
toc = new TOC({
map: map,
layerInfos: [
{
layer: baseMapLayerWorld,
title: "FDP Esri",
collapsed: true
//layerList: layerInfo
}
]
}, 'legendDiv');
toc.startup();
});
});
Map.js: var map;
var baseMapLayerWorld;
require([
"esri/map",
"esri/dijit/Search",
"esri/layers/ArcGISDynamicMapServiceLayer",
"esri/layers/FeatureLayer",
"esri/InfoTemplate",
"dijit/layout/BorderContainer",
"dijit/layout/ContentPane",
"dojo/domReady!"
], function (Map, Search, DynamicMapServiceLayer, FeatureLayer, InfoTemplate) {
baseMapLayerWorld = new esri.layers.ArcGISTiledMapServiceLayer("http://services.arcgisonline.com/arcgis/rest/services/World_Street_Map/MapServer");
map = new Map("map", {
center: [-150, -17], // lon, lat
zoom: 8
});
map.addLayers([baseMapLayerWorld]);
}); Print.js:
require([
"esri/map",
"esri/layers/FeatureLayer",
"esri/dijit/Print",
"esri/tasks/PrintTemplate",
"esri/request",
"esri/config",
"dojo/_base/array",
"dojo/dom",
"dojo/parser",
"dijit/layout/BorderContainer",
"dijit/layout/ContentPane",
"dojo/domReady!"
], function(
Map, FeatureLayer,
Print, PrintTemplate,
esriRequest, esriConfig,
arrayUtils, dom, parser
) {
parser.parse();
var printUrl = "http://sampleserver6.arcgisonline.com/arcgis/rest/services/Utilities/PrintingTools/GPServer/Export%20Web%20Map%20Task";
esriConfig.defaults.io.proxyUrl = "http://csslsystem-072/dotnet1/proxy.ashx";
// get print templates from the export web map task
var printInfo = esriRequest({
"url": printUrl,
"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";
plate.layoutOptions = {
"authorText": "Made by: Esri's JS API Team",
"copyrightText": "<copyright info here>",
"legendLayers": [],
"titleText": "Pool Permits",
"scalebarUnit": "Miles"
};
return plate;
});
// create the print dijit
printer = new Print({
"map": map,
"templates": templates,
url:printUrl
}, dom.byId("print_button"));
printer.startup();
}
function handleError(err) {
console.log("Something broke: ", err);
}
}); Search.js: require([
"esri/map", "esri/dijit/Search", "esri/layers/ArcGISDynamicMapServiceLayer","esri/layers/FeatureLayer", "esri/InfoTemplate", "dojo/domReady!"
], function (Map, Search, DynamicMapServiceLayer, FeatureLayer, InfoTemplate) {
var search = new Search({
enableButtonMode: true, //this enables the search widget to display as a single button
enableLabel: false,
enableInfoWindow: false,
showInfoWindowOnSelect: false,
map: map
}, "search");
var sources = search.get("sources");
//Push the sources used to search, by default the ArcGIS Online World geocoder is included. In addition there is a feature layer of US congressional districts. The districts search is set up to find the "DISTRICTID". Also, a feature layer of senator information is set up to find based on the senator name.
sources.push({
featureLayer: new FeatureLayer("https://services.arcgis.com/V6ZHFr6zdgNZuVG0/arcgis/rest/services/CongressionalDistricts/FeatureServer/0"),
searchFields: ["DISTRICTID"],
displayField: "DISTRICTID",
exactMatch: false,
outFields: ["DISTRICTID", "NAME", "PARTY"],
name: "Congressional Districts",
placeholder: "3708",
maxResults: 6,
maxSuggestions: 6,
//Create an InfoTemplate and include three fields
infoTemplate: new InfoTemplate("Congressional District", "District ID: ${DISTRICTID}</br>Name: ${NAME}</br>Party Affiliation: ${PARTY}"),
enableSuggestions: true,
minCharacters: 0
});
sources.push({
featureLayer: new FeatureLayer("https://services.arcgis.com/V6ZHFr6zdgNZuVG0/arcgis/rest/services/US_Senators/FeatureServer/0"),
searchFields: ["Name"],
displayField: "Name",
exactMatch: false,
name: "Senator",
outFields: ["*"],
placeholder: "Senator name",
maxResults: 6,
maxSuggestions: 6,
//Create an InfoTemplate
infoTemplate: new InfoTemplate("Senator information", "Name: ${Name}</br>State: ${State}</br>Party Affiliation: ${Party}</br>Phone No: ${Phone_Number}<br><a href=${Web_Page} target=_blank ;'>Website</a>"),
enableSuggestions: true,
minCharacters: 0
});
//Set the sources above to the search widget
search.set("sources", sources);
search.startup();
});
... View more
11-18-2016
11:45 AM
|
0
|
7
|
1678
|
POST
|
Hi Miriam, The baseMapLayerWorld was intended to be a tiled map service layer to act as the map's basemap. I'm hesitating to do what you suggest by adding this layer as a dynamic map service--should this make a difference for map loading? I've added the other requirements, but still get a TypeError related to PrintTask.js
... View more
10-18-2016
01:12 PM
|
0
|
1
|
561
|
POST
|
This print widget is blocked before creating an output. The combobox properly retrieves the print task url, but the console shows "TypeError: b is undefined" for http://js.arcgis.com/3.17/esri/tasks/PrintTask.js:25:13. Map is created in Map.js var map;
var baseMapLayerWorld;
require([
"esri/map", "esri/dijit/Search", "esri/layers/ArcGISDynamicMapServiceLayer","esri/layers/FeatureLayer", "esri/InfoTemplate", "dojo/domReady!"
], function (Map, Search, DynamicMapServiceLayer, FeatureLayer, InfoTemplate) {
baseMapLayerWorld = new esri.layers.ArcGISTiledMapServiceLayer("http://services.arcgisonline.com/arcgis/rest/services/World_Street_Map/MapServer");
map = new Map("map", {
center: [-150, -17], // lon, lat
zoom: 8
});
map.addLayers([baseMapLayerWorld);
}); The print widget is implemented in Print.js: var app = {};
require([
"esri/map", "esri/layers/FeatureLayer",
"esri/dijit/Print", "esri/tasks/PrintTemplate",
"esri/request", "esri/config",
"dojo/_base/array", "dojo/dom", "dojo/parser",
"dijit/layout/BorderContainer", "dijit/layout/ContentPane", "dojo/domReady!"
], function(
Map, FeatureLayer,
Print, PrintTemplate,
esriRequest, esriConfig,
arrayUtils, dom, parser
) {
parser.parse();
app.printUrl = "https://sampleserver6.arcgisonline.com/arcgis/rest/services/Utilities/PrintingTools/GPServer/Export%20Web%20Map%20Task";
esriConfig.defaults.io.proxyUrl = "http://our-server/Java/proxy.jsp";
// get print templates from the export web map task
var printInfo = esriRequest({
"url": app.printUrl,
"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";
plate.layoutOptions = {
"authorText": "Made by: Esri's JS API Team",
"copyrightText": "<copyright info here>",
"legendLayers": [],
"titleText": "Pool Permits",
"scalebarUnit": "Miles"
};
return plate;
});
// create the print dijit
app.printer = new Print({
"map": app.map,
"templates": templates,
url: app.printUrl
}, dom.byId("print_button"));
app.printer.startup();
}
function handleError(err) {
console.log("Something broke: ", err);
}
}); They come together in the index.html: <!DOCTYPE html>
<html dir="ltr">
<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" />
<link rel="stylesheet" href="https://js.arcgis.com/3.17/dijit/themes/claro/claro.css">
<link rel="stylesheet" href="https://js.arcgis.com/3.17/esri/css/esri.css">
<link rel="stylesheet" href="https://js.arcgis.com/3.18/dojox/layout/resources/ExpandoPane.css">
<link rel="stylesheet" href="css/widget_styles.css">
<script src="https://js.arcgis.com/3.17/"></script>
<script type="text/javascript">
dojo.require("dojox.layout.ExpandoPane");
</script>
<script src="js/Map.js"></script>
<script src="js/Legend.js"></script>
<script src="js/Search.js"></script>
<script src="js/Print.js"></script>
</head>
<body class="claro">
<div id="content"
data-dojo-type="dijit/layout/BorderContainer"
data-dojo-props="design:'headline', gutters:true"
style="width: 100%; height: 100%; margin: 0;">
<div id="rightPane"
data-dojo-type="dojox/layout/ExpandoPane"
data-dojo-props="region:'right',title:'Widgets',startExpanded:false">
<div data-dojo-type="dijit/layout/AccordionContainer">
<div data-dojo-type="dijit/layout/ContentPane" id="legendPane"
data-dojo-props="title:'Légende', selected:true">
<div id="legendDiv"></div>
</div>
<div data-dojo-type="dijit/layout/ContentPane"
data-dojo-props="title:'Pane 2'">
</div>
</div>
</div>
<div id="map"
data-dojo-type="dijit/layout/ContentPane"
data-dojo-props="region:'center'"
style="overflow: hidden;width: 100%; height: 100%; margin: 0;">
<div id="feedback" class="shadow">
<h3>
Print Templates Created from Info Returned by the Print Service using
<a href="https://developers.arcgis.com/javascript/3/jsapi/esri.request-amd.html">esri.request</a>
</h3>
<div id="info">
<div id="note">
Note: This sample uses an ArcGIS Server version 10.1 export web map task.
</div>
<div id="print_button"></div>
<div id="info">
<a href="https://developers.arcgis.com/javascript/3/jsapi/printtemplate.html">Print templates</a> are generated
from the Export Web Map Task's <a href="https://sampleserver6.arcgisonline.com/arcgis/rest/services/Utilities/PrintingTools/GPServer/Export%20Web%20Map%20Task">Layout_Template parameter</a>. This info is retrieved from the service
using <a href="https://developers.arcgis.com/javascript/3/jsapi/esri.request-amd.html">esri.request</a>.
</div>
</div>
</div>
</div>
<div id="search"></div>
</div>
</body>
</html>
... View more
10-15-2016
04:47 PM
|
0
|
3
|
1413
|
POST
|
Checkout branch ID_Mult, actually. Unless you'd already taken a look at the other. Many thanks, by the way.
... View more
10-15-2016
04:09 PM
|
0
|
1
|
809
|
POST
|
I sent you an invitation--the branch we've been discussing is called Identify. I've realized that the print branch also causes this typeerror: map is undefined from time to time as well, which is why I'm almost certain this is not directly caused by the identify code. Mahalo
... View more
10-12-2016
03:44 PM
|
0
|
0
|
809
|
Title | Kudos | Posted |
---|---|---|
1 | 01-21-2017 11:33 PM |
Online Status |
Offline
|
Date Last Visited |
11-11-2020
02:23 AM
|