A cross-platform bidirectional communication method and apparatus for Tianditu components based on message queues.

By using a message queue-based cross-platform bidirectional communication method for Tianditu components, the problems of chaotic concurrent processing, easy blocking, and weak fault recovery capabilities in existing technologies are solved, achieving efficient and stable cross-platform Tianditu component communication that is compatible with multiple mobile platforms.

CN121396962BActive Publication Date: 2026-03-13TAIHUA WISDOM IND GRP CO LTD +1
View PDF 1 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2025-12-23
Publication Date
2026-03-13

AI Technical Summary

Technical Problem

The existing cross-platform Tianditu component's bidirectional communication solution suffers from problems such as chaotic concurrent processing, easy blocking, and weak fault recovery capabilities, which affect communication efficiency and stability. Furthermore, it has not been optimized for the specific operation scenarios of the Tianditu component, resulting in poor component adaptability, long initialization time, and excessive memory consumption.

Method used

The system adopts a cross-platform Tianditu component bidirectional communication method based on message queues. Through message queue management module, data serialization module, asynchronous call processing module, and error retry mechanism module, it realizes independent processing of concurrent requests, automatic coordinate conversion, data format standardization, and intelligent fault recovery, avoids main thread blocking, and provides a unified asynchronous operation interface and intelligent retry mechanism.

Benefits of technology

It achieves efficient concurrent request matching and accurate result transmission, avoids main thread blocking, improves communication efficiency and stability, reduces message loss rate and memory leaks, enhances system fault recovery capability, and is compatible with multiple mobile platforms.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121396962B_ABST
    Figure CN121396962B_ABST
Patent Text Reader

Abstract

This invention relates to the field of cross-platform application communication technology, specifically to a method and apparatus for bidirectional communication between the application layer and the WebView layer of a cross-platform Tianditu component based on a message queue. This method addresses the bidirectional communication requirements between the application layer and the WebView layer in a cross-platform Tianditu component. It manages concurrent requests through a message queue, generates a unique identifier for each instruction, and achieves accurate message matching. It combines data serialization and deserialization to ensure consistent data format across layers, avoids main thread blocking through asynchronous calling mechanisms, and utilizes timed polling for rapid result feedback. Furthermore, it designs an error retry mechanism to address temporary faults such as network errors and WebView anomalies, ensuring communication reliability. This invention achieves a closed-loop communication system from "application layer → communication layer → WebView layer → communication layer → application layer," solving the problems of chaotic concurrent processing, easy blocking, and weak fault recovery capabilities in existing communication solutions. It is compatible with the uni-app X framework and multiple mobile platforms, improving the communication efficiency and stability of the cross-platform Tianditu component.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of cross-platform communication technology, and in particular to a cross-platform bidirectional communication method and apparatus for Tianditu components based on message queues. Background Technology

[0002] With the popularization of mobile internet technology and the widespread application of cross-platform application development frameworks (such as uni-app X), the demand for the integration of Geographic Information System (GIS) related components in cross-platform scenarios is becoming increasingly urgent. As a core geographic information service component, Tianditu needs to achieve bidirectional communication between the application layer and the WebView layer to support diverse operations such as map configuration, overlay rendering, and spatial service invocation. Its communication efficiency and stability directly affect the user experience of cross-platform applications.

[0003] Current cross-platform Tianditu component bidirectional communication solutions suffer from numerous technical bottlenecks, failing to meet practical application needs: First, a concurrency processing mechanism is lacking. Existing solutions often employ simple callbacks or unordered message transmission modes, failing to uniformly manage multiple concurrent requests and lacking unique identifiers and precise matching mechanisms. This leads to message confusion, high loss rates, and inaccurate correlation between request and response results in high-concurrency scenarios, severely impacting communication reliability. Second, main thread blocking is a significant issue. Most solutions rely on synchronous calls or imperfect asynchronous implementations, easily consuming main thread resources during cross-layer data transmission and map operation execution, causing UI lag, map response delays, and a high ANR rate. Third, coordinate system adaptation is cumbersome, and Tianditu services... The existing solution lacks an automatic conversion mechanism for the commonly used WGS84 and GCJ02 coordinate systems, requiring developers to manually handle coordinate adaptation. This not only increases development workload but also easily leads to geographical information display errors due to conversion errors. Fourth, there is insufficient data format compatibility. The data transmission format between the application layer JavaScript object and the WebView layer lacks a standardized serialization / deserialization process, which easily leads to problems such as data parsing failure and field loss. Fifth, the fault recovery capability is weak. For scenarios such as network fluctuations, abnormal WebView loading, and temporary service interruptions, the existing solution lacks effective timeout detection and intelligent retry mechanisms. The success rate of requests is low in weak network environments, and the system stability is difficult to guarantee.

