Skip to content

Commit

Permalink
add geolocation support
Browse files Browse the repository at this point in the history
  • Loading branch information
leftstick committed Jun 6, 2016
1 parent 498c197 commit 6251e00
Show file tree
Hide file tree
Showing 8 changed files with 114 additions and 21 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ npm-debug.log

src/**/*.js

#tsd
#typings
typings/
22 changes: 22 additions & 0 deletions dist/angular2-baidu-map.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,30 @@ export interface MapDefaultOptions {
scaleCtrl?: boolean;
overviewCtrl?: boolean;
enableScrollWheelZoom?: boolean;
geolocationCtrl?: boolean | GeolocationControlOptions;
zoom?: number;
}
export declare enum ControlAnchor {
BMAP_ANCHOR_TOP_LEFT = 0,
BMAP_ANCHOR_TOP_RIGHT = 1,
BMAP_ANCHOR_BOTTOM_LEFT = 2,
BMAP_ANCHOR_BOTTOM_RIGHT = 3,
}
export interface Size {
width: number;
height: number;
}
export interface Icon {
url: string;
size: Size;
}
export interface GeolocationControlOptions {
anchor?: ControlAnchor;
offset?: Size;
showAddressBar?: boolean;
enableAutoLocation?: boolean;
locationIcon?: Icon;
}
export interface MapOptions extends MapDefaultOptions {
center: {
longitude: number;
Expand Down
30 changes: 30 additions & 0 deletions dist/angular2-baidu-map.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,20 @@ var defaultOpts = {
scaleCtrl: true,
overviewCtrl: true,
enableScrollWheelZoom: true,
geolocationCtrl: false,
zoom: 10
};
var defaultOfflineOpts = {
retryInterval: 30000,
txt: 'OFFLINE'
};
(function (ControlAnchor) {
ControlAnchor[ControlAnchor["BMAP_ANCHOR_TOP_LEFT"] = 0] = "BMAP_ANCHOR_TOP_LEFT";
ControlAnchor[ControlAnchor["BMAP_ANCHOR_TOP_RIGHT"] = 1] = "BMAP_ANCHOR_TOP_RIGHT";
ControlAnchor[ControlAnchor["BMAP_ANCHOR_BOTTOM_LEFT"] = 2] = "BMAP_ANCHOR_BOTTOM_LEFT";
ControlAnchor[ControlAnchor["BMAP_ANCHOR_BOTTOM_RIGHT"] = 3] = "BMAP_ANCHOR_BOTTOM_RIGHT";
})(exports.ControlAnchor || (exports.ControlAnchor = {}));
var ControlAnchor = exports.ControlAnchor;
var MapStatus;
(function (MapStatus) {
MapStatus[MapStatus["LOADING"] = 0] = "LOADING";
Expand Down Expand Up @@ -136,6 +144,28 @@ var createInstance = function (opts, element) {
if (opts.enableScrollWheelZoom) {
map.enableScrollWheelZoom();
}
if (opts.geolocationCtrl) {
var geoOpts = {};
if (typeof opts.geolocationCtrl !== 'boolean') {
var ctrl = opts.geolocationCtrl;
if (ctrl.anchor) {
geoOpts.anchor = ctrl.anchor;
}
if (ctrl.offset) {
geoOpts.offset = new BMap.Size(ctrl.offset.width, ctrl.offset.height);
}
if (typeof geoOpts.showAddressBar === 'boolean') {
geoOpts.showAddressBar = ctrl.showAddressBar;
}
if (typeof geoOpts.enableAutoLocation === 'boolean') {
geoOpts.enableAutoLocation = ctrl.enableAutoLocation;
}
if (geoOpts.locationIcon) {
geoOpts.locationIcon = new BMap.Size(ctrl.locationIcon.url, new BMap.Size(ctrl.locationIcon.size.width, ctrl.locationIcon.size.height));
}
}
map.addControl(new BMap.GeolocationControl(geoOpts));
}
return map;
};
var createMarker = function (marker, pt) {
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"name": "angular2-baidu-map",
"version": "2.2.0",
"version": "2.3.0",
"description": "Angular2 component for Baidu map",
"main": "./dist/angular2-baidu-map.js",
"typings": "./dist/angular2-baidu-map.d.ts",
"scripts": {
"prepublish": "npm run dist",
"preinstall": "tsd install",
"preinstall": "typings install",
"dist": "rm -rf dist; tsc"
},
"files": [
Expand Down Expand Up @@ -36,7 +36,7 @@
"zone.js": "^0.6.12"
},
"devDependencies": {
"tsd": "^0.6.5",
"typings": "^1.0.4",
"typescript": "^1.8.10"
}
}
50 changes: 50 additions & 0 deletions src/angular2-baidu-map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ const defaultOpts: MapDefaultOptions = {
scaleCtrl: true,
overviewCtrl: true,
enableScrollWheelZoom: true,
geolocationCtrl: false,
zoom: 10
}

Expand All @@ -81,9 +82,35 @@ export interface MapDefaultOptions {
scaleCtrl?: boolean;
overviewCtrl?: boolean;
enableScrollWheelZoom?: boolean;
geolocationCtrl?: boolean | GeolocationControlOptions;
zoom?: number;
}

export enum ControlAnchor {
BMAP_ANCHOR_TOP_LEFT = 0,
BMAP_ANCHOR_TOP_RIGHT = 1,
BMAP_ANCHOR_BOTTOM_LEFT = 2,
BMAP_ANCHOR_BOTTOM_RIGHT = 3
}

export interface Size {
width: number;
height: number;
}

export interface Icon {
url: string;
size: Size;
}

export interface GeolocationControlOptions {
anchor?: ControlAnchor;
offset?: Size;
showAddressBar?: boolean;
enableAutoLocation?: boolean;
locationIcon?: Icon;
}

export interface MapOptions extends MapDefaultOptions {
center: { longitude: number, latitude: number };
markers?: MarkerOptions[];
Expand Down Expand Up @@ -185,6 +212,29 @@ const createInstance = function(opts: MapOptions, element: any) {
//enable scroll wheel zoom
map.enableScrollWheelZoom();
}
if (opts.geolocationCtrl) {
//enable GeolocationControl
var geoOpts: any = {};
if (typeof opts.geolocationCtrl !== 'boolean') {
var ctrl = <GeolocationControlOptions>opts.geolocationCtrl;
if (ctrl.anchor) {
geoOpts.anchor = ctrl.anchor;
}
if (ctrl.offset) {
geoOpts.offset = new BMap.Size(ctrl.offset.width, ctrl.offset.height);
}
if (typeof geoOpts.showAddressBar === 'boolean') {
geoOpts.showAddressBar = ctrl.showAddressBar;
}
if (typeof geoOpts.enableAutoLocation === 'boolean') {
geoOpts.enableAutoLocation = ctrl.enableAutoLocation;
}
if (geoOpts.locationIcon) {
geoOpts.locationIcon = new BMap.Size(ctrl.locationIcon.url, new BMap.Size(ctrl.locationIcon.size.width, ctrl.locationIcon.size.height));
}
}
map.addControl(new BMap.GeolocationControl(geoOpts));
}
return map;
};

Expand Down
4 changes: 2 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
"buildOnSave": false,
"compileOnSave": false,
"files": [
"typings/es6-collections/es6-collections.d.ts",
"typings/es6-promise/es6-promise.d.ts",
"typings/globals/es6-collections/index.d.ts",
"typings/globals/es6-promise/index.d.ts",
"src/angular2-baidu-map.ts",
"Object.d.ts"
],
Expand Down
15 changes: 0 additions & 15 deletions tsd.json

This file was deleted.

6 changes: 6 additions & 0 deletions typings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"globalDependencies": {
"es6-collections": "registry:dt/es6-collections#0.5.1+20160316155526",
"es6-promise": "registry:dt/es6-promise#0.0.0+20160423074304"
}
}

0 comments on commit 6251e00

Please sign in to comment.