Arcgis Esri地图:收集有关区域选择的pictureMarkerSymbols信息

时间:2015-10-19 08:06:46

标签: javascript json arcgis esri

我正在尝试创建一个地图,我可以创建一个选择区域,并获取其下的所有图形指针的信息,我尝试使用以下示例进行修改,但他们正在使用Web服务和查询,我希望它与json或数组。

这就是我跟随的例子http://developers.arcgis.com/javascript/samples/graphics_extent_query/

我想在选择后获取指针的电子邮件地址。这是一个开头的小提琴http://bit.ly/1jwLazp

1 个答案:

答案 0 :(得分:2)

我将你的小提琴与样本结合起来产生以下内容:

https://jsfiddle.net/gary4620/t9h513c7/17/

var map;
var s;
var gl;
var highlightSymbol;

require([
    "esri/map",
    "esri/geometry/Point",
    "esri/symbols/SimpleMarkerSymbol",
    "esri/graphic",
    "esri/layers/GraphicsLayer",
    "esri/toolbars/draw",
    "esri/symbols/SimpleMarkerSymbol",
    "esri/InfoTemplate",
    "dojo/domReady!"], function (
Map, Point, SimpleMarkerSymbol, Graphic, GraphicsLayer, Draw, SimpleMarkerSymbol, InfoTemplate) {
    function initToolbar(map) {
        var tb = new Draw(map);
        tb.on("draw-end", findPointsInExtent);
        tb.activate(Draw.EXTENT);
    }

    function findPointsInExtent(result) {
        var extent = result.geometry;
        var results = [];
        require(["dojo/_base/array"], function (array) {
            array.forEach(gl.graphics, function (graphic) {
                if (extent.contains(graphic.geometry)) {
                    graphic.setSymbol(highlightSymbol);
                    results.push(graphic.getContent());
                }
                //else if point was previously highlighted, reset its symbology
                else if (graphic.symbol == highlightSymbol) {
                    graphic.setSymbol(s);
                }
            });

            //TODO use results as needed; here we just print to console
            console.log("There are " + results.length + " results:");
            console.log(results.join(""));
        });
    }

    map = new Map("map", {
        basemap: "streets",
        center: [-88.21, 42.21],
        zoom: 10
    });
    map.on("load", function () {
        var content = 'email@address.com';
        gl = new GraphicsLayer();
        var p = new Point(-88.380801, 42.10560);
        s = new SimpleMarkerSymbol().setSize(20);
        var g = new Graphic(p, s, {
            'title': 'Title',
            'content': content
        }, new InfoTemplate('${title}', '${content}'));
        gl.add(g);
        map.addLayer(gl);

        initToolbar(this);
    });
    highlightSymbol = new SimpleMarkerSymbol().setColor(new dojo.Color([255,0,0]));
});