[0004] Furthermore, existing communication solutions are mostly general-purpose designs, failing to optimize for the specific operational scenarios of Tianditu components (such as map configuration, dynamic updates of overlays, and asynchronous calls to spatial services). This results in poor component adaptability, long initialization times, and excessive memory consumption. These issues collectively hinder the widespread application of cross-platform Tianditu components, necessitating a bidirectional communication technology solution that can address pain points such as concurrency chaos, blocking and lag, complex coordinate adaptation, and weak fault recovery capabilities.

[0005] Therefore, this invention proposes a cross-platform bidirectional communication method and apparatus for Tianditu components based on message queues to solve the above problems. Summary of the Invention

[0006] To address the shortcomings of existing technologies, this invention develops a cross-platform bidirectional communication method and device for Tianditu components based on message queues. This invention solves the problems of chaotic concurrent processing, easy blocking, and weak fault recovery capabilities in existing communication schemes, thereby improving the communication efficiency and stability of cross-platform Tianditu components.

[0007] On one hand, the technical solution of this invention to solve the technical problem is a cross-platform Tianditu component bidirectional communication method based on message queues. The encapsulation framework of the cross-platform Tianditu component includes an application layer, a communication layer, and a WebView layer, and includes the following steps:

[0008] S1. The cross-platform Tianditu component receives the developer's call instructions, and the application layer standardizes the instructions and defines the coordinate system parameter identifiers;

[0009] S2. Input the standardized instructions to the communication layer. The communication layer includes a message queue management module, a data serialization module, an asynchronous call processing module, and an error retry mechanism module. Input the output of each module to the WebView layer and send it back to the application layer. Automatic coordinate transformation is performed during the transmission process.

[0010] The HTML page container in the S3 WebView layer parses the input from the communication layer and performs map operations. The execution result is then sent back to the communication layer, processed by the communication layer, and fed back to the application layer, completing the two-way communication loop.

[0011] The coordinate system parameters in the application layer are identified as follows:

[0012] Coordinate system parameter identifiers are used to indicate whether a coordinate system transformation is required;

[0013] The application layer sets up a parameter verification class and a coordinate parameter receiving member to receive the Boolean coordinate system parameters passed in by the developer. After verification, the coordinate system parameter identifier is passed to the communication layer.

[0014] The message queue management module is used for independent processing and result matching of concurrent requests, and includes an identifier generation unit and a queue management unit;

[0015] (1) The identifier generation unit uses a combination of millisecond-level timestamps and random strings to generate a unique identifier for each request;

[0016] (2) The queue management unit stores the request message into the responsive array queue. The message object contains type identifier, unique identifier, parameter data and result field members;

[0017] The message queue management module has a result update mechanism class, which includes members for polling detection, matching completion, and resource reclamation. After receiving the response message, the communication layer performs dual matching of message object type and identifier, polls to detect the status update of the result field, triggers an asynchronous commitment callback and passes the result, marks the completion of the request and executes the callback process, and finally removes the message object to release memory.

[0018] The data serialization module is used for conversion between JavaScript objects and JSON format strings, including serialization and deserialization units;

[0019] (1) The serialization processing unit receives the message object and coordinate system parameter identifier, converts it into a JSON string and sets a coordinate transformation flag. If the flag is true, it instructs the WebView layer to perform the WGS84 to GCJ02 coordinate system transformation and transmits it through the cross-layer communication interface.

[0020] The message object is in JavaScript object format and contains a type identifier field, a unique identifier field, and parameter data fields;

[0021] (2) The deserialization processing unit receives the JSON string returned by the WebView layer and restores it into a structured JavaScript object, which includes type identifier, unique identifier and data payload field.

[0022] The asynchronous call processing module is used to avoid blocking the main thread and provide a unified asynchronous operation interface, including an asynchronous execution unit and a polling detection unit;

[0023] (1) The asynchronous execution unit receives the JSON message and the message object reference, creates an instance through the asynchronous commitment mechanism and returns immediately to avoid blocking the main thread, and then obtains the cross-layer communication interface through the WebView container reference to send the message to the WebView layer;

[0024] (2) The polling detection unit is used to detect whether the WebView layer has returned the execution result. It receives the result field member status of the message object in the message queue. The polling detection unit starts a timed polling mechanism with a fixed time interval to check the update status of the result field. After detecting that the result field has been updated, it triggers the success callback interface or failure callback interface of the asynchronous commitment mechanism according to the result type identifier value and passes the execution result object to the application layer.

[0025] The error retry mechanism module is used to automatically retry requests when the network is unstable or there is a temporary failure, including a timeout detection unit and a retry control unit;

[0026] (1) The timeout detection unit is used to prevent memory leaks caused by infinite waiting. It receives the accumulated value of the polling count from the polling detection interface and the preset timeout threshold parameter. It determines whether a timeout has occurred by accumulating the polling count and comparing it with the timeout threshold. If the polling count exceeds the preset threshold, the timer is cleared and a failure callback is triggered to return a timeout error message.

