Skip to content

Commit 4e667b7

Browse files
committed
test(harmony): enhance test pages and add image examples
Update test pages for new network features: - Enhance CustomHttpRequestTestPage with NetworkConfiguration UI - Add interactive header management (add/edit/remove/toggle) - Add request monitoring with ResourceTransform - Display request logs with resource types and timestamps - Test header configuration by triggering map style loads - Enhance UrlTransformTestPage with comprehensive test cases - Add CDN switching demo - Add offline resource mapping - Add authentication token injection - Add URL filtering and logging - Real-time request monitoring and statistics Add new image handling examples: - Add ImageMissingExample demonstrating lazy image loading - Implement OnStyleImageMissingListener - Dynamic image loading on demand - POI marker examples with missing image handling - Add StretchableImageExample for 9-patch style images - Demonstrate stretchX/stretchY configuration - Show content area definition - Chat bubble style UI examples Update existing test pages: - Update imports to use new APIs (NetworkConfiguration, ResourceTransform) - Fix GeoJSON type usage across test pages - Improve MapSnapshotter test cases - Add better error handling and user feedback Files changed: 28 files (+1956, -534 lines)
1 parent 189ec31 commit 4e667b7

28 files changed

Lines changed: 1956 additions & 534 deletions

platform/harmony/entry/src/main/ets/pages/Index.ets

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,10 @@ struct Index {
9797
// ==================== 12. Storage ====================
9898
this.createStorageGroup(),
9999

100-
// ==================== 13. Events ====================
100+
// ==================== 13. Network Configuration ====================
101+
this.createNetworkGroup(),
102+
103+
// ==================== 14. Events ====================
101104
this.createEventsGroup(),
102105

103106
// ==================== 14. Image Generator ====================
@@ -327,8 +330,17 @@ struct Index {
327330
]);
328331
}
329332

