Skip to content

Commit

Permalink
[fix]添加多个动态图层,改其中一个样式,所有都会变 review by qiw
Browse files Browse the repository at this point in the history
  • Loading branch information
luoxiao-supermap committed Nov 12, 2024
1 parent 21f5315 commit 60b11f4
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ describe('AnimateMarkerLayer.vue', () => {
});
await mapSubComponentLoaded(wrapper);
expect(wrapper.vm.mapTarget).toBe('map');
expect(wrapper.vm.viewModel.markersElement[0].className.includes('smanimatemarkerlayer-')).toBe(true);
done();
});

Expand All @@ -99,6 +100,7 @@ describe('AnimateMarkerLayer.vue', () => {
});
await mapSubComponentLoaded(wrapper);
expect(wrapper.vm.mapTarget).toBe('map');
expect(wrapper.vm.viewModel.markersElement[0].className.includes('smanimatemarkerlayer-')).toBe(true);
done();
});

Expand All @@ -116,6 +118,7 @@ describe('AnimateMarkerLayer.vue', () => {
});
await mapSubComponentLoaded(wrapper);
expect(wrapper.vm.mapTarget).toBe('map');
expect(wrapper.vm.viewModel.markersElement[0].className.includes('smanimatemarkerlayer-')).toBe(true);
done();
});

Expand All @@ -133,6 +136,7 @@ describe('AnimateMarkerLayer.vue', () => {
});
await mapSubComponentLoaded(wrapper);
expect(wrapper.vm.mapTarget).toBe('map');
expect(wrapper.vm.viewModel.markersElement[0].className.includes('smanimatemarkerlayer-')).toBe(true);
done();
});

