Browse Source

修复 回调函数中 this指向问题.

上海一张图
赵旭 4 years ago
parent
commit
c701c4a275
  1. 978
      src/app/statistic-analysis/home/home.component.ts
  2. 220
      src/modules/map/declare/gaode-map.ts

978
src/app/statistic-analysis/home/home.component.ts

File diff suppressed because it is too large Load Diff

220
src/modules/map/declare/gaode-map.ts

@ -14,7 +14,7 @@ export class GaoDeMap extends GaodeBasic implements IMap {
this.self = new AMap.Map(container, options);
}
setBounds(zoom?: any, x?: any, y?: any, is?: boolean) {
return this.self.setBounds(zoom,x,y,is)
return this.self.setBounds(zoom, x, y, is)
}
setFitView(options: any) {
return this.self.setFitView(options)
@ -52,7 +52,7 @@ export class GaoDeMap extends GaodeBasic implements IMap {
setZoom(zoom) {
return this.self.setZoom(zoom)
}
setCenter(pos:any) {
setCenter(pos: any) {
return this.self.setCenter(pos)
}
getCenter() {
@ -64,38 +64,38 @@ export class GaoDeMap extends GaodeBasic implements IMap {
on(eventName: string, callback: Function): void {
return this.self.on(eventName, callback);
}
setAdministrativeAreaStyle(component:any,getData?:Function, setData?:Function) {//自定义 行政区划 样式
setAdministrativeAreaStyle(component: any, getData?: Function, setData?: Function) {//自定义 行政区划 样式
let that = this
let level = sessionStorage.getItem("level")
AMapUI.loadUI(['geo/DistrictExplorer'], (DistrictExplorer)=> {
AMapUI.loadUI(['geo/DistrictExplorer'], (DistrictExplorer) => {
let colors = [
"#3366cc", "#dc3912", "#ff9900", "#109618", "#990099", "#0099c6", "#dd4477", "#66aa00",
"#b82e2e", "#316395", "#994499", "#22aa99", "#aaaa11", "#6633cc", "#e67300", "#8b0707",
"#651067", "#329262", "#5574a6", "#3b3eac"
];
//创建一个实例
let districtExplorer = new DistrictExplorer({
map: that.self,
eventSupport: true, //打开事件支持
});
let adcode = 310000 //上海行政编码
districtExplorer.loadAreaNode(adcode, (error, areaNode)=> {
districtExplorer.loadAreaNode(adcode, (error, areaNode) => {
//更新地图视野
that.setBounds(areaNode.getBounds(), null, null, true);
//设置定位节点,支持鼠标位置识别
//注意节点的顺序,前面的高优先级
districtExplorer.setAreaNodesForLocating(areaNode);
//清除已有的绘制内容
districtExplorer.clearFeaturePolygons();
//绘制子区域
districtExplorer.renderSubFeatures(areaNode, (feature, i) =>{
districtExplorer.renderSubFeatures(areaNode, (feature, i) => {
let fillColor = colors[i % colors.length];
let strokeColor = colors[colors.length - 1 - i % colors.length];
return {
@ -108,7 +108,7 @@ export class GaoDeMap extends GaodeBasic implements IMap {
fillOpacity: 0.5, //填充透明度
};
});
//绘制父区域
districtExplorer.renderParentFeature(areaNode, {
cursor: 'default',
@ -119,108 +119,108 @@ export class GaoDeMap extends GaodeBasic implements IMap {
fillColor: null, //填充色
fillOpacity: 0.5, //填充透明度
});
// 更新地图视野以适合区划面
that.setFitView(districtExplorer.getAllFeaturePolygons());
});
if(level=="0"||level=="1"||level=="2"){
if (level == "0" || level == "1" || level == "2") {
//区域内点击
districtExplorer.on('featureClick', (e, feature) =>{
getData && getData(feature);
let props = feature.properties;
adcode = props.adcode
let fillColor2
if(props.level == 'city'){
fillColor2 = null
}else{
fillColor2 = '#d0daee'
}
districtExplorer.loadAreaNode(adcode, (error, areaNode)=> {
//设置定位节点,支持鼠标位置识别
//注意节点的顺序,前面的高优先级
districtExplorer.setAreaNodesForLocating(areaNode);
//清除已有的绘制内容
districtExplorer.clearFeaturePolygons();
//绘制子区域
districtExplorer.renderSubFeatures(areaNode, (feature, i) =>{
let fillColor = colors[i % colors.length];
let strokeColor = colors[colors.length - 1 - i % colors.length];
return {
cursor: 'default',
bubble: true,
strokeColor: strokeColor, //线颜色
strokeOpacity: 1, //线透明度
strokeWeight: 1, //线宽
fillColor: fillColor, //填充色
fillOpacity: 0.5, //填充透明度
};
});
//绘制父区域
districtExplorer.renderParentFeature(areaNode, {
cursor: 'default',
bubble: true,
strokeColor: 'black', //线颜色
strokeOpacity: 1, //线透明度
strokeWeight: 1, //线宽
fillColor: fillColor2, //填充色
fillOpacity: 0.5, //填充透明度
});
// 更新地图视野以适合区划面
that.setFitView(districtExplorer.getAllFeaturePolygons());
});
});
districtExplorer.on('outsideClick', (e) => {
setData && setData(component);
let adcode = 310000
districtExplorer.loadAreaNode(adcode, (error, areaNode)=> {
//设置定位节点,支持鼠标位置识别
//注意节点的顺序,前面的高优先级
districtExplorer.setAreaNodesForLocating(areaNode);
//清除已有的绘制内容
districtExplorer.clearFeaturePolygons();
//绘制子区域
districtExplorer.renderSubFeatures(areaNode, (feature, i) =>{
let fillColor = colors[i % colors.length];
let strokeColor = colors[colors.length - 1 - i % colors.length];
return {
cursor: 'default',
bubble: true,
strokeColor: strokeColor, //线颜色
strokeOpacity: 1, //线透明度
strokeWeight: 1, //线宽
fillColor: fillColor, //填充色
fillOpacity: 0.5, //填充透明度
};
});
//绘制父区域
districtExplorer.renderParentFeature(areaNode, {
cursor: 'default',
bubble: true,
strokeColor: 'black', //线颜色
strokeOpacity: 1, //线透明度
strokeWeight: 1, //线宽
fillColor: null, //填充色
fillOpacity: 0.5, //填充透明度
});
// 更新地图视野以适合区划面
that.setFitView(districtExplorer.getAllFeaturePolygons());
districtExplorer.on('featureClick', (e, feature) => {
getData && getData.call(component, feature);
let props = feature.properties;
adcode = props.adcode
let fillColor2
if (props.level == 'city') {
fillColor2 = null
} else {
fillColor2 = '#d0daee'
}
districtExplorer.loadAreaNode(adcode, (error, areaNode) => {
//设置定位节点,支持鼠标位置识别
//注意节点的顺序,前面的高优先级
districtExplorer.setAreaNodesForLocating(areaNode);
//清除已有的绘制内容
districtExplorer.clearFeaturePolygons();
//绘制子区域
districtExplorer.renderSubFeatures(areaNode, (feature, i) => {
let fillColor = colors[i % colors.length];
let strokeColor = colors[colors.length - 1 - i % colors.length];
return {
cursor: 'default',
bubble: true,
strokeColor: strokeColor, //线颜色
strokeOpacity: 1, //线透明度
strokeWeight: 1, //线宽
fillColor: fillColor, //填充色
fillOpacity: 0.5, //填充透明度
};
});
//绘制父区域
districtExplorer.renderParentFeature(areaNode, {
cursor: 'default',
bubble: true,
strokeColor: 'black', //线颜色
strokeOpacity: 1, //线透明度
strokeWeight: 1, //线宽
fillColor: fillColor2, //填充色
fillOpacity: 0.5, //填充透明度
});
// 更新地图视野以适合区划面
that.setFitView(districtExplorer.getAllFeaturePolygons());
});
});
})
districtExplorer.on('outsideClick', (e) => {
setData && setData.call(component);
let adcode = 310000
districtExplorer.loadAreaNode(adcode, (error, areaNode) => {
//设置定位节点,支持鼠标位置识别
//注意节点的顺序,前面的高优先级
districtExplorer.setAreaNodesForLocating(areaNode);
//清除已有的绘制内容
districtExplorer.clearFeaturePolygons();
//绘制子区域
districtExplorer.renderSubFeatures(areaNode, (feature, i) => {
let fillColor = colors[i % colors.length];
let strokeColor = colors[colors.length - 1 - i % colors.length];
return {
cursor: 'default',
bubble: true,
strokeColor: strokeColor, //线颜色
strokeOpacity: 1, //线透明度
strokeWeight: 1, //线宽
fillColor: fillColor, //填充色
fillOpacity: 0.5, //填充透明度
};
});
//绘制父区域
districtExplorer.renderParentFeature(areaNode, {
cursor: 'default',
bubble: true,
strokeColor: 'black', //线颜色
strokeOpacity: 1, //线透明度
strokeWeight: 1, //线宽
fillColor: null, //填充色
fillOpacity: 0.5, //填充透明度
});
// 更新地图视野以适合区划面
that.setFitView(districtExplorer.getAllFeaturePolygons());
});
})
}
}); //end
}
}
@ -360,7 +360,7 @@ export class GaodePlaceSearch extends GaodeBasic implements IPlaceSearch {
this.self = new AMap.PlaceSearch()
}
search(text: string, callback: Function) {
return this.self.search(text,callback)
return this.self.search(text, callback)
}
}

Loading…
Cancel
Save