333+
// /**
334+
// * 13. Network Configuration - 网络配置
335+
// */
336+
// private createNetworkGroup(): TestPageGroup {
337+
// return new TestPageGroup('Network', '🌐', [
338+
// new TestPageItem('Custom HTTP Headers', '自定义HTTP请求头', 'pages/NetworkConfigTestPage', '📡'),
339+
// ]);
340+
// }
341+
330342
/**
331-
* 13. Events - 事件监听
343+
* 14. Events - 事件监听
332344
*/
333345
private createEventsGroup(): TestPageGroup {
334346
return new TestPageGroup('Events', '📡', [

platform/harmony/entry/src/main/ets/pages/basic/LocalGlyphTestPage.ets

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { showToast, DEFAULT_STYLE_URLS, TEST_LOCATIONS , DEFAULT_MAP_CONFIG } fr
1111
import { image } from '@kit.ImageKit';
1212
import { resourceManager } from '@kit.LocalizationKit';
1313

14+
import type { JSONValue } from 'libmaplibre.so';
1415
class LanguageText {
1516
language: string = '';
1617
text: string = '';
@@ -245,7 +246,7 @@ struct LocalGlyphTestPage {
245246

246247
// 3. 创建 GeoJSON 数据
247248
const features = multiLanguageTexts.map(item => {
248-
const props: Record<string, Object> = {
249+
const props: Record<string, JSONValue> = {
249250
'text': item.text,
250251
'language': item.language,
251252
'color': item.color

platform/harmony/entry/src/main/ets/pages/basic/SimpleMapTestPage.ets

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*/
77

88
import { TestPageLayout } from '../common/TestPageLayout';
9-
import { MapView, MapLibreMap, CameraPosition, LatLng } from 'maplibre_harmony';
9+
import { MapView, MapLibreMap, LatLng } from 'maplibre_harmony';
1010
import { showToast, DEFAULT_STYLE_URLS, DEFAULT_MAP_CONFIG } from '../common/TestUtils';
1111

1212
@Entry

platform/harmony/entry/src/main/ets/pages/feature/QueryRenderedFeaturesPropertiesTestPage.ets

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { MapLibreMap, MapView, OnMapClickListener, ScreenPoint } from 'maplibre_
66
*/
77
import { TestPageLayout } from '../common/TestPageLayout';
88
import { DEFAULT_STYLE_URLS, showToast , DEFAULT_MAP_CONFIG } from '../common/TestUtils';
9+
import type { JSONValue } from 'libmaplibre.so';
910

1011
@Entry
1112
@Component
@@ -96,7 +97,7 @@ struct QueryRenderedFeaturesPropertiesTestPage {
9697

9798
if (features.length > 0) {
9899
const feature = features[0];
99-
const props: Record<string, Object> = feature.properties || {};
100+
const props: Record<string, JSONValue> = feature.properties || {};
100101
const propStr = JSON.stringify(props, null, 2);
101102
const layerName: string = feature.layer || '未知';
102103
this.featureInfo = `类型: ${feature.type}\n图层: ${layerName}\n属性:\n${propStr}`;

platform/harmony/entry/src/main/ets/pages/feature/QuerySourceFeaturesTestPage.ets

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { GeoJson, GeoJsonSource, LatLng, MapLibreMap, MapView, ScreenPoint, Circ
88
import { DEFAULT_STYLE_URLS, showToast , DEFAULT_MAP_CONFIG } from '../common/TestUtils';
99
import type { JsonObject } from '../../types/EntryTypes';
1010
import type { IFeature } from 'maplibre_harmony/src/main/ets/maps/geojson/types';
11+
import type { JSONValue } from 'libmaplibre.so';
1112

1213
@Entry
1314
@Component
@@ -48,10 +49,10 @@ struct QuerySourceFeaturesTestPage {
4849

4950
private addTestSource(map: MapLibreMap): void {
5051
// 添加测试 GeoJSON 数据源,包含多个测试点
51-
const props1: Record<string, Object> = { 'name': '北京', 'type': 'city', 'population': 21540000 };
52-
const props2: Record<string, Object> = { 'name': '天津', 'type': 'city', 'population': 13870000 };
53-
const props3: Record<string, Object> = { 'name': '石家庄', 'type': 'city', 'population': 11040000 };
54-
const props4: Record<string, Object> = { 'name': '太原', 'type': 'city', 'population': 5300000 };
52+
const props1: Record<string, JSONValue> = { 'name': '北京', 'type': 'city', 'population': 21540000 };
53+
const props2: Record<string, JSONValue> = { 'name': '天津', 'type': 'city', 'population': 13870000 };
54+
const props3: Record<string, JSONValue> = { 'name': '石家庄', 'type': 'city', 'population': 11040000 };
55+
const props4: Record<string, JSONValue> = { 'name': '太原', 'type': 'city', 'population': 5300000 };
5556

5657
const geojsonData = GeoJson.featureCollection([
5758
GeoJson.pointFeature([116.4074, 39.9042], props1),

platform/harmony/entry/src/main/ets/pages/snapshot/MapSnapshotterBitmapOverlayTestPage.ets

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,9 @@ struct MapSnapshotterBitmapOverlayTestPage {
5656
const latLng = this.mapController?.getLatLng() || LatLng.create(39.9042, 116.4074);
5757
const zoom = this.mapController?.getZoom() || 12;
5858

59-
const cameraPosition = CameraPosition.create(latLng, zoom, 0, 0);
59+
const cameraPosition: CameraPosition = {
60+
target: latLng, zoom, bearing: 0, tilt: 0
61+
};
6062

6163
const options: SnapshotOptions = {
6264
size: { width: 800, height: 600 },

platform/harmony/entry/src/main/ets/pages/snapshot/MapSnapshotterHeatMapTestPage.ets

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
*/
99

1010
import { TestPageLayout } from '../common/TestPageLayout';
11+
import type { JSONValue } from 'libmaplibre.so';
1112
import {
1213
NativeMapView,
1314
MapLibreMap,
@@ -53,7 +54,7 @@ struct MapSnapshotterHeatMapTestPage {
5354
private generateHeatmapData(): IFeatureCollection {
5455
const features: IFeature[] = [];
5556
for (let i = 0; i < 100; i++) {
56-
const props: Record<string, Object> = {
57+
const props: Record<string, JSONValue> = {
5758
'intensity': Math.random()
5859
};
5960
features.push(GeoJson.pointFeature(
@@ -98,12 +99,12 @@ struct MapSnapshotterHeatMapTestPage {
9899
this.isGenerating = true;
99100

100101
try {
101-
const cameraPosition = CameraPosition.create(
102-
LatLng.create(35, 105),
103-
4,
104-
0,
105-
0
106-
);
102+
const cameraPosition: CameraPosition = {
103+
target: LatLng.create(35, 105),
104+
zoom: 4,
105+
bearing: 0,
106+
tilt: 0
107+
}
107108

108109
// 注意:MapSnapshotter需要自己配置样式和图层
109110
// 这里使用当前地图的样式JSON

platform/harmony/entry/src/main/ets/pages/snapshot/MapSnapshotterLocalStyleTestPage.ets

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,9 @@ struct MapSnapshotterLocalStyleTestPage {
8787

8888
this.mapController?.setStyleJson(this.styleJson);
8989
showToast('本地样式已加载');
90-
} catch (error) {
91-
showToast(`加载样式失败: ${error}`);
90+
} catch (e) {
91+
const error = e as Error;
92+
showToast(`加载样式失败: ${error.message || String(e)}`);
9293
}
9394
};
9495

@@ -104,12 +105,12 @@ struct MapSnapshotterLocalStyleTestPage {
104105
this.isGenerating = true;
105106

106107
try {
107-
const cameraPosition = CameraPosition.create(
108-
LatLng.create(30, 120),
109-
5,
110-
0,
111-
0
112-
);
108+
const cameraPosition: CameraPosition = {
109+
target: new LatLng(30, 120),
110+
zoom: 5,
111+
bearing: 0,
112+
tilt: 0
113+
};
113114

114115
const options: SnapshotOptions = {
115116
size: { width: 800, height: 600 },
@@ -123,9 +124,10 @@ struct MapSnapshotterLocalStyleTestPage {
123124
const snapshotter = new MapSnapshotter(options);
124125

125126
snapshotter.start(new ReadyCallback(this, snapshotter) , new ErrorCallback(this) );
126-
} catch (error) {
127+
} catch (e) {
128+
const error = e as Error;
127129
this.isGenerating = false;
128-
showToast(`生成失败: ${error}`);
130+
showToast(`生成失败: ${error.message || String(e)}`);
129131
}
130132
};
131133

0 commit comments

Comments
 (0)