ArcGIS API for JavaScript call dynamic map Service + attributes, spatial query __arcgis

Source: Internet
Author: User

Introduction Call Dynamic Map Service Requirement 1 hide a layer in the service according to requirements 11 code explanation 2 through the attribute query map service Information 21 Code Implementation 22 code interpretation 3 through Space query Map service 31 Code Implementation 32 code explanation 4 Supplemental

1. Introduction

In this blog, the main record in the ArcGIS API how to invoke its own published dynamic map Services, the use of dynamic map services we can complete some of the requirements and so on.

Note:(how to use ArcGIS Server to publish dynamic map services please see blog ArcGIS Server release dynamic map Service) , 2. Invoke dynamic Map Service

The ArcGIS API provides us with a class called Arcgisdynamicmapservicelayer to use this class, and we can get the published map service. Calling a dynamic map service typically takes only two steps: Create a Arcgisdynamicmapservicelayer object from the URL of the map service add the object of the dynamic map service to the map container

The code is as follows:

<! DOCTYPE html> 

Click Run, and then run it as shown below:

Note: Unlike ArcMap in the ArcGIS API, a service layer is the equivalent of a set of layers (that is, multiple layers). 3. Demand

in the real development process, the dynamic Map service can help us to complete a lot of functional requirements, such as: according to the requirements of the hidden service in a layer (dynamic map services can be implemented, but slicing map services cannot be implemented) through the property query map service information Through the Space Query map service information (including point query, line query, face query, etc.) 3.1. Hide a layer in a service based on requirements

There are four layers in the map service we have released

In this demand. We mainly add a button to the page and then hide the road2 in the map service.
The code is:

 Require (["Esri/map", "Dojo/dom", "dojo/on", "Esri/layers/arcgisdynamicmapservicelayer", "dojo/domready!"
                    ], function (map,dom,on,arcgisdynamicmapservicelayer) {var map = new Map ("Mapdiv"); var layer=new arcgisdynamicmapservicelayer ("Http://localhost:6080/arcgis/rest/services/Test/MyServer/Map
                    Server ");
                    Map.addlayer (layer);
                        Bind Click event on (Dom.byid ("btn") to the button with ID btn, "click", Function () {
                    Layer.setvisiblelayers ([1,2,3]);
      
      }) 1 2 3 4 5
     
     
     
     
      
      
     
     
     
     
      
      6 7 8 9 10 11 12
      
      1 2 3 4 5
 6 7     
      8 9 10 11 12
     
      
3.1.1 Code Explanation: The implementation of this code function is very simple, using only the Setvisiblelayers method, tell the service, I want to show the layer number is 1,2,3 layer. A new module Dojo/dom module is loaded in require, which provides us with a method Dom.byid (ID), which we can get DOM objects, similar to the document.getElementById () method. A new module dojo/on module was loaded in require, in Dojo, where the first parameter of the On (Target,type,listener) is to bind the event, the second parameter is the type of the event, and the third is the callback function. 3.2. Query the information in the map service through the attribute

In the development process, there is often the need to query the attributes according to the graph of the elements we want, and then highlight the graphic (in this case, query the classroom building information, such as the classroom building according to the name of the floor into a highlight)

Teaching Building Layer Property sheet information:

In implementing this feature, we'll start with a few steps: Create a new text box on a Web page to get the name of the classroom building in the text box, and creating a Property query object to get the floor information (geometry information) of the query and use graphics highlighting 3.2.1. Code implementation Create a text box

Name:<input class= "nm" type= "text" >
<input type= "button" value= "Query" >
     
     
      
      1
      
      2
     
     
     
     
      
      
     
     
     
     
      
      1
      
      2
     
     
Gets the name of the teaching building in the text box and createsProperty Query Object
Query ("#btn"). On ("click", Function () {///Get the name of the teaching building var name=query (". Nm") [0].V
                        Alue;
                        Instantiate query parameter var findparams = new Esri.tasks.FindParameters ();
                        Findparams.returngeometry = true;
                        Findparams.layerids = [3];
                        Findparams.searchfields = ["Name"];
                        Findparams.searchtext = name; Materialized Query object var findtask = new Esri.tasks.FindTask ("http://localhost:6080/arcgis/rest/services/Test/
                        Myserver/mapserver ");
     
     
      
      Query Findtask.execute (findparams,showfindresult)}) 
      
      1 2 3 4 5 6 7 8 9
     
     
     
     
10 11 12 13 14      
      
     
     
     
     
      
      1 2 3 4 5
      
      6 7 8 9 10 11 12 13
     
      14
Get the floor information (geometric information) of the query to be highlighted by graphics
function Showfindresult (queryresult) {if (queryresult.length = 0) {
                            Alert ("No such element");
                        Return
                                for (var i = 0; i < queryresult.length i++) {//Get the shape of the graphic
                                var graphic = queryresult[i].feature;
                                var geometry = graphic.geometry; Defines the symbol//1 for a highlighted graphic. Defines the boundary line symbol for a face var outline= new Simplelinesymbo
                                L (simplelinesymbol.style_dashdot,new Color ([255, 0, 0]), 1); 2. Define the face symbol var polygonsymbol = new Simplefillsymbol (Simplefillsymbol.style_solid, Outline,n
                                EW Color ([0, 255, 0, 1]);
      Create client graphics var graphic = new Graphic (geometry, polygonsymbol);                          Adds a client graphic to the map map.graphics.add (graphic);
      
      }} 1
      
      2 3 4 5 6 7 8 9
      
      10 11 12 13 14 15 16 17
     
     
     
     
      
      
     
     
     
     
      
      18 19 20 21
      
      1 2 3 4 5 6 7 8
      
      9 10 11 12 13 14 15
     
      16 17 18 19 20 21
View Results
Property query before:

After the property query:

Complete code:

<! DOCTYPE html>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.