[0027] (2) The retry control unit is used to improve the success rate of requests through the retry mechanism and receives the error type identifier, current retry count and maximum retry count configuration returned by the asynchronous call processing module;

[0028] Based on the information returned by the WebView layer in the error events that occur during the map operation, the error event results are obtained, including the error type identifier and error description information. The two are encapsulated in the response message, and the response message is sent back to the communication layer through the message sending interface.

[0029] The retry control unit determines whether the retry conditions are met based on the error type identifier. If the current number of retries is less than the maximum number of retries and the error retry conditions are met, the request is resent. If the error retry conditions are not met and the error type is not met, the request is resent. Error types include network errors, WebView exceptions, or temporary failures. If the current number of retries reaches or exceeds the maximum number of retries, the retry operation is stopped and the final failure result is returned to the application layer.

[0030] The specific operations during the return transmission process are as follows:

[0031] (1) The forward processing status feedback module is used to provide status feedback for request processing to the application layer, including a status data collection unit and a status transmission unit;

[0032] 1) The status data collection unit is used to summarize the status information of request processing, and collect the output status of four operations: message queue management, data serialization, asynchronous call processing and error retry mechanism. The output status includes response result object and queue management status, serialized string and coordinate transformation identifier, asynchronous commitment object, timeout error object or retry execution status.

[0033] 2) The state transmission unit is used to synchronize the processing state to the application layer. It transmits the output of the four operations through the internal state variables of the application layer and the reactive system to update the component state and trigger the view to re-render. The application layer determines whether the request has successfully entered the queue, whether the data has been correctly serialized, whether the asynchronous commitment has been created normally, and whether the error handling mechanism is working properly based on the returned state data.

[0034] (2) The WebView execution result processing module is used to provide the final execution result of map operations to the application layer, including a result receiving unit, a result processing unit and a result transmission unit;

[0035] 1) The result receiving unit is used to receive response messages from the WebView layer. The WebView layer sends result messages through the message sending interface, and the message listening and processing function of the communication layer receives the messages.

[0036] 2) The result processing unit is used to process and match the execution results. It extracts the type identifier and unique identifier from the message for queue matching. The message queue management locates the corresponding message in the queue based on the type identifier and unique identifier and updates the result field. The data field is parsed through the JSON parsing mechanism. The polling detection mechanism detects the update of the result field. The asynchronous call processing triggers the success or failure callback of the asynchronous commitment. The error retry mechanism decides whether to resend the request based on the retry conditions.

[0037] 3) The result transmission unit completes the entire data transmission link from WebView to the developer application according to the transmission path.

[0038] On the other hand, the present invention also provides a cross-platform Tianditu component bidirectional communication device based on message queue, for executing a cross-platform Tianditu component bidirectional communication method based on message queue, including an application layer module, a communication layer module and a WebView layer module, wherein each module works together to realize a bidirectional communication closed loop;

[0039] Application layer module: includes instruction standardization unit and coordinate parameter management unit;

[0040] The instruction standardization unit receives invocation instructions from developers and standardizes the method name, parameter objects, and callback functions.

[0041] The coordinate parameter management unit has a parameter verification class and a coordinate parameter receiving member. After verification, it generates a coordinate system parameter identifier. At the same time, it receives the processing status and results returned by the communication layer through internal state variables and a reactive system, updates the component status, and triggers view rendering.

[0042] Communication layer module: includes message queue management module, data serialization module, asynchronous call processing module, error retry mechanism module, positive processing status feedback module, and WebView execution result processing module;

[0043] The message queue management module includes an identifier generation unit, a queue management unit, and a result update mechanism class.

[0044] The data serialization module includes serialization and deserialization processing units and a coordinate transformation judgment class;

[0045] The asynchronous call processing module achieves non-blocking communication and result detection through asynchronous execution and polling detection units.

[0046] The error retry mechanism module handles timeouts and retries through timeout detection and a retry control unit;

[0047] The positive processing status feedback module collects and transmits the status of each operation;

[0048] The WebView execution result processing module receives, processes, and transmits the results.

[0049] WebView layer module: contains HTML page container unit and message sending interface unit. The HTML page container receives and parses the input from the communication layer, performs map operations, and the message sending interface sends the execution result back to the communication layer in JSON format string.

[0050] The effects described in the invention are merely those of the embodiments, and not all the effects of the invention. The above technical solutions have the following advantages or beneficial effects:

