mirror of https://gitee.com/antv-l7/antv-l7
fix: fix clusterMarker style
This commit is contained in:
parent
a439cf44e7
commit
0b7d3e1626
|
@ -50,8 +50,6 @@ scene.addMarkerLayer(markerLayer);
|
||||||
- point_min 聚合最小值 根据 field 和 method 计算
|
- point_min 聚合最小值 根据 field 和 method 计算
|
||||||
- point_mean 聚合平均值 根据 field 和 method 计算
|
- point_mean 聚合平均值 根据 field 和 method 计算
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
### 方法
|
### 方法
|
||||||
|
|
||||||
#### addMarker
|
#### addMarker
|
||||||
|
|
|
@ -7,7 +7,7 @@ import Supercluster from 'supercluster';
|
||||||
import Marker from './marker';
|
import Marker from './marker';
|
||||||
type CallBack = (...args: any[]) => any;
|
type CallBack = (...args: any[]) => any;
|
||||||
interface IMarkerStyleOption {
|
interface IMarkerStyleOption {
|
||||||
element: CallBack;
|
element?: CallBack;
|
||||||
style: { [key: string]: any } | CallBack;
|
style: { [key: string]: any } | CallBack;
|
||||||
className: string;
|
className: string;
|
||||||
field?: string;
|
field?: string;
|
||||||
|
@ -56,7 +56,6 @@ export default class MarkerLayer extends EventEmitter {
|
||||||
zoom: -99,
|
zoom: -99,
|
||||||
style: {},
|
style: {},
|
||||||
className: '',
|
className: '',
|
||||||
element: this.generateElement,
|
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -171,10 +170,10 @@ export default class MarkerLayer extends EventEmitter {
|
||||||
feature.properties[fieldName] = stat;
|
feature.properties[fieldName] = stat;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const marker =
|
const marker = this.clusterMarker(feature);
|
||||||
feature.properties && feature.properties.hasOwnProperty('point_count')
|
// feature.properties && feature.properties.hasOwnProperty('point_count')
|
||||||
? this.clusterMarker(feature)
|
// ? this.clusterMarker(feature)
|
||||||
: this.normalMarker(feature);
|
// : this.normalMarker(feature);
|
||||||
|
|
||||||
this.clusterMarkers.push(marker);
|
this.clusterMarkers.push(marker);
|
||||||
marker.addTo(this.scene);
|
marker.addTo(this.scene);
|
||||||
|
@ -193,7 +192,9 @@ export default class MarkerLayer extends EventEmitter {
|
||||||
private clusterMarker(feature: any) {
|
private clusterMarker(feature: any) {
|
||||||
const clusterOption = this.markerLayerOption.clusterOption;
|
const clusterOption = this.markerLayerOption.clusterOption;
|
||||||
|
|
||||||
const { element } = clusterOption as IMarkerStyleOption;
|
const {
|
||||||
|
element = this.generateElement.bind(this),
|
||||||
|
} = clusterOption as IMarkerStyleOption;
|
||||||
const marker = new Marker({
|
const marker = new Marker({
|
||||||
element: element(feature),
|
element: element(feature),
|
||||||
}).setLnglat({
|
}).setLnglat({
|
||||||
|
@ -204,12 +205,7 @@ export default class MarkerLayer extends EventEmitter {
|
||||||
}
|
}
|
||||||
private normalMarker(feature: any) {
|
private normalMarker(feature: any) {
|
||||||
const marker_id = feature.properties.marker_id;
|
const marker_id = feature.properties.marker_id;
|
||||||
return marker_id
|
return this.markers[marker_id];
|
||||||
? new Marker().setLnglat({
|
|
||||||
lng: feature.geometry.coordinates[0],
|
|
||||||
lat: feature.geometry.coordinates[1],
|
|
||||||
})
|
|
||||||
: this.markers[marker_id];
|
|
||||||
}
|
}
|
||||||
private update() {
|
private update() {
|
||||||
const zoom = this.mapsService.getZoom();
|
const zoom = this.mapsService.getZoom();
|
||||||
|
@ -222,11 +218,14 @@ export default class MarkerLayer extends EventEmitter {
|
||||||
const el = DOM.create('div', 'l7-marker-cluster');
|
const el = DOM.create('div', 'l7-marker-cluster');
|
||||||
const label = DOM.create('div', '', el);
|
const label = DOM.create('div', '', el);
|
||||||
const span = DOM.create('span', '', label);
|
const span = DOM.create('span', '', label);
|
||||||
span.textContent = feature.properties.point_count;
|
const { field, method } = this.markerLayerOption.clusterOption;
|
||||||
// if (className !== '') {
|
feature.properties.point_count = feature.properties.point_count || 1;
|
||||||
// DOM.addClass(el, className);
|
|
||||||
// }
|
const text =
|
||||||
// span.textContent = feature.properties.point_count;
|
field && method
|
||||||
|
? feature.properties['point_' + method] || feature.properties[field]
|
||||||
|
: feature.properties.point_count;
|
||||||
|
span.textContent = text;
|
||||||
// const elStyle = isFunction(style)
|
// const elStyle = isFunction(style)
|
||||||
// ? style(feature.properties.point_count)
|
// ? style(feature.properties.point_count)
|
||||||
// : style;
|
// : style;
|
||||||
|
|
|
@ -27,9 +27,9 @@ export default class LayerService implements ILayerService {
|
||||||
private readonly configService: IGlobalConfigService;
|
private readonly configService: IGlobalConfigService;
|
||||||
|
|
||||||
public add(layer: ILayer) {
|
public add(layer: ILayer) {
|
||||||
// if (this.sceneInited) {
|
if (this.sceneInited) {
|
||||||
// layer.init();
|
layer.init();
|
||||||
// }
|
}
|
||||||
this.layers.push(layer);
|
this.layers.push(layer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -213,7 +213,9 @@ export default class Scene extends EventEmitter implements ISceneService {
|
||||||
}
|
}
|
||||||
|
|
||||||
// 尝试初始化未初始化的图层
|
// 尝试初始化未初始化的图层
|
||||||
|
this.once('loaded', () => {
|
||||||
this.layerService.initLayers();
|
this.layerService.initLayers();
|
||||||
|
});
|
||||||
this.layerService.renderLayers();
|
this.layerService.renderLayers();
|
||||||
// 组件需要等待layer 初始化完成之后添加
|
// 组件需要等待layer 初始化完成之后添加
|
||||||
|
|
||||||
|
|
|
@ -56,7 +56,7 @@ let layerIdCounter = 0;
|
||||||
export default class BaseLayer<ChildLayerStyleOptions = {}> extends EventEmitter
|
export default class BaseLayer<ChildLayerStyleOptions = {}> extends EventEmitter
|
||||||
implements ILayer {
|
implements ILayer {
|
||||||
public id: string = `${layerIdCounter++}`;
|
public id: string = `${layerIdCounter++}`;
|
||||||
public name: string = `${layerIdCounter++}`;
|
public name: string = `${layerIdCounter}`;
|
||||||
public type: string;
|
public type: string;
|
||||||
public visible: boolean = true;
|
public visible: boolean = true;
|
||||||
public zIndex: number = 0;
|
public zIndex: number = 0;
|
||||||
|
|
|
@ -52,6 +52,7 @@ export default class ClusterMarkerLayer extends React.Component {
|
||||||
for (let i = 0; i < nodes.features.length; i++) {
|
for (let i = 0; i < nodes.features.length; i++) {
|
||||||
const { coordinates } = nodes.features[i].geometry;
|
const { coordinates } = nodes.features[i].geometry;
|
||||||
const marker = new Marker({
|
const marker = new Marker({
|
||||||
|
color: 'red',
|
||||||
extData: nodes.features[i].properties,
|
extData: nodes.features[i].properties,
|
||||||
}).setLnglat({
|
}).setLnglat({
|
||||||
lng: coordinates[0],
|
lng: coordinates[0],
|
||||||
|
|
Loading…
Reference in New Issue