I'm developing a simple map service widget that will add and remove a dynamic map service layer. A much cut down version of the mapservices widget in Flex. However the service doesn't seem to be adding (hence I can't test the remove layer functionality either!).
I'm still using the initial beta as i'm suffering from the organisation login bug in the latest version.
I'm utilising the following button click event within a div in the widget.html:
data-dojo-attach-event="click:addMapService"
This is calling the addMapService function in the widget.js file:
addMapService: function(){
this.map.addLayer(dynamicMapServiceLayer);
alert("Map Service Added");
},
The dynamicMapServiceLayer variable is populated (prior to "return declare([BaseWidget]") as follows in the widget.js file:
var dynamicMapServiceLayer = new ArcGISDynamicMapServiceLayer("http://webservices.spatialni.gov.uk/arcgis/rest/services/NIHE/NIHEAreas/MapServer",{
"opacity" : 1
});
When i debug the addMapService function, it seems to be adding the dynamicMapServiceLayer and the alert/pop up appears ok. When I check the layerslist widget the layer isn't present though.
I'm assuming the layerlist widget is only compiled and populated when clicked, therefore I shouldn't need to refresh this if i click it after adding the map service. Am I naive in expecting the map service widget to add a layer on the click of a button without any further event?
Has anyone else had any issues developing widgets thus far?
Solved! Go to Solution.
Damien, i would enter an enhancement request on the WAB Beta site for this.
Damien,
So are you saying that you do not see the layer in the map or in the layer list widget, or just not in the layer list widget?
Hi Robert, I don't see the layer on the map nor do I see it appear in the layer list widget.
I know I am implementing the ArcGISdynamicmapservicelayer function ok as I have used it in several different standalone javascript viewers i've created. When I debug the application, it seems to work ok as I have added break points before and after the function call and followed it through. I added an alert popup after the function call, and it implements this ok. I know ArcGISdynamicmapservicelayer function doesn't have a click event in the API that the feature layer equivalent function does. However, as i'm implementing the click event using dojo, I would have assumed ArcGISdynamicmapservicelayer doesn't need to know how it was implemented and would just perform the functionality.
Damien,
So you are sure that you actually see the layer being added to the map (i.e. see the polygon features on the map)? So is the issue the map click event. Looking at the LayerList widgets code, It looks like the LayerList widget is not wired up to detect programmatic additions to the map for any other layer type than a GraphicsLayer.
Hi Robert,
I wasn't very clear when I read back what i've written! I haven't physically viewed the mapservice in the application (features on the map). When debugging the code I have passed over the code being called by setting various breakpoints, and based on my analysis of the code between the breakpoints, the function seems to be called successfully. But it doesn't physically add the layer to the map. Hence my suspicion around the map click event.
I have used ArcGISDynamicMapServiceLayer in single page (i.e. the html,css and javascript in one file) viewers that I have built using the javascript API in the past, and the function definitely works. Just doesn't seem to work on a map click event. I suspect a FeatureLayer may work, but it is dependent on adding a specific individual subset (if that's the correct term!) of the data (i.e. ".../MapServer/0" instead of ".../Mapserver"). I'll have to test my hunch on the featurelayer, but it isn't ideal to call each subset individually, as it means a lot of additional config for a user to add, especially for large map services.
UPDATE:
I replaced the ArcGISdynamicmapservicelayer function with the featurelayer function. The data now appears on the map and in the layerlist widget. Must be something to do with the ArcGISdynamicmapservicelayer function rather than click events. I could only assume it is down to the featurelayer function defining a click event in the API and the dynamicmapservicelayer not.
Alas not as simple a widget as i initially thought!
UPDATE:
ArcGISdynamicmapservicelayer is now bringing the data in on the map click. Was just taking its time. It still doesn't populate the layerlist widget though.
Damien,
As I mentioned earlier the LayerList widget does not listen for layers added to the map other than graphic layer.
Damien, i would enter an enhancement request on the WAB Beta site for this.
Hi Robert,
I have raised the enhancement on the beta site. In an ideal world the layerlist widget would permit the ability to toggle on/off sub layers of a dynamic map service, when added using the arcgisdynamicmapservicelayer function. Sub-layers don't seem to be possible with the featurelayer function as you have to declare a definitive REST endpoint when adding a layer.
Thanks for your advice!