Wednesday 21 March 2018

javascript - Which framework is best to implement an application robustly, using ArcGIS Server JS API?



Over on the Esri forum, user Matt Moyles suggested that the approach used in the Esri JS samples isn't suitable for robust development of a web mapping application using HTML, JavaScript and CSS:



ESRI's suggested approach to javascript application development is ancient and outdated. I would not recommend following the samples. Dojo 1.7 supports AMD with Asynchronous dependency loading. I would start with the dojo boilerplate template and "work" the arcgis api into that. The samples are not suitable for serious application developers. They are mostly just proof of concept snippets.


A serious application should be developed with the aid of some sort of framework to help structure things. I have been using dojox.mvc with great success! But other options include things like backbone.js, spine.js, or even javascript MVC.


Dojo Boilerplate - https://github.com/csnover/dojo-boilerplate




  • does anyone agree/disagree with this statement?

  • are there any online examples of better approaches to web application development using the ArcGIS Server JS API?




Answer



I would agree with Moyles that the samples are just samples and dojo boileplate is a great resource however at current snovers boilerplate isn't a viable solution. You have two different versions of dojo going on there. The current js api still uses the classic require syntax of dojo 1.6.1 and does not support AMD. I'm sure that a newer js api will be built on 1.7.x and since converting classic dojo.defined modules to AMD is mostly trivial I would choose that route.


If you're starting your project now then I would choose whatever server side framework you wanted to use (if it is necessary for your application. If its just a single page viewer with no server side requirements then don't over complicate things). It could be rails, php, asp, whatever. Follow the best practices for your framework/language.


Then since esri is built on dojo you are already loading a great js framework for creating large scale web applications. Structure your code so that the dojo's loader can load your widgets and modules with the dojo require syntax. Write dojo widgets and modules, use dijits and dojox tools when necessary ( http://dojotoolkit.org/documentation/tutorials/1.6/declare, http://dojotoolkit.org/documentation/tutorials/1.6/recipes/custom_widget/, http://dojotoolkit.org/documentation/tutorials/1.6/understanding_widget, http://dojotoolkit.org/documentation/tutorials/1.6/templated, http://dojotoolkit.org/documentation/tutorials/1.6/cdn). Do not write inline js like the samples do. Create a build profile to optimize all your code when its time for production.


You have to keep your esri and custom code separate to a certain degree because they don't offer the source for compiling - it's already built and minified. The build tool doesn't like that so much.


EDIT


I built a grunt tool, esri_slurp to download the esri js api so you can use it as a package in your applications. This allows you to run the build and get a single file.


No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...