AnsweredAssumed Answered

How to add FeatureLayer outside of initialization code

Question asked by JM1984 on Jul 11, 2017
Latest reply on Jul 11, 2017 by TSolow-esristaff

How would i add a FeatureLayer from outside the initializing function?

 

example:

 

require(
[
    "esri/map",
    "esri/layers/FeatureLayer",
    "esri/dijit/PopupTemplate",
    "esri/geometry/Point",
    "esri/graphic",
    "dojo/domReady!"
],
function(Map, FeatureLayer, PopupTemplate, Point, Graphic)
{


    map = new Map("mapDiv", { basemap: "streets", center: [22, 65], zoom: 5 });
    getBasestationList();

 

});
});

 

function getBasestationList() {

 

    fromdatetime = fromdatetime.toLocaleString();
    todatetime = todatetime.toLocaleString();

    $.ajax(
    {
        type: "post",
        url: "{% url 'get_latest_basestation_list' %}",
        data:
        {
            "csrfmiddlewaretoken": "{{ csrf_token }}",
            "fromdate": fromdatetime,
            "todate": todatetime,
    },
    success: function (data, status)
    {
        featureLayer = new FeatureLayer(data, { id: 'basestations' });
        map.addLayers([featureLayer]);
    },
    error: function (request, status, error)
    {
        alert(request.responseText);
    }
});
};

 

However this gives me an error that FeatureLayer is not defined, if I do this in the intializing function it works, however I need to be able to add stuff to the map outside of the initializing function.

Outcomes