Skip to content

Commit 189ec31

Browse files
committed
feat(harmony): add network configuration and resource management features
Major changes: - Network: Add NetworkConfiguration for custom HTTP headers - Network: Add ResourceTransform for URL interception and transformation - Network: Implement C++ NAPI bindings (network_napi, url_transform_napi) - Network: Implement backend support (HTTPRequestConfig, URLTransformManager) - Style: Improve addImage/addImages implementation with Image NAPI wrapper - Style: Add async image loading APIs (addImageAsync, addImagesAsync) - Style: Export image APIs through FileSource.setResourceTransform() - Types: Refactor GeoJSON types to re-export from libmaplibre.so - Types: Fix JSONValue usage across Feature and FeatureCollection - Types: Simplify Light type to alias LightSpecification - Docs: Update README with alpha version warnings and disclaimers - Docs: Add comprehensive API documentation for network features - Docs: Document resource transform callback usage - Build: Add Hvigor plugin for bytecode HAR version management - Build: Export plugin utilities for ABC version handling API additions: - NetworkConfiguration.setCustomHttpHeaders() - NetworkConfiguration.addCustomHttpHeader() - ResourceTransform.setCallback() - Style.addImageAsync() - Style.addImagesAsync() Breaking changes: None (all additions are backward compatible) Refs: Network configuration follows Android HttpRequestUtil and iOS MLNNetworkConfiguration patterns
1 parent 4914807 commit 189ec31

51 files changed

Lines changed: 3236 additions & 656 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

platform/harmony/maplibre_harmony/README.md

Lines changed: 62 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,33 @@
11
# MapLibre Native for HarmonyOS
22

