mirror of https://gitee.com/antv-l7/antv-l7
docs(distrcit): add district demo
This commit is contained in:
parent
61e75d5479
commit
4f106d9e24
File diff suppressed because it is too large
Load Diff
|
@ -1,5 +1,4 @@
|
||||||
// tslint:disable-next-line:no-submodule-imports
|
// tslint:disable-next-line:no-submodule-imports
|
||||||
// import '!style-loader!css-loader!sass-loader!./iframe.scss';
|
|
||||||
import { addParameters, configure } from '@storybook/react';
|
import { addParameters, configure } from '@storybook/react';
|
||||||
import { create } from '@storybook/theming';
|
import { create } from '@storybook/theming';
|
||||||
|
|
||||||
|
|
|
@ -13,27 +13,23 @@ module.exports = ({ config }) => {
|
||||||
// options: { inline: true, fallback: false }
|
// options: { inline: true, fallback: false }
|
||||||
// }
|
// }
|
||||||
// });
|
// });
|
||||||
|
config.module.rules =[];
|
||||||
|
|
||||||
|
config.module.rules.push(
|
||||||
|
|
||||||
|
{
|
||||||
|
|
||||||
config.module.rules.push({
|
|
||||||
test: /\.(ts|tsx)$/,
|
test: /\.(ts|tsx)$/,
|
||||||
loader: require.resolve('awesome-typescript-loader'),
|
loader: require.resolve('awesome-typescript-loader'),
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
config.module.rules.push({
|
config.module.rules.push(
|
||||||
test: /\.stories\.tsx?$/,
|
{
|
||||||
// loaders: [
|
test: /.css$/,
|
||||||
// {
|
use: ["style-loader", "css-loader", 'sass-loader'],
|
||||||
// loader: require.resolve('@storybook/addon-storysource/loader'),
|
|
||||||
// options: { parser: 'typescript' },
|
|
||||||
// },
|
|
||||||
// ],
|
|
||||||
enforce: 'pre',
|
enforce: 'pre',
|
||||||
},{
|
|
||||||
test: /.css?$/,
|
|
||||||
include: [
|
|
||||||
path.resolve(__dirname, "../src"),
|
|
||||||
],
|
|
||||||
use: ["style-loader", "css-loader", "sass-loader"]
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
test: /\.stories\.svg$/,
|
test: /\.stories\.svg$/,
|
||||||
|
@ -41,7 +37,7 @@ module.exports = ({ config }) => {
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
config.resolve.extensions.push('.ts', '.tsx', '.js', '.glsl');
|
config.resolve.extensions.push('.ts', '.tsx', 'css', '.js', '.glsl');
|
||||||
|
|
||||||
return config;
|
return config;
|
||||||
};
|
};
|
||||||
|
|
|
@ -91,6 +91,7 @@
|
||||||
"react-docgen-typescript-loader": "^3.1.0",
|
"react-docgen-typescript-loader": "^3.1.0",
|
||||||
"react-dom": "^16.13.1",
|
"react-dom": "^16.13.1",
|
||||||
"react-i18next": "^11.0.1",
|
"react-i18next": "^11.0.1",
|
||||||
|
"react-scripts": "^3.4.1",
|
||||||
"rimraf": "^2.6.2",
|
"rimraf": "^2.6.2",
|
||||||
"rollup": "^1.27.14",
|
"rollup": "^1.27.14",
|
||||||
"rollup-plugin-analyzer": "^3.2.2",
|
"rollup-plugin-analyzer": "^3.2.2",
|
||||||
|
|
|
@ -17,6 +17,8 @@ import Pbf from 'pbf';
|
||||||
import { IDistrictLayerOption } from './interface';
|
import { IDistrictLayerOption } from './interface';
|
||||||
export default class BaseLayer {
|
export default class BaseLayer {
|
||||||
public fillLayer: ILayer;
|
public fillLayer: ILayer;
|
||||||
|
public lineLayer: ILayer;
|
||||||
|
public labelLayer: ILayer;
|
||||||
protected scene: Scene;
|
protected scene: Scene;
|
||||||
protected options: IDistrictLayerOption;
|
protected options: IDistrictLayerOption;
|
||||||
protected layers: ILayer[] = [];
|
protected layers: ILayer[] = [];
|
||||||
|
@ -134,9 +136,9 @@ export default class BaseLayer {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected addFillLine(provinceLine: any) {
|
protected addFillLine(provinceLine: any) {
|
||||||
const { stroke, strokeWidth } = this.options;
|
const { stroke, strokeWidth, zIndex } = this.options;
|
||||||
const layer2 = new LineLayer({
|
const layer2 = new LineLayer({
|
||||||
zIndex: 2,
|
zIndex: zIndex + 1,
|
||||||
})
|
})
|
||||||
.source(provinceLine)
|
.source(provinceLine)
|
||||||
.color(stroke)
|
.color(stroke)
|
||||||
|
@ -146,9 +148,10 @@ export default class BaseLayer {
|
||||||
});
|
});
|
||||||
this.scene.addLayer(layer2);
|
this.scene.addLayer(layer2);
|
||||||
this.layers.push(layer2);
|
this.layers.push(layer2);
|
||||||
|
this.lineLayer = layer2;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected addLableLayer(labelData: any, type: string = 'json') {
|
protected addLabelLayer(labelData: any, type: string = 'json') {
|
||||||
const { label, zIndex } = this.options;
|
const { label, zIndex } = this.options;
|
||||||
const labelLayer = new PointLayer({
|
const labelLayer = new PointLayer({
|
||||||
zIndex: zIndex + 2,
|
zIndex: zIndex + 2,
|
||||||
|
@ -170,6 +173,7 @@ export default class BaseLayer {
|
||||||
});
|
});
|
||||||
this.scene.addLayer(labelLayer);
|
this.scene.addLayer(labelLayer);
|
||||||
this.layers.push(labelLayer);
|
this.layers.push(labelLayer);
|
||||||
|
this.labelLayer = labelLayer;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected addPopup() {
|
protected addPopup() {
|
||||||
|
|
|
@ -8,19 +8,14 @@ import {
|
||||||
} from '@antv/l7';
|
} from '@antv/l7';
|
||||||
// tslint:disable-next-line: no-submodule-imports
|
// tslint:disable-next-line: no-submodule-imports
|
||||||
import merge from 'lodash/merge';
|
import merge from 'lodash/merge';
|
||||||
import { DataConfig } from '../config';
|
|
||||||
import BaseLayer from './baseLayer';
|
import { adcodeType, IDistrictLayerOption } from './interface';
|
||||||
import { IDistrictLayerOption } from './interface';
|
import ProvinceLayer from './province';
|
||||||
|
|
||||||
export interface IProvinceLayerOption extends IDistrictLayerOption {
|
export interface IProvinceLayerOption extends IDistrictLayerOption {
|
||||||
adcode: string[];
|
adcode: string[];
|
||||||
}
|
}
|
||||||
export default class CityLayer extends BaseLayer {
|
export default class CityLayer extends ProvinceLayer {
|
||||||
constructor(scene: Scene, option: Partial<IProvinceLayerOption> = {}) {
|
|
||||||
super(scene, option);
|
|
||||||
this.addCityFillLayer();
|
|
||||||
this.addCityLineLayer();
|
|
||||||
}
|
|
||||||
protected getdefaultOption(): IProvinceLayerOption {
|
protected getdefaultOption(): IProvinceLayerOption {
|
||||||
const config = super.getdefaultOption();
|
const config = super.getdefaultOption();
|
||||||
return merge({}, config, {
|
return merge({}, config, {
|
||||||
|
@ -28,25 +23,27 @@ export default class CityLayer extends BaseLayer {
|
||||||
depth: 3,
|
depth: 3,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
private async addCityFillLayer() {
|
protected filterData(data: any, adcode: adcodeType) {
|
||||||
const { depth, adcode } = this.options as IProvinceLayerOption;
|
const adcodeArray = Array.isArray(adcode) ? adcode : [adcode];
|
||||||
const countryConfig = DataConfig.country.CHN[depth];
|
const features = data.features.filter((fe: any) => {
|
||||||
const fillData = await this.fetchData(countryConfig.fill);
|
|
||||||
const data = fillData.features.filter((fe: any) => {
|
|
||||||
const code = fe.properties.adcode_cit;
|
const code = fe.properties.adcode_cit;
|
||||||
return adcode.indexOf('' + code) !== -1;
|
return (
|
||||||
|
adcodeArray.indexOf(code) !== -1 ||
|
||||||
|
adcodeArray.indexOf('' + code) !== -1
|
||||||
|
);
|
||||||
});
|
});
|
||||||
this.addFillLayer({ type: 'FeatureCollection', features: data });
|
return { type: 'FeatureCollection', features };
|
||||||
}
|
}
|
||||||
|
|
||||||
private async addCityLineLayer() {
|
protected filterLabelData(data: any, adcode: adcodeType) {
|
||||||
const { depth, adcode } = this.options as IProvinceLayerOption;
|
const adcodeArray = Array.isArray(adcode) ? adcode : [adcode];
|
||||||
const countryConfig = DataConfig.country.CHN[depth];
|
const features = data.filter((fe: any) => {
|
||||||
const fillData = await this.fetchData(countryConfig.line);
|
const code = fe.adcode_cit;
|
||||||
const data = fillData.features.filter((fe: any) => {
|
return (
|
||||||
const code = fe.properties.adcode_cit;
|
adcodeArray.indexOf(code) !== -1 ||
|
||||||
return adcode.indexOf(code) !== -1 || adcode.indexOf('' + code) !== -1;
|
adcodeArray.indexOf('' + code) !== -1
|
||||||
|
);
|
||||||
});
|
});
|
||||||
this.addFillLine({ type: 'FeatureCollection', features: data });
|
return features;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,7 +17,7 @@ export default class CountryLayer extends BaseLayer {
|
||||||
this.loadData().then(([fillData, fillLabel]) => {
|
this.loadData().then(([fillData, fillLabel]) => {
|
||||||
this.addFillLayer(fillData);
|
this.addFillLayer(fillData);
|
||||||
if (fillLabel && this.options.label?.enable) {
|
if (fillLabel && this.options.label?.enable) {
|
||||||
this.addLableLayer(fillLabel);
|
this.addLabelLayer(fillLabel);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
const countryConfig = DataConfig.country.CHN[depth];
|
const countryConfig = DataConfig.country.CHN[depth];
|
||||||
|
|
|
@ -1,19 +1,13 @@
|
||||||
import { Scene } from '@antv/l7';
|
import { Scene } from '@antv/l7';
|
||||||
// tslint:disable-next-line: no-submodule-imports
|
// tslint:disable-next-line: no-submodule-imports
|
||||||
import merge from 'lodash/merge';
|
import merge from 'lodash/merge';
|
||||||
import { DataConfig } from '../config';
|
import { adcodeType, IDistrictLayerOption } from './interface';
|
||||||
import BaseLayer from './baseLayer';
|
import ProvinceLayer from './province';
|
||||||
import { IDistrictLayerOption } from './interface';
|
|
||||||
|
|
||||||
export interface IProvinceLayerOption extends IDistrictLayerOption {
|
export interface IProvinceLayerOption extends IDistrictLayerOption {
|
||||||
adcode: string[];
|
adcode: string[];
|
||||||
}
|
}
|
||||||
export default class CityLayer extends BaseLayer {
|
export default class CityLayer extends ProvinceLayer {
|
||||||
constructor(scene: Scene, option: Partial<IProvinceLayerOption> = {}) {
|
|
||||||
super(scene, option);
|
|
||||||
this.addCountyFillLayer();
|
|
||||||
this.addCountyLineLayer();
|
|
||||||
}
|
|
||||||
protected getdefaultOption(): IProvinceLayerOption {
|
protected getdefaultOption(): IProvinceLayerOption {
|
||||||
const config = super.getdefaultOption();
|
const config = super.getdefaultOption();
|
||||||
return merge({}, config, {
|
return merge({}, config, {
|
||||||
|
@ -21,25 +15,27 @@ export default class CityLayer extends BaseLayer {
|
||||||
depth: 3,
|
depth: 3,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
private async addCountyFillLayer() {
|
protected filterData(data: any, adcode: adcodeType) {
|
||||||
const { depth, adcode } = this.options as IProvinceLayerOption;
|
const adcodeArray = Array.isArray(adcode) ? adcode : [adcode];
|
||||||
const countryConfig = DataConfig.country.CHN[depth];
|
const features = data.features.filter((fe: any) => {
|
||||||
const fillData = await this.fetchData(countryConfig.fill);
|
|
||||||
const data = fillData.features.filter((fe: any) => {
|
|
||||||
const code = fe.properties.adcode;
|
const code = fe.properties.adcode;
|
||||||
return adcode.indexOf('' + code) !== -1;
|
return (
|
||||||
|
adcodeArray.indexOf(code) !== -1 ||
|
||||||
|
adcodeArray.indexOf('' + code) !== -1
|
||||||
|
);
|
||||||
});
|
});
|
||||||
this.addFillLayer({ type: 'FeatureCollection', features: data });
|
return { type: 'FeatureCollection', features };
|
||||||
}
|
}
|
||||||
|
|
||||||
private async addCountyLineLayer() {
|
protected filterLabelData(data: any, adcode: adcodeType) {
|
||||||
const { depth, adcode } = this.options as IProvinceLayerOption;
|
const adcodeArray = Array.isArray(adcode) ? adcode : [adcode];
|
||||||
const countryConfig = DataConfig.country.CHN[depth];
|
const features = data.filter((fe: any) => {
|
||||||
const fillData = await this.fetchData(countryConfig.line);
|
const code = fe.adcode;
|
||||||
const data = fillData.features.filter((fe: any) => {
|
return (
|
||||||
const code = fe.properties.adcode;
|
adcodeArray.indexOf(code) !== -1 ||
|
||||||
return adcode.indexOf(code) !== -1 || adcode.indexOf('' + code) !== -1;
|
adcodeArray.indexOf('' + code) !== -1
|
||||||
|
);
|
||||||
});
|
});
|
||||||
this.addFillLine({ type: 'FeatureCollection', features: data });
|
return features;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,6 +9,7 @@ export interface ILabelOption {
|
||||||
textAllowOverlap: boolean;
|
textAllowOverlap: boolean;
|
||||||
opacity: number;
|
opacity: number;
|
||||||
}
|
}
|
||||||
|
export type adcodeType = string[] | string | number | number[];
|
||||||
export interface IDistrictLayerOption {
|
export interface IDistrictLayerOption {
|
||||||
zIndex: number;
|
zIndex: number;
|
||||||
data?: Array<{ [key: string]: any }>;
|
data?: Array<{ [key: string]: any }>;
|
||||||
|
|
|
@ -10,43 +10,91 @@ import {
|
||||||
import merge from 'lodash/merge';
|
import merge from 'lodash/merge';
|
||||||
import { DataConfig } from '../config';
|
import { DataConfig } from '../config';
|
||||||
import BaseLayer from './baseLayer';
|
import BaseLayer from './baseLayer';
|
||||||
import { IDistrictLayerOption } from './interface';
|
import { adcodeType, IDistrictLayerOption } from './interface';
|
||||||
|
|
||||||
export interface IProvinceLayerOption extends IDistrictLayerOption {
|
export interface IProvinceLayerOption extends IDistrictLayerOption {
|
||||||
adcode: string[];
|
adcode: adcodeType;
|
||||||
}
|
}
|
||||||
export default class ProvinceLayer extends BaseLayer {
|
export default class ProvinceLayer extends BaseLayer {
|
||||||
|
private fillData: any;
|
||||||
|
private lineData: any;
|
||||||
|
private labelData: any;
|
||||||
constructor(scene: Scene, option: Partial<IProvinceLayerOption> = {}) {
|
constructor(scene: Scene, option: Partial<IProvinceLayerOption> = {}) {
|
||||||
super(scene, option);
|
super(scene, option);
|
||||||
this.addProvinceFillLayer();
|
this.addProvinceFillLayer();
|
||||||
this.addProvinceLineLayer();
|
this.addProvinceLineLayer();
|
||||||
}
|
}
|
||||||
|
// 通过adcode 更新
|
||||||
|
public updateDistrict(adcode: adcodeType) {
|
||||||
|
const fillData = this.filterData(this.fillData, adcode);
|
||||||
|
const lineData = this.filterData(this.lineData, adcode);
|
||||||
|
const labelData = this.filterLabelData(this.labelData, adcode);
|
||||||
|
this.fillLayer.setData(fillData);
|
||||||
|
this.lineLayer.setData(lineData);
|
||||||
|
this.labelLayer.setData(labelData);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 更新渲染数据
|
||||||
|
|
||||||
|
public updateData() {
|
||||||
|
return 'update data';
|
||||||
|
}
|
||||||
|
|
||||||
protected getdefaultOption(): IProvinceLayerOption {
|
protected getdefaultOption(): IProvinceLayerOption {
|
||||||
const config = super.getdefaultOption();
|
const config = super.getdefaultOption();
|
||||||
return merge({}, config, {
|
return merge({}, config, {
|
||||||
adcode: ['440000'],
|
adcode: ['110000'],
|
||||||
depth: 2,
|
depth: 2,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected filterData(data: any, adcode: adcodeType) {
|
||||||
|
const adcodeArray = Array.isArray(adcode) ? adcode : [adcode];
|
||||||
|
const features = data.features.filter((fe: any) => {
|
||||||
|
const code = fe.properties.adcode_pro;
|
||||||
|
return (
|
||||||
|
adcodeArray.indexOf(code) !== -1 ||
|
||||||
|
adcodeArray.indexOf('' + code) !== -1
|
||||||
|
);
|
||||||
|
});
|
||||||
|
return { type: 'FeatureCollection', features };
|
||||||
|
}
|
||||||
|
|
||||||
|
protected filterLabelData(data: any, adcode: adcodeType) {
|
||||||
|
const adcodeArray = Array.isArray(adcode) ? adcode : [adcode];
|
||||||
|
const features = data.filter((fe: any) => {
|
||||||
|
const code = fe.adcode_pro;
|
||||||
|
return (
|
||||||
|
adcodeArray.indexOf(code) !== -1 ||
|
||||||
|
adcodeArray.indexOf('' + code) !== -1
|
||||||
|
);
|
||||||
|
});
|
||||||
|
return features;
|
||||||
|
}
|
||||||
private async addProvinceFillLayer() {
|
private async addProvinceFillLayer() {
|
||||||
const { depth, adcode } = this.options as IProvinceLayerOption;
|
const { depth, adcode } = this.options as IProvinceLayerOption;
|
||||||
const countryConfig = DataConfig.country.CHN[depth];
|
const countryConfig = DataConfig.country.CHN[depth];
|
||||||
const fillData = await this.fetchData(countryConfig.fill);
|
const fillData = await this.fetchData(countryConfig.fill);
|
||||||
const data = fillData.features.filter((fe: any) => {
|
|
||||||
const code = fe.properties.adcode_pro;
|
this.labelData = fillData.features.map((feature: any) => {
|
||||||
return adcode.indexOf('' + code) !== -1;
|
return {
|
||||||
|
...feature.properties,
|
||||||
|
center: [feature.properties.x, feature.properties.y],
|
||||||
|
};
|
||||||
});
|
});
|
||||||
this.addFillLayer({ type: 'FeatureCollection', features: data });
|
const data = this.filterData(fillData, adcode);
|
||||||
|
const labelData = this.filterLabelData(this.labelData, adcode);
|
||||||
|
this.fillData = fillData;
|
||||||
|
this.addFillLayer(data);
|
||||||
|
this.addLabelLayer(labelData);
|
||||||
}
|
}
|
||||||
|
|
||||||
private async addProvinceLineLayer() {
|
private async addProvinceLineLayer() {
|
||||||
const { depth, adcode } = this.options as IProvinceLayerOption;
|
const { depth, adcode } = this.options as IProvinceLayerOption;
|
||||||
const countryConfig = DataConfig.country.CHN[depth];
|
const countryConfig = DataConfig.country.CHN[depth];
|
||||||
const fillData = await this.fetchData(countryConfig.line);
|
const fillData = await this.fetchData(countryConfig.line);
|
||||||
const data = fillData.features.filter((fe: any) => {
|
const data = this.filterData(fillData, adcode);
|
||||||
const code = fe.properties.adcode_pro;
|
this.lineData = fillData;
|
||||||
return adcode.indexOf(code) !== -1 || adcode.indexOf('' + code) !== -1;
|
this.addFillLine(data);
|
||||||
});
|
|
||||||
this.addFillLine({ type: 'FeatureCollection', features: data });
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,7 +17,7 @@ export default class WorldLayer extends BaseLayer {
|
||||||
this.addFillLayer(fillData);
|
this.addFillLayer(fillData);
|
||||||
this.addFillLine(lineData);
|
this.addFillLine(lineData);
|
||||||
if (this.options.label?.enable) {
|
if (this.options.label?.enable) {
|
||||||
this.addLableLayer(fillLabel, 'geojson');
|
this.addLabelLayer(fillLabel, 'geojson');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,7 +21,7 @@ void main() {
|
||||||
// float blur = smoothstep(1.0, u_blur, length(v_normal.xy));
|
// float blur = smoothstep(1.0, u_blur, length(v_normal.xy));
|
||||||
gl_FragColor.a *= u_opacity;
|
gl_FragColor.a *= u_opacity;
|
||||||
if(u_line_type == LineTypeDash) {
|
if(u_line_type == LineTypeDash) {
|
||||||
gl_FragColor.a *= blur * (1.0- step(v_dash_array.x, mod(v_distance_ratio, v_dash_array.x +v_dash_array.y)));
|
gl_FragColor.a *= (1.0- step(v_dash_array.x, mod(v_distance_ratio, v_dash_array.x +v_dash_array.y)));
|
||||||
}
|
}
|
||||||
|
|
||||||
if(u_aimate.x == Animate) {
|
if(u_aimate.x == Animate) {
|
||||||
|
|
|
@ -1,17 +1,29 @@
|
||||||
import { Scene } from '@antv/l7';
|
import { Scene } from '@antv/l7';
|
||||||
import { CityLayer } from '@antv/l7-district';
|
import { CityLayer } from '@antv/l7-district';
|
||||||
import { GaodeMap, Mapbox } from '@antv/l7-maps';
|
import { GaodeMap, Mapbox } from '@antv/l7-maps';
|
||||||
|
import { Cascader } from 'antd';
|
||||||
import * as React from 'react';
|
import * as React from 'react';
|
||||||
|
|
||||||
export default class Country extends React.Component {
|
export default class Country extends React.Component {
|
||||||
|
public state = {
|
||||||
|
options: [],
|
||||||
|
};
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
private scene: Scene;
|
private scene: Scene;
|
||||||
|
private cityLayer: CityLayer;
|
||||||
|
|
||||||
public componentWillUnmount() {
|
public componentWillUnmount() {
|
||||||
this.scene.destroy();
|
this.scene.destroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
public async componentDidMount() {
|
public async componentDidMount() {
|
||||||
|
const res = await fetch(
|
||||||
|
'https://gw.alipayobjects.com/os/bmw-prod/551e3ca6-6dad-421b-a8b4-b225e47f73ca.json',
|
||||||
|
);
|
||||||
|
const options = await res.json();
|
||||||
|
this.setState({
|
||||||
|
options,
|
||||||
|
});
|
||||||
const scene = new Scene({
|
const scene = new Scene({
|
||||||
id: 'map',
|
id: 'map',
|
||||||
map: new Mapbox({
|
map: new Mapbox({
|
||||||
|
@ -24,10 +36,14 @@ export default class Country extends React.Component {
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
scene.on('loaded', () => {
|
scene.on('loaded', () => {
|
||||||
const Layer = new CityLayer(scene, {
|
this.cityLayer = new CityLayer(scene, {
|
||||||
data: [],
|
data: [],
|
||||||
adcode: ['540200', '110100'],
|
adcode: ['110100'],
|
||||||
depth: 3,
|
depth: 3,
|
||||||
|
label: {
|
||||||
|
field: 'NAME_CHN',
|
||||||
|
textAllowOverlap: false,
|
||||||
|
},
|
||||||
fill: {
|
fill: {
|
||||||
field: 'NAME_CHN',
|
field: 'NAME_CHN',
|
||||||
values: [
|
values: [
|
||||||
|
@ -52,16 +68,34 @@ export default class Country extends React.Component {
|
||||||
|
|
||||||
public render() {
|
public render() {
|
||||||
return (
|
return (
|
||||||
<div
|
<>
|
||||||
id="map"
|
<Cascader
|
||||||
style={{
|
style={{
|
||||||
position: 'absolute',
|
width: 200,
|
||||||
top: 0,
|
zIndex: 2,
|
||||||
left: 0,
|
position: 'absolute',
|
||||||
right: 0,
|
right: '10px',
|
||||||
bottom: 0,
|
top: '10px',
|
||||||
}}
|
}}
|
||||||
/>
|
options={this.state.options}
|
||||||
|
defaultValue={['110000', '110100']}
|
||||||
|
onChange={this.handleProvinceChange}
|
||||||
|
placeholder="Please select"
|
||||||
|
/>
|
||||||
|
<div
|
||||||
|
id="map"
|
||||||
|
style={{
|
||||||
|
position: 'absolute',
|
||||||
|
top: 0,
|
||||||
|
left: 0,
|
||||||
|
right: 0,
|
||||||
|
bottom: 0,
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
private handleProvinceChange = (value: string[]) => {
|
||||||
|
this.cityLayer.updateDistrict([value[1]]);
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,17 +1,28 @@
|
||||||
import { Scene } from '@antv/l7';
|
import { Scene } from '@antv/l7';
|
||||||
import { CountyLayer } from '@antv/l7-district';
|
import { CountyLayer } from '@antv/l7-district';
|
||||||
import { GaodeMap, Mapbox } from '@antv/l7-maps';
|
import { GaodeMap, Mapbox } from '@antv/l7-maps';
|
||||||
|
import { Cascader } from 'antd';
|
||||||
import * as React from 'react';
|
import * as React from 'react';
|
||||||
|
|
||||||
export default class Country extends React.Component {
|
export default class Country extends React.Component {
|
||||||
|
public state = {
|
||||||
|
options: [],
|
||||||
|
};
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
private scene: Scene;
|
private scene: Scene;
|
||||||
|
private countyLayer: CountyLayer;
|
||||||
|
|
||||||
public componentWillUnmount() {
|
public componentWillUnmount() {
|
||||||
this.scene.destroy();
|
this.scene.destroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
public async componentDidMount() {
|
public async componentDidMount() {
|
||||||
|
const res = await fetch(
|
||||||
|
'https://gw.alipayobjects.com/os/bmw-prod/04de56cc-5998-4f7e-9ad3-e87e9ac5fd39.json',
|
||||||
|
);
|
||||||
|
const options = await res.json();
|
||||||
|
this.setState({
|
||||||
|
options,
|
||||||
|
});
|
||||||
const scene = new Scene({
|
const scene = new Scene({
|
||||||
id: 'map',
|
id: 'map',
|
||||||
map: new Mapbox({
|
map: new Mapbox({
|
||||||
|
@ -24,10 +35,13 @@ export default class Country extends React.Component {
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
scene.on('loaded', () => {
|
scene.on('loaded', () => {
|
||||||
const Layer = new CountyLayer(scene, {
|
this.countyLayer = new CountyLayer(scene, {
|
||||||
data: [],
|
data: [],
|
||||||
adcode: ['110101', '110102'],
|
adcode: ['110101'],
|
||||||
depth: 3,
|
depth: 3,
|
||||||
|
label: {
|
||||||
|
field: 'NAME_CHN',
|
||||||
|
},
|
||||||
fill: {
|
fill: {
|
||||||
field: 'NAME_CHN',
|
field: 'NAME_CHN',
|
||||||
values: [
|
values: [
|
||||||
|
@ -52,16 +66,35 @@ export default class Country extends React.Component {
|
||||||
|
|
||||||
public render() {
|
public render() {
|
||||||
return (
|
return (
|
||||||
<div
|
<>
|
||||||
id="map"
|
<Cascader
|
||||||
style={{
|
style={{
|
||||||
position: 'absolute',
|
width: 200,
|
||||||
top: 0,
|
zIndex: 2,
|
||||||
left: 0,
|
position: 'absolute',
|
||||||
right: 0,
|
right: '10px',
|
||||||
bottom: 0,
|
top: '10px',
|
||||||
}}
|
}}
|
||||||
/>
|
options={this.state.options}
|
||||||
|
defaultValue={['110000', '110100', '110101']}
|
||||||
|
onChange={this.handleProvinceChange}
|
||||||
|
placeholder="Please select"
|
||||||
|
/>
|
||||||
|
<div
|
||||||
|
id="map"
|
||||||
|
style={{
|
||||||
|
position: 'absolute',
|
||||||
|
top: 0,
|
||||||
|
left: 0,
|
||||||
|
right: 0,
|
||||||
|
bottom: 0,
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private handleProvinceChange = (value: string[]) => {
|
||||||
|
this.countyLayer.updateDistrict([value[2]]);
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,14 +1,155 @@
|
||||||
import { Scene } from '@antv/l7';
|
import { Scene } from '@antv/l7';
|
||||||
import { ProvinceLayer } from '@antv/l7-district';
|
import { ProvinceLayer } from '@antv/l7-district';
|
||||||
import { GaodeMap, Mapbox } from '@antv/l7-maps';
|
import { GaodeMap, Mapbox } from '@antv/l7-maps';
|
||||||
import 'antd/dist/antd.css';
|
// tslint:disable-next-line:no-submodule-imports
|
||||||
import { Select } from 'antd';
|
import { Select } from 'antd';
|
||||||
import * as React from 'react';
|
import * as React from 'react';
|
||||||
const { Option } = Select;
|
const { Option } = Select;
|
||||||
|
const ProvinceData = [
|
||||||
|
{
|
||||||
|
NAME_CHN: '云南省',
|
||||||
|
adcode: 530000,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
NAME_CHN: '黑龙江省',
|
||||||
|
adcode: 230000,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
NAME_CHN: '贵州省',
|
||||||
|
adcode: 520000,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
NAME_CHN: '北京市',
|
||||||
|
adcode: 110000,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
NAME_CHN: '河北省',
|
||||||
|
adcode: 130000,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
NAME_CHN: '山西省',
|
||||||
|
adcode: 140000,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
NAME_CHN: '吉林省',
|
||||||
|
adcode: 220000,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
NAME_CHN: '宁夏回族自治区',
|
||||||
|
adcode: 640000,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
NAME_CHN: '辽宁省',
|
||||||
|
adcode: 210000,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
NAME_CHN: '海南省',
|
||||||
|
adcode: 460000,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
NAME_CHN: '内蒙古自治区',
|
||||||
|
adcode: 150000,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
NAME_CHN: '天津市',
|
||||||
|
adcode: 120000,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
NAME_CHN: '新疆维吾尔自治区',
|
||||||
|
adcode: 650000,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
NAME_CHN: '上海市',
|
||||||
|
adcode: 310000,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
NAME_CHN: '陕西省',
|
||||||
|
adcode: 610000,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
NAME_CHN: '甘肃省',
|
||||||
|
adcode: 620000,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
NAME_CHN: '安徽省',
|
||||||
|
adcode: 340000,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
NAME_CHN: '香港特别行政区',
|
||||||
|
adcode: 810000,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
NAME_CHN: '广东省',
|
||||||
|
adcode: 440000,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
NAME_CHN: '河南省',
|
||||||
|
adcode: 410000,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
NAME_CHN: '湖南省',
|
||||||
|
adcode: 430000,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
NAME_CHN: '江西省',
|
||||||
|
adcode: 360000,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
NAME_CHN: '四川省',
|
||||||
|
adcode: 510000,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
NAME_CHN: '广西壮族自治区',
|
||||||
|
adcode: 450000,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
NAME_CHN: '江苏省',
|
||||||
|
adcode: 320000,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
NAME_CHN: '澳门特别行政区',
|
||||||
|
adcode: 820000,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
NAME_CHN: '浙江省',
|
||||||
|
adcode: 330000,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
NAME_CHN: '山东省',
|
||||||
|
adcode: 370000,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
NAME_CHN: '青海省',
|
||||||
|
adcode: 630000,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
NAME_CHN: '重庆市',
|
||||||
|
adcode: 500000,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
NAME_CHN: '福建省',
|
||||||
|
adcode: 350000,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
NAME_CHN: '湖北省',
|
||||||
|
adcode: 420000,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
NAME_CHN: '西藏自治区',
|
||||||
|
adcode: 540000,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
NAME_CHN: '台湾省',
|
||||||
|
adcode: 710000,
|
||||||
|
},
|
||||||
|
];
|
||||||
export default class Country extends React.Component {
|
export default class Country extends React.Component {
|
||||||
|
public state = {
|
||||||
|
province: '110000',
|
||||||
|
};
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
private scene: Scene;
|
private scene: Scene;
|
||||||
|
private provinceLayer: ProvinceLayer;
|
||||||
public componentWillUnmount() {
|
public componentWillUnmount() {
|
||||||
this.scene.destroy();
|
this.scene.destroy();
|
||||||
}
|
}
|
||||||
|
@ -25,11 +166,17 @@ export default class Country extends React.Component {
|
||||||
maxZoom: 10,
|
maxZoom: 10,
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
|
|
||||||
scene.on('loaded', () => {
|
scene.on('loaded', () => {
|
||||||
const Layer = new ProvinceLayer(scene, {
|
const { province } = this.state;
|
||||||
|
this.provinceLayer = new ProvinceLayer(scene, {
|
||||||
data: [],
|
data: [],
|
||||||
adcode: ['440000', '110000'],
|
adcode: [province],
|
||||||
depth: 1,
|
depth: 3,
|
||||||
|
label: {
|
||||||
|
field: 'NAME_CHN',
|
||||||
|
textAllowOverlap: false,
|
||||||
|
},
|
||||||
fill: {
|
fill: {
|
||||||
field: 'NAME_CHN',
|
field: 'NAME_CHN',
|
||||||
values: [
|
values: [
|
||||||
|
@ -55,10 +202,24 @@ export default class Country extends React.Component {
|
||||||
public render() {
|
public render() {
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<Select defaultValue="lucy" style={{ width: 120 }}>
|
<Select
|
||||||
<Option value="jack">Jack</Option>
|
defaultValue="北京市"
|
||||||
<Option value="lucy">Lucy</Option>
|
style={{
|
||||||
<Option value="Yiminghe">yiminghe</Option>
|
width: 120,
|
||||||
|
zIndex: 2,
|
||||||
|
position: 'absolute',
|
||||||
|
right: '10px',
|
||||||
|
top: '10px',
|
||||||
|
}}
|
||||||
|
onChange={this.handleProvinceChange}
|
||||||
|
>
|
||||||
|
{ProvinceData.map((province, i) => {
|
||||||
|
return (
|
||||||
|
<Option key={i} value={province.adcode}>
|
||||||
|
{province.NAME_CHN}
|
||||||
|
</Option>
|
||||||
|
);
|
||||||
|
})}
|
||||||
</Select>
|
</Select>
|
||||||
<div
|
<div
|
||||||
id="map"
|
id="map"
|
||||||
|
@ -73,4 +234,11 @@ export default class Country extends React.Component {
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private handleProvinceChange = (value: string) => {
|
||||||
|
this.setState({
|
||||||
|
province: value,
|
||||||
|
});
|
||||||
|
this.provinceLayer.updateDistrict([value]);
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import { storiesOf } from '@storybook/react';
|
import { storiesOf } from '@storybook/react';
|
||||||
|
require('./../assets/css/antd.css');
|
||||||
import * as React from 'react';
|
import * as React from 'react';
|
||||||
import City from './Layer/city';
|
import City from './Layer/city';
|
||||||
import Country from './Layer/Country';
|
import Country from './Layer/Country';
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue