Merge pull request #103 from antvis/fix_stories

Fix(component): marker
This commit is contained in:
@thinkinggis 2019-11-28 17:52:14 +08:00 committed by GitHub
commit d6517ee62f
24 changed files with 219 additions and 143 deletions

View File

@ -40,7 +40,7 @@ new Layer(option)
## 鼠标事件 ## 鼠标事件
beta版当前不支持正式版会支持 ⚠️ beta版当前不支持正式版会支持
```javascript ```javascript
layer.on('click', (ev)=>{}); // 鼠标左键点击图层事件 layer.on('click', (ev)=>{}); // 鼠标左键点击图层事件
@ -319,4 +319,4 @@ layer.hide();
```javascript ```javascript
layer.fitBounds() layer.fitBounds()
``` ```

View File

@ -40,7 +40,7 @@ new Layer(option)
## 鼠标事件 ## 鼠标事件
beta版当前不支持正式版会支持 ⚠️ beta版当前不支持正式版会支持
```javascript ```javascript
layer.on('click', (ev)=>{}); // 鼠标左键点击图层事件 layer.on('click', (ev)=>{}); // 鼠标左键点击图层事件
@ -319,4 +319,4 @@ layer.hide();
```javascript ```javascript
layer.fitBounds() layer.fitBounds()
``` ```

View File

@ -39,18 +39,21 @@ order: 0
### 初始化 L7 Scene ### 初始化 L7 Scene
``` javascript
``` javascript ``` javascript
const scene = new L7.Scene({ const scene = new L7.Scene({
id: 'map', id: 'map',
style: 'dark', // 样式URL map: new L7.Mapbox({
center: [120.19382669582967, 30.258134], style: 'dark', // 样式URL
pitch: 0, center: [120.19382669582967, 30.258134],
zoom: 12, pitch: 0,
type:'mapbox', zoom: 12,
token: 'mapbox token' token: 'mapbox token',
}),
}); });
``` ```
这样我们就完成了通过L7 实例化mapbox地图 这样我们就完成了通过L7 实例化mapbox地图
@ -116,12 +119,13 @@ fetch('https://gw.alipayobjects.com/os/rmsportal/oVTMqfzuuRFKiDwhPSFL.json')
<script> <script>
const scene = new L7.Scene({ const scene = new L7.Scene({
id: 'map', id: 'map',
style: 'dark', // 样式URL map: new L7.Mapbox({
center: [120.19382669582967, 30.258134], style: 'dark', // 样式URL
pitch: 0, center: [120.19382669582967, 30.258134],
zoom: 12, pitch: 0,
type:'amap', zoom: 12,
token: 'mapbox token',
}),
}); });
fetch('https://gw.alipayobjects.com/os/rmsportal/oVTMqfzuuRFKiDwhPSFL.json') fetch('https://gw.alipayobjects.com/os/rmsportal/oVTMqfzuuRFKiDwhPSFL.json')

View File

@ -11,7 +11,8 @@ Current version: 2.0.0-beta.10
# 使用方法 # 使用方法
## 通过 L7 CDN 使用
## 通过L7 CDN 使用
Include the L7 JS JavaScript <head> of your HTML file. Include the L7 JS JavaScript <head> of your HTML file.
@ -33,9 +34,50 @@ Install the npm package.
```bash ```bash
// L7 依赖
npm install --save @antv/l7@beta npm install --save @antv/l7@beta
// 或者 // 第三方底图依赖
yarn add --save @antv/l7@beta npm install --save @antv/l7-maps;
``` ```
### 初始化地图
#### 使用 Mapbox 底图
```javascript
import { Scene, PointLayer } from '@antv/l7';
import { GaodeMap } from '@antv/l7-maps';
const scene = new Scene({
id: 'map',
map: new GaodeMap({
pitch: 35.210526315789465,
style: 'dark',
center: [ 104.288144, 31.239692 ],
zoom: 4.4
})
});
```
#### 使用Mapbox 底图
```javascript
import { Scene, HeatmapLayer } from '@antv/l7';
import { Mapbox } from '@antv/l7-maps';
const scene = new Scene({
id: 'map',
map: new Mapbox({
style: 'dark',
pitch: 0,
center: [ 127.5671666579043, 7.445038892195569 ],
zoom: 2.632456779444394
})
});
```

View File

@ -33,9 +33,50 @@ Install the npm package.
```bash ```bash
// L7 依赖
npm install --save @antv/l7@beta npm install --save @antv/l7@beta
// 或者 // 第三方底图依赖
yarn add --save @antv/l7@beta npm install --save @antv/l7-maps;
``` ```
### 初始化地图
#### 使用 Mapbox 底图
```javascript
import { Scene, PointLayer } from '@antv/l7';
import { GaodeMap } from '@antv/l7-maps';
const scene = new Scene({
id: 'map',
map: new GaodeMap({
pitch: 35.210526315789465,
style: 'dark',
center: [ 104.288144, 31.239692 ],
zoom: 4.4
})
});
```
#### 使用Mapbox 底图
```javascript
import { Scene, HeatmapLayer } from '@antv/l7';
import { Mapbox } from '@antv/l7-maps';
const scene = new Scene({
id: 'map',
map: new Mapbox({
style: 'dark',
pitch: 0,
center: [ 127.5671666579043, 7.445038892195569 ],
zoom: 2.632456779444394
})
});
```

View File

@ -11,10 +11,10 @@ const scene = new Scene({
zoom: 4.19 zoom: 4.19
}) })
}); });
addChart();
scene.render(); scene.render();
scene.on('loaded', () => {
addChart();
});
function addChart() { function addChart() {
fetch( fetch(
'https://gw.alipayobjects.com/os/basement_prod/0b96cca4-7e83-449a-93d0-2a77053e74ab.json' 'https://gw.alipayobjects.com/os/basement_prod/0b96cca4-7e83-449a-93d0-2a77053e74ab.json'
@ -67,14 +67,14 @@ function addChart() {
.color('item', [ '#5CCEA1', '#5D7092', '#5B8FF9' ]) .color('item', [ '#5CCEA1', '#5D7092', '#5B8FF9' ])
.opacity(1); .opacity(1);
chart.render(); chart.render();
new Marker({ const marker = new Marker({
element: el element: el
}) })
.setLnglat({ .setLnglat({
lng: item.coordinates[0], lng: item.coordinates[0],
lat: item.coordinates[1] lat: item.coordinates[1]
}) });
.addTo(scene); scene.addMarker(marker);
}); });
}); });
} }

View File

@ -11,10 +11,9 @@ const scene = new Scene({
zoom: 4.19 zoom: 4.19
}) })
}); });
addChart();
scene.render(); scene.render();
scene.on('loaded', () => {
addChart();
});
function addChart() { function addChart() {
fetch( fetch(
'https://gw.alipayobjects.com/os/basement_prod/0b96cca4-7e83-449a-93d0-2a77053e74ab.json' 'https://gw.alipayobjects.com/os/basement_prod/0b96cca4-7e83-449a-93d0-2a77053e74ab.json'
@ -89,14 +88,14 @@ function addChart() {
.color('item', [ '#5CCEA1', '#5D7092', '#5B8FF9' ]) .color('item', [ '#5CCEA1', '#5D7092', '#5B8FF9' ])
.shape('sliceShape'); .shape('sliceShape');
chart.render(); chart.render();
new Marker({ const marker = new Marker({
element: el element: el
}) })
.setLnglat({ .setLnglat({
lng: item.coordinates[0], lng: item.coordinates[0],
lat: item.coordinates[1] lat: item.coordinates[1]
}) });
.addTo(scene); scene.addMarker(marker);
}); });
}); });
} }

View File

@ -44,69 +44,66 @@ const scene = new Scene({
zoom: 3.802 zoom: 3.802
}) })
}); });
scene.render(); Promise.all([
scene.on('loaded', () => { fetch(
Promise.all([ 'https://gw.alipayobjects.com/os/basement_prod/5b772136-a1f4-4fc5-9a80-9f9974b4b182.json'
fetch( ).then(d => d.json()),
'https://gw.alipayobjects.com/os/basement_prod/5b772136-a1f4-4fc5-9a80-9f9974b4b182.json' fetch(
).then(d => d.json()), 'https://gw.alipayobjects.com/os/basement_prod/f3c467a4-9ae0-4f08-bb5f-11f9c869b2cb.json'
fetch( ).then(d => d.json())
'https://gw.alipayobjects.com/os/basement_prod/f3c467a4-9ae0-4f08-bb5f-11f9c869b2cb.json' ]).then(function onLoad([ center, population ]) {
).then(d => d.json()) const popobj = {};
]).then(function onLoad([ center, population ]) { population.forEach(element => {
const popobj = {}; popobj[element.Code] =
population.forEach(element => { element['Population, female (% of total) (% of total)'];
popobj[element.Code] = });
element['Population, female (% of total) (% of total)']; // 数据绑定
});
// 数据绑定
center.features = center.features.map(fe => { center.features = center.features.map(fe => {
fe.properties.female = popobj[fe.properties.id] * 1 || 0; fe.properties.female = popobj[fe.properties.id] * 1 || 0;
return fe; return fe;
});
center.features.forEach(point => {
const el = document.createElement('div');
const coord = point.geometry.coordinates;
const v = point.properties.female * 1;
if (v < 1 || (v > 46 && v < 54)) { return; }
const size = 60;
const data = [
{
type: '男性',
value: 100.0 - v.toFixed(2)
},
{
type: '女性',
value: v.toFixed(2) * 1
}
];
const chart = new G2.Chart({
container: el,
width: size,
height: size,
render: 'svg',
padding: 0
}); });
center.features.forEach(point => { chart.source(data);
const el = document.createElement('div'); chart.legend(false);
const coord = point.geometry.coordinates; chart.tooltip(false);
const v = point.properties.female * 1; chart.coord('theta', {
if (v < 1 || (v > 46 && v < 54)) { return; } radius: 0.9,
const size = 60; innerRadius: 0.6
const data = [
{
type: '男性',
value: 100.0 - v.toFixed(2)
},
{
type: '女性',
value: v.toFixed(2) * 1
}
];
const chart = new G2.Chart({
container: el,
width: size,
height: size,
render: 'svg',
padding: 0
});
chart.source(data);
chart.legend(false);
chart.tooltip(false);
chart.coord('theta', {
radius: 0.9,
innerRadius: 0.6
});
chart
.intervalStack()
.position('value')
.color('type', [ '#5CCEA1', '#5B8FF9' ])
.opacity(1);
chart.render();
new Marker({ element: el })
.setLnglat({
lng: coord[0],
lat: coord[1]
})
.addTo(scene);
}); });
chart
.intervalStack()
.position('value')
.color('type', [ '#5CCEA1', '#5B8FF9' ])
.opacity(1);
chart.render();
const marker = new Marker({ element: el })
.setLnglat({
lng: coord[0],
lat: coord[1]
});
scene.addMarker(marker);
}); });
}); });

View File

@ -10,10 +10,9 @@ const scene = new Scene({
zoom: 4 zoom: 4
}) })
}); });
addMarkers();
scene.render(); scene.render();
scene.on('loaded', () => {
addMarkers();
});
function addMarkers() { function addMarkers() {
fetch( fetch(
@ -28,11 +27,11 @@ function addMarkers() {
el.textContent = nodes[i].v + '℃'; el.textContent = nodes[i].v + '℃';
el.style.background = getColor(nodes[i].v); el.style.background = getColor(nodes[i].v);
el.style.borderColor = getColor(nodes[i].v); el.style.borderColor = getColor(nodes[i].v);
new Marker({ const marker = new Marker({
element: el element: el
}) })
.setLnglat({ lng: nodes[i].x * 1, lat: nodes[i].y }) .setLnglat({ lng: nodes[i].x * 1, lat: nodes[i].y });
.addTo(scene); scene.addMarker(marker);
} }
}); });
} }

View File

@ -1,8 +1,8 @@
import { Scene, Marker, Popup } from '@antv/l7'; import { Scene, Marker, Popup } from '@antv/l7';
import { GaodeMap } from '@antv/l7-maps'; import { Mapbox } from '@antv/l7-maps';
const scene = new Scene({ const scene = new Scene({
id: 'map', id: 'map',
map: new GaodeMap({ map: new Mapbox({
style: 'light', style: 'light',
pitch: 0, pitch: 0,
center: [ 121.4316962, 31.26082325 ], center: [ 121.4316962, 31.26082325 ],

View File

@ -33,7 +33,7 @@
"inversify-logging": "^0.2.1", "inversify-logging": "^0.2.1",
"load-styles": "^2.0.0" "load-styles": "^2.0.0"
}, },
"gitHead": "0563f357f3a07c099bf1ffa9350e6fa3c88353ae", "gitHead": "5360c93be63ef4d8d580ca9fafd8fb05cb5fbe30",
"publishConfig": { "publishConfig": {
"access": "public" "access": "public"
} }

View File

@ -43,7 +43,7 @@
"@types/lodash": "^4.14.138", "@types/lodash": "^4.14.138",
"@types/viewport-mercator-project": "^6.1.0" "@types/viewport-mercator-project": "^6.1.0"
}, },
"gitHead": "0563f357f3a07c099bf1ffa9350e6fa3c88353ae", "gitHead": "5360c93be63ef4d8d580ca9fafd8fb05cb5fbe30",
"publishConfig": { "publishConfig": {
"access": "public" "access": "public"
} }

View File

@ -11,11 +11,11 @@ export default class MarkerService implements IMarkerService {
private markers: IMarker[] = []; private markers: IMarker[] = [];
private unAddMarkers: IMarker[] = []; private unAddMarkers: IMarker[] = [];
public addMarker(marker: IMarker): void { public addMarker(marker: IMarker): void {
if (!this.mapsService.map) { if (!this.mapsService.map && this.mapsService.getMarkerContainer()) {
this.unAddMarkers.push(marker);
} else {
this.markers.push(marker); this.markers.push(marker);
marker.addTo(this.scene); marker.addTo(this.scene);
} else {
this.unAddMarkers.push(marker);
} }
} }
public addMarkers(): void { public addMarkers(): void {

View File

@ -29,7 +29,7 @@
"@antv/l7-maps": "^2.0.0-beta.11", "@antv/l7-maps": "^2.0.0-beta.11",
"@antv/l7-scene": "^2.0.0-beta.11" "@antv/l7-scene": "^2.0.0-beta.11"
}, },
"gitHead": "0563f357f3a07c099bf1ffa9350e6fa3c88353ae", "gitHead": "5360c93be63ef4d8d580ca9fafd8fb05cb5fbe30",
"publishConfig": { "publishConfig": {
"access": "public" "access": "public"
} }

View File

@ -49,7 +49,7 @@
"@types/gl-matrix": "^2.4.5", "@types/gl-matrix": "^2.4.5",
"@types/lodash": "^4.14.138" "@types/lodash": "^4.14.138"
}, },
"gitHead": "0563f357f3a07c099bf1ffa9350e6fa3c88353ae", "gitHead": "5360c93be63ef4d8d580ca9fafd8fb05cb5fbe30",
"publishConfig": { "publishConfig": {
"access": "public" "access": "public"
} }

View File

@ -36,7 +36,7 @@
"@types/mapbox-gl": "^0.54.3", "@types/mapbox-gl": "^0.54.3",
"@types/viewport-mercator-project": "^6.1.0" "@types/viewport-mercator-project": "^6.1.0"
}, },
"gitHead": "0563f357f3a07c099bf1ffa9350e6fa3c88353ae", "gitHead": "5360c93be63ef4d8d580ca9fafd8fb05cb5fbe30",
"publishConfig": { "publishConfig": {
"access": "public" "access": "public"
} }

View File

@ -30,7 +30,7 @@
"reflect-metadata": "^0.1.13", "reflect-metadata": "^0.1.13",
"regl": "^1.3.11" "regl": "^1.3.11"
}, },
"gitHead": "0563f357f3a07c099bf1ffa9350e6fa3c88353ae", "gitHead": "5360c93be63ef4d8d580ca9fafd8fb05cb5fbe30",
"publishConfig": { "publishConfig": {
"access": "public" "access": "public"
} }

View File

@ -32,7 +32,7 @@
"mapbox-gl": "^1.2.1", "mapbox-gl": "^1.2.1",
"reflect-metadata": "^0.1.13" "reflect-metadata": "^0.1.13"
}, },
"gitHead": "0563f357f3a07c099bf1ffa9350e6fa3c88353ae", "gitHead": "5360c93be63ef4d8d580ca9fafd8fb05cb5fbe30",
"publishConfig": { "publishConfig": {
"access": "public" "access": "public"
} }

View File

@ -49,7 +49,7 @@
"@types/lodash": "^4.14.138", "@types/lodash": "^4.14.138",
"@types/viewport-mercator-project": "^6.1.0" "@types/viewport-mercator-project": "^6.1.0"
}, },
"gitHead": "0563f357f3a07c099bf1ffa9350e6fa3c88353ae", "gitHead": "5360c93be63ef4d8d580ca9fafd8fb05cb5fbe30",
"publishConfig": { "publishConfig": {
"access": "public" "access": "public"
} }

View File

@ -36,7 +36,7 @@
"@types/gl-matrix": "^2.4.5", "@types/gl-matrix": "^2.4.5",
"@types/lodash": "^4.14.138" "@types/lodash": "^4.14.138"
}, },
"gitHead": "0563f357f3a07c099bf1ffa9350e6fa3c88353ae", "gitHead": "5360c93be63ef4d8d580ca9fafd8fb05cb5fbe30",
"publishConfig": { "publishConfig": {
"access": "public" "access": "public"
} }

View File

@ -1,6 +1,6 @@
// @ts-ignore // @ts-ignore
import { Marker, PolygonLayer, Scene } from '@antv/l7'; import { Marker, PolygonLayer, Scene } from '@antv/l7';
import { Mapbox } from '@antv/l7-maps'; import { Mapbox, GaodeMap } from '@antv/l7-maps';
import * as React from 'react'; import * as React from 'react';
export default class MarkerComponent extends React.Component { export default class MarkerComponent extends React.Component {
@ -18,7 +18,7 @@ export default class MarkerComponent extends React.Component {
const scene = new Scene({ const scene = new Scene({
id: 'map', id: 'map',
map: new Mapbox({ map: new Mapbox({
style: 'mapbox://styles/mapbox/streets-v9', style: 'dark',
center: [110.19382669582967, 30.258134], center: [110.19382669582967, 30.258134],
pitch: 0, pitch: 0,
zoom: 3, zoom: 3,
@ -43,14 +43,12 @@ export default class MarkerComponent extends React.Component {
opacity: 0.3, opacity: 0.3,
}); });
scene.addLayer(layer); scene.addLayer(layer);
scene.on('loaded', () => { const marker = new Marker().setLnglat({
new Marker() lng: 120.19382669582967,
.setLnglat({ lat: 30.258134,
lng: 120.19382669582967,
lat: 30.258134,
})
.addTo(scene);
}); });
scene.addMarker(marker);
} }
public render() { public render() {

View File

@ -43,17 +43,16 @@ export default class PopupComponent extends React.Component {
opacity: 0.3, opacity: 0.3,
}); });
scene.addLayer(layer); scene.addLayer(layer);
scene.on('loaded', () => { const popup = new Popup({
new Popup({ offsets: [0, 20],
offsets: [0, 20], })
.setLnglat({
lng: 120.19382669582967,
lat: 30.258134,
}) })
.setLnglat({ .setText('hello');
lng: 120.19382669582967, scene.addPopup(popup);
lat: 30.258134,
})
.setText('hello')
.addTo(scene);
});
} }
public render() { public render() {

View File

@ -43,10 +43,9 @@ export default class ScaleComponent extends React.Component {
opacity: 0.3, opacity: 0.3,
}); });
scene.addLayer(layer); scene.addLayer(layer);
scene.on('loaded', () => {
const scaleControl = new Scale(); const scaleControl = new Scale();
scene.addControl(scaleControl); scene.addControl(scaleControl);
});
} }
public render() { public render() {

View File

@ -44,12 +44,10 @@ export default class ZoomComponent extends React.Component {
opacity: 0.3, opacity: 0.3,
}); });
scene.addLayer(layer); scene.addLayer(layer);
scene.on('loaded', () => { const zoomControl = new Zoom({
const zoomControl = new Zoom({ position: 'bottomright',
position: 'bottomright',
});
scene.addControl(zoomControl);
}); });
scene.addControl(zoomControl);
} }
public render() { public render() {