[0051] The message queue management module of the communication layer in this invention achieves independent tracking and accurate result matching of concurrent requests through a unique identifier generation mechanism using millisecond-level timestamps and random strings, combined with the storage of a reactive array queue and dual matching logic. This completely solves the industry pain points of multiple request conflicts and result confusion. At the same time, the polling detection, matching marking, and resource reclamation process of the result update mechanism ensures that memory is released in a timely manner after the request is completed, avoiding memory leaks. Furthermore, the timeout detection and targeted retry strategy of the error retry mechanism module effectively reduce the request failure rate in unstable environments, significantly enhancing the fault tolerance of bidirectional communication. The application layer receives Boolean coordinate system parameter identifiers through the parameter verification class. After detection and marking by the coordinate transformation judgment class of the data serialization module, automatic conversion between the WGS84 and GCJ02 coordinate systems is achieved. This eliminates the need for manual coordinate adaptation by developers, reducing human coding errors and meeting the coordinate system requirements of Tianditu (a map application). Simultaneously, the bidirectional format conversion of the data serialization module ensures the integrity of cross-layer data transmission. The deserialized structured object allows the communication layer to directly parse the results returned by the WebView, avoiding data parsing distortion and improving the transmission accuracy of map operation commands and execution results. The asynchronous call processing module uses an asynchronous commitment mechanism to create commitment instances, returning to the application layer immediately after sending the request, completely avoiding main thread blocking and ensuring smooth application interface response. The polling detection unit's timed polling mechanism accurately tracks the status of result fields, enabling immediate callback triggering after result return, balancing performance overhead and response timeliness.

[0052] This invention realizes a closed-loop communication system from "application layer → communication layer → WebView layer → communication layer → application layer", solving the problems of chaotic concurrent processing, easy blocking, and weak fault recovery capabilities in existing communication solutions. It is compatible with the uni-app X framework and multiple mobile platforms, improving the communication efficiency and stability of cross-platform Tianditu components. Attached Figure Description

[0053] The accompanying drawings are provided to further illustrate the invention and form part of the specification. They are used together with the embodiments of the invention to explain the invention and do not constitute a limitation thereof.

[0054] Figure 1 This is a schematic diagram of the method flow of the present invention. Detailed Implementation

[0055] To clearly illustrate the technical features of this solution, the invention will be described in detail below through specific implementation methods and in conjunction with the accompanying drawings.

[0056] Example 1

[0057] like Figure 1 As shown, a cross-platform Tianditu component bidirectional communication method based on message queues is presented. The encapsulation framework of the cross-platform Tianditu component includes an application layer, a communication layer, and a WebView layer, and includes the following steps:

[0058] S1. The cross-platform Tianditu component receives the call instructions from the developer. The application layer standardizes the received instructions and defines coordinate system parameter identifiers for the received instructions. The call instructions include the method name, parameter object and callback function.

[0059] S2. Input the standardized instructions to the communication layer. The communication layer includes a message queue management module, a data serialization module, an asynchronous call processing module, and an error retry mechanism module. Input the output of each module to the WebView layer and send it back to the application layer.

[0060] Automatic coordinate transformation is performed during the process of transmitting the output from the communication layer to the WebView layer;

[0061] The HTML page container in the S3 WebView layer receives and parses the input from the communication layer, then performs map operations and sends the results back to the communication layer. The communication layer processes the results and sends them back to the application layer, completing the bidirectional communication loop.

[0062] In a specific implementation, the coordinate system parameter identifiers in the application layer are as follows:

[0063] Coordinate system parameter identifiers are used to indicate whether a coordinate system transformation is required;

[0064] The application layer includes a parameter validation class, which sets a coordinate parameter receiving member. The coordinate parameter receiving member is used to receive the coordinate system parameters passed by the developer when calling the cross-platform Tianditu component. The coordinate system parameters are boolean type identifiers. After the coordinate parameter receiving member is validated by the parameter validation class, the coordinate system parameter identifiers are passed to the communication layer.

[0065] In a specific implementation, the operations in the message queue management module are as follows:

[0066] The message queue management module is used for independent processing and result matching of concurrent requests, and includes an identifier generation unit and a queue management unit;

[0067] 1) The identifier generation unit generates a unique identifier for each request in the input instruction. The identifier is generated by combining a millisecond-level timestamp with a random string. The identifier consists of a 13-bit millisecond-level timestamp and 30-bit random characters.

[0068] 2) The queue management unit stores the request message in the input instruction, and stores the generated unique identifier and the message object corresponding to the data in the input instruction into the reactive array queue, thus obtaining a reactive array queue storing message objects;

[0069] The message object, defined in the communication layer, is used to store and track complete information about requests in the message queue. It includes a type identifier member, a unique identifier member, parameter data members, and a result field member. The type identifier member records the operation type information, including map configuration operations, overlay operations, and service operations. The unique identifier member stores the request tracking identifier generated by the identifier generation interface, used for precise matching of requests and responses. The parameter data member stores the parameter information passed from the application layer. The result field member, initially empty, stores the execution result returned by the WebView layer, which includes a result type identifier and a return data payload.

