POST
|
Sounds Like what Ken is saying is right, attaching the function to the checkbox inline via the "onclick" attribute will look for a global function by that name. However if you defined that function inside the require statement, it will be scoped to that require and not globally which will probably show some errors in the console when you try to check them. Putting it in JSBin or JSFiddle so we could see the whole code would be really helpful or you can try adding the listeners programmatically via document.addEventListener (or attachEvent depending what browsers you want to support) or just use dojo's on module. It would look something like this.
require(["dojo/on", "dojo/dom"], function (on, dom) {
function updateLayerVisibility() {
...
}
on(dom.byId("myCheckbox"),"click",updateLayerVisibility);
});
Make sure the modules you require map to your aliases and remember that your aliases are case-sensitive, for example:
require(["dojo/dom"], function (dom) {
Dom.byId(); // This will fail because its using a capital,
dom.byId(); // This is the right way
});
and if you require dojo/dom, then dojo/on, and in the function parameters you specify them in a different order (on, dom) they will not work as expected, the order must match the order in which they were required.
... View more
01-28-2014
06:09 AM
|
0
|
0
|
390
|
POST
|
Can you post your code that you are trying to do this with. I do not think there is anything that you specifically need to require to make this work. You should be able to just get a valid reference to your layer object, and call setVisibleLayers with a valid array of layer id's and it should work.
... View more
01-27-2014
12:01 PM
|
0
|
0
|
390
|
POST
|
Hi everyone, I am trying to use the Print Task to print legends with titles and am unsure how to include legend titles in the output. I can get the legends and everything to print correctly but if the user has multiple layers on the map which means multiple layers in the legend, how can I include titles in the printout. Attached is a screenshot of my current output, and if you look at the legend it has eight items all labeled but the actual layer names are not there. We would like to be able to label these with Legal Classification Layer and Oil Palm Custom Suitability Layer if possible over the appropriate legend items. Is there any way to add in legend titles ? [ATTACH=CONFIG]30898[/ATTACH]
... View more
01-27-2014
11:38 AM
|
1
|
0
|
478
|
POST
|
You can try using the PrintTask. You can find info on it here: https://developers.arcgis.com/javascript/jsapi/printtask-amd.html. It takes a URL and a PrintParameters object as its params. Inside the PrintParameters object you can pass in a PrintTemplate object which can use all the default values and then you can pass inside the layoutOptions, an array of legend layers. The legend Layers need to be legend layer objects and not an array of layer ids, something like here: https://developers.arcgis.com/javascript/jsapi/legendlayer-amd.html. You will need to create a new legend layer object, give it a layerId and sublayer ids and then push that into the array of legend layers. Here's a small snippet from one of my apps:
if (optionalLayer.visible) {
legendLayer = new esri.tasks.LegendLayer();
legendLayer.layerId = optionalLayer.id;
legendLayer.subLayerIds = optionalLayer.visibleLayers;
options.legendLayers.push(legendLayer);
}
If you pass in the legend layer info correctly the print task should be able to pull in custom symbology for your layer from the renderer, you should actually be able to see it in your outgoing request JSON.
... View more
01-27-2014
11:30 AM
|
1
|
1
|
1162
|
POST
|
Hey Jian, Thanks for the snippet, that really helped, it is now working as it should, I had to just make a minor tweak to my class and everything is now working as expected. It seems I was missing the "esri/layers/ArcGISImageServiceLayer" from my initial define, adding that in pretty much did the trick. I also had to play with the renderingRule to JSON function to get it working correctly with our renderingRule but everything is working great now without the need for the esri.setRequestPreCallback. 🙂 Thanks again!!
... View more
12-20-2013
04:52 AM
|
0
|
0
|
220
|
POST
|
I looked at the source code. PrintTask doesn't work with any custom layer. Because it checks the property layer.declaredClass to decide what to serialize into the json output. In your case, only when layer.declaredClass === "esri.layers.ArcGISImagerServiceLayer", it will serialize renderingRule. Is your custom layer written in AMD style or legacy style? You can try to override .declaredClass property as "esri.layers.ArcGISImagerServiceLayer". It shouldn't cause any conflicts. Thanks Jian, we are using the AMD style, the whole class is listed below if that will be of some help. I tried overriding the .declaredClass property and it still did not seem like it wanted to pick it up. Here is our version of the class, it makes use of Knockout to store values from sliders and checkboxes in Model.getVM().suitabilityCustomSettings().computeBinaryRaster as an array and through some helper functions we are able to construct our custom renderingRule.
define(["declare", "esri/layers/RasterFunction", "esri/layers/ImageServiceParameters", "toolsmodel", "dojo/_base/array", "dojo/_base/lang"],
function (declare, RasterFunction, ImageServiceParameters, Model, arrayUtils, lang) {
return declare("SuitabilityImageServiceLayer", esri.layers.ArcGISImageServiceLayer, {
constructor: function () {
// raster function arguments must be in same order as in image service moasic dataset
this.rasterFunctionArguments = {};
this.rasterFunctionArguments.ElevRaster = "$1";
this.rasterFunctionArguments.SlopeRaster = "$2";
this.rasterFunctionArguments.WaterRaster = "$3";
this.rasterFunctionArguments.ConsRaster = "$4";
this.rasterFunctionArguments.STypeRaster = "$5";
this.rasterFunctionArguments.SDepthRaster = "$6";
this.rasterFunctionArguments.PeatRaster = "$7";
this.rasterFunctionArguments.SAcidRaster = "$8";
this.rasterFunctionArguments.SDrainRaster = "$9";
this.rasterFunctionArguments.RainfallRaster = "$10";
this.rasterFunctionArguments.LCRaster = "$11";
// scalars are harded-coded based on raster pre-processing scripts
this.rasterFunctionScalars = {};
this.rasterFunctionScalars.Elev = 10;
this.rasterFunctionScalars.Slope = 1;
this.rasterFunctionScalars.Water = 10;
this.rasterFunctionScalars.Cons = 100;
this.rasterFunctionScalars.SType = 1;
this.rasterFunctionScalars.SDepth = 1;
this.rasterFunctionScalars.Peat = 1;
this.rasterFunctionScalars.SAcid = 1;
this.rasterFunctionScalars.SDrain = 1;
this.rasterFunctionScalars.Rainfall = 10;
this.rasterFunctionScalars.LC = 1;
this.renderingRule = {};
this.declaredClass = "esri.layers.ArcGISImageServiceLayer";
var rasterFunction = new RasterFunction();
rasterFunction.functionName = "RemapColormap2Prashant";
rasterFunction.arguments = this.rasterFunctionArguments;
var params = new ImageServiceParameters();
params.noData = 0;
params.renderingRule = rasterFunction;
this.imageServiceParameters = params;
},
getExportUrl: function(extent,width,height,callback,options){
function callback(url){
return;
}
},
getRenderingRule: function () {
//console.log("GET RENDER RULE");
var _self = this;
var suitabilitySettings = _self.returnRasterSettingsAsObject();
var render_rule = {};
lang.mixin(render_rule, this.rasterFunctionArguments);
_self.addThresholdArgument(suitabilitySettings, render_rule, 'Elev', _self.rasterFunctionScalars, 'MAX');
_self.addThresholdArgument(suitabilitySettings, render_rule, 'Slope', _self.rasterFunctionScalars, 'MAX');
_self.addThresholdArgument(suitabilitySettings, render_rule, 'Water', _self.rasterFunctionScalars, 'MIN');
_self.addThresholdArgument(suitabilitySettings, render_rule, 'Cons', _self.rasterFunctionScalars, 'MIN');
_self.addThresholdArgument(suitabilitySettings, render_rule, 'Rainfall', _self.rasterFunctionScalars, 'BETWEEN');
_self.addMembershipArgument(suitabilitySettings, render_rule, 'SDepth', [0, 1, 2, 3, 4, 5, 6, 7]);
_self.addMembershipArgument(suitabilitySettings, render_rule, 'Peat', [0, 1, 2, 3, 4, 5, 6]);
_self.addMembershipArgument(suitabilitySettings, render_rule, 'SAcid', [0, 1, 2, 3, 4, 5, 6, 7]);
_self.addMembershipArgument(suitabilitySettings, render_rule, 'SDrain', [0, 1, 2, 3, 4]);
_self.addMembershipArgument(suitabilitySettings, render_rule, 'LC', [0, 1, 2, 3, 4, 5, 6, 7, 8]);
_self.addMembershipArgument(suitabilitySettings, render_rule, 'SType', [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
var rasterFunction = new RasterFunction();
rasterFunction.rasterFunction = "PalmOilSuitabilityNew";
rasterFunction.rasterFunctionArguments = render_rule;
return rasterFunction;
},
getImageUrl: function (extent, width, height, callback, options) {
var _self = this;
var bbox = [extent.xmin, extent.ymin, extent.xmax, extent.ymax],
params,
min,
max,
tempArray,
membership_arguments;
var rasterFunction = _self.getRenderingRule();
if (options) {
params = options;
params['renderingRule'] = JSON.stringify(rasterFunction);
params['bbox'] = bbox.join(",");
_self.renderingRule = rasterFunction;
callback(_self.url + "/exportImage?",params);
} else {
params = {
noData: 0,
noDataInterpretation: "esriNoDataMatchAny",
interpolation: "RSP_BilinearInterpolation",
renderingRule: JSON.stringify(rasterFunction),
format: "png8",
size: width + "," + height,
imageSR: 3857,
bboxSR: 3857,
f: "image",
pixelType: 'U8',
bbox: bbox.join(",")
};
_self.renderingRule = rasterFunction;
callback(_self.url + "/exportImage?" + dojo.objectToQuery(params));
}
},
returnRasterSettingsAsObject: function () {
var result = {};
var settingsArray = Model.getVM().suitabilityCustomSettings().computeBinaryRaster;
arrayUtils.forEach(settingsArray, function (setting) {
result[setting.name] = setting.values;
});
return result;
},
returnNumericArray : function (stringArray) {
var temp = stringArray.split(",");
var result = [];
arrayUtils.forEach(temp, function (value) {
result.push(parseInt(value, 10));
});
return result;
},
addThresholdArgument: function (suitabilitySettings, renderRule, variableName, scalars, breakType) {
var _self = this;
scalar = scalars[variableName];
if (breakType === 'BETWEEN') {
var tempArray = _self.returnNumericArray(suitabilitySettings[variableName + 'InpR']);
var min = tempArray[0];
var max = tempArray[tempArray.length - 1];
renderRule[variableName + 'InpR'] = [0, min / scalar, min / scalar, max / scalar, max / scalar, 1000000];
renderRule[variableName + 'OutV'] = [1, 1, 0];
} else {
var breakpoint = parseInt(suitabilitySettings[variableName + 'InpR'], 10);
renderRule[variableName + 'InpR'] = [0, breakpoint / scalar, breakpoint / scalar, 1000000];
renderRule[variableName + 'OutV'] = breakType === 'MIN' ? [0, 1] : [1, 0];
}
},
addMembershipArgument: function (suitabilitySettings, renderRule, variableName, allValues) {
var _self = this;
var validValues = _self.returnNumericArray(suitabilitySettings[variableName + 'InpR']);
var input_values = [];
var output_values = [];
var includeNulls = ["SDepth","SAcid","SDrain","LC"];
var val;
var i;
if (includeNulls.indexOf(variableName) > -1 && validValues[0] !== 0)
validValues.unshift(0);
for (i = 0; i < allValues.length; i++) {
val = allValues;
input_values.push(val, val);
if (validValues.indexOf(val) === -1) {
output_values.push(0);
} else {
output_values.push(1);
}
}
renderRule[variableName + 'InpR'] = input_values;
renderRule[variableName + 'OutV'] = output_values;
}
});
});
... View more
12-19-2013
04:30 AM
|
0
|
0
|
220
|
POST
|
Can you post the web map json sent to print service? Ahhh that's it. I was using GET not POST. That got it working from the endpoint. Im not sure why but on the JavaScript side when we call print task our renderingRule isn't being inserted automatically in to the web map JSON so I will do some digging to see if we messed something up with our custom ImageServiceLayer that's preventing this. In the meantime, I was able to get it to work properly when I used something along the lines of this:
require(["esri/request"], function(request) {
request.setRequestPreCallback(function(ioArgs) {
// if request is to the PrintingTools url
// Get my Image Service Layer from ioArgs.content.Web_Map_as_JSON
// Add in my rendering rule and rasterFunctionArguments
// replace webmap JSON with updated JSON and request now uses POST instead of GET
return ioArgs;
});
});
Thanks for your help.
... View more
12-18-2013
05:01 AM
|
0
|
0
|
613
|
POST
|
Would there happen to be a sample anywhere that shows print task working with ImageServiceLayer or a working URL so I could see what a successful request looks like, we tried manually changing the JSON at the rest endpoint and kept getting 404 errors because we are not sure what a successful request with a rendering rule would look like.
... View more
12-13-2013
09:18 AM
|
0
|
0
|
613
|
POST
|
PrintTask includes renderingRule if that property exists in your layer. Please check yourCustomImageServiceLayer.renderingRule is there, and yourCustomImageServiceLayer.renderingRule.toJson() is a valid function. Ahh I think you may be on to something. I logged the layer to the console and noticed the renderingRule was null, so I added a this.renderingRule = _self.getRenderingRule() inside the getImageUrl() function, which the getRenderingRule() is a function we have added in to build the custom rendering rule based off some slider and checkbox controls we have in the app. After doing this I did a console.dir(layer.renderingRule.toJson()) and kept getting a blank object. I overwrote the toJson method inside the constructor and was getting the same response, just a blank object, so I then moved it to the getImageUrl() function and was able to get it to retrieve the JSON string but still am unable to see it print. I put in alert in the layer.renderingRule.toJson() and it does not fire when I call the print task. I tried just logging layer.renderingRule.toJson() to the console and this was what it returned.
"{"rasterFunction":"PalmOilSuitabilityNew","rasterFunctionArguments":{"ElevRaster":"$1","SlopeRaster":"$2","WaterRaster":"$3","ConsRaster":"$4","STypeRaster":"$5","SDepthRaster":"$6","PeatRaster":"$7","SAcidRaster":"$8","SDrainRaster":"$9","RainfallRaster":"$10","LCRaster":"$11","ElevInpR":[0,100,100,1000000],"ElevOutV":[1,0],"SlopeInpR":[0,30,30,1000000],"SlopeOutV":[1,0],"WaterInpR":[0,10,10,1000000],"WaterOutV":[0,1],"ConsInpR":[0,10,10,1000000],"ConsOutV":[0,1],"RainfallInpR":[0,150,150,700,700,1000000],"RainfallOutV":[1,1,0],"SDepthInpR":[0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7],"SDepthOutV":[1,0,0,0,1,1,1,1],"PeatInpR":[0,0,1,1,2,2,3,3,4,4,5,5,6,6],"PeatOutV":[1,0,0,0,0,0,0],"SAcidInpR":[0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7],"SAcidOutV":[1,1,1,1,1,1,1,1],"SDrainInpR":[0,0,1,1,2,2,3,3,4,4],"SDrainOutV":[1,0,1,1,1],"LCInpR":[0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8],"LCOutV":[1,1,1,1,0,0,0,0,0],"STypeInpR":[1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10],"STypeOutV":[1,1,1,0,1,1,1,1,1,0]}}"
does this look like a valid renderingRule and is setting the this.renderingRule to the newly created custom renderingRule in getImageUrl() the best way to keep it up to date and setting the toJson() function in the getImageUrl() as well the right way to override it ?
... View more
12-12-2013
03:11 PM
|
0
|
0
|
613
|
POST
|
It's quite a bit of code and it's on a password protected staging url unfortunately, I could zip up the project and email it or would it be helpful if I uploaded my custom ImageServiceLayer class and provided the parameters I use with it such as my raster function and other settings I am using in the getImageUrl function I overrided. I could probably extract the minimum resources necessary and put it in a fiddle if needs be. Which would be the best for you? Do you know if by default the print task is supposed to include the rendering rule from an ArcGISImageServiceLayer and that possibly in my implementation of the class I changed something that is causing it to not be picked up when the print task executes. Here is some small snippets of how I am using the print task and from my custom class:
require(["esri/tasks/PrintTask","esri/tasks/PrintParameters","esri/tasks/PrintTemplate","mapui","mainmodel"],
function(PrintTask,PrintParameters,PrintTemplate,MapUI,MainModel){
var printConfig = Config.getConfig().print,
printTask = new PrintTask(printConfig.url),
params = new PrintParameters(),
viewModel = MainModel.getVM();
params.map = MapUI.getMap();
params.template = new PrintTemplate();
params.template.label = printConfig.template.label;
params.template.format = printConfig.template.format;
params.template.layout = printConfig.template.layout;
params.template.layoutOptions = printConfig.template.layoutOptions;
var languageIsEnglish = (query(".selectedLanguage")[0].id === "languageEnglish");
if(languageIsEnglish)
viewModel.printMap("Printing");
else
viewModel.printMap("Printing");
printTask.execute(params,function(response){
window.open(response.url);
if(languageIsEnglish)
viewModel.printMap("Print");
else
viewModel.printMap("Cetak");
},function(error){
if(languageIsEnglish)
viewModel.printMap("Print");
else
viewModel.printMap("Cetak");
});
});
The printConfig looks like this :
print: {
url:"http://gis-stage.wri.org/arcgis/rest/services/Utilities/PrintingTools/GPServer/Export%20Web%20Map%20Task",
template: {
label:"Map",
format:"PNG32",
layout:"A4 Landscape",
layoutOptions: {
titleText: "Suitability Map",
authorText: "WRI & esri",
copyrightText: "WRI",
scalebarUnit: "Miles"
}
}
}
and here is my getImageUrl method from my custom class
getImageUrl: function (extent, width, height, callback,options) {
var _self = this;
var bbox = [extent.xmin, extent.ymin, extent.xmax, extent.ymax],
params,
min,
max,
tempArray,
membership_arguments;
var rasterFunction = _self.getRenderingRule();
if (options) {
params = options;
params['renderingRule'] = JSON.stringify(rasterFunction);
params['bbox'] = bbox.join(",");
callback(_self.url + "/exportImage?",params);
}
else {
params = {
noData: 0,
noDataInterpretation: "esriNoDataMatchAny",
interpolation: "RSP_BilinearInterpolation",
renderingRule: JSON.stringify(rasterFunction),
format: "png8",
size: width + "," + height,
imageSR: 3857,
bboxSR: 3857,
f: "image",
pixelType: 'U8',
bbox: bbox.join(",")
};
callback(_self.url + "/exportImage?" + dojo.objectToQuery(params));
}
},
Everything works fine except the print task is just not including the rendering rule.
... View more
12-11-2013
05:27 AM
|
0
|
0
|
613
|
POST
|
Hi Everyone, I am working on executing a print task on a map with a custom ArcGISImageServiceLayer and am hitting a bit of a snag. It seems that when I execute the print task it will work but it returns back a incorrect image in grey and black and not one including the colors or parameters currently shown in the layer. I noticed in the json being sent in it does not include any params or a rendering rule which I am assuming might have something to do with this. Is there anyway to override a method in the layer so when using the print task I can include the rendering rule and any other necessary params into the request?
... View more
12-09-2013
10:29 AM
|
0
|
13
|
3189
|
POST
|
If you are working with the basemap gallery, then you will have to monitor it's change events and use it's methods to get the current selected basemap.
basemapGallery.on('selection-change', function(){
alert(basemapGallery.getSelected().title);
});
You'll probably want to return the id instead of the title, since that's what the basemapGallery.select() requires. Yea that's what I ended up doing, but since that returns the label or the id as "basemap_0" or whatever number the id has, I had to use a sort of lookup table to map the id/title to it's well-known name so that I can call map.setBasemap("gray") (or whatever the basemap name is) on the other map objects that are synced with the main one. Was kind of hoping I could call map.getBasemap() but it seems this is not tied to the basemap gallery so once you change basemaps, map.getBasemap() returns the incorrect name or use one of the aforementioned events which is supposed to return the well-known name but I can't get those to fire
... View more
10-23-2013
10:43 AM
|
0
|
0
|
393
|
POST
|
Hi all, I am having some troubles with these two event listeners(onBasemapChange() and it's on equivalent "basemap-change") for the map as well as the map.getBasemap() function. I have tried this in my own code and then also went to the basemap gallery sample and added these events/function to the sandbox to test there as well. The sample I used is here: http://developers.arcgis.com/en/javascript/sandbox/sandbox.html?sample=widget_basemap I then added the following code:
map.on("load",function(){
map.on("basemap-change",function(){
alert("Fired Basemap-change");
});
});
basemapGallery.on("selection-change",function(){
alert(map.getBasemap());
}); The "Fired Basemap-change" alert never fires even when I tried this
dojo.connect(map,"onBasemapChange",function(){
alert("Fired Basemap-change")
}) The second alert will fire as it is inside the basemapGallery.on("selection-change") but the map.getBasemap() returns the same string every time, whatever I set the default basemap inside the map constructor to is the value this function always returns, I thought it was supposed to return the well-known name of the current basemap, is this normal for this function? In the end I am building a custom dojo widget to sync 4 map objects together and am trying to add in a basemap syncing option as well so that when the user changes the basemap on the main map, it changes the other maps basemaps as well. My thought was to get the well-known name of the current basemap from the main map and then loop through my array of other maps and just simply call map.setBasemap. Is there another way to get this well-known basemap name?
... View more
10-23-2013
08:12 AM
|
0
|
2
|
780
|
POST
|
Anyone have any ideas for this one? I noticed the code sample under portal > add shape file works in IE9 so I am not sure if this is an error on client side or if I need to configure the proxy a special way, any help or even a point in the right direction would be helpful, can post code if needed.
... View more
06-21-2013
11:01 AM
|
0
|
0
|
738
|
POST
|
So I am having some trouble uploading a shapefile in IE9. I was able to get it working in Chrome, Safari, and FF. In IE9 at first it was failing giving me an access denied error, so I pointed the app to my local php proxy and added the url in the serverURL's array and I got past this part. But now I am getting an error stating 'Unable to get value of the property 'value'. object is null or undefined'. As far as I can tell I am getting all the way to esri.request and then that is where the error is happening. My code is pretty much the same thing as the sample code but just in case, here is the esri.request code
esri.request({
url: portalURL+"/sharing/rest/content/features/generate",
content: myContent,
form: dom.byId("uploadForm"),
handleAs: 'json',
load:lang.hitch(this,function(response){
if(response.error){
_self._uploadErrorHandler(response.error);
return;
}
dom.byId("upload-status").innerHTML = "<p style='color:#0F0'>Loaded: "+response.featureCollection.layers[0].layerDefinition.name+"</p>";
_self._addShapeFileToMap(response.featureCollection);
}),
error: lang.hitch(this,_self._uploadErrorHandler)
}); Edit: I noticed when logging the error to the console in IE, the only two things I found that were null or undefined so far are in the error object, error._ssl is undefined and error.response.options.query is null
... View more
06-20-2013
12:16 PM
|
0
|
7
|
3509
|
Title | Kudos | Posted |
---|---|---|
1 | 01-08-2015 01:10 PM | |
1 | 08-28-2015 08:59 AM | |
1 | 08-11-2015 08:52 AM | |
1 | 08-31-2015 12:26 PM | |
1 | 04-13-2016 09:04 AM |
Online Status |
Offline
|
Date Last Visited |
11-11-2020
02:23 AM
|