2

I need help with ArcGIS API for JavaScript, I need to use private modules in code for my tools, but I can't figure out how use them in my app like on click launch this module.

I'm lost in DoJo...

The map.js:

     /**
 * This file contain :
   * - Map init
   * - Principal layers to add
   * - Reference to the tools files
   * - Style of the principal page (map, navbar...
  **/

require({
    packages: [{ name: "src", location: "/src", type: "text/javascript" }]
},[
"esri/map", 
"esri/toolbars/draw",
"esri/graphic",
"dojo/parser",
"esri/symbols/SimpleFillSymbol",

"dijit/registry",
"esri/geometry/Geometry",
"dijit/layout/BorderContainer", 
"dijit/layout/ContentPane", 
"dijit/form/Button", 
"dijit/WidgetSet",
"src/modules/zoningSelection",
"dojo/domReady!"], 
function(Map, Draw, Graphic, parser, registry, dijit, zoningSelection){
   parser.parse();

   map = new Map(map,{
      basemap:"hybrid",
      center:[-1.486075,46.199997],
      zoom:15
   });
   console.log(map);
    var selectionTool = dijit.byId("select");
    selectionTool.on("click",startSelect);

    var validationTool = dijit.byId("end");
    validationTool.on("click", endSelect);

    var deleteTool = dijit.byId("del");
    deleteTool.on("click", delSelect);


   function startSelect(){

        var select = new zoningSelection(map, Draw.POLYGON);
        console.log(select);
    };

    function endSelect (){
        alert("Validé");
    }
    function delSelect(){
        alert("Suppr");
    }
});

My Module to load in the first code:

require(["esri/map", 
    "esri/toolbars/draw",
    "esri/graphic",

    "esri/symbols/SimpleFillSymbol",

    "dojo/parser", "dijit/registry",
    "esri/layers/GraphicsLayer",
    "esri/graphicsUtils",
    "esri/geometry/Polygon",
    "esri/geometry/Geometry",
    "esri/dijit/Popup",
    "dijit/layout/BorderContainer", "dijit/layout/ContentPane", 
    "dijit/form/Button", "dijit/WidgetSet", 
    //"dojo/_base/array",
    "dojo/domReady!"],function (map, drawType, Draw, GraphicsLayer, Graphic, SimpleFillSymbol, graphicsUtils, dijit) {
        console.log("séléction lancée ou non ");
        console.log(map);
        console.log(drawType);
    var _drawTool = new Draw(map);
    var _drawingLayer = new GraphicsLayer();
    console.log(_drawingLayer);

    map.addLayer(_drawingLayer);

    _drawTool.setRespectDrawingVertexOrder(true);
    _drawTool.on("draw-complete", _onDrawComplete);

    activate(drawType);
    //map.disableMapNavigation();

    var _onDrawComplete = function(evt) {
        var symbol = new SimpleFillSymbol();
        map.enableMapNavigation();

        var geom = evt.geometry;
        //create object from geometry and symbol
        var graphic = new Graphic(geom, symbol);        
        _drawingLayer.add(graphic);

        var points = graphicsUtils.getGeometries(_drawingLayer.graphics)[0].rings[0];

        require(["dojo/_base/array"], function(array){
            array.forEach(points, function(point, i){
                console.log("point #" + i + " : x=" + point[0] + ", y=" + point[1]);
            });
        });
    };
});

How can I use them together?

1 Answer 1

1

I fix my problems by hours on the dojo docs i try this solution before but without thinking of variable order in function here is the corrected code fort the module

define(["dojo/_base/declare",
    "esri/map", 
    "esri/toolbars/draw",
    "esri/graphic",
    "esri/symbols/SimpleFillSymbol",
    "esri/layers/GraphicsLayer",
    "esri/graphicsUtils",
    "esri/geometry/Polygon",
    "esri/geometry/Geometry",
    "dojo/_base/array",
    //"src/map.js",
    "dojo/domReady!"],function (declare, Map, Draw, Graphic, SimpleFillSymbol, GraphicsLayer,
        GraphicsUtils, Polygon, Geometry, array) {
        var _drawTool;
        var _drawingLayer;
        var _map;

        return declare(null, {

            constructor: function(map){
                _map = map;
                _drawTool = new Draw(_map);
                _drawingLayer = new GraphicsLayer();                    
                _map.addLayer(_drawingLayer);

                _drawTool.setRespectDrawingVertexOrder(true);                   

                var _onDrawComplete = function(evt) {
                    var symbol = new SimpleFillSymbol();

                    var geom = evt.geometry;
                    //create object from geometry and symbol
                    var graphic = new Graphic(geom, symbol);        
                    _drawingLayer.add(graphic);
                };

                _drawTool.on("draw-complete", _onDrawComplete);
            },

            activate: function(drawType) {
                _drawTool.activate(drawType);
                //_map.disableMapNavigation();
            },

            deactivate: function() {
                _drawTool.deactivate();
                //_map.enableMapNavigation();
            },

            getGeometry: function() {
                return GraphicsUtils.getGeometries(_drawingLayer.graphics);
            },

            getSelectedPolygons: function() {
                var polygons = new Array();

                array.forEach(GraphicsUtils.getGeometries(_drawingLayer.graphics),
                    function(graphic){
                        var polygon = new Array();
                        array.forEach(polygon.rings[0],
                            function(point) {
                            polygon.push(point);
                        });

                        polygons.push(polygon);
                });

                /*var points = GraphicsUtils.getGeometries(_drawingLayer.graphics)[0].rings[0];

                require(["dojo/_base/array"], function(array){
                    array.forEach(points, function(point, i){
                        console.log("point #" + i + " : x=" + point[0] + ", y=" + point[1]);
                    });
                });*/
            }

}); });

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.