[0070] The message queue management module includes a result update mechanism class, which comprises a polling detection member, a matching completion member, and a resource recycling member. When the communication layer receives a response message from the WebView layer, it performs a dual matching mechanism using the message object type and identifier. Specifically, the polling detection member continuously checks the status of the result field members of the message object. When it detects that a result field member has been updated from null to a response result object, it activates the success or failure callback of the asynchronous commitment mechanism through a callback trigger interface, passing the result data to the application layer. Then, the matching completion member uses the update status of the result field members to indicate that the request has been completed. The asynchronous call processing module determines the success or failure status of the operation based on the result type identifier value and executes the corresponding callback processing flow. Finally, after the result field members are updated and the callback is triggered, the resource recycling member removes the completed message object from the queue through the queue removal interface, releasing memory resources.

[0071] In a specific implementation, the operations in the data serialization module are as follows:

[0072] The data serialization module is used for conversion between JavaScript objects and JSON format strings, including serialization and deserialization units;

[0073] 1) The serialization processing unit receives the message object constructed by the message queue management module. The message object is in JavaScript object format and contains a type identifier field, a unique identifier field, and a parameter data field. The serialization processing unit also receives the coordinate system parameter identifier passed in by the application layer.

[0074] The serialization processing unit converts the JavaScript object into a JSON string, detects the coordinate system parameter identifier, sets a coordinate transformation flag in the message object to instruct the WebView layer to perform coordinate system transformation, and then serializes the message object into a JSON string and transmits it to the WebView layer through the cross-layer communication interface.

[0075] The data serialization module includes a coordinate transformation judgment class, which includes a parameter detection member and a flag setting member. The parameter detection member detects the value of the coordinate system parameter identifier. If the coordinate system parameter identifier is true, the flag setting member sets the coordinate transformation flag field in the message object to true. The coordinate transformation flag field is used to instruct the overlay rendering interface of the WebView layer to perform the transformation from the WGS84 coordinate system to the GCJ02 coordinate system.

[0076] 2) The deserialization processing unit receives a JSON format string returned by the WebView layer through the message sending interface. The JSON format string contains the execution result data. The deserialization processing unit restores the JSON format string into a JavaScript object and restores the string data into a structured object format through the JSON parsing mechanism, so that the communication layer can access and process the data content returned by the WebView layer. The data content includes a type identifier field, a unique identifier field, and a data payload field.

[0077] In a specific implementation, the operations in the asynchronous call processing module are as follows:

[0078] The asynchronous call processing module is used to avoid blocking the main thread and provide a unified asynchronous operation interface, including an asynchronous execution unit and a polling detection unit;

[0079] 1) The asynchronous execution unit is used to implement asynchronous non-blocking cross-layer communication. It receives the JSON format string message output by the data serialization module and the corresponding message object reference in the message queue. Then, it creates a commitment instance through the asynchronous commitment mechanism and immediately returns it to the application layer so that the main thread is not blocked. Finally, it obtains the cross-layer communication interface through the WebView container reference and sends the message to the WebView layer.

[0080] 2) The polling detection unit is used to detect whether the WebView layer has returned the execution result. It receives the result field member status of the message object in the message queue. The polling detection unit starts a timed polling mechanism at fixed time intervals to check the update status of the result field. After detecting that the result field has been updated, it triggers the success callback interface or failure callback interface of the asynchronous commitment mechanism according to the result type identifier value and passes the execution result object to the application layer.

[0081] In a specific implementation, the operations in the error retry mechanism module are as follows:

[0082] The error retry mechanism module is used to automatically retry requests when the network is unstable or there is a temporary failure, including a timeout detection unit and a retry control unit;

[0083] 1) The timeout detection unit is used to prevent memory leaks caused by infinite waiting. It receives the accumulated polling count from the polling detection interface and the preset timeout threshold parameter. It determines whether a timeout has occurred by accumulating the polling count and comparing it with the timeout threshold. If the polling count exceeds the preset threshold, the timer is cleared and a failure callback is triggered to return a timeout error message.

[0084] 2) The retry control unit is used to improve the success rate of requests through the retry mechanism. It receives the error type identifier, current retry count, and maximum retry count configuration returned by the asynchronous call processing module.

[0085] Based on the information returned by the WebView layer in the error events that occur during the map operation, the error event results are obtained, including the error type identifier and error description information. The two are encapsulated in the response message, and the response message is sent back to the communication layer through the message sending interface.

[0086] The retry control unit determines whether the retry conditions are met based on the error type identifier. If the current number of retries is less than the maximum number of retries and the error retry conditions are met, the request is resent. If the error retry conditions are not met, the request is resent. Error types include network errors, WebView exceptions, or temporary failures. If the current number of retries reaches or exceeds the maximum number of retries, the retry operation is stopped and the final failure result is returned to the application layer.

[0087] In a specific implementation, the specific operations during the data return process are as follows:

[0088] (1) The forward processing status feedback module is used to provide status feedback for request processing to the application layer, including a status data collection unit and a status transmission unit;

[0089] 1) The status data collection unit is used to summarize the status information of request processing, and collect the output status of four operations: message queue management, data serialization, asynchronous call processing and error retry mechanism. The output status includes response result object and queue management status, serialized string and coordinate transformation identifier, asynchronous commitment object, timeout error object or retry execution status.

