maplibre-gl-js-amplify
Version:
MapLibre Plugin to Support Amplify Geo Integration
37 lines (36 loc) • 2.17 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.getPopupRenderFunction = void 0;
const utils_1 = require("./utils");
const constants_1 = require("./constants");
function getPopupRenderFunction(unclusteredLayerId, { popupBackgroundColor: background = constants_1.COLOR_WHITE, popupBorderColor: borderColor = constants_1.POPUP_BORDER_COLOR, popupBorderWidth: borderWidth = 2, popupFontColor: fontColor = constants_1.COLOR_BLACK, popupPadding: padding = 20, popupBorderRadius: radius = 4, popupTitleFontWeight: fontWeight = 'bold', }) {
return (selectedFeature) => {
let title, address;
// Try to get Title and address from existing feature properties
if ((0, utils_1.strHasLength)(selectedFeature.properties.place_name)) {
const placeName = selectedFeature.properties.place_name.split(',');
title = placeName[0];
address = placeName.splice(1, placeName.length).join(',');
}
else if ((0, utils_1.strHasLength)(selectedFeature.properties.title) ||
(0, utils_1.strHasLength)(selectedFeature.properties.address)) {
title = selectedFeature.properties.title;
address = selectedFeature.properties.address;
}
else {
title = 'Coordinates';
address = selectedFeature.geometry.coordinates;
}
const titleHtml = `<div class="${unclusteredLayerId}-popup-title" style="font-weight: ${fontWeight};">${title}</div>`;
const addressHtml = `<div class="${unclusteredLayerId}-popup-address">${address}</div>`;
const popupHtmlStyle = `background: ${background}; border: ${borderWidth}px solid ${borderColor}; color: ${fontColor}; border-radius: ${radius}px; padding: ${padding}px; word-wrap: break-word; margin: -10px -10px -15px;`;
let popupHtml = `<div class="${unclusteredLayerId}-popup" style="${popupHtmlStyle}">`;
if (title)
popupHtml += titleHtml;
if (address)
popupHtml += addressHtml;
popupHtml += '</div>';
return popupHtml;
};
}
exports.getPopupRenderFunction = getPopupRenderFunction;