3+
![Development Status](https://img.shields.io/badge/Status-Alpha%20%2F%20Unstable-red)
4+
![Production Ready](https://img.shields.io/badge/Production%20Ready-No-red)
5+
![API Stability](https://img.shields.io/badge/API%20Stability-Unstable-orange)
6+
37
OpenGL-based vector map rendering library for HarmonyOS.
48

9+
> ⚠️ **IMPORTANT: Development Status - Alpha/Unstable**
10+
>
11+
> This project is currently under **active development** and is **NOT production-ready**.
12+
>
13+
> **Current Status**:
14+
> - 🚧 **Stability**: Alpha stage - expect bugs, crashes, and memory leaks
15+
> - 🔄 **API Changes**: Breaking changes WILL occur without notice
16+
> - 🧪 **Testing**: Limited testing coverage, many edge cases untested
17+
> - 📝 **Documentation**: Work in progress, incomplete
18+
> -**Performance**: Not optimized for production workloads
19+
> - 🔒 **Security**: Security review not yet performed
20+
>
21+
> **⛔ NOT RECOMMENDED for production applications**
22+
>
23+
> **Use at your own risk** - This software is provided "AS IS" without warranty of any kind.
24+
> Only suitable for:
25+
> - 🧪 Experimental projects
26+
> - 📚 Learning and research
27+
> - 🔬 Early testing and feedback
28+
>
29+
> If you need production-ready map solutions, please use the mature Android or iOS platforms.
30+
531
## Features
632

733
- 🗺️ Vector map rendering using OpenGL ES
@@ -213,6 +239,8 @@ Map updates and triggers render
213239

214240
## Installation
215241

242+
> ⚠️ **Warning**: This library is in **alpha stage**. Please evaluate thoroughly before using in any application.
243+
216244
### Prerequisites
217245

218246
- **HarmonyOS SDK**: 5.0.0 (API 12) or higher
@@ -221,7 +249,7 @@ Map updates and triggers render
221249

222250
### From npm registry
223251

224-
> ohpm registry not support.
252+
> ⚠️ **Note**: This package is not yet published to npm/ohpm registry. Currently for development and testing only.
225253
226254
```bash
227255
npm install maplibre-harmony
@@ -239,6 +267,8 @@ Add to your module's `oh-package.json5`:
239267

240268
## Usage
241269

270+
> ⚠️ **Alpha Software Notice**: The following APIs are subject to change. Always check the latest documentation before upgrading.
271+
242272
### Basic Map
243273

244274
```typescript
@@ -427,20 +457,31 @@ build/default/outputs/default/maplibre-harmony.har
427457

428458
## Troubleshooting
429459

460+
> ⚠️ **Known Issues**: This is alpha software. Many edge cases and stability issues are still being addressed.
461+
430462
### Map not rendering
431463
1. Verify OpenGL ES 3.0 support
432464
2. Check style URL accessibility
433465
3. Inspect HiLog: `hdc hilog | grep MapLibre`
466+
4. **Known Issue**: Map may crash on repeated page transitions (being fixed)
434467

435468
### Build errors
436469
1. Clean build cache: `npm run clean`
437470
2. Verify environment variables are set
438471
3. Check HarmonyOS SDK version (≥5.0.0)
472+
4. **Known Issue**: Incremental builds may fail, try clean build
439473

440474
### Gesture issues
441475
1. Ensure proper DPI configuration
442476
2. Check XComponent touch event handling
443477
3. Verify gesture settings are enabled
478+
4. **Known Issue**: Some gesture combinations may not work as expected
479+
480+
### Stability issues
481+
1. **Memory leaks**: May occur in long-running applications
482+
2. **Thread safety**: Some race conditions still being addressed
483+
3. **Crash recovery**: Limited error recovery mechanisms
484+
4. **Performance**: Not optimized for production workloads
444485

445486
## Documentation
446487

@@ -465,13 +506,22 @@ See the [`entry`](../entry/) module for complete working examples:
465506

466507
We welcome contributions! Please see the main repository's [CONTRIBUTING.md](../../../CONTRIBUTING.md) for guidelines.
467508

509+
> 🙏 **Help Wanted**: This project is in early development. Contributions for bug fixes, testing, and documentation are especially appreciated!
510+
468511
### Development Setup
469512

470513
1. Clone the repository
471514
2. Set up environment variables
472515
3. Build the project: `npm run build:debug`
473516
4. Run tests in DevEco Studio
474517

518+
### Known Development Issues
519+
520+
- Build system may require clean builds frequently
521+
- Some test cases are still being developed
522+
- Documentation is incomplete
523+
- Performance profiling not yet complete
524+
475525
## License
476526

477527
BSD-2-Clause License - See [LICENSE.md](../../../LICENSE.md)
@@ -486,11 +536,19 @@ BSD-2-Clause License - See [LICENSE.md](../../../LICENSE.md)
486536

487537
## Support
488538

489-
- **Documentation**: See `/docs` directory
539+
- **Documentation**: See `/docs` directory (⚠️ incomplete)
490540
- **Issues**: Report bugs on GitHub Issues
491541
- **Discussions**: Join MapLibre community discussions
492-
- **Commercial Support**: Contact MapLibre team
542+
- **Commercial Support**: ⚠️ Not available for HarmonyOS platform yet
543+
544+
## Disclaimer
545+
546+
**THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND.**
547+
548+
This is experimental software under active development. It may contain bugs, security vulnerabilities, and performance issues. The maintainers are not responsible for any damages or issues arising from the use of this software.
549+
550+
**Use in production environments is strongly discouraged at this stage.**
493551

494552
---
495553

496-
Made with ❤️ by the MapLibre community
554+
Made with ❤️ by the MapLibre community (HarmonyOS port in alpha)

platform/harmony/maplibre_harmony/index.ets

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,4 +59,9 @@ export type {
5959
CameraOptionsLiteral
6060
} from './src/main/ets/maps/types/NativeTypes';
6161

62+
// ========== 声明式组件 (Declarative API) ==========
63+
// 由于 ArkTS 限制(属性名冲突、不支持 @Watch 等),声明式 API 暂时不可用
64+
// 请使用命令式 API(MapLibreMap.addMarker, Style.addLayer 等)
65+
// 参考文档: docs/DECLARATIVE_API_LIMITATIONS.md
66+
6267

platform/harmony/maplibre_harmony/src/main/cpp/CMakeLists.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,11 +137,19 @@ add_library(maplibre
137137
napi/bindings/style/style_napi_images.cpp
138138
napi/bindings/style/custom_layer_napi.hpp
139139
napi/bindings/style/custom_layer_napi.cpp
140+
napi/bindings/network/network_napi.hpp
141+
napi/bindings/network/network_napi.cpp
142+
napi/bindings/network/url_transform_napi.hpp
143+
napi/bindings/network/url_transform_napi.cpp
140144

141145
# Network module
142146
network/http_file_source_harmony.cpp
143147
network/curl_event_loop.hpp
144148
network/curl_event_loop.cpp
149+
network/http_request_config.hpp
150+
network/http_request_config.cpp
151+
network/url_transform_manager.hpp
152+
network/url_transform_manager.cpp
145153

146154
# VSync management
147155
vsync/harmony_vsync_manager.hpp

platform/harmony/maplibre_harmony/src/main/cpp/core/native_map_view/native_map_view_style.cpp

Lines changed: 97 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include "native_map_view_harmony.hpp"
22
#include "rendering/harmony_renderer.hpp"
33
#include "napi/bindings/style/style_napi.hpp"
4+
#include "napi/bindings/image/image_napi.hpp"
45
#include "napi/core/napi_args.hpp"
56
#include "utils/logger.h"
67
#include "style/transition_options_harmony.hpp"
@@ -16,6 +17,7 @@
1617

1718
using mbgl::harmony::Logger;
1819
using mbgl::harmony::napi::NapiArgs;
20+
using maplibre::harmony::ImageNAPI;
1921

2022
namespace mbgl {
2123
namespace harmony {
@@ -692,25 +694,112 @@ napi_value NativeMapView::removeSource(napi_env env, napi_callback_info info) {
692694
}
693695

694696
napi_value NativeMapView::addImage(napi_env env, napi_callback_info info) {
697+
NapiArgs args(env, info);
698+
args.RequireMinArgs(4);
699+
695700
napi_value undefined;
696701
napi_get_undefined(env, &undefined);
697702

698-
// TODO: 需要实现 Bitmap 的 NAPI 包装类
699-
// 参考 Android: platform/android/MapLibreAndroid/src/cpp/bitmap.cpp
700-
Logger::warn("NativeMapView", "addImage: Not implemented - requires Bitmap wrapper class");
703+
if (args.HasError()) {
704+
Logger::error("NativeMapView", "addImage: Invalid arguments");
705+
return undefined;
706+
}
701707

702-
return undefined;
708+
// 获取 NativeMapView 实例
709+
NativeMapView* instance = nullptr;
710+
if (napi_unwrap(env, args.This(), reinterpret_cast<void**>(&instance)) != napi_ok || !instance->map) {
711+
Logger::error("NativeMapView", "addImage: Map not initialized");
712+
return undefined;
713+
}
714+
715+
try {
716+
// TODO: 实现从 PixelMap 创建图像
717+
// 参考 Android bitmap.cpp 和 iOS UIImage+MLNAdditions.mm
718+
// 需要实现 PixelMap -> PremultipliedImage 的转换
719+
Logger::warn("NativeMapView", "addImage: PixelMap conversion not implemented yet");
720+
Logger::info("NativeMapView", "addImage: Please use Image class or Style.addImage() instead");
721+
722+
return undefined;
723+
} catch (const std::exception& e) {
724+
Logger::error("NativeMapView", "addImage: Failed - %s", e.what());
725+
return undefined;
726+
}
703727
}
704728

705729
napi_value NativeMapView::addImages(napi_env env, napi_callback_info info) {
730+
NapiArgs args(env, info);
731+
args.RequireMinArgs(1);
732+
706733
napi_value undefined;
707734
napi_get_undefined(env, &undefined);
708735

709-
// TODO: 需要实现 Image 的 NAPI 包装类
710-
// 参考 Android: platform/android/MapLibreAndroid/src/cpp/map/image.cpp
711-
Logger::warn("NativeMapView", "addImages: Not implemented - requires Image wrapper class");
736+
if (args.HasError()) {
737+
Logger::error("NativeMapView", "addImages: Invalid arguments");
738+
return undefined;
739+
}
712740

713-
return undefined;
741+
// 获取 NativeMapView 实例
742+
NativeMapView* instance = nullptr;
743+
if (napi_unwrap(env, args.This(), reinterpret_cast<void**>(&instance)) != napi_ok || !instance->map) {
744+
Logger::error("NativeMapView", "addImages: Map not initialized");
745+
return undefined;
746+
}
747+
748+
try {
749+
// 获取 Image 数组参数
750+
napi_value imagesArray = args.GetValue(0);
751+
bool isArray = false;
752+
napi_is_array(env, imagesArray, &isArray);
753+
754+
if (!isArray) {
755+
Logger::error("NativeMapView", "addImages: First argument must be an array");
756+
return undefined;
757+
}
758+
759+
uint32_t length = 0;
760+
napi_get_array_length(env, imagesArray, &length);
761+
762+
if (length == 0) {
763+
Logger::warn("NativeMapView", "addImages: Empty array provided");
764+
return undefined;
765+
}
766+
767+
// 遍历数组,逐个添加图像
768+
for (uint32_t i = 0; i < length; i++) {
769+
napi_value imageValue;
770+
napi_get_element(env, imagesArray, i, &imageValue);
771+
772+
// Unwrap Image NAPI object
773+
ImageNAPI* imageNapi = ImageNAPI::Unwrap(env, imageValue);
774+
if (!imageNapi) {
775+
Logger::error("NativeMapView", "addImages: Failed to unwrap Image at index %u", i);
776+
continue;
777+
}
778+
779+
// Convert to mbgl::style::Image
780+
auto styleImage = imageNapi->toStyleImage();
781+
if (!styleImage) {
782+
Logger::error("NativeMapView", "addImages: Failed to convert Image to style::Image at index %u", i);
783+
continue;
784+
}
785+
786+
// Add to style
787+
std::string imageName = imageNapi->getName();
788+
instance->invokeOnMapThread([styleImagePtr = styleImage.release()](mbgl::Map* m) {
789+
std::unique_ptr<mbgl::style::Image> img(styleImagePtr);
790+
m->getStyle().addImage(std::move(img));
791+
});
792+
793+
Logger::info("NativeMapView", "addImages: Added image '%s'", imageName.c_str());
794+
}
795+
796+
Logger::info("NativeMapView", "addImages: Successfully added %u images", length);
797+
return undefined;
798+
799+
} catch (const std::exception& e) {
800+
Logger::error("NativeMapView", "addImages: Failed - %s", e.what());
801+
return undefined;
802+
}
714803
}
715804

716805
napi_value NativeMapView::removeImage(napi_env env, napi_callback_info info) {

0 commit comments

Comments
 (0)