TypeError:g不是函数

时间:2014-07-27 08:31:12

标签: javascript arcgis-js-api

从头开始重写我的一个应用程序(从遗留到AMD)我遇到了一个我无法弄清楚的错误。这让我发疯了。我可能只是拼错了一些东西或者有另一个小错误,但我无法弄清楚是什么。任何帮助将非常感谢!

我仍然处于开发模式,所以我的代码目前还不是那么漂亮。您可以在此处看到它的实际效果:http://tpgrf.nl/testserver/alpha/topotrainer/flevoland

javascript代码:

//Define area and url's  
var currentPath = window.location.pathname.split('/');
var AREA = currentPath[currentPath.length - 2];
if (AREA == 'europa' || AREA == 'wereld' || AREA == 'nederland') {
    var AREAURL = AREA;
    var AREAisProvince = false;
} else {
    AREAURL = 'nederland';
    var AREAisProvince = true;
}; //Ondervang provincies  


var basemapURL = window.location.protocol + "//tiles.arcgis.com/tiles/nSZVuSZjHpEZZbRo/arcgis/rest/services/Topografie_in_de_klas_" + AREAURL + "_ondergrond/MapServer";
var contentFeatureURL = window.location.protocol + "//services.arcgis.com/nSZVuSZjHpEZZbRo/ArcGIS/rest/services/Topografie_in_de_klas_" + AREAURL + "/FeatureServer/0";




var CONTENT = 'cito100'; //Default to 'cito100', user can adjust manually  
var TYPES = ''; //empty for now, will be defined later by the user  
var TYPES = 'plaats'; //for testingunction's//  
//  
function generateUUID() {
    var d = new Date().getTime();
    var uuid = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
        var r = (d + Math.random() * 16) % 16 | 0;
        d = Math.floor(d / 16);
        return (c == 'x' ? r : (r & 0x7 | 0x8)).toString(16);
    });
    return uuid;
};


//  
//Figure something out here to detect if the user as a new or returning visitor  
//  


//////////////////////////////////////  
//Create a basemap and load features//  
//////////////////////////////////////  
var dojoConfig = { parseOnLoad: true };


