A method for generating disaster maps regularly based on NodeJs
The NodeJs technology is used to regularly generate disaster maps in the flood control system, using multi-threading and high concurrency features to solve the problems of slow disaster map rendering speed and high equipment performance in the existing technology, achieving fast and accurate disaster map display, and improving User experience.
Patent Information
- Application Number
- CN202010762703.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-07-31
- Publication Date
- 2024-08-30
- Estimated Expiration
- 2040-07-31
AI Technical Summary
The existing flood control system cannot effectively render and update maps in real-time under rapidly changing disaster conditions, resulting in page freezes or crashes. Manual screenshots are required to display real-time disaster changes, which requires high equipment performance and poor user experience.
Using NodeJs technology, the disaster map is generated regularly through timers, using multi-threading and high concurrency features to pre-generate disaster pictures, and use a headless browser and leafletjs library to draw the map in the sub-thread, use html2canvas to take screenshots, save and return the pictures, Avoid manual screenshot operations.
It improves the efficiency of map generation, reduces user network bandwidth consumption and equipment performance requirements, avoids page freezes, achieves fast and accurate disaster map display, and enhances user experience.
Smart Images

Figure CN111966876B
Abstract
Description
Technical Field
[0001] The invention belongs to the technical field of flood prevention informatization, and specifically relates to a method for regularly generating a disaster map based on NodeJs. Background Art
[0002] In the field of flood prevention, if it is possible to quickly and in real time produce, save, publish and display maps of disaster changes such as water conditions, rainfall conditions, flood conditions, etc. at different times, more accurate judgments can be made on the disaster situation, and the public can also be kept informed of the development of the disaster in a timely manner.
[0003] At present, the real-time display of flood, rainfall and water conditions in various provinces and cities is displayed after processing the data on the web. This kind of rendering method has high requirements on network performance and equipment performance. The rendering speed cannot be guaranteed when the data volume is too large. When the disaster situation changes quickly and the refresh rate is high, it will cause the page to freeze or crash. In addition, if you need to show the public a real-time disaster situation change map, you need to manually screenshot or draw the map separately.
[0004] To solve the problem of image rendering failure on devices with poor performance, the real-time data can be used to generate disaster pictures on the server in advance, and then the pictures can be returned to the access device. Summary of the invention
[0005] The purpose of the present invention is to provide a method for generating disaster maps based on NodeJs at a regular interval. The method is conducive to providing users with disaster pictures, has low requirements on user networks and devices, and is easy to operate and use.
[0006] The technical solution adopted by the present invention is: a method for regularly generating a disaster map based on NodeJs, comprising the following steps:
[0007] 1) The system has a built-in timer that automatically generates special tasks. At the same time, the system monitors external requests. If an external request for disaster pictures is received, it determines whether the pictures exist. If so, it retrieves the required disaster pictures from the file system and returns them to the external request. Otherwise, it creates a custom task.
[0008] 2) All image generation tasks are passed into the task scheduling queue and each task is processed according to the task priority;
[0009] 3) The main thread creates a child thread for each task, starts a headless browser in the child thread, creates a map canvas, and then zooms the map to the task-specified level to prepare for drawing the map; reads the latitude and longitude turning point data of the task-related area and its corresponding real-time data from the database, draws a map and loads it onto the canvas; reads the task-related basic layer from the file system and loads the layer onto the canvas; reads the task-related online service layer from the online map service and loads the layer onto the canvas;
[0010] 4) After all layers are loaded, capture the task output area and generate disaster pictures;
[0011] 5) Save the disaster pictures to the file system according to the task type and generation time so that they can be read next time;
[0012] 6) If the task type is an external request, the generated disaster picture is returned to the external request.
[0013] Furthermore, in step 1, the system has multiple built-in timers, including a rain map task generation timer, a water map task generation timer and a flood map task generation timer. The timed and automatically generated special tasks correspond to rain picture generation tasks, water picture generation tasks and flood picture generation tasks.
[0014] Furthermore, in step 2, among all the image generation tasks, the processing priority of the custom task is higher than that of the special task.
[0015] Furthermore, in step 3, the main thread creates a Node work_thread sub-thread for each task.
[0016] Furthermore, in step 3, the map canvas is created using the leafletjs library.
[0017] Furthermore, in step 4, html2canvas is used to capture the task output area.
[0018] Compared with the prior art, the present invention has the following beneficial effects: a method for generating disaster maps based on NodeJs at a scheduled time is provided. The method utilizes the high concurrency and multi-threading characteristics of NodeJs, supports the pre-setting of multiple scheduled generation tasks and external incoming tasks, and improves the efficiency of map output. In addition to consuming server computing resources when generating the image for the first time, for subsequent requests, it is only necessary to read and return the generated image to the accessing party, which consumes less user network bandwidth and has basically no performance requirements for user access devices. In addition, using NodeJs to generate images on the server side can avoid manual screenshot misoperations and can break through the limitation of the limited manual screenshot area. Therefore, the present invention has strong practicality and broad application prospects. BRIEF DESCRIPTION OF THE DRAWINGS
[0019] Figure 1 It is a flow chart of the method implementation of the embodiment of the present invention. DETAILED DESCRIPTION
[0020] The present invention will be further described in detail below in conjunction with the accompanying drawings and specific embodiments.
[0021] The present invention provides a method for generating disaster maps based on NodeJs at a fixed time. Figure 1 As shown, the following steps are included:
[0022] 1) The system has a built-in timer that automatically generates special tasks at regular intervals; at the same time, the system monitors external requests. If an external request for disaster pictures is received, it determines whether the pictures exist. If so, it retrieves the required disaster pictures from the file system and returns them to the external requester. Otherwise, it creates a custom task.
[0023] In this embodiment, the system has multiple built-in timers, including a rain map task generation timer, a water map task generation timer, and a flood map task generation timer. The timed and automatically generated special tasks correspond to rain picture generation tasks, water picture generation tasks, and flood picture generation tasks.
[0024] 2) All image generation tasks are passed into the task scheduling queue and each task is processed according to the task priority.
[0025] Since users who initiate external requests generally have a high degree of urgency in their demand for disaster images, among all image generation tasks, custom tasks have a higher processing priority than special tasks.
[0026] 3) The main thread creates a Node work_thread child thread for each task, starts a headless browser in the child thread, and uses the leafletjs library to create a map canvas, then zooms the map to the task-specified level to prepare for drawing the map; reads the latitude and longitude inflection point data of the task-related area and its corresponding real-time data in the database, draws it into a map and loads it onto the canvas; reads the task-related basic layer from the file system and loads the layer onto the canvas; reads the task-related online service layer from the online map service and loads the layer onto the canvas.
[0027] 4) After all layers are loaded, use html2canvas to capture the task output area and generate disaster pictures.
[0028] 5) Save the disaster pictures to the file system according to the task type and generation time so that they can be read next time.
[0029] 6) If the task type is an external request, the generated disaster picture is returned to the external request.
[0030] The above are preferred embodiments of the present invention. Any changes made according to the technical solution of the present invention, as long as the resulting functions do not exceed the scope of the technical solution of the present invention, belong to the protection scope of the present invention.
Claims
1. A method for generating disaster maps based on NodeJs at regular intervals, characterized in that: The following steps are involved: 1) The system has a built-in timer that automatically generates special tasks at regular intervals; at the same time, the system monitors external requests. If an external request for disaster pictures is received, it determines whether the pictures exist. If so, it retrieves the required disaster pictures from the file system and returns them to the external requester. Otherwise, it creates a custom task; In step 1, the system has multiple built-in timers, including a rain map task generation timer, a water map task generation timer, and a flood map task generation timer. The timed and automatically generated special tasks include a rain picture generation task, a water picture generation task, and a flood picture generation task. 2) All image generation tasks are passed into the task scheduling queue and each task is processed according to the task priority; In step 2, among all image generation tasks, the processing priority of custom tasks is higher than that of special tasks; 3) The main thread creates a child thread for each task, starts a headless browser in the child thread, creates a map canvas, and then zooms the map to the task-specified level to prepare for drawing the map; Read the latitude and longitude turning point data of the task-related area in the database and its corresponding real-time data, draw a graph and load it onto the canvas; Read the task-related base layer from the file system and load the layer onto the canvas; Read the task-related online service layer from the online map service and load the layer onto the canvas; In step 3, the main thread creates a Node work_thread child thread for each task; the map canvas is created using the leafletjs library; 4) After all layers are loaded, capture the task output area and generate disaster pictures; In step 4, use html2canvas to capture the task output area; 5) Save the disaster pictures to the file system according to the task type and generation time so that they can be read next time; 6) If the task type is an external request, the generated disaster picture is returned to the external request.
Citation Information
Patent Citations
Dynamic traffic information service providing method based on map layer overlapping
CN103177577A
Picture generation method, server and computer readable storage medium
CN108600373A