[0090] 2) The state transmission unit is used to synchronize the processing state to the application layer. It transmits the output of the four operations through the internal state variables of the application layer and the reactive system to update the component state and trigger the view to re-render. The application layer determines whether the request has successfully entered the queue, whether the data has been correctly serialized, whether the asynchronous commitment has been created normally, and whether the error handling mechanism is working properly based on the returned state data.

[0091] (2) The WebView execution result processing module is used to provide the final execution result of map operations to the application layer, including a result receiving unit, a result processing unit and a result transmission unit;

[0092] 1) The result receiving unit is used to receive response messages from the WebView layer. The WebView layer sends result messages through the message sending interface, and the message listening and processing function of the communication layer receives the messages.

[0093] 2) The result processing unit is used to process and match the execution results. It extracts the type identifier and unique identifier from the message for queue matching. The message queue management locates the corresponding message in the queue based on the type identifier and unique identifier and updates the result field. The data field is parsed through the JSON parsing mechanism. The polling detection mechanism detects the update of the result field. The asynchronous call processing triggers the success or failure callback of the asynchronous commitment. The error retry mechanism decides whether to resend the request based on the retry conditions.

[0094] 3) The result transmission unit completes the entire data transmission chain from WebView to the developer application, transmitting data through the following paths:

[0095] The WebView layer sends result messages through a message sending interface;

[0096] The message receiving function in the communication layer receives messages;

[0097] The communication layer extracts type identifiers and unique identifiers from messages for queue matching.

[0098] The communication layer parses data fields using a JSON parsing mechanism;

[0099] The communication layer updates the result field of the message in the queue;

[0100] The polling detection mechanism detected an update in the result field;

[0101] The communication layer triggers a success or failure callback for the asynchronous commitment.

[0102] The communication layer calls the success or failure callback function passed from the application layer.

[0103] The application layer emits events to the developer's application through an event emission mechanism.

[0104] Example 2

[0105] A cross-platform Tianditu component bidirectional communication device based on message queue is used to execute a cross-platform Tianditu component bidirectional communication method based on message queue. It includes an application layer module, a communication layer module, and a WebView layer module. The modules work together to realize a bidirectional communication closed loop.

[0106] Application layer module: includes instruction standardization unit and coordinate parameter management unit;

[0107] The instruction standardization unit receives invocation instructions from developers and standardizes the method name, parameter objects, and callback functions.

[0108] The coordinate parameter management unit has a parameter verification class and a coordinate parameter receiving member. After verification, it generates a coordinate system parameter identifier. At the same time, it receives the processing status and results returned by the communication layer through internal state variables and a reactive system, updates the component status, and triggers view rendering.

[0109] Communication layer module: includes message queue management module, data serialization module, asynchronous call processing module, error retry mechanism module, positive processing status feedback module, and WebView execution result processing module;

[0110] The message queue management module includes an identifier generation unit, a queue management unit, and a result update mechanism class.

[0111] The data serialization module includes serialization and deserialization processing units and a coordinate transformation judgment class;

[0112] The asynchronous call processing module achieves non-blocking communication and result detection through asynchronous execution and polling detection units.

[0113] The error retry mechanism module handles timeouts and retries through timeout detection and a retry control unit;

[0114] The positive processing status feedback module collects and transmits the status of each operation;

[0115] The WebView execution result processing module receives, processes, and transmits the results.

[0116] WebView layer module: contains HTML page container unit and message sending interface unit. The HTML page container receives and parses the input from the communication layer, performs map operations, and the message sending interface sends the execution result back to the communication layer in JSON format string.

[0117] Example 3

[0118] The new communication mechanism of uni-app X is applied to a street light management system. This system needs to implement unified Tianditu functionality across Android, iOS, and HarmonyOS platforms, including street light location marking, inspection route planning, and real-time positioning. A cross-platform Tianditu component is used within the uni-app X framework, which involves the communication mechanism of this invention. The specific performance improvements achieved through the application of the methods described in this invention are as follows: (Details of performance improvements are provided in four aspects: message queue management mechanism, asynchronous call processing module, automatic coordinate system conversion, and error retry mechanism.)

[0119] The message queue management mechanism of this invention completely solves the message loss problem in high-concurrency scenarios through unique identifiers and dual matching mechanisms, as shown in Table 1;

[0120] Table 1. Effects of the Improved Message Queue Management Mechanism

[0121]

[0122] The asynchronous call processing module of the present invention avoids main thread blocking and significantly improves user experience, as shown in Table 2;

[0123] Table 2 Improvement in Asynchronous Call Processing

[0124]

[0125] Automatic conversion from WGS84 to GCJ02 coordinate system was achieved, as shown in Table 3;

[0126] Table 3. Accuracy of Automatic Coordinate System Transformation

[0127]

[0128] The error retry mechanism significantly improves system reliability, as shown in Table 4;

[0129] Table 4 Improvements to the Error Retry Mechanism

