在arcgis java script api中添加要映射的图形图层

时间:2016-02-09 13:29:31

标签: arcgis-js-api

我正在使用arcgis js api。我已经按顺序调用了所有必需的esri类模块和所有类名。我正在使用查询任务将点添加到地图作为图形图层。我收到图形错误。我无法追踪错误。

var map;
var toc;
var mapserviceurl = "http://......./arcgisserver/rest/services/CRD/CRD1/MapServer";
require(["dojo/parser",
    "dojo/on", "esri/map","esri/dijit/HomeButton",
     "esri/dijit/Measurement", "dojo/_base/lang","esri/layers/ArcGISDynamicMapServiceLayer",
    "esri/layers/FeatureLayer","esri/graphic","esri/layers/GraphicsLayer",
    "esri/dijit/Scalebar","esri/dijit/BasemapGallery","esri/toolbars/navigation",
    "esri/dijit/OverviewMap","esri/geometry/Extent","esri/SpatialReference",
    "esri/geometry/webMercatorUtils","esri/tasks/query","esri/tasks/QueryTask",
    "esri/toolbars/draw","esri/symbols/SimpleLineSymbol","esri/symbols/SimpleFillSymbol",
    "esri/symbols/PictureMarkerSymbol","esri/symbols/SimpleMarkerSymbol",
    "esri/renderers/SimpleRenderer","esri/geometry/Point","esri/Color",
    "agsjs/dijit/TOC","esri/InfoTemplate", "esri/tasks/IdentifyTask",
    "esri/tasks/IdentifyParameters", "esri/dijit/Popup", "dojo/dom-construct",
    "esri/tasks/locator","dojo/_base/array", "dojo/domReady!"],
    function (parser, on, Map, HomeButton, Measurement,lang, ArcGISDynamicMapServiceLayer, FeatureLayer, graphic, GraphicsLayer, Scalebar, BasemapGallery, Navigation, OverviewMap, Extent, SpatialReference,
        webMercatorUtils, Query, QueryTask, DrawToolbar, SimpleLineSymbol, SimpleFillSymbol,
        PictureMarkerSymbol, SimpleMarkerSymbol, SimpleRenderer,Point,Color,TOC,InfoTemplate,IdentifyTask,IdentifyParameters,
        Popup,domConstruct,Locator,arrayUtils) {
        parser.parse();
        createDialogs();

        var identifyTask, identifyParams;
        var intialextent = new Extent(7778597.959975056, 1564947.1810059766, 9217107.340624947, 2133123.2518000016, new SpatialReference({ wkid: 102100 }));
        map = new Map("divMap", {
            basemap: "streets",
            center: [75, 14],
            zoom: 7,
            extent: intialextent,
            logo: false,
            fitExtent: true,
            slider: true
        });
        var operationalLayer = new ArcGISDynamicMapServiceLayer(mapserviceurl);

        var samplelocations = new GraphicsLayer({ id: "Samplelocations" });

        var samplelocationsSymbol = new SimpleMarkerSymbol(SimpleMarkerSymbol.STYLE_CIRCLE, 10, SimpleLineSymbol(SimpleLineSymbol.STYLE_SOLID, new Color([239, 107, 0]), 1), new Color([239, 107, 0]));
        var samplelocationrenderer = new SimpleRenderer(samplelocations);
        samplelocations.setRenderer(samplelocationrenderer);
        var home = new HomeButton({
            map: map
        }, "HomeButton");
        home.startup();

        map.on('layers-add-result', function (evt) {
            try {
                var toc = new TOC({
                    map: map,
                    layerInfos: [{
                        layer: pointFeatureLayer,
                        title: "My Feature"
                    }, {
                        layer: operationalLayer,
                        title: "Dynamic Map"
                    }]
                }, "tocDiv");
                toc.startup();

                toc.on("load", function () {
                    console.log("TOC loaded");
                });
            }
            catch (e) {
                console.error(e.message);
            }

        });
        map.addLayers([operationalLayer, pointFeatureLayer, samplelocations]);

        var basemapGallery = new BasemapGallery({
            showArcGISBasemaps: true,
            map: map
        }, "basemapGallery");
        basemapGallery.on("load", function () {

            basemapGallery.remove('basemap_1');
            basemapGallery.remove('basemap_2');
            basemapGallery.remove('basemap_3');
            basemapGallery.remove('basemap_4');
            basemapGallery.remove('basemap_5');
            basemapGallery.remove('basemap_8');
        });

        basemapGallery.startup();

        var Scalebar = new Scalebar({
            map: map,
            scalebarUnit: 'metric',
            scalebarStyle: 'line'
        });

        var measurement = new Measurement({
            map: map
        }, measurementDiv);
        measurement.startup();

        map.on("mouse-move", showcoordiantes);
        map.on("mouse-drag", showcoordiantes);

        //overview tools
        var OverviewMap = new OverviewMap({
            map: map,
            attachTo: "bottom-right",
            color: " #D84E13",
            opacity: .40
        });

        OverviewMap.startup();

        function showcoordiantes(evt) {
            var p = webMercatorUtils.webMercatorToGeographic(evt.mapPoint);
            $("#latlong").html("Lat,Long : " + p.y.toFixed(4) + "," + p.x.toFixed(4));

        }


        $("#ClearGraphics").click(function (e) {
            e.preventDefault();
            // drawtools.deactivate();
            map.infoWindow.hide();
            map.setMapCursor("default");
            map.graphics.clear();
        });

        var navToolbar = new Navigation(map);

        //zoom In
        $("#ZoomInTool").click(function (e) {
            e.preventDefault();
            map.setMapCursor("url('images/cursors/zoomin.cur'), auto");
            navToolbar.activate(Navigation.ZOOM_IN);
        });

        //ZoomOut
        $("#ZoomOutTool").click(function (e) {
            e.preventDefault();
            map.setMapCursor("url('images/cursors/zoomout.cur'), auto");
            navToolbar.activate(Navigation.ZOOM_OUT);
        });

        //Pan
        $("#panTool").click(function (e) {
            e.preventDefault();
            map.setMapCursor("url('images/cursors/pan.cur'), auto");
            navToolbar.activate(Navigation.PAN);
        });

        //FullExtent
        $("#zoomfullext").click(function (e) {
            e.preventDefault();
            map.setMapCursor("default");
            navToolbar.deactivate();
            // navToolbar.zoomToFullExtent();
            map.setExtent(intialextent, true);
        });

        //Zoom to previous     
        $("#zoomtoPrevExtent").click(function (e) {
            e.preventDefault();
            map.setMapCursor("default");
            navToolbar.deactivate();
            navToolbar.zoomToPrevExtent();
        });
        //Zoom to Next    
        $("#zoomtoNextExtent").click(function (e) {
            e.preventDefault();
            map.setMapCursor("default");
            navToolbar.deactivate();
            navToolbar.zoomToNextExtent();
        });
        map.on("load", showresults)

        function showresults() {
        var queryTask = new esri.tasks.QueryTask('http://......./arcgisserver/rest/services/CRD/CRD2/MapServer/0');
                    var query = new esri.tasks.Query();

                    symbol = new esri.symbol.SimpleMarkerSymbol();
                    symbol.setStyle(esri.symbol.SimpleMarkerSymbol.STYLE_SQUARE);
                    symbol.setSize(10);
                    symbol.setColor(new dojo.Color([255, 255, 0, 0.5]));
                    query.returnGeometry = true;
                    query.outFields = ["*"];
                    query.outSpatialReference = map.spatialReference;

                    query.where = "objectid = '" + 5281902 + "'";
                    map.graphics.clear();
                    queryTask.execute(query, addPointsToMap);
                    function addPointsToMap(featureSet) {
                        var graphic = featureSet.features;
                        graphic.setSymbol(symbol);
                        map.graphics.add(graphic);
                        var extent = esri.graphicsExtent(features);
                        if (extent) {                           
                                map.setExtent(extent)
                            }

                    }
                }
    });

我收到错误graphic error

1 个答案:

答案 0 :(得分:0)

您正在为图形变量指定一个数组:

var graphic = featureSet.features;

选择阵列的单个特征并设置符号,例如

var graphic = featureSet.features[0];