|
POST
|
Jake Skinner, Since this is a 3rd party TOC widget I don't think it has a destroy function. I ended up doing it the following way. <!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>NOAA</title>
<link rel="stylesheet" href="https://community.esri.com//js.arcgis.com/3.12/dijit/themes/claro/claro.css"/>
<link rel="stylesheet" href="https://js.arcgis.com/3.13/esri/css/esri.css"/>
<link rel="stylesheet" type="text/css" href="https://timw1984.github.io/agsjs/css/agsjs.css" />
<style>
html, body{
height: 100%;
width: 100%;
margin: 0;
padding: 1px;
font-family: helvetica, arial, sans-serif;
font-size: 90%;
overflow: hidden;
}
#borderContainer {
width: 100%;
height: 100%;
}
#leftPane {
width: 20%;
}
#bottomPane {
width: 100%;
}
#centerPane {
width: 100%;
height: 100%;
}
#map {
width: 100%;
height: 100%;
}
</style>
<script type="text/javascript">
var dojoConfig = {
paths: {
agsjs: location.pathname.replace(/\/[^/]+$/, '') + 'https://timw1984.github.io/agsjs'
}
};
</script>
<script src="https://js.arcgis.com/3.13/"></script>
<script>
var map;
require(["esri/map", "esri/layers/ArcGISDynamicMapServiceLayer", "dojo/parser", "agsjs/dijit/TOC","dojo/_base/connect","dojo/dom", "dojo/parser","dojo/on", "dojo/_base/Color","dijit/form/Button","esri/layers/FeatureLayer","dojo/dom-construct",
"dijit/layout/BorderContainer","dijit/layout/ContentPane","dijit/layout/AccordionContainer","dijit/layout/ContentPane", "dijit/layout/AccordionContainer","dijit/form/TextBox","dojo/domReady!"],
function(Map,ArcGISDynamicMapServiceLayer, parser,TOC,connect, dom, parser, on,Color, Button, FeatureLayer,domConstruct) {
parser.parse();
map = new Map("map", {
basemap: "topo",
center: [-95.45, 37.75],
zoom: 4
});
var county, toc,currentLayer,currentDiv,previouseDiv;
var click = 0;
var AddedLayer = "";
var gauge = new ArcGISDynamicMapServiceLayer("http://gis.srh.noaa.gov/arcgis/rest/services/ahps_gauges/MapServer",{
refreshInterval: 1,
visible: false
});
var radar = new ArcGISDynamicMapServiceLayer("http://gis.srh.noaa.gov/arcgis/rest/services/RIDGERadar/MapServer",{
refreshInterval: 1,
visible: false
});
var hazard = new ArcGISDynamicMapServiceLayer("http://gis.srh.noaa.gov/arcgis/rest/services/cpc_weather_hazards/MapServer",{
refreshInterval: 1,
visible: false
});
map.addLayers([radar,hazard,gauge] );
map.on('layers-add-result', legenddoit);
function legenddoit(evt){
if ( AddedLayer == "") {
var LegendLayers = [{
layer: hazard,
title: "Hazard",
collapse: true
},{
layer: radar,
title: "Radar",
collapsed: true, // whether this root layer should be collapsed initially, default false.
slider: true,
noLegend: true // whether to display a transparency slider.
},{
layer: gauge,
title: "Gauge",
collapse: true,
}];
//radar.setVisibleLayers([0]);
//gauge.setVisibleLayers([0]);
//hazard.setVisibleLayers([0]);
toc = new TOC({
map: map,
layerInfos: LegendLayers
}, 'tocDiv');
toc.startup();
} else {
var currentDiv = currentLayer;
var LegendLayers = [{
layer: hazard,
title: "Hazard",
collapse: true
},{
layer: radar,
title: "Radar",
collapsed: true,
slider: true,
noLegend: true
},{
layer: gauge,
title: "Gauge",
collapse: true,
}, {
layer: county,
title: "County",
collapse: true,
}];
toc2 = new TOC({
map: map,
layerInfos: LegendLayers
}, currentDiv );
toc2.startup();
}
};
var myButton = new Button({
label: "Click me!",
onClick: function(){
click += 1;
previouseDiv = currentDiv;
previouseLayer = currentLayer;
currentLayer = "layer" + click;
console.log(currentLayer);
if (county !== undefined){
console.log(county);
map.removeLayer(county);
}
currentDiv = "<div id=" + currentLayer +">";
NeededValue = dom.byId("myURL").value;
console.log(NeededValue);
county = new FeatureLayer(NeededValue,{
outFields: ['*']
});
var MyName = county.name;
map.addLayers([county]);
AddedLayer = "Gotem";
if (currentLayer == "layer1"){
domConstruct.place(currentDiv + "<div>", 'tocDiv',"replace");
} else {
domConstruct.place(currentDiv + "<div>", previouseLayer,"replace");
}
}
}, "progButtonNode").startup();
});
</script>
</head>
<body class ="claro">
<div id="borderContainer" data-dojo-type="dijit/layout/BorderContainer" data-dojo-props="design:'headline', gutters:true, liveSplitters:true">
<div id="centerPane" data-dojo-type="dijit/layout/ContentPane" data-dojo-props="splitter:true, region:'center'">
<div id="map">
</div>
</div>
<div id="bottomPane" data-dojo-type="dijit/layout/ContentPane" data-dojo-props="splitter:true, region:'bottom'">
<label for="firstname">Add a layer:</label>
<input type="text" name="myURL" value="http://gis.brevardcounty.us/gissrv/rest/services/Base_Map/General_WKID102100/MapServer/5"
data-dojo-type="dijit/form/TextBox"
data-dojo-props="trim:true, propercase:true" id="myURL" />
<button id="progButtonNode" type="button"></button><div id="result1"></div>
</div>
<div id="leftPane" data-dojo-type="dijit/layout/ContentPane" data-dojo-props="region:'leading'">
<div data-dojo-type="dijit/layout/AccordionContainer" style="height: 300px;">
<div data-dojo-type="dijit/layout/ContentPane" title="Legend" selected="true">
<div id ="LegendInHere">
<div id="tocDiv">
</div>
</div>
</div>
<div data-dojo-type="dijit/layout/ContentPane" title="Pane 2">
<div id="tocDiv2">
</div>
</div>
</div>
</div>
</div>
</body>
</html> Tim
... View more
06-05-2015
06:08 AM
|
0
|
0
|
2430
|
|
POST
|
Hey everybody, I use the following code to create a map with a legend: <!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>NOAA</title>
<link rel="stylesheet" href="https://community.esri.com//js.arcgis.com/3.12/dijit/themes/claro/claro.css"/>
<link rel="stylesheet" href="https://js.arcgis.com/3.13/esri/css/esri.css"/>
<link rel="stylesheet" type="text/css" href="https://timw1984.github.io/agsjs/css/agsjs.css" />
<style>
html, body{
height: 100%;
width: 100%;
margin: 0;
padding: 1px;
font-family: helvetica, arial, sans-serif;
font-size: 90%;
overflow: hidden;
}
#borderContainer {
width: 100%;
height: 100%;
}
#leftPane {
width: 20%;
}
#bottomPane {
width: 100%;
}
#centerPane {
width: 100%;
height: 100%;
}
#map {
width: 100%;
height: 100%;
}
</style>
<script type="text/javascript">
var dojoConfig = {
paths: {
agsjs: location.pathname.replace(/\/[^/]+$/, '') + 'https://timw1984.github.io/agsjs'
}
};
</script>
<script src="https://js.arcgis.com/3.13/"></script>
<script>
var map;
require(["esri/map", "esri/layers/ArcGISDynamicMapServiceLayer", "dojo/parser", "agsjs/dijit/TOC","dojo/_base/connect","dojo/dom", "dojo/parser","dojo/on", "dojo/_base/Color","dijit/form/Button","esri/layers/FeatureLayer","dojo/dom-construct",
"dijit/layout/BorderContainer","dijit/layout/ContentPane","dijit/layout/AccordionContainer","dijit/layout/ContentPane", "dijit/layout/AccordionContainer","dijit/form/TextBox","dojo/domReady!"],
function(Map,ArcGISDynamicMapServiceLayer, parser,TOC,connect, dom, parser, on,Color, Button, FeatureLayer,domConstruct) {
parser.parse();
map = new Map("map", {
basemap: "topo",
center: [-95.45, 37.75],
zoom: 4
});
var county;
var AddedLayer = "";
var gauge = new ArcGISDynamicMapServiceLayer("http://gis.srh.noaa.gov/arcgis/rest/services/ahps_gauges/MapServer",{
refreshInterval: 1,
visible: false
});
var radar = new ArcGISDynamicMapServiceLayer("http://gis.srh.noaa.gov/arcgis/rest/services/RIDGERadar/MapServer",{
refreshInterval: 1,
visible: false
});
var hazard = new ArcGISDynamicMapServiceLayer("http://gis.srh.noaa.gov/arcgis/rest/services/cpc_weather_hazards/MapServer",{
refreshInterval: 1,
visible: false
});
map.addLayers([radar,hazard,gauge] );
map.on('layers-add-result', legenddoit);
function legenddoit(evt){
if ( AddedLayer == "") {
var LegendLayers = [{
layer: hazard,
title: "Hazard",
collapse: true
},{
layer: radar,
title: "Radar",
collapsed: true, // whether this root layer should be collapsed initially, default false.
slider: true,
noLegend: true // whether to display a transparency slider.
},{
layer: gauge,
title: "Gauge",
collapse: true,
}];
//radar.setVisibleLayers([0]);
//gauge.setVisibleLayers([0]);
//hazard.setVisibleLayers([0]);
toc = new TOC({
map: map,
layerInfos: LegendLayers
}, 'tocDiv');
toc.startup();
} else {
var LegendLayers = [{
layer: hazard,
title: "Hazard",
collapse: true
},{
layer: radar,
title: "Radar",
collapsed: true,
slider: true,
noLegend: true
},{
layer: gauge,
title: "Gauge",
collapse: true,
}, {
layer: county,
title: "County",
collapse: true,
}];
toc2 = new TOC({
map: map,
layerInfos: LegendLayers
}, 'tocDiv');
toc2.startup();
}
};
var myButton = new Button({
label: "Click me!",
onClick: function(){
if (county !== undefined){
console.log(county);
map.removeLayer(county);
}
// Do something:
NeededValue = dom.byId("myURL").value;
console.log(NeededValue);
county = new FeatureLayer(NeededValue,{
outFields: ['*']
});
var MyName = county.name;
map.addLayers([county]);
AddedLayer = "Gotem";
domConstruct.destroy("tocDiv");
dojo.create("div", {id: "tocDiv"}, "LegendInHere");
}
}, "progButtonNode").startup();
});
</script>
</head>
<body class ="claro">
<div id="borderContainer" data-dojo-type="dijit/layout/BorderContainer" data-dojo-props="design:'headline', gutters:true, liveSplitters:true">
<div id="centerPane" data-dojo-type="dijit/layout/ContentPane" data-dojo-props="splitter:true, region:'center'">
<div id="map">
</div>
</div>
<div id="bottomPane" data-dojo-type="dijit/layout/ContentPane" data-dojo-props="splitter:true, region:'bottom'">
<label for="firstname">Add a layer:</label>
<input type="text" name="myURL" value="http://gis.brevardcounty.us/gissrv/rest/services/Base_Map/General_WKID102100/MapServer/5"
data-dojo-type="dijit/form/TextBox"
data-dojo-props="trim:true, propercase:true" id="myURL" />
<button id="progButtonNode" type="button"></button><div id="result1"></div>
</div>
<div id="leftPane" data-dojo-type="dijit/layout/ContentPane" data-dojo-props="region:'leading'">
<div data-dojo-type="dijit/layout/AccordionContainer" style="height: 300px;">
<div data-dojo-type="dijit/layout/ContentPane" title="Legend" selected="true">
<div id ="LegendInHere">
<div id="tocDiv">
</div>
</div>
</div>
<div data-dojo-type="dijit/layout/ContentPane" title="Pane 2">
<div id="tocDiv2">
</div>
</div>
</div>
</div>
</div>
</body>
</html> What I try to accomplish is that if you click on the button, the layer in the textbox is added, the current legend will be destroyed and rebuild with the new layer added. Everything works, if I change the id in line 161 to anything but the id that I destroy a line before. The problem is that I need it to be the same name. any idea what I am doing wrong? You can test to see what I want it to look like by replacing tocDiv in line 161 and 137 to tocDiv2 Thanks! Tim
... View more
06-04-2015
01:41 PM
|
0
|
4
|
6333
|
|
POST
|
I really like the jquery date picker. It looks very slick!
... View more
06-04-2015
07:18 AM
|
1
|
0
|
2345
|
|
POST
|
Kristen, did you use a custom picture as your point symbol? When you open it in ArcGIS.com do you get the same error? Tim
... View more
06-04-2015
07:00 AM
|
1
|
4
|
2913
|
|
POST
|
That's ok, as developers we always like to look for the most difficult way to do an easy task
... View more
06-03-2015
01:20 PM
|
2
|
1
|
1550
|
|
POST
|
Also check out this great thread if you like to customize! Web AppBuilder Developer Edition – Customization Resource List
... View more
06-03-2015
01:18 PM
|
3
|
2
|
5205
|
|
POST
|
Anything that your builder will use to built your applications can be found here: arcgis-web-appbuilder-1.1\client\stemapp This is where you can add widgets, changes widget, add themes etc. If you need to make changes to specific applications you can do that here" arcgis-web-appbuilder-1.1\server\apps\your specific app number
... View more
06-03-2015
01:16 PM
|
2
|
0
|
5205
|
|
BLOG
|
Das sieht sehr professionel aus in ein paar Schritten!
... View more
06-03-2015
05:22 AM
|
0
|
0
|
297
|
|
POST
|
Hi Satya, It would be helpful to know in which program you are trying to do that (javascript, flex....). You might also get more answers if you post it in that specific space and add tags. Tim
... View more
06-03-2015
05:19 AM
|
1
|
0
|
3132
|
|
DOC
|
Kevin MacLeod check out the latest version. Now you will only be able to delete an extent until changes have been made to the edit.js to allow editing to an extent. Let me know if it works! Tim
... View more
06-02-2015
06:36 AM
|
2
|
0
|
18645
|
|
BLOG
|
Rebecca I have added 2 live sites for my widgets: Advanced Draw: ArcGIS Web Application Location: ArcGIS Web Application Tim
... View more
06-02-2015
05:54 AM
|
0
|
0
|
22089
|
|
DOC
|
Ramon Reimets, this should work for you: Dropbox - Coordinate.zip Tim
... View more
06-02-2015
05:34 AM
|
0
|
0
|
6624
|
|
DOC
|
It seems to be a very stripped down version of the editor. I was able to add the possibility of moving and re-sizing an extent to the edit.js but for some reason after I make the adjustment the extent goes right back to how it looked before I made changes. Maybe I should just write a request to add the extent to the edit.js.
... View more
06-02-2015
05:05 AM
|
1
|
0
|
18645
|
|
DOC
|
Robert, looking here http://js.arcgis.com/3.13/esri/toolbars/edit.js there is no case for an extent. Could it be that the editor dijit, instead of the toolbar,is used in the example you have posted? http://js.arcgis.com/3.13/esri/dijit/editing/Editor.js here I can see a case for an extent. Tim
... View more
06-01-2015
11:24 AM
|
1
|
0
|
18645
|
| Title | Kudos | Posted |
|---|---|---|
| 1 | 07-06-2015 06:58 AM | |
| 1 | 05-04-2016 07:27 AM | |
| 1 | 07-06-2017 08:12 AM | |
| 1 | 10-26-2015 11:51 AM | |
| 1 | 12-12-2014 12:05 PM |
| Online Status |
Offline
|
| Date Last Visited |
11-11-2020
02:23 AM
|