Expand All @@ -150,6 +154,7 @@ describe('AnimateMarkerLayer.vue', () => {
});
await mapSubComponentLoaded(wrapper);
expect(wrapper.vm.mapTarget).toBe('map');
expect(wrapper.vm.viewModel.markersElement[0].className.includes('smanimatemarkerlayer-')).toBe(true);
done();
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ export default class BreathingApertureMarker extends Marker {

public setMarkersWidth(width: number): void {
this.options.width = width;
let pulse = document.getElementsByClassName('sm-component-animate-marker__pulse');
let pulse = document.querySelectorAll(`.${this.uuid} .sm-component-animate-marker__pulse`);

for (let i = 0; i < pulse.length; i++) {
// @ts-ignore
this._setBreathingApertureWidth(pulse[i].style);
Expand All @@ -27,12 +28,12 @@ export default class BreathingApertureMarker extends Marker {
public setMarkersColors(colors: [string, string]): void {
this.options.colors = colors;
if (colors && colors.length && colors.length > 0) {
let dot = document.getElementsByClassName('sm-component-animate-marker__dot-point');
let dot = document.querySelectorAll(`.${this.uuid} .sm-component-animate-marker__dot-point`);
for (let i = 0; i < dot.length; i++) {
// @ts-ignore
dot[i].style.background = this.options.colors[0];
}
let pulse = document.getElementsByClassName('sm-component-animate-marker__pulse');
let pulse = document.querySelectorAll(`.${this.uuid} .sm-component-animate-marker__pulse`);
for (let i = 0; i < pulse.length; i++) {
// @ts-ignore
let style = pulse[i].style;
Expand All @@ -45,7 +46,7 @@ export default class BreathingApertureMarker extends Marker {
_createMarker(): void {
this.features.features.forEach(point => {
let markerContainer = document.createElement('div');
markerContainer.className = 'sm-component-animate-marker--breathing-aperture';
markerContainer.className = `${this.uuid} sm-component-animate-marker--breathing-aperture`;
let dot = document.createElement('span');
dot.className = 'sm-component-animate-marker__dot-point';
let colors;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ export default class DiffusedApertureMarker extends Marker {

public setMarkersWidth(width: number): void {
this.options.width = width;
let markerContainer = document.getElementsByClassName('sm-component-animate-marker--diffused-aperture');
let markerContainer = document.querySelectorAll(`.${this.uuid}.sm-component-animate-marker--diffused-aperture`);

for (let i = 0; i < markerContainer.length; i++) {
// @ts-ignore
let style = markerContainer[i].style;
Expand All @@ -28,7 +29,7 @@ export default class DiffusedApertureMarker extends Marker {
public setMarkersColors(colors: [string, string]): void {
this.options.colors = colors;
if (colors && colors.length && colors.length > 0) {
let markerContainer = document.getElementsByClassName('sm-component-animate-marker--diffused-aperture');
let markerContainer = document.querySelectorAll(`.${this.uuid}.sm-component-animate-marker--diffused-aperture`);
for (let i = 0; i < markerContainer.length; i++) {
// @ts-ignore
let style = markerContainer[i].style;
Expand All @@ -41,7 +42,7 @@ export default class DiffusedApertureMarker extends Marker {
_createMarker(): void {
this.features.features.forEach(point => {
let markerContainer = document.createElement('div');
markerContainer.className = 'sm-component-animate-marker--diffused-aperture';
markerContainer.className = `${this.uuid} sm-component-animate-marker--diffused-aperture`;
let wrapper = document.createElement('div');
wrapper.className = 'sm-component-animate-marker__diffused-aperture-wrapper';
let bg = document.createElement('div');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ export default class FluorescenceMarker extends Marker {

public setMarkersWidth(width: number): void {
this.options.width = width;
let markerContainer = document.getElementsByClassName('sm-component-animate-marker--fluorescence');
let markerContainer = document.querySelectorAll(`.${this.uuid}.sm-component-animate-marker--fluorescence`);

for (let i = 0; i < markerContainer.length; i++) {
// @ts-ignore
this._setFluorescenceWidth(markerContainer[i].style);
Expand All @@ -27,7 +28,7 @@ export default class FluorescenceMarker extends Marker {
public setMarkersColors(colors: [string, string]): void {
this.options.colors = colors;
if (colors && colors.length && colors.length > 0) {
let markerContainer = document.getElementsByClassName('sm-component-animate-marker--fluorescence');
let markerContainer = document.querySelectorAll(`.${this.uuid}.sm-component-animate-marker--fluorescence`);
for (let i = 0; i < markerContainer.length; i++) {
// @ts-ignore
this._setFluorescenceColor(markerContainer[i].style);
Expand All @@ -38,7 +39,7 @@ export default class FluorescenceMarker extends Marker {
_createMarker(): void {
this.features.features.forEach(point => {
let markerContainer = document.createElement('div');
markerContainer.className = 'sm-component-animate-marker--fluorescence';
markerContainer.className = `${this.uuid} sm-component-animate-marker--fluorescence`;
let marker = document.createElement('div');
marker.className = 'sm-component-animate-marker__fluorescence';
markerContainer.appendChild(marker);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export default class HaloRingMarker extends Marker {

public setMarkersWidth(width: number): void {
this.options.width = width;
let markerContainer = document.getElementsByClassName('sm-component-animate-marker--halo-ring');
let markerContainer = document.querySelectorAll(`.${this.uuid}.sm-component-animate-marker--halo-ring`);
for (let i = 0; i < markerContainer.length; i++) {
// @ts-ignore
let style = markerContainer[i].style;
Expand All @@ -31,7 +31,7 @@ export default class HaloRingMarker extends Marker {
public setMarkersColors(colors: [string, string]): void {
this.options.colors = colors;
if (colors && colors.length && colors.length > 0) {
let markerContainer = document.getElementsByClassName('sm-component-animate-marker--halo-ring');
let markerContainer = document.querySelectorAll(`.${this.uuid}.sm-component-animate-marker--halo-ring`);
for (let i = 0; i < markerContainer.length; i++) {
// @ts-ignore
let style = markerContainer[i].style;
Expand All @@ -46,7 +46,7 @@ export default class HaloRingMarker extends Marker {
_createMarker(): void {
this.features.features.forEach(point => {
let markerContainer = document.createElement('div');
markerContainer.className = 'sm-component-animate-marker--halo-ring';
markerContainer.className = `${this.uuid} sm-component-animate-marker--halo-ring`;
let childElements = this._createMakerElement(8, 'div', [
'sm-component-animate-marker__ring',
'sm-component-animate-marker__halo'
Expand Down
4 changes: 4 additions & 0 deletions src/mapboxgl/web-map/layer/animate-marker/marker/Marker.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { FeatureCollection, Feature } from 'geojson';
import { getColorWithOpacity } from 'vue-iclient/src/common/_utils/util';
import UniqueId from 'lodash.uniqueid';

interface markerOptions {
width?: number;
Expand All @@ -9,6 +10,8 @@ interface markerOptions {
textFontSize?: number;
}
export default abstract class Marker {
uuid: string;

features: FeatureCollection;

markersElement: HTMLElement[] = [];
Expand All @@ -18,6 +21,7 @@ export default abstract class Marker {
constructor(features: FeatureCollection, options: markerOptions = {}) {
this.features = features;
this.options = options;
this.uuid = UniqueId(`smanimatemarkerlayer-`);
}

public setFeatures(features: FeatureCollection): void {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export default class RotatingApertureMarker extends Marker {
if (!this.options.width || this.options.width < 40) {
return;
}
let dotsMarker = document.getElementsByClassName('sm-component-animate-marker--rotating-aperture');
let dotsMarker = document.querySelectorAll(`.${this.uuid}.sm-component-animate-marker--rotating-aperture`);

for (let i = 0; i < dotsMarker.length; i++) {
// @ts-ignore
Expand All @@ -37,7 +37,7 @@ export default class RotatingApertureMarker extends Marker {
public setMarkersColors(colors: [string, string]): void {
this.options.colors = colors;
if (colors && colors.length && colors.length > 0) {
let dotsMarker = document.getElementsByClassName('sm-component-animate-marker--rotating-aperture');
let dotsMarker = document.querySelectorAll(`.${this.uuid}.sm-component-animate-marker--rotating-aperture`);
for (let i = 0; i < dotsMarker.length; i++) {
// @ts-ignore
let style = dotsMarker[i].style;
Expand All @@ -52,7 +52,7 @@ export default class RotatingApertureMarker extends Marker {
this.features.features.forEach(point => {
let width = this.options.width && this.options.width >= 40 ? this.options.width : 50;
let markerContainer = document.createElement('div');
markerContainer.className = 'sm-component-animate-marker--rotating-aperture';
markerContainer.className = `sm-component-animate-marker--rotating-aperture ${this.uuid}` ;

let childElements = this._createMakerElement(3, 'div', [
'sm-component-animate-marker__dots',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ export default class RotatingTextBorderMarker extends Marker {
options: markerOptions;

constructor(features: FeatureCollection, options: markerOptions = {}) {
super(features);
this.options = options;
super(features, options);
this.features && this._createMarker();
}

Expand Down Expand Up @@ -81,7 +80,7 @@ export default class RotatingTextBorderMarker extends Marker {
_createMarker(): void {
this.features.features.forEach(point => {
let markerContainer = document.createElement('div');
markerContainer.className = 'sm-component-animate-marker--text-boder';
markerContainer.className = `${this.uuid} sm-component-animate-marker--text-boder`;
let border = document.createElement('div');
border.className = 'sm-component-animate-marker__boder';

Expand Down Expand Up @@ -123,7 +122,7 @@ export default class RotatingTextBorderMarker extends Marker {
}

private _setMarkerContainerProperty(properties) {
let markerContainer = document.getElementsByClassName('sm-component-animate-marker--text-boder');
let markerContainer = document.querySelectorAll(`.${this.uuid}.sm-component-animate-marker--text-boder`);
for (let i = 0; i < markerContainer.length; i++) {
// @ts-ignore
let style = markerContainer[i].style;
Expand Down

0 comments on commit 60b11f4

Please sign in to comment.