├── .gitignore ├── README.md ├── angular.json ├── browserslist ├── capacitor.config.json ├── demo ├── mobile.gif └── web.gif ├── e2e ├── protractor.conf.js ├── src │ ├── app.e2e-spec.ts │ └── app.po.ts └── tsconfig.json ├── ionic.config.json ├── karma.conf.js ├── master ├── package-lock.json ├── package.json ├── src ├── app │ ├── app-routing.module.ts │ ├── app.component.html │ ├── app.component.scss │ ├── app.component.spec.ts │ ├── app.component.ts │ ├── app.module.ts │ └── home │ │ ├── home.module.ts │ │ ├── home.page.html │ │ ├── home.page.scss │ │ ├── home.page.spec.ts │ │ └── home.page.ts ├── assets │ ├── icon │ │ └── favicon.png │ └── shapes.svg ├── environments │ ├── environment.prod.ts │ └── environment.ts ├── global.scss ├── index.html ├── main.ts ├── polyfills.ts ├── test.ts ├── theme │ └── variables.scss └── zone-flags.ts ├── tsconfig.app.json ├── tsconfig.json ├── tsconfig.spec.json └── tslint.json /.gitignore: -------------------------------------------------------------------------------- 1 | # Specifies intentionally untracked files to ignore when using Git 2 | # http://git-scm.com/docs/gitignore 3 | 4 | *~ 5 | *.sw[mnpcod] 6 | .tmp 7 | *.tmp 8 | *.tmp.* 9 | *.sublime-project 10 | *.sublime-workspace 11 | .DS_Store 12 | Thumbs.db 13 | UserInterfaceState.xcuserstate 14 | $RECYCLE.BIN/ 15 | 16 | *.log 17 | log.txt 18 | npm-debug.log* 19 | 20 | /.idea 21 | /.ionic 22 | /.sass-cache 23 | /.sourcemaps 24 | /.versions 25 | /.vscode 26 | /coverage 27 | /dist 28 | /node_modules 29 | /platforms 30 | /plugins 31 | /www 32 | 33 | # NPM renames .gitignore to .npmignore 34 | # In order to prevent that, we remove the initial "." 35 | # And the CLI then renames it 36 | 37 | # Using Android gitignore template: https://github.com/github/gitignore/blob/master/Android.gitignore 38 | 39 | # Built application files 40 | *.ap_ 41 | *.aab 42 | *.apk 43 | 44 | # Files for the ART/Dalvik VM 45 | *.dex 46 | 47 | # Java class files 48 | *.class 49 | 50 | # Generated files 51 | /android/bin/ 52 | /android/gen/ 53 | /android/out/ 54 | /android/release/ 55 | 56 | # Gradle files 57 | /android/.gradle/ 58 | /android/build/ 59 | 60 | # Local configuration file (sdk path, etc) 61 | /android/local.properties 62 | 63 | # Proguard folder generated by Eclipse 64 | /android/proguard/ 65 | 66 | # Log Files 67 | *.log 68 | 69 | # Android Studio Navigation editor temp files 70 | /android/.navigation/ 71 | 72 | # Android Studio captures folder 73 | /android/captures/ 74 | 75 | # IntelliJ 76 | *.iml 77 | /android/.idea/workspace.xml 78 | /android/.idea/tasks.xml 79 | /android/.idea/gradle.xml 80 | /android/.idea/assetWizardSettings.xml 81 | /android/.idea/dictionaries 82 | /android/.idea/libraries 83 | # Android Studio 3 in .gitignore file. 84 | /android/.idea/caches 85 | /android/.idea/modules.xml 86 | # Comment next line if keeping position of elements in Navigation Editor is relevant for you 87 | /android/.idea/navEditor.xml 88 | 89 | # Keystore files 90 | # Uncomment the following lines if you do not want to check your keystore files in. 91 | #*.jks 92 | #*.keystore 93 | 94 | # External native build folder generated in Android Studio 2.2 and later 95 | /android/.externalNativeBuild 96 | 97 | # Freeline 98 | /android/freeline.py 99 | /android/freeline/ 100 | /android/freeline_project_description.json 101 | 102 | # fastlane 103 | /android/fastlane/report.xml 104 | /android/fastlane/Preview.html 105 | /android/fastlane/screenshots 106 | /android/fastlane/test_output 107 | /android/fastlane/readme.md 108 | 109 | # Version control 110 | /android/vcs.xml 111 | 112 | # lint 113 | /android/lint/intermediates/ 114 | /android/lint/generated/ 115 | /android/lint/outputs/ 116 | /android/lint/tmp/ 117 | # lint/reports/ 118 | 119 | # Cordova plugins for Capacitor 120 | /android/capacitor-cordova-android-plugins 121 | 122 | # Copied web assets 123 | /android/app/src/main/assets/public -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Ionic HMS Map Demo 2 | An Ionic sample integrated with HMS Map Kit JavaScript Api. 3 | 4 |  5 | 6 | ## Running the application 7 | 8 | ### Adding HMS API Key 9 | 10 | 1. Copy your API Key from following section 11 | 12 | ```sh 13 | AppGallery Connect > Your App > Develop > Overview > App Information > API key 14 | ``` 15 | 16 | 2. Open src/index.html 17 | 18 | 3. Modify loadMapScript() function and paste your API Key here 19 | 20 | ```js 21 | const apiKey = encodeURIComponent("YOUR_API_KEY"); 22 | const src = `https://mapapi.cloud.huawei.com/mapjs/v1/api/js?callback=initMap&key=${apiKey}`; 23 | 24 | const mapScript = document.createElement('script'); 25 | mapScript.setAttribute('src', src); 26 | document.head.appendChild(mapScript); 27 | ``` 28 | 29 | ### Run Locally in a Web Browser 30 | 31 | 1. Add your HMS API Key 32 | 33 | 2. Install dependencies 34 | 35 | ```sh 36 | cd ionic-hms-map-demo 37 | npm install 38 | ``` 39 | 40 | 3. Run following command and you can visit http://localhost:8100/ in your web browser to see the app in action 41 | 42 | ```sh 43 | ionic serve 44 | ``` 45 | 46 | ### Running on Android 47 | 48 | 1. Add your HMS API Key 49 | 50 | 2. Install dependencies 51 | 52 | ```sh 53 | cd ionic-hms-map-demo 54 | npm install 55 | ``` 56 | 57 | 3. Build Ionic app with the following command 58 | 59 | ```sh 60 | ionic build 61 | ``` 62 | 63 | 4. Manually add the Android project. 64 | 65 | ```sh 66 | npx cap add android 67 | ``` 68 | 69 | 5. Build and run the Ionic App using Android Studio. Once Android Studio launches, you can build/emulate/run your app through the standard Android Studio workflow. 70 | 71 | ```sh 72 | npx cap open android 73 | ``` 74 | 75 | If you are having issues, you can follow [getting started.](https://capacitor.ionicframework.com/docs/android/) 76 | 77 | ## HMS Map Kit JavaScript API 78 | 79 | 1. Provide the HUAWEI Map Kit API file. The key must be transcoded using the URL 80 | 81 | ```html 82 | 83 | ``` 84 | 85 | 2. Create map container elements in the body 86 | 87 | ```html 88 |
89 | ``` 90 | 91 | 3. Initialize the map. The following sample code is to create a map with Paris as the center and a zoom level of 8: 92 | 93 | ```js 94 | function initMap() { 95 | const mapOptions = {}; 96 | mapOptions.center = {lat: 48.856613, lng: 2.352222}; 97 | mapOptions.zoom = 8; 98 | mapOptions.language='ENG'; 99 | const map = new HWMapJsSDK.HWMap(document.getElementById('map'), mapOptions); 100 | } 101 | ``` 102 | 103 | 4. Adding Marker 104 | 105 | ```js 106 | const mMarker = new HWMapJsSDK.HWMarker({ 107 | map: map, 108 | position: {lat: 48.85, lng: 2.35}, 109 | label: 'A', 110 | icon: { 111 | opacity: 0.5 112 | } 113 | }); 114 | ``` 115 | 116 | 5. Showing Information Window 117 | 118 | ```js 119 | const infoWindow = new HWMapJsSDK.HWInfoWindow({ 120 | map, 121 | position: 10, 122 | content: 'This is a InfoWindow.', 123 | offset: [0, -40], 124 | }); 125 | 126 | infoWindow.open(mMarker); 127 | 128 | mMarker.addListener('click', () => { 129 | infoWindow.open(mMarker); 130 | }); 131 | ``` 132 | 133 |  134 | 135 | 136 | You can have more infromation from the official documentation of [Huawei Map Kit - JS API](https://developer.huawei.com/consumer/en/doc/development/HMS-Guides/hms-map-js-about-the-service) and you can integrate it in any JS based project. 137 | 138 | -------------------------------------------------------------------------------- /angular.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "./node_modules/@angular/cli/lib/config/schema.json", 3 | "version": 1, 4 | "defaultProject": "app", 5 | "newProjectRoot": "projects", 6 | "projects": { 7 | "app": { 8 | "root": "", 9 | "sourceRoot": "src", 10 | "projectType": "application", 11 | "prefix": "app", 12 | "schematics": {}, 13 | "architect": { 14 | "build": { 15 | "builder": "@angular-devkit/build-angular:browser", 16 | "options": { 17 | "outputPath": "www", 18 | "index": "src/index.html", 19 | "main": "src/main.ts", 20 | "polyfills": "src/polyfills.ts", 21 | "tsConfig": "tsconfig.app.json", 22 | "assets": [ 23 | { 24 | "glob": "**/*", 25 | "input": "src/assets", 26 | "output": "assets" 27 | }, 28 | { 29 | "glob": "**/*.svg", 30 | "input": "node_modules/ionicons/dist/ionicons/svg", 31 | "output": "./svg" 32 | } 33 | ], 34 | "styles": [ 35 | { 36 | "input": "src/theme/variables.scss" 37 | }, 38 | { 39 | "input": "src/global.scss" 40 | } 41 | ], 42 | "scripts": [] 43 | }, 44 | "configurations": { 45 | "production": { 46 | "fileReplacements": [ 47 | { 48 | "replace": "src/environments/environment.ts", 49 | "with": "src/environments/environment.prod.ts" 50 | } 51 | ], 52 | "optimization": true, 53 | "outputHashing": "all", 54 | "sourceMap": false, 55 | "extractCss": true, 56 | "namedChunks": false, 57 | "aot": true, 58 | "extractLicenses": true, 59 | "vendorChunk": false, 60 | "buildOptimizer": true, 61 | "budgets": [ 62 | { 63 | "type": "initial", 64 | "maximumWarning": "2mb", 65 | "maximumError": "5mb" 66 | } 67 | ] 68 | }, 69 | "ci": { 70 | "progress": false 71 | } 72 | } 73 | }, 74 | "serve": { 75 | "builder": "@angular-devkit/build-angular:dev-server", 76 | "options": { 77 | "browserTarget": "app:build" 78 | }, 79 | "configurations": { 80 | "production": { 81 | "browserTarget": "app:build:production" 82 | }, 83 | "ci": { 84 | "progress": false 85 | } 86 | } 87 | }, 88 | "extract-i18n": { 89 | "builder": "@angular-devkit/build-angular:extract-i18n", 90 | "options": { 91 | "browserTarget": "app:build" 92 | } 93 | }, 94 | "test": { 95 | "builder": "@angular-devkit/build-angular:karma", 96 | "options": { 97 | "main": "src/test.ts", 98 | "polyfills": "src/polyfills.ts", 99 | "tsConfig": "tsconfig.spec.json", 100 | "karmaConfig": "karma.conf.js", 101 | "styles": [], 102 | "scripts": [], 103 | "assets": [ 104 | { 105 | "glob": "favicon.ico", 106 | "input": "src/", 107 | "output": "/" 108 | }, 109 | { 110 | "glob": "**/*", 111 | "input": "src/assets", 112 | "output": "/assets" 113 | } 114 | ] 115 | }, 116 | "configurations": { 117 | "ci": { 118 | "progress": false, 119 | "watch": false 120 | } 121 | } 122 | }, 123 | "lint": { 124 | "builder": "@angular-devkit/build-angular:tslint", 125 | "options": { 126 | "tsConfig": [ 127 | "tsconfig.app.json", 128 | "tsconfig.spec.json", 129 | "e2e/tsconfig.json" 130 | ], 131 | "exclude": ["**/node_modules/**"] 132 | } 133 | }, 134 | "e2e": { 135 | "builder": "@angular-devkit/build-angular:protractor", 136 | "options": { 137 | "protractorConfig": "e2e/protractor.conf.js", 138 | "devServerTarget": "app:serve" 139 | }, 140 | "configurations": { 141 | "production": { 142 | "devServerTarget": "app:serve:production" 143 | }, 144 | "ci": { 145 | "devServerTarget": "app:serve:ci" 146 | } 147 | } 148 | }, 149 | "ionic-cordova-build": { 150 | "builder": "@ionic/angular-toolkit:cordova-build", 151 | "options": { 152 | "browserTarget": "app:build" 153 | }, 154 | "configurations": { 155 | "production": { 156 | "browserTarget": "app:build:production" 157 | } 158 | } 159 | }, 160 | "ionic-cordova-serve": { 161 | "builder": "@ionic/angular-toolkit:cordova-serve", 162 | "options": { 163 | "cordovaBuildTarget": "app:ionic-cordova-build", 164 | "devServerTarget": "app:serve" 165 | }, 166 | "configurations": { 167 | "production": { 168 | "cordovaBuildTarget": "app:ionic-cordova-build:production", 169 | "devServerTarget": "app:serve:production" 170 | } 171 | } 172 | } 173 | } 174 | } 175 | }, 176 | "cli": { 177 | "defaultCollection": "@ionic/angular-toolkit" 178 | }, 179 | "schematics": { 180 | "@ionic/angular-toolkit:component": { 181 | "styleext": "scss" 182 | }, 183 | "@ionic/angular-toolkit:page": { 184 | "styleext": "scss" 185 | } 186 | } 187 | } 188 | -------------------------------------------------------------------------------- /browserslist: -------------------------------------------------------------------------------- 1 | # This file is used by the build system to adjust CSS and JS output to support the specified browsers below. 2 | # For additional information regarding the format and rule options, please see: 3 | # https://github.com/browserslist/browserslist#queries 4 | 5 | # You can see what browsers were selected by your queries by running: 6 | # npx browserslist 7 | 8 | > 0.5% 9 | last 2 versions 10 | Firefox ESR 11 | not dead 12 | not IE 9-11 # For IE 9-11 support, remove 'not'. 13 | -------------------------------------------------------------------------------- /capacitor.config.json: -------------------------------------------------------------------------------- 1 | { 2 | "appId": "com.onurkenis.ionichmsmapdemo", 3 | "appName": "ionic-hms-map-demo", 4 | "bundledWebRuntime": false, 5 | "npmClient": "npm", 6 | "webDir": "www", 7 | "cordova": {} 8 | } 9 | -------------------------------------------------------------------------------- /demo/mobile.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onurkenis/ionic-hms-map-demo/b168a3c16fa50d558cbea31474a06a857ad376f8/demo/mobile.gif -------------------------------------------------------------------------------- /demo/web.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onurkenis/ionic-hms-map-demo/b168a3c16fa50d558cbea31474a06a857ad376f8/demo/web.gif -------------------------------------------------------------------------------- /e2e/protractor.conf.js: -------------------------------------------------------------------------------- 1 | // Protractor configuration file, see link for more information 2 | // https://github.com/angular/protractor/blob/master/lib/config.ts 3 | 4 | const { SpecReporter } = require('jasmine-spec-reporter'); 5 | 6 | exports.config = { 7 | allScriptsTimeout: 11000, 8 | specs: [ 9 | './src/**/*.e2e-spec.ts' 10 | ], 11 | capabilities: { 12 | 'browserName': 'chrome' 13 | }, 14 | directConnect: true, 15 | baseUrl: 'http://localhost:4200/', 16 | framework: 'jasmine', 17 | jasmineNodeOpts: { 18 | showColors: true, 19 | defaultTimeoutInterval: 30000, 20 | print: function() {} 21 | }, 22 | onPrepare() { 23 | require('ts-node').register({ 24 | project: require('path').join(__dirname, './tsconfig.json') 25 | }); 26 | jasmine.getEnv().addReporter(new SpecReporter({ spec: { displayStacktrace: true } })); 27 | } 28 | }; 29 | -------------------------------------------------------------------------------- /e2e/src/app.e2e-spec.ts: -------------------------------------------------------------------------------- 1 | import { AppPage } from './app.po'; 2 | 3 | describe('new App', () => { 4 | let page: AppPage; 5 | 6 | beforeEach(() => { 7 | page = new AppPage(); 8 | }); 9 | 10 | it('should be blank', () => { 11 | page.navigateTo(); 12 | expect(page.getParagraphText()).toContain('Start with Ionic UI Components'); 13 | }); 14 | }); 15 | -------------------------------------------------------------------------------- /e2e/src/app.po.ts: -------------------------------------------------------------------------------- 1 | import { browser, by, element } from 'protractor'; 2 | 3 | export class AppPage { 4 | navigateTo() { 5 | return browser.get('/'); 6 | } 7 | 8 | getParagraphText() { 9 | return element(by.deepCss('app-root ion-content')).getText(); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /e2e/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "../out-tsc/app", 5 | "module": "commonjs", 6 | "target": "es5", 7 | "types": [ 8 | "jasmine", 9 | "jasminewd2", 10 | "node" 11 | ] 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /ionic.config.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "ionic-hms-map-demo", 3 | "integrations": {}, 4 | "type": "angular" 5 | } 6 | -------------------------------------------------------------------------------- /karma.conf.js: -------------------------------------------------------------------------------- 1 | // Karma configuration file, see link for more information 2 | // https://karma-runner.github.io/1.0/config/configuration-file.html 3 | 4 | module.exports = function (config) { 5 | config.set({ 6 | basePath: '', 7 | frameworks: ['jasmine', '@angular-devkit/build-angular'], 8 | plugins: [ 9 | require('karma-jasmine'), 10 | require('karma-chrome-launcher'), 11 | require('karma-jasmine-html-reporter'), 12 | require('karma-coverage-istanbul-reporter'), 13 | require('@angular-devkit/build-angular/plugins/karma') 14 | ], 15 | client: { 16 | clearContext: false // leave Jasmine Spec Runner output visible in browser 17 | }, 18 | coverageIstanbulReporter: { 19 | dir: require('path').join(__dirname, '../coverage'), 20 | reports: ['html', 'lcovonly', 'text-summary'], 21 | fixWebpackSourcePaths: true 22 | }, 23 | reporters: ['progress', 'kjhtml'], 24 | port: 9876, 25 | colors: true, 26 | logLevel: config.LOG_INFO, 27 | autoWatch: true, 28 | browsers: ['Chrome'], 29 | singleRun: false 30 | }); 31 | }; 32 | -------------------------------------------------------------------------------- /master: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onurkenis/ionic-hms-map-demo/b168a3c16fa50d558cbea31474a06a857ad376f8/master -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "ionic-hms-map-demo", 3 | "version": "0.0.1", 4 | "author": "Onur Kenis", 5 | "homepage": "https://ionicframework.com/", 6 | "scripts": { 7 | "ng": "ng", 8 | "start": "ng serve", 9 | "build": "ng build", 10 | "test": "ng test", 11 | "lint": "ng lint", 12 | "e2e": "ng e2e" 13 | }, 14 | "private": true, 15 | "dependencies": { 16 | "@angular/common": "~8.2.14", 17 | "@angular/core": "~8.2.14", 18 | "@angular/forms": "~8.2.14", 19 | "@angular/platform-browser": "~8.2.14", 20 | "@angular/platform-browser-dynamic": "~8.2.14", 21 | "@angular/router": "~8.2.14", 22 | "@capacitor/android": "^1.5.1", 23 | "@capacitor/core": "^1.5.1", 24 | "@ionic-native/core": "^5.0.0", 25 | "@ionic-native/splash-screen": "^5.0.0", 26 | "@ionic-native/status-bar": "^5.0.0", 27 | "@ionic/angular": "^5.0.0", 28 | "again": "0.0.1", 29 | "core-js": "^2.5.4", 30 | "rxjs": "~6.5.1", 31 | "tslib": "^1.9.0", 32 | "zone.js": "~0.9.1" 33 | }, 34 | "devDependencies": { 35 | "@angular-devkit/build-angular": "~0.803.20", 36 | "@angular/cli": "~8.3.23", 37 | "@angular/compiler": "~8.2.14", 38 | "@angular/compiler-cli": "~8.2.14", 39 | "@angular/language-service": "~8.2.14", 40 | "@capacitor/cli": "^1.5.1", 41 | "@ionic/angular-toolkit": "^2.1.1", 42 | "@types/jasmine": "~3.3.8", 43 | "@types/jasminewd2": "~2.0.3", 44 | "@types/node": "~8.9.4", 45 | "codelyzer": "^5.0.0", 46 | "jasmine-core": "~3.4.0", 47 | "jasmine-spec-reporter": "~4.2.1", 48 | "karma": "~4.1.0", 49 | "karma-chrome-launcher": "~2.2.0", 50 | "karma-coverage-istanbul-reporter": "~2.0.1", 51 | "karma-jasmine": "~2.0.1", 52 | "karma-jasmine-html-reporter": "^1.4.0", 53 | "npm-force-resolutions": "0.0.3", 54 | "protractor": "~5.4.0", 55 | "ts-node": "~7.0.0", 56 | "tslint": "~5.15.0", 57 | "typescript": "~3.4.3" 58 | }, 59 | "description": "HMS Map Kit JavaScript Sample with Ionic", 60 | "resolutions": { 61 | "@babel/preset-env": "^7.8.7" 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /src/app/app-routing.module.ts: -------------------------------------------------------------------------------- 1 | import { NgModule } from '@angular/core'; 2 | import { PreloadAllModules, RouterModule, Routes } from '@angular/router'; 3 | 4 | const routes: Routes = [ 5 | { path: '', redirectTo: 'home', pathMatch: 'full' }, 6 | { path: 'home', loadChildren: () => import('./home/home.module').then( m => m.HomePageModule)}, 7 | ]; 8 | 9 | @NgModule({ 10 | imports: [ 11 | RouterModule.forRoot(routes, { preloadingStrategy: PreloadAllModules }) 12 | ], 13 | exports: [RouterModule] 14 | }) 15 | export class AppRoutingModule { } 16 | -------------------------------------------------------------------------------- /src/app/app.component.html: -------------------------------------------------------------------------------- 1 |