var map;
require(["esri/geometry/Extent", "esri/SpatialReference", "esri/map", "esri/graphic", "esri/layers/ArcGISTiledMapServiceLayer", "esri/tasks/query", "esri/tasks/QueryTask", "esri/tasks/FeatureSet", "esri/layers/GraphicsLayer", "esri/Color", "esri/symbols/SimpleMarkerSymbol", "esri/symbols/SimpleLineSymbol", "esri/symbols/PictureMarkerSymbol", "esri/renderers/UniqueValueRenderer", "esri/renderers/ClassBreaksRenderer",
    "dijit/layout/BorderContainer", "dijit/layout/ContentPane", "dijit/TitlePane",
    "dojo/domReady!", "dojo/dom", "dojo/on"],
    function (Extent, SpatialReference, Map, Graphic, Tiled, Query, QueryTask, FeatureSet, GraphicsLayer, Color, SimpleMarkerSymbol, SimpleLineSymbol, PictureMarkerSymbol, UniqueValueRenderer, ClassBreaksRenderer, dom, on) {
        //@TODO: Can we actually define this on the basemap mapserver?  
        if (AREA == 'nederland' || AREAisProvince == true) {
            var initExtent = new Extent(-165715, 6453119, 1435181, 7205260, new SpatialReference({ wkid: 102100 }));
        }
        if (AREA == 'europa') {
            var initExtent = new Extent(-2827847, 2851709, 6838658, 11375669, new SpatialReference({ wkid: 102100 }));
        }
        if (AREA == 'wereld') {
            var initExtent = new Extent(-19705424, -14849545, 21700207, 21624981, new SpatialReference({ wkid: 102100 }));
        }

        map = new Map("map", {
            extent: initExtent
        });


        //let's add a basemap  
        var tiled = new Tiled(basemapURL);
        map.addLayer(tiled);

        where = 'Cito100_onderdeel=1';
        if (AREAisProvince == true) {
            where += ' AND Provincie=\'' + AREA + '\'';
        }
        map.on("load", getFeaturesToMapAndStorage(where));

        function getFeaturesToMapAndStorage(whereClause) {
            console.log(whereClause);
            //query the featureService  
            var query = new Query();
            query.returnGeometry = true;
            query.outFields = ["*"];
            query.outSpatialReference = new SpatialReference({ wkid: 102100 });
            query.where = whereClause;

            var queryTask = new QueryTask(contentFeatureURL);

            queryTask.on("complete", function (event) {
                //map.graphics.clear();  
                var featureGraphicsLayer = new GraphicsLayer();


                //@TODO: Can't we find a way to use the symbols from the featurservice directly, instead of the url's?  
                defaultSymbol = new SimpleMarkerSymbol(SimpleMarkerSymbol.STYLE_SQUARE, 10,
            new SimpleLineSymbol(SimpleLineSymbol.STYLE_SOLID,
            new Color([255, 0, 0]), 1),
            new Color([0, 255, 0, 0.25]));

                var renderer = new UniqueValueRenderer(defaultSymbol, "Type");
                renderer.addValue("Plaats", new PictureMarkerSymbol("https://services.arcgis.com/nSZVuSZjHpEZZbRo/ArcGIS/rest/services/Topografie_in_de_klas_nederland/FeatureServer/0/images/89e5f81878a69f9cc0525c841f98af54", 11, 11));
                renderer.addValue("Gebied", new PictureMarkerSymbol("https://services.arcgis.com/nSZVuSZjHpEZZbRo/ArcGIS/rest/services/Topografie_in_de_klas_nederland/FeatureServer/0/images/165c76bd4465728a34f6d18df4a1ec03", 28, 28));
                renderer.addValue("Water", new PictureMarkerSymbol("https://services.arcgis.com/nSZVuSZjHpEZZbRo/ArcGIS/rest/services/Topografie_in_de_klas_nederland/FeatureServer/0/images/f9c146a401f48c4f38202e83c2e4582a", 22, 22));
                renderer.addValue("Provincie", new PictureMarkerSymbol("https://services.arcgis.com/nSZVuSZjHpEZZbRo/ArcGIS/rest/services/Topografie_in_de_klas_nederland/FeatureServer/0/images/7a5373d8f1dcd1ecc03cefbab687b97c", 38, 32));
                renderer.addValue("Land", new PictureMarkerSymbol("https://services.arcgis.com/nSZVuSZjHpEZZbRo/ArcGIS/rest/services/Topografie_in_de_klas_europa/FeatureServer/0/images/7a5373d8f1dcd1ecc03cefbab687b97c", 38, 32));
                renderer.addValue("Werelddeel", new PictureMarkerSymbol("https://services.arcgis.com/nSZVuSZjHpEZZbRo/ArcGIS/rest/services/Topografie_in_de_klas_wereld/FeatureServer/0/images/48f2256a49253388488d813d721c054b", 32, 38));

                var features = event.featureSet.features;
                var featureCount = features.length;
                for (var i = 0; i < featureCount; i++) {
                    var graphic = features[i];
                    featureGraphicsLayer.add(graphic);
                }
                featureGraphicsLayer.renderer = renderer;
                map.addLayer(featureGraphicsLayer);

                //@TODO: Update localstorage    

            }); //end on queryTask complete  

            queryTask.execute(query, queryComplete);

            function queryComplete() {
                console.log("fire function queryComplete");
                //@TODO: reset progressbar  
            }; //End function queryComplete  


        } //end function getFeaturesToMapAndStorage  

        //The two closing tags below are essential and close the complete DOJO part.    
    } //end function after require (AMD style)  
    ); //end require

1 个答案:

答案 0 :(得分:3)

您的问题是:map.on("load", getFeaturesToMapAndStorage(where));

您正在调用返回undefined的getFeaturesToMapAndStorage,并将其作为"load"处理程序传递。我猜测您使用的缩小版本使用g作为对处理程序的引用。

由于g未定义,您基本上是在说undefined(loadEvent)


编辑:我猜你打算做这样的事情:

map.on("load", function(){
    getFeaturesToMapAndStorage(where);
});

编辑2:为清楚起见,我将更详细地解释错误。 您所拥有的内容与我上面建议的内容之间的区别在于您在包含getFeaturesToMapAndStorage的行上调用map.on("load", getFeaturesToMapAndStorage(where));(而不是在map之后调用load getFeaturesToMapAndStorage 1}}事件)。为了使用预定参数调用函数function(){...},您需要从函数(如上面的匿名函数 - where)调用它,然后将其作为事件处理程序传入。

或者,由于您的工作范围如何,您可以引用getFeaturesToMapAndStorage内的whereClause代替{{1}}参数。