Skip to content

Commit

Permalink
Plugin Refactoring PreFinal
Browse files Browse the repository at this point in the history
  • Loading branch information
alxart committed Mar 27, 2024
1 parent 6107623 commit c823541
Show file tree
Hide file tree
Showing 34 changed files with 577 additions and 664 deletions.
13 changes: 3 additions & 10 deletions demo/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { REALTY_SCENE, REALTY_SCENE_1 } from './mocks';
let isDarkTheme = false;

async function start() {
const mapglAPI = await load('https://mapgl.2gis.com/api/js/v0.0.323');
const mapglAPI = await load();

const map = new mapglAPI.Map('container', {
center: [47.245286302641034, 56.134743473834099],
Expand All @@ -15,6 +15,7 @@ async function start() {
pitch: 45,
rotation: 330,
enableTrackResize: true,
webglVersion: 1,
});

(window as any).map = map;
Expand All @@ -23,16 +24,8 @@ async function start() {
modelsLoadStrategy: 'dontWaitAll',
modelsBaseUrl: 'https://disk.2gis.com/digital-twin/models_s3/realty_ads/zgktechnology/',
floorsControl: { position: 'centerRight' },
poiConfig: {
primary: {
fontSize: 14,
},
secondary: {
fontSize: 14,
},
},
hoverOptions: {
color: '#FFEFEF',
color: '#FFF3F3',
},
groundCoveringColor: 'rgba(0, 0, 0, 0.8)',
});
Expand Down
139 changes: 79 additions & 60 deletions demo/mocks.ts

Large diffs are not rendered by default.

14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"author": "2GIS WebMaps Team",
"license": "BSD-2-Clause",
"devDependencies": {
"@2gis/mapgl": "1.37.2",
"@2gis/mapgl": "1.46.0",
"@documentalist/compiler": "^2.8.1",
"@types/geojson": "^7946.0.10",
"@types/jest": "^27.4.0",
Expand Down
9 changes: 7 additions & 2 deletions src/constants.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import type { GeoJsonSourceOptions } from '@2gis/mapgl/types';

export const PLUGIN_PREFIX = '__mapglPlugins_mapgl-gltf2';

export const GROUND_COVERING_SOURCE_DATA: GeoJsonSourceOptions['data'] = {
type: 'Feature',
properties: {},
Expand All @@ -17,9 +19,10 @@ export const GROUND_COVERING_SOURCE_DATA: GeoJsonSourceOptions['data'] = {
},
};

export const GROUND_COVERING_SOURCE_PURPOSE = '__mapglPlugins_mapgl-gltf';
export const GROUND_COVERING_SOURCE_PURPOSE = `${PLUGIN_PREFIX}-covering`;
export const GROUND_COVERING_LAYER_ID = `${PLUGIN_PREFIX}-covering`;
export const GROUND_COVERING_LAYER = {
id: '__mapglPlugins_mapgl-gltf',
id: GROUND_COVERING_LAYER_ID,
type: 'polygon',
style: {
color: ['to-color', ['sourceAttr', 'color']],
Expand All @@ -30,3 +33,5 @@ export const GROUND_COVERING_LAYER = {
['to-boolean', ['sourceAttr', 'color']],
],
};

export const pluginEvents = ['click', 'mousemove', 'mouseover', 'mouseout'] as const;
5 changes: 2 additions & 3 deletions src/control/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import icon_building from 'raw-loader!./icon_building.svg';
import icon_parking from 'raw-loader!./icon_parking.svg';
import classes from './control.module.css';
import { Control } from './control';
import { Id } from '../types';

const content = /* HTML */ `
<div class="${classes.root}">
Expand Down Expand Up @@ -120,15 +119,15 @@ export class GltfFloorControl extends Control {
});
}

private _controlHandler = (modelId: Id) => () => {
private _controlHandler = (modelId: string) => () => {
this._switchCurrentFloorLevel(modelId);

this.emit('floorchange', {
modelId,
});
};

private _switchCurrentFloorLevel(modelId: Id) {
private _switchCurrentFloorLevel(modelId: string) {
if (this._currentFloorId === undefined) {
return;
}
Expand Down
10 changes: 4 additions & 6 deletions src/control/types.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import { Id } from '../types/plugin';

/**
* Floor level data
*/
export interface FloorLevel {
modelId: Id; // id модели этажа или здания
modelId: string; // id модели этажа или здания
text: string;
icon?: 'parking' | 'building' | string;
}
Expand All @@ -13,16 +11,16 @@ export interface FloorLevel {
* Options for the method show
*/
export interface ControlShowOptions {
buildingModelId: Id;
activeModelId: Id;
buildingModelId: string;
activeModelId: string;
floorLevels?: FloorLevel[];
}

/**
* Event that emitted on button presses of the control
*/
export interface FloorChangeEvent {
modelId: Id; // id модели этажа или здания
modelId: string; // id модели этажа или здания
}

export interface ControlEventTable {
Expand Down
10 changes: 0 additions & 10 deletions src/defaultOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,6 @@ export const defaultOptions: Required<PluginOptions> = {
},
modelsBaseUrl: '',
modelsLoadStrategy: 'waitAll',
poiConfig: {
primary: {
fontSize: 14,
fontColor: '#000000',
},
secondary: {
fontSize: 14,
fontColor: '#000000',
},
},
floorsControl: {
position: 'centerLeft',
},
Expand Down
61 changes: 61 additions & 0 deletions src/labelGroups.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import type { Map as MapGL, Label } from '@2gis/mapgl/types';
import type { BuildingState, LabelGroupOptions } from './types/plugin';
import { GltfPlugin } from './plugin';
// import { pluginEvents } from './constants';
// import { createLabelEvenData } from './utils/events';

export class LabelGroups {
private labelsByGroupId: Map<string, Label[]> = new Map();

constructor(private map: MapGL, private plugin: GltfPlugin) {}

public add(groupOptions: LabelGroupOptions, state?: BuildingState) {
const { id } = groupOptions;
if (this.labelsByGroupId.has(id)) {
console.error(
`Poi group with id "${id}" already exists. Please use different identifiers for poi groups`,
);
return;
}

const { image, minZoom, maxZoom, fontColor: color, fontSize } = groupOptions;
const labels = groupOptions.labels.map((labelOptions) => {
const { coordinates, text, userData } = labelOptions;
const label = new mapgl.Label(this.map, {
coordinates, // + label.elevation ?? groupOptions.elevation
text,
userData,
image,
minZoom,
maxZoom,
color,
fontSize,
relativeAnchor: [0.5, 1],
zIndex: 1, // чтобы были выше моделей
});

// pluginEvents.forEach((eventType) => {
// label.on(eventType, (ev) => {
// this.plugin.emit(eventType, createLabelEvenData(ev, labelOptions, state));
// });
// });

return label;
});

this.labelsByGroupId.set(id, labels);
}

public remove(id: string) {
const labels = this.labelsByGroupId.get(id);
this.labelsByGroupId.delete(id);
labels?.forEach((label) => label.destroy());
}

public destroy() {
this.labelsByGroupId.forEach((labels) => {
labels.forEach((label) => label.destroy());
});
this.labelsByGroupId.clear();
}
}
Loading

0 comments on commit c823541

Please sign in to comment.