Select to view content in your preferred language

create ArcGISDynamicMapServiceLayer from uploaded shapefile

1059
6
Jump to solution
01-24-2013 05:30 AM
johnjackson2
Emerging Contributor
Hello,

I'm trying to code against ArcGisOnline as much as possible.
So far, I have been able to use esri.arcgis.utils.createMap() against a custom map I created and uploaded.

I'm trying to follow along with more advanced samples, but they use ArcGISDynamicMapServiceLayer objects.
Is the object produced by create map usable in that context. If not, can use ArcGisOnline to generate a link like:

http://servicesbeta.esri.com/arcgis/rest/services/SanFrancisco/SFStreetTreesRendered/MapServer/0

for my custom uploaded map?

Thanks in advance for your help.

--John Jackson
0 Kudos
1 Solution

Accepted Solutions
KellyHutchins
Esri Notable Contributor
John you are on the right track. You'll need to set the info template for the layer's layerObject. Here's an example:

    <script>       dojo.require("dijit.layout.BorderContainer");       dojo.require("dijit.layout.ContentPane");       dojo.require("esri.map");         dojo.require("esri.arcgis.utils");              var map;              function pageReady() {           var mapDeferred = new esri.arcgis.utils.createMap("0ab0004e243641568713ba968d1c424a", "map",{             //ignorePopups:true         });         mapDeferred.then(function(response){             map = response.map;             dojo.addClass(map.infoWindow.domNode, "myTheme");                var layers = response.itemInfo.itemData.operationalLayers;             //get the layer we want to define popups for              dojo.forEach(layers, function(layer){                 if(layer.id === "Weekly_Flu_Surveillance_(20130112)_5177"){                                            var template = new esri.dijit.PopupTemplate();                       template.setContent(getTextContent);                       layer.layerObject.setInfoTemplate(template);                 }                           });          });        }       function getTextContent(graphic){         var template = "<b>${STATENAME}</b>: has an activity level of ${ACTIVITY_LEVEL}";         return esri.substitute(graphic.attributes, template);       }                       dojo.ready(pageReady);     </script> 

View solution in original post

0 Kudos
6 Replies
KellyHutchins
Esri Notable Contributor
Hi John,

When you use createMap to build a map based on a web map you can access info about the layers in the map from the response object like this:

var layers = response.itemInfo.itemData.operationalLayers;


This should give you access to any feature layers you have in your map. See this help topic for more details.
http://help.arcgis.com/en/webapi/javascript/arcgis/jshelp/#intro_webmap


Hello,

I'm trying to code against ArcGisOnline as much as possible.
So far, I have been able to use esri.arcgis.utils.createMap() against a custom map I created and uploaded.

I'm trying to follow along with more advanced samples, but they use ArcGISDynamicMapServiceLayer objects.
Is the object produced by create map usable in that context. If not, can use ArcGisOnline to generate a link like:

http://servicesbeta.esri.com/arcgis/rest/services/SanFrancisco/SFStreetTreesRendered/MapServer/0

for my custom uploaded map?

Thanks in advance for your help.

--John Jackson
0 Kudos
johnjackson2
Emerging Contributor
Kelly,

I've been looking at the operationalLayers property... what I'm trying to do is make custom popups when someone clicks my polygon. I am looking at the sample

http://help.arcgis.com/en/webapi/javascript/arcgis/jssamples/#sample/fl_popup

to understand how to integrate custom popups. It sounds like custom maps uploaded to ArcGisOnline can't be plugged directly into this particular sample.
0 Kudos
KellyHutchins
Esri Notable Contributor
Its actually a much easier process to apply a custom popup theme if you are working with a web map from ArcGIS.com. If your webmap has popups enabled then those popups are automatically available in your map. So all you need to do is define your new theme using css then apply it using the dojo.addClass method.

        var mapDeferred = new esri.arcgis.utils.createMap("0ab0004e243641568713ba968d1c424a", "map");
        mapDeferred.then(function(response){
            map = response.map;
            dojo.addClass(map.infoWindow.domNode, "myTheme");        
        });



I've attached a revised version of the sample you linked to so that it works with web maps.
0 Kudos
johnjackson2
Emerging Contributor
Kelly,
What I'm ultimately trying to do is set custom text for the default infowindow that displays when a feature is clicked.
The critical part of that example for me is this section:

        var template = new esri.InfoTemplate();
        template.setContent(getTextContent);

        var featureLayer = new esri.layers.FeatureLayer("http://servicesbeta.esri.com/arcgis/rest/services/SanFrancisco/SFStreetTreesRendered/MapServer/0",{
          mode: esri.layers.FeatureLayer.MODE_SELECTION,
          outFields: ["*"],
          infoTemplate:template


My question is:
How can I set the infotemplate for my operational layer?

Thanks for all your help

--John Jackson
0 Kudos
johnjackson2
Emerging Contributor
Update:

On http://help.arcgis.com/en/webapi/javascript/arcgis/jsapi/#FeatureLayer/setInfoTemplate
I found the setInfoTemplate function which sounds like it sould do exactly what I want.
However, I couldn't call it via response.itemInfo.itemData.operationalLayers[0].setInfoTemplate();
0 Kudos
KellyHutchins
Esri Notable Contributor
John you are on the right track. You'll need to set the info template for the layer's layerObject. Here's an example:

    <script>       dojo.require("dijit.layout.BorderContainer");       dojo.require("dijit.layout.ContentPane");       dojo.require("esri.map");         dojo.require("esri.arcgis.utils");              var map;              function pageReady() {           var mapDeferred = new esri.arcgis.utils.createMap("0ab0004e243641568713ba968d1c424a", "map",{             //ignorePopups:true         });         mapDeferred.then(function(response){             map = response.map;             dojo.addClass(map.infoWindow.domNode, "myTheme");                var layers = response.itemInfo.itemData.operationalLayers;             //get the layer we want to define popups for              dojo.forEach(layers, function(layer){                 if(layer.id === "Weekly_Flu_Surveillance_(20130112)_5177"){                                            var template = new esri.dijit.PopupTemplate();                       template.setContent(getTextContent);                       layer.layerObject.setInfoTemplate(template);                 }                           });          });        }       function getTextContent(graphic){         var template = "<b>${STATENAME}</b>: has an activity level of ${ACTIVITY_LEVEL}";         return esri.substitute(graphic.attributes, template);       }                       dojo.ready(pageReady);     </script> 
0 Kudos