I have a Leaflet web map displaying 13 points and 3 arrows diverging from each point (4 layers total). The map was exported from QGIS via QGIS2Web.
I'm using placeRotatedSymbol()
to place the arrow SVG markers. It calculates the positions for the left arrow, right arrow, and heading arrow based on the input coordinates and rotation angles. I have been adjusting the offset values to move arrows closer to the points. It worked for the left & right arrows (blue), but the heading arrow (yellow) is not responding as expected. Here is the relevant snippet, (full code below):
//===============================================
// Function to place rotated symbols
//===============================================
function placeRotatedSymbol(coords, lhead, rhead, head) {
//==================================
// Calculate offsets for left arrow
//==================================
var L_offsetX = Math.cos((lhead - 90) * Math.PI / 180) * 0.00000000000009;
var L_offsetY = Math.sin((lhead - 90) * Math.PI / 180) * -0.00000000000009;
var L_offset = [coords[1] + L_offsetY, coords[0] + L_offsetX];
// Add left arrow marker
var leftMarker = L.marker(L_offset, {
icon: L_arrow,
rotationAngle: lhead
});
//==================================
// Calculate offsets for right arrow
//==================================
var R_offsetX = Math.cos((rhead - 90) * Math.PI / 180) * 0.00000000000009;
var R_offsetY = Math.sin((rhead - 90) * Math.PI / 180) * -0.00000000000009;
var R_offset = [coords[1] + R_offsetY, coords[0] + R_offsetX];
// Add right arrow marker
var rightMarker = L.marker(R_offset, {
icon: R_arrow,
rotationAngle: rhead
});
//==================================
// Calculate offsets for heading arrow
//==================================
var H_offsetX = Math.cos((head - 90) * Math.PI / 180) * -0.00000000000009;
var H_offsetY = Math.sin((head - 90) * Math.PI / 180) * -0.00000000000009;
var H_offset = [coords[1] + H_offsetY, coords[0] + H_offsetX];
// Add heading arrow marker
var headingMarker = L.marker(H_offset, {
icon: H_arrow,
rotationAngle: head
});
I need to make a minor adjustment so that base of the yellow arrow is centered. Currently it is a bit to right of each point. It also needs to move closer to the point so that there is no gap.
Here is what it currently looks like
here is what i want it to look like. They need to be offset about 1.6 points to the left
Code:
//==============================================================
// Define custom icons for each symbol (1 point, 3 arrows)
//==============================================================
// Sensor marker dimensions
const circleRadius = 6;
// LR arrow icon dimensions
const LR_Width = 64;
const LR_Height = 64;
// Heading arrow icon dimensions
const H_Height = 40;
const H_Width = 40;
// Left arrow SVG (stored in Leaflet markers exported by QGIS2Web)
var L_arrow = L.icon({
iconUrl: 'markers/test2.svg',
iconSize: [LR_Width, LR_Height],
iconAnchor: [LR_Width / 2, LR_Height + circleRadius]
});
// Right arrow SVG
var R_arrow = L.icon({
iconUrl: 'markers/test2.svg',
iconSize: [LR_Width, LR_Height],
iconAnchor: [LR_Width / 2, LR_Height + circleRadius]
});
// Heading arrow SVG
var H_arrow = L.icon({
iconUrl: 'markers/head.svg',
iconSize: [H_Width, H_Height],
iconAnchor: [H_Width / 2, H_Height + circleRadius]
});
//===============================================
// Function to place rotated symbols
//===============================================
function placeRotatedSymbol(coords, lhead, rhead, head) {
//==================================
// Calculate offsets for left arrow
//==================================
var L_offsetX = Math.cos((lhead - 90) * Math.PI / 180) * 0.00000000000009;
var L_offsetY = Math.sin((lhead - 90) * Math.PI / 180) * -0.00000000000009;
var L_offset = [coords[1] + L_offsetY, coords[0] + L_offsetX];
// Add left arrow marker
var leftMarker = L.marker(L_offset, {
icon: L_arrow,
rotationAngle: lhead
});
//==================================
// Calculate offsets for right arrow
//==================================
var R_offsetX = Math.cos((rhead - 90) * Math.PI / 180) * 0.00000000000009;
var R_offsetY = Math.sin((rhead - 90) * Math.PI / 180) * -0.00000000000009;
var R_offset = [coords[1] + R_offsetY, coords[0] + R_offsetX];
// Add right arrow marker
var rightMarker = L.marker(R_offset, {
icon: R_arrow,
rotationAngle: rhead
});
//==================================
// Calculate offsets for heading arrow
//==================================
var H_offsetX = Math.cos((head - 90) * Math.PI / 180) * -0.00000000000009; //this is the problem
var H_offsetY = Math.sin((head - 90) * Math.PI / 180) * -0.00000000000009;
var H_offset = [coords[1] + H_offsetY, coords[0] + H_offsetX];
// Add heading arrow marker
var headingMarker = L.marker(H_offset, {
icon: H_arrow,
rotationAngle: head
});