[0130]

[0131] In summary, the message queue management mechanism of this invention solves the problem of message loss in high concurrency through unique identifiers and a dual matching mechanism, achieving a 900% improvement in concurrent processing capability and a 99.9% reduction in message loss rate in actual tests. The asynchronous call processing mechanism avoids main thread blocking, and by providing a unified asynchronous operation interface, it improves UI smoothness by 97% and reduces ANR occurrence by 99.6% in actual tests. The automatic coordinate system conversion automatically identifies domestic and foreign coordinates and performs WGS84 to GCJ02 conversion, achieving a 99.99% accuracy rate and a conversion performance of 0.19ms / point in actual tests. The error retry mechanism intelligently judges the error type and automatically retryes, improving the success rate in weak network environments by 37.2% in actual tests, with an overall success rate of 99.7%.

[0132] Although the specific embodiments of the invention have been described above in conjunction with the accompanying drawings, this is not intended to limit the scope of protection of the invention. Based on the technical solutions of the invention, various modifications or variations that can be made by those skilled in the art without creative effort are still within the scope of protection of the invention.

Claims

1. A cross-platform Tianditu component bidirectional communication method based on message queues, wherein the encapsulation framework of the cross-platform Tianditu component includes an application layer, a communication layer, and a WebView layer, characterized in that... Includes the following steps: S1. The cross-platform Tianditu component receives the developer's call instructions. The application layer standardizes the instructions and defines coordinate system parameter identifiers. The coordinate system parameter identifiers are used to indicate whether coordinate system transformation is required. S2. Input the standardized instructions to the communication layer. The communication layer includes a message queue management module, a data serialization module, an asynchronous call processing module, and an error retry mechanism module. Input the output of each module to the WebView layer and send it back to the application layer. Automatic coordinate transformation is performed during the process of sending the output of the communication layer to the WebView layer. The message queue management module is used for independent processing and result matching of concurrent requests, including an identifier generation unit and a queue management unit. The identifier generation unit uses a combination of millisecond-level timestamps and random strings to generate a unique identifier for each request. The queue management unit stores the request messages into a reactive array queue. The message object contains a type identifier, a unique identifier, parameter data, and result field members. The data serialization module is used for conversion between JavaScript objects and JSON format strings, including serialization and deserialization units; The asynchronous call handling module is used to avoid blocking the main thread and provide a unified asynchronous operation interface, including an asynchronous execution unit and a polling detection unit. The asynchronous execution unit receives JSON messages and message object references, creates an instance through the asynchronous commitment mechanism and returns immediately to avoid blocking the main thread, and then sends the message to the WebView layer by obtaining the cross-layer communication interface through the WebView container reference. The polling detection unit is used to detect whether the WebView layer has returned the execution result. The error retry mechanism module is used to automatically retry requests when the network is unstable or there is a temporary failure. It includes a timeout detection unit and a retry control unit. The timeout detection unit is used to prevent memory leaks caused by infinite waiting. The retry control unit is used to improve the success rate of requests through the retry mechanism. The HTML page container in the S3 WebView layer parses the input from the communication layer and performs map operations. The execution result is then sent back to the communication layer, processed by the communication layer, and fed back to the application layer, completing the two-way communication loop.

2. The cross-platform bidirectional communication method for Tianditu components based on message queues according to claim 1, characterized in that, The coordinate system parameters in the application layer are identified as follows: The application layer sets up a parameter verification class and a coordinate parameter receiving member to receive the Boolean coordinate system parameters passed in by the developer. After verification, the coordinate system parameter identifier is passed to the communication layer.

3. The cross-platform bidirectional communication method for Tianditu components based on message queues according to claim 2, characterized in that: The message queue management module includes an identifier generation unit and a queue management unit; The message queue management module has a result update mechanism class, which includes members for polling detection, matching completion, and resource reclamation. After receiving the response message, the communication layer performs dual matching of message object type and identifier, polls to detect the status update of the result field, triggers an asynchronous commitment callback and passes the result, marks the completion of the request and executes the callback process, and finally removes the message object to release memory.

4. The cross-platform bidirectional communication method for Tianditu components based on message queues according to claim 3, characterized in that: The data serialization module includes a serialization processing unit and a deserialization processing unit; (1) The serialization processing unit receives the message object and coordinate system parameter identifier, converts it into a JSON string and sets a coordinate transformation flag. If the flag is true, it instructs the WebView layer to perform the WGS84 to GCJ02 coordinate system transformation and transmits it through the cross-layer communication interface. The message object is in JavaScript object format and contains a type identifier field, a unique identifier field, and parameter data fields; (2) The deserialization processing unit receives the JSON string returned by the WebView layer and restores it into a structured JavaScript object, which includes type identifier, unique identifier and data payload field.

