(eight) design of grid layer in Webgis

Source: Internet
Author: User
Tags event listener

1. Preface

In the previous chapter, we learned about the nature of the raster layer in Webgis-the map image. From the second chapter to the fifth chapter, we introduce the principle and method of the map image acquisition in detail. So before designing a raster layer, we already know how the data in the raster layer is obtained, and the rest is how to implement it in a way that conforms to the object-oriented design principles.

2. The process of raster data acquisition

Here I once again describe the process of getting the raster data again:

First, the screen in the range of the coordinates of the four corners, according to the four-dimensional coordinates of the map to the nearest map level, and the tile line number range and column number range, and then by the line number and column number mosaic tile request, tile loading. The resulting tiles are then stitched together into a whole block of maps, which are then displayed in the front.

3. Problems in practice

Before the design we put forward such a question:

There may be many different sources of raster data, such as online maps and offline maps. At the same time, online maps may be data obtained from different requests, and offline maps may also come from different cut-chart formats.

We are not sure which data source the user is using, or whether the user will change the data source halfway.

4. Ideas

After careful analysis of the above questions, combined with the inheritance, encapsulation, polymorphism and three characteristics in object-oriented design, we can abstract a kind of design idea:

(1) Design a class that--baselayer the highest parent class for all raster layers. Define some of the features required for all classes in this class, and provide the most basic methods, such as event listener methods.

(2) Design an overly--imagelayer class, which inherits from Baselayer, but implements some common methods in this class. For example, in the request of tiles, the line number and column number are required for each raster layer, and the tiling method is also common. So by these few things in common, you can define some of the methods associated with this.

(3) Design specific raster layer classes, such as the classes designed for ArcGIS online maps, the class of needles for the Super map online, classes for WMS request methods, and so on. And these specific classes are inherited from Imagelayer.

5.UML figure

Based on the ideas in section 4th, we give you a way to design a raster layer:

6. A detailed description of the raster layer design

As can be seen from the UML diagram, we first extracted a common base class for each tile layer, Baselayer, which includes several attributes that are necessary to make up each layer, such as the intrinsic-canvas of a tile layer, And the geometric boundaries of each tile layer as well as the monitoring and removal methods for map events.

And all tile layers involved in the core algorithm, that is, to obtain the column number of tiles, tiles in the screen coordinates, etc. are first in the inheritance of Baselayer in the Imagelayer in the definition and part of the common algorithm written. Where Getmapbygeoextent is the core algorithm, the function of this algorithm is to convert the URL of the tile in the range and tile request and load through the URL.

Each specific tile layer class is directly inherited from the Imagelayer, and then in the specific tile layer to achieve the conversion of the tile row number, as well as the tile URL conversion. After the map load event is triggered, the Exectilerequest method is called to call the Geomapbyextent method in the base class parent class Imagelayer.

7. Optimizing the design of raster layers

Based on the principle of tile layer design, it can be optimized in two ways. One is the optimization of the requested map extent when the tile is requested; One is caching the requested tiles in memory according to certain rules.

7.1 Optimization of Tile request range

If the map only requests tiles in the screen range at a time, tile requests are made whenever the map shift is triggered, which makes the front end often in the tile request state. But similarly, the scope of the tile request can not be too large, the assembly caused the request tile when the user waits too long. Therefore, it is necessary to set a reasonable cache range outside the screen range so that the requested map extent for each request is the screen range plus the sum of the cache range (screenboundary+toleranceboundary).

7.2 Cache of Tiles

If each request tile needs to be obtained from the server or the browser tile cache, this will inevitably extend the display time of the front-end map, if you can directly cache tiles in memory, and then encounter the same tiles directly from memory read, this is faster than the above two ways, can speed up the front-end map display. However, tiles can not be cached too much, so that the memory load is too large, and many tiles have been used once, may not be used for a long time, it is necessary to use a certain schedule rules and a reasonable size of the memory container to place and manage tiles.

8. Optimize the implementation of 8.1 request scope optimization

In the actual project, some projects are by default on the scope of the tile of the screen, and in addition to expand the width of one or more tiles around the range. And some projects do not do anything about it, because we actually get the tile range, which itself is larger than the geographical range of the screen.

For readers who want to artificially expand the width of one or more tiles, in the third chapter of this series, the actual start number of the tile can be calculated by artificially changing the tile start number. After changing the starting number of the tile, the actual geographic range of the tiles that are calculated later needs to make relevant adjustments.

Of course, the simplest is not to do this optimization, because as I said above, we have calculated by the formula Tile range itself is larger than the screen geographical range. Optimization has been implemented in the basic algorithm.

Implementation of 8.2 tile cache mechanism

We can define a container of fixed size, where content is stored by key-value pairs. Each tile's URL is unique and can be used as a key. The rules for the control of tiles in containers are the use of frequency sequencing plus the FIFO principle. The detailed process is as follows:

(1) The newly added tiles in the container are placed on top of all tiles, Max (index).

(2) The tiles that are called in the container are re-placed on top of all tiles (Max index), while the other tiles are automatically moving forward one (index-1)

(3) When the container is full, the lowest layer tile is deleted, that is, the tile with index 0 is deleted.

9. Summary

Based on the knowledge of the previous chapters, we do not describe the principle and method of raster data acquisition in this chapter, but focus on the design of the raster layer, and finally we introduce two optimized raster layer design ideas. Raster layer as the display core of topographic map in Webgis, it is very important to design a good grid layer organization, otherwise it will be too slow to be taken as topographic map, or can not support many topographic map sources well. And if the design is unreasonable, it will be a lot of code redundancy, resulting in any extension or maintenance will be very difficult. Of course, the design framework given here is certainly not the best, I hope I can give the reader to throw bricks to welcome jade. The next chapter begins with a series of chapters to explain the design of the vector layer. I'll go through the data sources, coordinate transformations, and final design implementations of the vector layers to explore the vector layers in Webgis in a comprehensive way. We welcome your continued attention.

------Welcome reprint, but retain the copyright, please indicate the source in obvious place: Http://www.cnblogs.com/naaoveGIS

If we linger, or feel regret, it is because we are afraid of the regrets that we linger on and will not go through again.

and experience can be created, and much effort.

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.