Add tooltip support
This commit is contained in:
parent
d05b7a63ac
commit
90ec2080ee
1
src/index.d.ts
vendored
1
src/index.d.ts
vendored
@ -208,6 +208,7 @@ interface LiveAtlasPath {
|
|||||||
minZoom?: number;
|
minZoom?: number;
|
||||||
maxZoom?: number;
|
maxZoom?: number;
|
||||||
popupContent?: string;
|
popupContent?: string;
|
||||||
|
tooltipContent?: string;
|
||||||
isPopupHTML: boolean;
|
isPopupHTML: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
@import "leaflet/controls";
|
@import "leaflet/controls";
|
||||||
@import "leaflet/popups";
|
@import "leaflet/popups";
|
||||||
|
@import "leaflet/tooltips";
|
||||||
@import "leaflet/markers";
|
@import "leaflet/markers";
|
||||||
|
|
||||||
.leaflet-container {
|
.leaflet-container {
|
||||||
|
28
src/scss/leaflet/_tooltips.scss
Normal file
28
src/scss/leaflet/_tooltips.scss
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
/*!
|
||||||
|
* Copyright 2021 James Lyne
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
.leaflet-tooltip {
|
||||||
|
background-color: var(--background-base);
|
||||||
|
color: var(--text-base);
|
||||||
|
box-shadow: var(--box-shadow);
|
||||||
|
border-radius: var(--border-radius);
|
||||||
|
border: none;
|
||||||
|
will-change: transform;
|
||||||
|
|
||||||
|
&:before {
|
||||||
|
content: none;
|
||||||
|
}
|
||||||
|
}
|
@ -21,7 +21,7 @@ import {LatLngExpression} from "leaflet";
|
|||||||
import LiveAtlasPolyline from "@/leaflet/vector/LiveAtlasPolyline";
|
import LiveAtlasPolyline from "@/leaflet/vector/LiveAtlasPolyline";
|
||||||
import LiveAtlasPolygon from "@/leaflet/vector/LiveAtlasPolygon";
|
import LiveAtlasPolygon from "@/leaflet/vector/LiveAtlasPolygon";
|
||||||
import {Coordinate, LiveAtlasArea} from "@/index";
|
import {Coordinate, LiveAtlasArea} from "@/index";
|
||||||
import {arePointsEqual, createPopup, isStyleEqual} from "@/util/paths";
|
import {arePointsEqual, createPopup, isStyleEqual, tooltipOptions} from "@/util/paths";
|
||||||
|
|
||||||
export const createArea = (options: LiveAtlasArea, converter: Function): LiveAtlasPolyline | LiveAtlasPolygon => {
|
export const createArea = (options: LiveAtlasArea, converter: Function): LiveAtlasPolyline | LiveAtlasPolygon => {
|
||||||
const outline = !options.style.fillOpacity || (options.style.fillOpacity <= 0),
|
const outline = !options.style.fillOpacity || (options.style.fillOpacity <= 0),
|
||||||
@ -32,6 +32,10 @@ export const createArea = (options: LiveAtlasArea, converter: Function): LiveAtl
|
|||||||
area.bindPopup(() => createPopup(options, 'AreaPopup'));
|
area.bindPopup(() => createPopup(options, 'AreaPopup'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (options.tooltipContent) {
|
||||||
|
area.bindTooltip(() => options.tooltipContent, tooltipOptions);
|
||||||
|
}
|
||||||
|
|
||||||
return area;
|
return area;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -21,7 +21,7 @@ import {LatLngExpression} from "leaflet";
|
|||||||
import LiveAtlasPolyline from "@/leaflet/vector/LiveAtlasPolyline";
|
import LiveAtlasPolyline from "@/leaflet/vector/LiveAtlasPolyline";
|
||||||
import LiveAtlasPolygon from "@/leaflet/vector/LiveAtlasPolygon";
|
import LiveAtlasPolygon from "@/leaflet/vector/LiveAtlasPolygon";
|
||||||
import {LiveAtlasCircle} from "@/index";
|
import {LiveAtlasCircle} from "@/index";
|
||||||
import {createPopup} from "@/util/paths";
|
import {createPopup, tooltipOptions} from "@/util/paths";
|
||||||
|
|
||||||
export const createCircle = (options: LiveAtlasCircle, converter: Function): LiveAtlasPolyline | LiveAtlasPolygon => {
|
export const createCircle = (options: LiveAtlasCircle, converter: Function): LiveAtlasPolyline | LiveAtlasPolygon => {
|
||||||
const outline = !options.style.fillOpacity || (options.style.fillOpacity <= 0),
|
const outline = !options.style.fillOpacity || (options.style.fillOpacity <= 0),
|
||||||
@ -32,6 +32,10 @@ export const createCircle = (options: LiveAtlasCircle, converter: Function): Liv
|
|||||||
circle.bindPopup(() => createPopup(options, 'CirclePopup'));
|
circle.bindPopup(() => createPopup(options, 'CirclePopup'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (options.tooltipContent) {
|
||||||
|
circle.bindTooltip(() => options.tooltipContent, tooltipOptions);
|
||||||
|
}
|
||||||
|
|
||||||
return circle;
|
return circle;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -20,7 +20,7 @@
|
|||||||
import LiveAtlasPolyline from "@/leaflet/vector/LiveAtlasPolyline";
|
import LiveAtlasPolyline from "@/leaflet/vector/LiveAtlasPolyline";
|
||||||
import {Coordinate, LiveAtlasLine} from "@/index";
|
import {Coordinate, LiveAtlasLine} from "@/index";
|
||||||
import {LatLngExpression} from "leaflet";
|
import {LatLngExpression} from "leaflet";
|
||||||
import {createPopup} from "@/util/paths";
|
import {createPopup, tooltipOptions} from "@/util/paths";
|
||||||
|
|
||||||
export const createLine = (options: LiveAtlasLine, converter: Function): LiveAtlasPolyline => {
|
export const createLine = (options: LiveAtlasLine, converter: Function): LiveAtlasPolyline => {
|
||||||
const points = options.points.map(projectPointsMapCallback, converter),
|
const points = options.points.map(projectPointsMapCallback, converter),
|
||||||
@ -30,6 +30,10 @@ export const createLine = (options: LiveAtlasLine, converter: Function): LiveAtl
|
|||||||
line.bindPopup(() => createPopup(options, 'LinePopup'));
|
line.bindPopup(() => createPopup(options, 'LinePopup'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (options.tooltipContent) {
|
||||||
|
line.bindTooltip(() => options.tooltipContent, tooltipOptions);
|
||||||
|
}
|
||||||
|
|
||||||
return line;
|
return line;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -17,6 +17,13 @@
|
|||||||
import {LatLngExpression, PathOptions} from "leaflet";
|
import {LatLngExpression, PathOptions} from "leaflet";
|
||||||
import {LiveAtlasPath} from "@/index";
|
import {LiveAtlasPath} from "@/index";
|
||||||
|
|
||||||
|
export const tooltipOptions = {
|
||||||
|
direction: 'top',
|
||||||
|
sticky: true,
|
||||||
|
opacity: 1.0,
|
||||||
|
interactive: false,
|
||||||
|
};
|
||||||
|
|
||||||
export const arePointsEqual = (oldPoints: LatLngExpression | LatLngExpression[] | LatLngExpression[][] | LatLngExpression[][][],
|
export const arePointsEqual = (oldPoints: LatLngExpression | LatLngExpression[] | LatLngExpression[][] | LatLngExpression[][][],
|
||||||
newPoints: LatLngExpression | LatLngExpression[] | LatLngExpression[][] | LatLngExpression[][][]) => {
|
newPoints: LatLngExpression | LatLngExpression[] | LatLngExpression[][] | LatLngExpression[][][]) => {
|
||||||
return JSON.stringify(oldPoints) === JSON.stringify(newPoints);
|
return JSON.stringify(oldPoints) === JSON.stringify(newPoints);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user