5. The cross-platform bidirectional communication method for Tianditu components based on message queues according to claim 4, characterized in that: The asynchronous call processing module includes an asynchronous execution unit and a polling detection unit; The polling detection unit receives the status of the result field members of the message object in the message queue. The polling detection unit starts a timed polling mechanism at fixed time intervals to check the update status of the result field. After detecting an update of the result field, it triggers the success callback interface or failure callback interface of the asynchronous commitment mechanism according to the result type identifier value, and passes the execution result object to the application layer.

6. The cross-platform bidirectional communication method for Tianditu components based on message queues according to claim 5, characterized in that: The error retry mechanism module includes a timeout detection unit and a retry control unit; (1) The timeout detection unit receives the cumulative polling count from the polling detection interface and the preset timeout threshold parameter. It determines whether a timeout has occurred by accumulating the polling count and comparing it with the timeout threshold. If the polling count exceeds the preset threshold, the timer is cleared and a failure callback is triggered to return a timeout error message. (2) The retry control unit receives the error type identifier, current retry count, and maximum retry count configuration returned by the asynchronous call processing module; Based on the information returned by the WebView layer in the error events that occur during the map operation, the error event results are obtained, including the error type identifier and error description information. The two are encapsulated in the response message, and the response message is sent back to the communication layer through the message sending interface. The retry control unit determines whether the retry conditions are met based on the error type identifier. If the current number of retries is less than the maximum number of retries and the error retry conditions are met, the request is resent. If the error retry conditions are not met, the request is resent. Error types include network errors, WebView exceptions, or temporary failures. If the current number of retries reaches or exceeds the maximum number of retries, the retry operation will be stopped and the final failure result will be returned to the application layer.

7. The cross-platform bidirectional communication method for Tianditu components based on message queues according to claim 6, characterized in that, The specific operations during the return process are as follows: (1) The forward processing status feedback module is used to provide status feedback for request processing to the application layer, including a status data collection unit and a status transmission unit; 1) The status data collection unit is used to summarize the status information of request processing, and collect the output status of four operations: message queue management, data serialization, asynchronous call processing and error retry mechanism. The output status includes response result object and queue management status, serialized string and coordinate transformation identifier, asynchronous commitment object, timeout error object or retry execution status. 2) The state transmission unit is used to synchronize the processing state to the application layer. It transmits the output of the four operations through the internal state variables of the application layer and the reactive system to update the component state and trigger the view to re-render. The application layer determines whether the request has successfully entered the queue, whether the data has been correctly serialized, whether the asynchronous commitment has been created normally, and whether the error handling mechanism is working properly based on the returned state data. (2) The WebView execution result processing module is used to provide the final execution result of map operations to the application layer, including a result receiving unit, a result processing unit and a result transmission unit; 1) The result receiving unit is used to receive response messages from the WebView layer. The WebView layer sends result messages through the message sending interface, and the message listening and processing function of the communication layer receives the messages. 2) The result processing unit is used to process and match the execution results. It extracts the type identifier and unique identifier from the message for queue matching. The message queue management locates the corresponding message in the queue based on the type identifier and unique identifier and updates the result field. The data field is parsed through the JSON parsing mechanism. The polling detection mechanism detects the update of the result field. The asynchronous call processing triggers the success or failure callback of the asynchronous commitment. The error retry mechanism decides whether to resend the request based on the retry conditions. 3) The result transmission unit completes the entire data transmission link from WebView to the developer application according to the transmission path.

8. A cross-platform bidirectional communication device for Tianditu components based on message queues, used to execute the cross-platform bidirectional communication method for Tianditu components based on message queues as described in any one of claims 1 to 7, characterized in that: It includes an application layer module, a communication layer module, and a WebView layer module, and these modules work together to achieve a two-way communication closed loop; Application layer module: includes instruction standardization unit and coordinate parameter management unit; The instruction standardization unit receives invocation instructions from developers and standardizes the method name, parameter objects, and callback functions. The coordinate parameter management unit has a parameter verification class and a coordinate parameter receiving member. After verification, it generates a coordinate system parameter identifier. At the same time, it receives the processing status and results returned by the communication layer through internal state variables and a reactive system, updates the component status, and triggers view rendering. Communication layer module: includes message queue management module, data serialization module, asynchronous call processing module, error retry mechanism module, positive processing status feedback module, and WebView execution result processing module; The message queue management module includes an identifier generation unit and a queue management unit; The data serialization module includes a serialization processing unit and a deserialization processing unit; The asynchronous call processing module includes an asynchronous execution unit and a polling detection unit; The error retry mechanism module includes a timeout detection unit and a retry control unit; The positive feedback processing module collects and transmits the outputs of each module; The WebView execution result processing module receives, processes, and transmits the results. WebView layer module: contains HTML page container unit and message sending interface unit. The HTML page container receives and parses the input from the communication layer, performs map operations, and the message sending interface sends the execution result back to the communication layer in JSON format string.

Citation Information

Patent Citations

  • Cross-platform sky map component packaging method and device based on unit-app X framework

    CN121349523A