18. Design and implementation of emptying functions and map location functions in WebGIS

18.1. Background

When a lot of elements are added to the map, different elements need to be controlled. The simplest control is to selectively clear and delete the elements. In this section, we will also introduce another common feature in WebGIS, the map location feature. The specific description is: when a coordinate point is input, the map can be scaled to that point. Below I will expand the content of this chapter for the above two functions.

18.2. Empty function

18.2.1. Design ideas

Depending on the function point, we can divide the emptying into the following scenarios:

a.Empty ingenaying a certain or specified number of elements

b.Empty a class or more of an element

c.Empty all elements

In the previous section on the principles of vector layers, I’ve covered in detail the principles of vector layers in WebGIS, with a vector layer corresponding to a Canvas, and elements are added in element. So, for the three scenarios involved in the above emptying, here is the following design:

a.Empty this corresponding element in Canvas according to childname.

b.If you delete some of the classes in a Canvas, you should also code the naming of the childname, that is, the catalogname, and delete the corresponding class element in canvas based on the catalogname. If the class to be deleted will be good according to Canvas to distinguish, at this point, directly empty the corresponding canvas of the class can be.

c.Traverse all canvases and empty all the elements in the canvas.

18.2.2. Specific implementation

To make it easier to manage all canvases. Specific implementation, it is necessary to do a management canvas class, which provides to get the specified canvas, delete the specified canvas, empty the specified canvas and other management functions.

If you design this management class itself as a class that inherits from Canvas, and treats other Canvas as an element, you already have the management of the canvas. And there is also an advantage that, since other vector canvases are their elements, the operation of the mouse on the canvas can be used only on this layer for monitoring. .. figure:: img/img_1.png

18.3. Map location function

Friends who have used arcmap should have used the map positioning tool in arcmap, which can zoom the map to the coordinates after entering the X and Y coordinates. The tool interface in Arcmap is as follows:

../_images/img_29.png

18.3.1. Design ideas

When designing this feature, we first need to have a basic understanding of tile conversion (see the third chapter of this series). Here I give the entire flowchart directly:

../_images/img_39.png

18.3.2. Specific implementation

In arcmap, as the mouse moves around the map, the lower right corner of the map shows the geographic coordinates where the mouse is located. In WebGIS, we can also add this feature, but the way we’re presented needs to be designed.

When designing the map location function, I incorporated the ability to pick up mouse geographic coordinates into this feature:

a.As the mouse moves, the XY input box displays the geographic coordinates of where the mouse is located in real time.

b.Click the anchor button and the map zooms to the input box XY coordinates.

The effect chart is as follows:

../_images/img_43.png

18.4. Summary

In this chapter, I discussed with you the two basic functions of WebGIS, map emptying and map positioning. In the next chapter, we begin to explore a very important feature in WebGIS, I query. And explore how you can make I queries configurable, extensible, and how interfaces are presented.