arcgis api for js3.16做的一些简单功能

使用了jquery easyUI和arcgis api for js3.16离线API,地图服务是自己用arcgis server10.1发布的,代码如下:
  var map;

        require([
            "esri/map",
            "esri/layers/ArcGISTiledMapServiceLayer",
            "esri/layers/FeatureLayer",
            "esri/dijit/OverviewMap",
            "dojo/parser",
            "esri/InfoTemplate",
            "esri/layers/ArcGISDynamicMapServiceLayer",
            "esri/symbols/SimpleFillSymbol",
            "esri/symbols/SimpleLineSymbol",
            "esri/tasks/IdentifyTask",
            "esri/tasks/IdentifyParameters",
            "esri/dijit/Popup",
            "dojo/_base/array",
            "esri/Color",
            "dojo/dom-construct",
            "esri/dijit/Measurement",
            "dojo/dom",
            "esri/dijit/Search",
            "dojo/domReady!"
        ], function (Map, Tiled,FeatureLayer,OverviewMap,
                     parser,InfoTemplate, ArcGISDynamicMapServiceLayer, SimpleFillSymbol,
                     SimpleLineSymbol, IdentifyTask, IdentifyParameters, Popup,
                     arrayUtils, Color, domConstruct,Measurement,dom,Search) {

            var identifyTask, identifyParams;var mapclick;

            var popup = new Popup({
                <!-- Popup是用来查询的窗口类,支持改变被选中物体的颜色等状态-->
                fillSymbol: new SimpleFillSymbol(SimpleFillSymbol.STYLE_SOLID,
                        new SimpleLineSymbol(SimpleLineSymbol.STYLE_SOLID,
                                new Color([255, 0, 0]), 2), new Color([255, 255, 0, 0.25]))
            }, domConstruct.create("div"));
            parser.parse();
            <!--设置地图的信息窗口 -->

            map = new Map("map", {
                infoWindow: popup,
                nav: false,//8个pan 箭头
                slider: false,//左上的缩放 +/-;
                logo: false//右下的esri logo
            });
            var tiled = new Tiled("http://localhost:6080/arcgis/rest/services/tilemap/tiledmap/MapServer");
            map.addLayer(tiled);
            var parcelsURL = "http://localhost:6080/arcgis/rest/services/dynamic/MapServer";
            var feature=new FeatureLayer("http://localhost:6080/arcgis/rest/services/dynamic/FeatureServer");
            <!-- 加载矢量化地图-->
            map.addLayer(new ArcGISDynamicMapServiceLayer(parcelsURL
            ));
            map.on("load",doh);
            <!--地图首次加载完成后执行-->
            function doh() {
                Coord();//显示坐标
                measure();//测距
                togglebutton();//显隐测距按钮
                searchi();
            }
            <!--ID点查询-->
            function searchi() {
                var search = new Search({
                    sources: [{
                        featureLayer: new FeatureLayer("http://localhost:6080/arcgis/rest/services/dynamic/FeatureServer/0", {
                            outFields: ["*"],
                            //searchFields: ["Code"],
                            infoTemplate: new InfoTemplate("管点", "编号: ${OBJECTID} <br/>类型:${Code}<br/>建设年代:${SDate}")
                        }),
                        exactMatch: true,//精确查找
                        outFields: ["OBJECTID","Code","SDate"],
                        searchFields: ["OBJECTID"],//查找的关键字
                        displayField: "OBJECTID",
                        suggestionTemplate: "${OBJECTID}: ${SDate}",
                        name: "管点",
                        placeholder: "例如: 1",//搜索提示
                        enableSuggestions: true
                    }],
                    map: map
                }, "search");
                search.hide();
                document.getElementById("checkbox2").addEventListener("change", function () {
                    if (this.checked) {
                        search.startup();
                        search.show();
                    } else {
                        search.hide();
                    }
                });


            }
            <!--ID点查询-->
            <!--测距-->
            function togglebutton() {
                $(document).ready(function () {
                    $("#measurementDiv").hide();
                    $("#measure").click(function () {
                        $("#measurementDiv").toggle();
                    })
                })
            }
            function measure() {
                var measurement=new Measurement({map:map},dom.byId("measurementDiv"));
                measurement.startup();
            }
            <!--测距-->
            <!--显示坐标-->
            function Coord() {
                map.on("mouse-move", showCoordinates);
                map.on("mouse-out", hideCoordinates);
                function showCoordinates(evt)
                {
                    var mp = evt.mapPoint;
                    $(document).ready(function () {
                        $("#info").text(mp.x.toFixed(4)+","+mp.y.toFixed(4));
                    })
                }
                function hideCoordinates(evt)
                {
                    var mp = evt.mapPoint;
                    $(document).ready(function () {
                        $("#info").text("");
                    })
                }
            }
            <!--显示坐标-->

            <!--属性查询-->
            document.getElementById("checkbox1").addEventListener("change", function () {
                if (this.checked) {
                    mapready()
                } else {
                    mapclick.remove();
                }
            });
            function mapready() {
                mapclick= map.on("click", executeIdentifyTask);
                //添加地图点击事件
                identifyTask = new IdentifyTask(parcelsURL);
                //实例化IdentifyTask类
                identifyParams = new IdentifyParameters();
                identifyParams.tolerance = 3;
                //鼠标点击的容错度
                identifyParams.returnGeometry = true;
                identifyParams.layerIds = [0, 1];
                //设置参与查询的图层的ID
                identifyParams.layerOption = IdentifyParameters.LAYER_OPTION_ALL;
                identifyParams.width = map.width;
                identifyParams.height = map.height;
            }
            function executeIdentifyTask(event) {
                identifyParams.geometry = event.mapPoint;
                //鼠标点击事件的处理
                identifyParams.mapExtent = map.extent;

                var deferred = identifyTask
                        .execute(identifyParams)
                        .addCallback(function (response) {
                            // response is an array of identify result objects
                            // Let's return an array of features.
                            return arrayUtils.map(response, function (result) {
                                var feature = result.feature;
                                var layerName = result.layerName;

                                feature.attributes.layerName = layerName;
                                //设置不同的图层,不同点的处理
                                if (layerName === 'feature.SDE.Point') {
                                    var taxParcelTemplate = new InfoTemplate("管点信息",
                                            "编号: ${OBJECTID} <br/>类型:${Code}<br/>建设年代:${SDate}");
                                    feature.setInfoTemplate(taxParcelTemplate);
                                    //设置查找对象的信息窗口
                                }
                                else if (layerName === 'feature.SDE.Line') {
                                    var buildingFootprintTemplate = new InfoTemplate("管线信息",
                                            "编号: ${OBJECTID} <br/>管径:${PSize}<br/>所在道路:${Road}<br/>建设年代:${SDate}");
                                    feature.setInfoTemplate(buildingFootprintTemplate);
                                }
                                return feature;
                            });
                        });

                // InfoWindow expects an array of features from each deferred
                // object that you pass. If the response from the task execution
                // above is not an array of features, then you need to add a callback
                // like the one above to post-process the response and return an
                // array of features.
                map.infoWindow.setFeatures([deferred]);
                map.infoWindow.show(event.mapPoint);

            }
            <!--属性查询-->
            <!--鹰眼图-->
            var overviewMapDijit = new OverviewMap({
                map: map,
                visible: true,
                attachTo: "bottom-right",
                color: " #D84E13",
                opacity: .40
            });
            overviewMapDijit.startup();
            overviewMapDijit.hide();
            var overbutton = document.getElementById("checkbox");
            overbutton.addEventListener("change", function () {
                if (this.checked) {
                    overviewMapDijit.show();
                } else {
                    overviewMapDijit.hide();
                }
            });
            <!--鹰眼图-->

        });

功能如下图:


  • 1
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 4
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

GIS开发者

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值