Skip to content

Commit

Permalink
fix removeTileLayer bug
Browse files Browse the repository at this point in the history
  • Loading branch information
callmedanieldaniel committed Jun 4, 2019
2 parents 09cd179 + 944b883 commit d6e1e81
Show file tree
Hide file tree
Showing 10 changed files with 41 additions and 15 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ React-BMap只是利用了React组件的生命周期,来调用对应的百度
## 获取 `BMap.Map` 实例
如果你使用 `BMapLib`,需要 `BMap.Map` 实例的话,可以通过 `<Map>` 组件实例的 `map` 属性访问到它。

<Map ref={ref => this.map = ref.map} />
<Map ref={ref => {this.map = ref.map}} />

## 许可证
[MIT](./LICENSE)
2 changes: 1 addition & 1 deletion docs/dist/react-bmap.min.js

Large diffs are not rendered by default.

11 changes: 8 additions & 3 deletions docs/examples/build/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -14729,6 +14729,7 @@ var App = function (_Component) {
), this.contentDom);
this.marker = new _CustomOverlay2.default(position, this.contentDom, {
zIndex: this.props.zIndex,
pane: this.props.pane,
offset: this.props.offset
});
map.addOverlay(this.marker);
Expand Down Expand Up @@ -31330,7 +31331,8 @@ CustomOverlay.prototype.initialize = function (map) {
} else {
div.appendChild(this.content);
}
map.getPanes().labelPane.appendChild(div);
var pane = this.options.pane || 'labelPane';
map.getPanes()[pane].appendChild(div);
return div;
};

Expand Down Expand Up @@ -33394,8 +33396,11 @@ var App = function (_Component) {
}, {
key: 'componentWillUnmount',
value: function componentWillUnmount() {
this.props.map.removeTileLayer(this.tileLayer);
this.tileLayer = null;
var map = this.props.map;
if (map && map.removeTileLayer && map.removeTileLayer instanceof Function && this.tileLayer) {
map.removeTileLayer(this.tileLayer);
this.tileLayer = null;
}
}
}, {
key: 'initialize',
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-bmap",
"version": "1.0.95",
"version": "1.0.97",
"description": "react-bmap",
"main": "lib/index.js",
"contributors": [
Expand Down Expand Up @@ -47,7 +47,7 @@
},
"dependencies": {
"kits-js": "^0.0.7",
"mapv": "^2.0.33"
"mapv": "^2.0.34"
},
"config": {
"commitizen": {
Expand Down
16 changes: 16 additions & 0 deletions src/components/geolocation-control.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import Control from './control';

export default class GeolocationControl extends Control {
constructor(args) {
super(args);
}

get options() {
return ['anchor', 'offset', 'showAddressBar', 'enableAutoLocation', 'locationIcon'];
}

getControl() {
return new BMap.GeolocationControl(this.getOptions(this.options));
}

}
7 changes: 4 additions & 3 deletions src/components/infowindow.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# InfoWindow
信息窗口组件,可参考官网对于一些[属性](http://lbsyun.baidu.com/cms/jsapi/reference/jsapi_reference.html#a3b7)
可配置属性:

### 可配置属性
- position
- width
- height
Expand All @@ -11,9 +12,9 @@
- enableCloseOnClick
- enableMessage
- message
- events
- events={事件options}

事件options
### InfoWindow的事件options包含以下属性,可传回调函数
- close
- open
- maximize
Expand Down
5 changes: 3 additions & 2 deletions src/components/map.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
# Map
最外层地图基础组件,其它组件都在包含在地图组件里面。对应的一些属性也可以查看官方文档对应的[Map对象](http://lbsyun.baidu.com/cms/jsapi/reference/jsapi_reference.html#a0b0)

## 可配置属性
### 可配置属性
* center={{lng: 123, lat}}
* zoom={{10}}
* style={{height: '300px'}} css样式对象
* mapStyle={{styleJson: []}} 个性化底图json样式可以通过[底图编辑器](http://wiki.lbsyun.baidu.com/custom/)配置
* mapStyleV2={{styleJson: []}} 如果您使用的是3.0版本的jsapi,个性化底图json样式可以通过[底图编辑器](http://lbsyun.baidu.com/index.php?title=open/custom)配置
* minZoom='3'
* maxZoom='19'

Expand All @@ -20,7 +21,7 @@
* enableAutoResize={false}
* events={事件options}

### map的事件options包含以下属性
### Map的事件options包含以下属性,可传回调函数
* click
* dblclick
* rightclick
Expand Down
1 change: 1 addition & 0 deletions src/components/marker.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ export default class App extends Component {
render(<div>{child}</div>, this.contentDom)
this.marker = new CustomOverlay(position, this.contentDom, {
zIndex: this.props.zIndex,
pane: this.props.pane,
offset: this.props.offset
});
map.addOverlay(this.marker);
Expand Down
5 changes: 3 additions & 2 deletions src/components/marker.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Marker
标注组建,可在地图上打标注。对应的一些属性也可以查看官方文档对应的[Marker对象](http://lbsyun.baidu.com/cms/jsapi/reference/jsapi_reference.html#a3b2)

## 可配置属性
### 可配置属性
- position={{lng: 123, lat: 23}}
- zIndex="10" 目前只对自定义覆盖物生效
- offset={new BMap.Size(10, 10)}
Expand All @@ -16,8 +16,9 @@
- enableDragging={false}
- autoViewport={true}
- viewportOptions={{zoomFactor: -2}}
- events={事件options}

### marker的事件options包含以下属性,可传回调函数:
### Marker的事件options包含以下属性,可传回调函数:
- click
- dblclick
- mousedown
Expand Down
3 changes: 2 additions & 1 deletion src/overlay/CustomOverlay.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ CustomOverlay.prototype.initialize = function(map){
} else {
div.appendChild(this.content);
}
map.getPanes().labelPane.appendChild(div);
var pane = this.options.pane || 'labelPane';
map.getPanes()[pane].appendChild(div);
return div;
}

Expand Down

0 comments on commit d6e1e81

Please sign in to comment.