Skip to content

Commit 9e8b2a7

Browse files
committed
new func supported
1 parent 442056e commit 9e8b2a7

7 files changed

Lines changed: 22 additions & 7 deletions

File tree

demo/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
</head>
88

99
<body ng-controller="demoCtrl">
10-
<baidu-map options="mapOptions" ak="gd0GyxGUxSCoAbmdyQBhyhrZ" offline="offlineOpts" style="width: 500px; height: 500px;display: block;"></baidu-map>
10+
<baidu-map options="mapOptions" ak="gd0GyxGUxSCoAbmdyQBhyhrZ" offline="offlineOpts" style="width: 500px; height: 500px;display: block;" on-map-loaded="mapLoaded(map)"></baidu-map>
1111
</body>
1212

1313
</html>

demo/libs/Demo.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ demo.controller('demoCtrl', ['$scope', '$timeout',
2525
}]
2626
};
2727

28+
$scope.mapLoaded = function(map) {
29+
console.log(map);
30+
};
31+
2832
$timeout(function() {
2933
$scope.mapOptions.center.longitude = 121.500885;
3034
$scope.mapOptions.center.latitude = 31.190032;

dist/angular-baidu-map.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,8 @@ return /******/ (function(modules) { // webpackBootstrap
8787
scope: {
8888
options: '=',
8989
ak: '@',
90-
offline: '='
90+
offline: '=',
91+
onMapLoaded: '&'
9192
},
9293
link: function link($scope, element, attrs) {
9394

@@ -104,6 +105,8 @@ return /******/ (function(modules) { // webpackBootstrap
104105

105106
var map = (0, _map.createInstance)(opts, element);
106107

108+
$scope.onMapLoaded({ map: map });
109+
107110
//create markers
108111
var previousMarkers = [];
109112

dist/angular-baidu-map.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/APIDocs.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,12 @@ var app = angular.module('app', [ngBaiduMap]);
3939
### Use `baidu-map` directive in the template
4040

4141
```html
42-
<baidu-map options="mapOptions" ak="<your-ak>" offline="offlineOpts" class="<style-for-it>"></baidu-map>
42+
<baidu-map options="mapOptions" ak="<your-ak>" offline="offlineOpts" on-map-loaded="loadMap(map)" class="<style-for-it>"></baidu-map>
4343
```
4444
* `mapOptions` is what you defined in the controller
4545
* `ak` is a plain text you applied at [开放平台](http://lbsyun.baidu.com/apiconsole/key)
4646
* `offlineOpts` is used to control offline retry interval
47+
* `on-map-loaded` is used for hacking purpose, in case some of you insist getting `map` instance
4748
* `class` or `style` has to be defined, otherwise the map cannot be shown
4849

4950
### Define `mapOptions` in controller
@@ -76,6 +77,10 @@ app.controller('demoCtrl', ['$scope',
7677
content: 'Put description here'
7778
}]
7879
};
80+
81+
$scope.loadMap = function(map) {
82+
console.log(map);//gets called while map instance created
83+
};
7984
}
8085
]);
8186
```

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "angular-baidu-map",
3-
"version": "2.0.1",
3+
"version": "2.1.0",
44
"description": "A baidu-map directive for AngularJS",
55
"main": "dist/angular-baidu-map.js",
66
"repository": {
@@ -36,7 +36,7 @@
3636
"homepage": "https://github.com/leftstick/BaiduMapForAngularJS",
3737
"devDependencies": {
3838
"angular": "^1.5.5",
39-
"babel-core": "^6.7.7",
39+
"babel-core": "^6.8.0",
4040
"babel-loader": "^6.2.4",
4141
"babel-preset-es2015": "^6.6.0",
4242
"lite-server": "^2.2.0",

src/index.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ export const ngBaiduMap = (function() {
1515
scope: {
1616
options: '=',
1717
ak: '@',
18-
offline: '='
18+
offline: '=',
19+
onMapLoaded: '&'
1920
},
2021
link: function($scope, element, attrs) {
2122

@@ -32,6 +33,8 @@ export const ngBaiduMap = (function() {
3233

3334
var map = createInstance(opts, element);
3435

36+
$scope.onMapLoaded({map});
37+
3538
//create markers
3639
var previousMarkers = [];
3740

0 commit comments

Comments
 (0)