Skip to content

Commit

Permalink
label interactivity
Browse files Browse the repository at this point in the history
  • Loading branch information
alxart committed Apr 17, 2024
1 parent 67cd315 commit 809b946
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
5 changes: 5 additions & 0 deletions demo/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export const REALTY_SCENE: BuildingOptions[] = [
elevation: 5,
fontSize: 12,
fontColor: '#3a3a3a',
interactive: true,
labels: [
{
coordinates: [47.245048150280994, 56.134470449142164],
Expand Down Expand Up @@ -75,6 +76,7 @@ export const REALTY_SCENE: BuildingOptions[] = [
elevation: 5,
fontSize: 12,
fontColor: '#3a3a3a',
interactive: true,
labels: [
{
coordinates: [47.245350349632965, 56.134414208205776],
Expand Down Expand Up @@ -125,6 +127,7 @@ export const REALTY_SCENE: BuildingOptions[] = [
elevation: 35,
fontSize: 12,
fontColor: '#fff',
interactive: true,
labels: [
{
coordinates: [47.245048150280994, 56.134470449142164],
Expand Down Expand Up @@ -204,6 +207,7 @@ export const REALTY_SCENE: BuildingOptions[] = [
elevation: 7,
fontSize: 12,
fontColor: '#3a3a3a',
interactive: true,
labels: [
{
coordinates: [47.24452417991248, 56.13469284843933],
Expand Down Expand Up @@ -275,6 +279,7 @@ export const REALTY_SCENE: BuildingOptions[] = [
elevation: 53,
fontSize: 12,
fontColor: '#fff',
interactive: true,
labels: [
{
coordinates: [47.24452417991248, 56.13469284843933],
Expand Down
6 changes: 4 additions & 2 deletions src/labelGroups.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import type { GltfPlugin } from './plugin';
import { pluginEvents } from './constants';
import { createLabelEvenData } from './utils/events';

const DEFAULT_INTERACTIVE = false;
export const DEFAULT_FONT_SIZE = 14;
export const DEFAULT_FONT_COLOR = '#000000';
export const DEFAULT_IMAGE: LabelImage = {
Expand Down Expand Up @@ -39,11 +40,12 @@ export class LabelGroups {
fontColor,
fontSize,
elevation: groupElevation,
interactive: groupInteractive,
} = groupOptions;
const { labelGroupDefaults, zIndex } = this.options;

const labels = groupOptions.labels.map((labelOptions) => {
const { coordinates, text, userData, elevation } = labelOptions;
const { coordinates, text, userData, elevation, interactive } = labelOptions;
const label = new mapgl.Label(this.map, {
coordinates: [...coordinates, elevation ?? groupElevation],
text,
Expand All @@ -55,7 +57,7 @@ export class LabelGroups {
fontSize: fontSize ?? labelGroupDefaults.fontSize ?? DEFAULT_FONT_SIZE,
relativeAnchor: [0.5, 1],
zIndex: zIndex + 0.00001, // чтобы были выше моделей
interactive: true,
interactive: interactive ?? groupInteractive ?? DEFAULT_INTERACTIVE,
labeling: { type: 'pointLabelsOnly' },
});

Expand Down
10 changes: 9 additions & 1 deletion src/types/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ export interface ModelOptions {
*/
userData?: any;
/**
* Interactivity of model. All models are interactive by default.
* Interactivity of a model. The model isn't interactive by default.
*/
interactive?: boolean;
}
Expand All @@ -179,6 +179,10 @@ export interface LabelOptions {
* User specific data.
*/
userData?: any;
/**
* Interactivity of a label. The label isn't interactive by default.
*/
interactive?: boolean;
}

/**
Expand Down Expand Up @@ -217,6 +221,10 @@ export interface LabelGroupOptions {
* Image settings for labels' text background.
*/
image?: LabelImage | 'default';
/**
* Interactivity of a label group. The label group isn't interactive by default.
*/
interactive?: boolean;
}

/**
Expand Down

0 comments on commit 809b946

Please sign in to comment.