ionic2 百度地图
来源:互联网 发布:如何两个人练口语 知乎 编辑:程序博客网 时间:2024/06/05 16:20
最近开发一个地图项目,晕,ionic2的google和高德地图很多用,但是百度地图却很少,总算是找到一个,用法如下:
github地址:https://github.com/leftstick/angular2-baidu-map
Install via npm
You can install and manage angular2-baidu-map
via npm:
npm install angular2-baidu-map --save
Import
ES2015
import { NgModule } from '@angular/core';import { BrowserModule } from '@angular/platform-browser';import { BaiduMapModule } from 'angular2-baidu-map';//import BaiduMapModuleimport { MainApp } from './demo.app';@NgModule({ imports: [ BrowserModule, BaiduMapModule ], declarations: [ MainApp ], bootstrap: [ MainApp ]})class AppModule { }
Usage
import {Component, OnInit} from '@angular/core';import { OfflineOptions, ControlAnchor, NavigationControlType } from 'angular2-baidu-map';@Component({ selector: 'map-presentation', template: ` <h1>Test Baidu-Map<h1> <baidu-map ak="put your ak here" [options]="opts" [offline]="offlineOpts" (onMapLoaded)="loadMap($event)" (onMarkerClicked)="clickMarker($event)" (onClicked)="clickmap($event)" ></baidu-map> `, styles: [` baidu-map{ width: 500px; height: 400px; display: block; } `]})export class MainApp implements OnInit { opts: any; offlineOpts: OfflineOptions; ngOnInit() { this.opts = { center: { longitude: 121.506191, latitude: 31.245554 }, zoom: 17, markers: [{ longitude: 121.506191, latitude: 31.245554, title: 'Where', content: 'Put description here', enableDragging: true }], geolocationCtrl: { anchor: ControlAnchor.BMAP_ANCHOR_BOTTOM_RIGHT }, scaleCtrl: { anchor: ControlAnchor.BMAP_ANCHOR_BOTTOM_LEFT }, overviewCtrl: { isOpen: true }, navCtrl: { type: NavigationControlType.BMAP_NAVIGATION_CONTROL_LARGE } }; this.offlineOpts = { retryInterval: 5000, txt: 'NO-NETWORK' }; } loadMap(map: any) { console.log('map instance here', map); } clickMarker(marker: any) { console.log('The clicked marker is', marker); } clickmap(e: any) { console.log(`Map clicked with coordinate: ${e.point.lng}, ${e.point.lat}`); }}
Be aware thatwidth
,height
must be specified tobaidu-map
component. Otherwise, the map cannot be displayed.
Update map dynamically
@Component({ selector: 'map-presentation', template: ` <baidu-map ak="put your ak here" [options]="opts"></baidu-map> <button (click)="updateCoordinate($event)">Update Coordinate<button> `, styles: [...]})export class MainApp implements OnInit { opts: any; ngOnInit() { ... } /** * the map will be pointed to * new coordinate once click * the button */ updateCoordinate(e: MouseEvent){ this.opts = { center: { longitude: 121.500885, latitude: 31.190032 } }; }}
API
attributes
http:
, https:
optionsMapOptionsoptions used to draw the mapofflineOfflineOptionsoptions applied while no-network availableonMapLoadedExpressionExpression to evaluate upon callback, (Event object is available as the map instance)onMarkerClickedExpressionExpression to evaluate upon callback, (Event object is available as the marker instance)onClickedExpressionExpression to evaluate upon callback, (Event object is map clicked event instance)MapOptions
{ longitude: 121.506191, latitude: 31.245554}
zoomNumberNozoom level which will be displayed on the map. default is 10
15
navCtrlNavigationControlOptions || BooleanNoAdd a NavigationControl to the map. default is true
false
scaleCtrlScaleControlOptions || BooleanNoAdd a ScaleControl to the map. default is true
false
overviewCtrlOverviewMapControlOptions || BooleanNoAdd a OverviewMapControl to the map. default is true
false
enableScrollWheelZoomBooleanNowhether to enableScrollWheelZoom to the map. default is true
false
geolocationCtrlGeolocationControlOptions || BooleanNoAdd GeolocationControl to the map{ anchor: ControlAnchor.BMAP_ANCHOR_BOTTOM_RIGHT, offset: { width: 100, height: 200}, showAddressBar: true, enableAutoLocation: true, locationIcon: { url: 'http://xxx/url.png', size: { width: 100, height: 100 } }}
markersMarker[]Nomarker will be displayed on the map. default is empty
[{ longitude: 121.506191, latitude: 31.245554, title: 'Where', content: 'Put description here'}]
Marker
121.506191
latitudeNumberYesThe latitude of geographical coordinate31.245554
iconStringNoThe URL of customized ICONhttp://xxx/url.png
widthNumberNoThe width of marker100
heightNumberNoThe height of marker100
titleStringNoThe title of BMap.InfoWindow, which will be displayed by clicking the markerWhere
contentStringNoThe content of BMap.InfoWindow, which will be displayed by clicking the markerPut description here
enableMessageBooleanNoWhether to enable SMS in the BMap.InfoWindowtrue
autoDisplayInfoWindowBooleanNoWhether to display the BMap.InfoWindow along with the Markertrue
enableDraggingBooleanNoWhether to enable draggable function for the markertrue
OfflineOptions
5000
txtStringNotext to be displayed while no-network available. "OFFLINE" by defaultNO-NETWORK
GeolocationControlOptions
ControlAnchor.BMAP_ANCHOR_TOP_LEFT
offsetSizeNoHorizontal offset of the GeoLocaltionControl{ width: 100, height: 100}
showAddressBarBooleanNoWhether to display the control paneltrue
enableAutoLocationBooleanNoWhether to positioning while map addedtrue
locationIconIconNoCustomize the icon{ url: 'http://wwww/xx.png', size: { width: 50, height: 50} }
NavigationControlOptions
ControlAnchor.BMAP_ANCHOR_TOP_LEFT
offsetSizeNoHorizontal offset of the NavigationControl{ width: 100, height: 100}
typeNavigationControlTypeNoSpecify type of displayed NavigationControlNavigationControlType.BMAP_NAVIGATION_CONTROL_SMALL
showZoomInfoBooleanNoWhether to display zoom infotrue
enableGeolocationBooleanNoWhether to enable Geolocation featuretrue
OverviewMapControlOptions
ControlAnchor.BMAP_ANCHOR_TOP_LEFT
offsetSizeNoHorizontal offset of the OverviewMapControl{ width: 100, height: 100}
sizeSizeNoSpecify size of displayed OverviewMapControl{ width: 100, height: 100 }
isOpenBooleanNoWhether to display OverviewMapControl once map displayedtrue
ScaleControlOptions
ControlAnchor.BMAP_ANCHOR_TOP_LEFT
offsetSizeNoHorizontal offset of the ScaleControl{ width: 100, height: 100}
阅读全文
0 0
- ionic2 百度地图应用
- ionic2 百度地图
- 使用ionic2接入百度地图
- ionic2 百度地图的使用
- ionic2 引用百度地图报错
- Ionic2使用百度地图和html5 geolocation的一些注意事项
- ionic2 引入百度ECharts3
- 请问Ionic2.0如何在ts文件内倒入百度地图插件?
- Ionic2 使用高德地图
- Ionic2 使用高德地图
- 百度地图
- 百度地图
- 百度地图
- 百度地图
- 百度地图
- 百度地图
- 百度地图
- 百度地图
- Linux 文件类型特殊权限 s、t、i、a
- 猎豹移动 CEO 傅盛:后互联网时代 ,“中国模式”弯道超车
- hibernate一对多及多对多配置
- Dialog
- error: style attribute '@android:attr/windowEnterAnimation' not found.
- ionic2 百度地图
- 得到本周日的日期
- RecyclerView
- org.apache.catalina.LifecycleException
- Node.js模块
- 用Jpa查询的数据,不能用PageHelper进行分页
- oracle锁表处理
- aliyun阿里云Maven仓库地址——加速你的maven构建
- Zookeeper的个人理解(非专业技术角度 只是方便于理解)