// Boundary layer import L from 'leaflet'; import { toGeoJson, geoJsonOptions } from './GeoJson'; import uniqBy from 'lodash/fp/uniqBy'; import { GeoJson } from 'leaflet'; import { Feature, GeometryObject } from 'geojson'; const colors = ['black', 'blue', 'red', 'green', 'yellow']; const weights = [2, 1, 0.75, 0.5, 0.5]; export function boundary(options) { const { geofeature, layerOptions, displaySettings, opacity, id } = options; const radiusLow = layerOptions.radiusLow; const features = toGeoJson(geofeature); if (!features.length) { return; } const levels = uniqBy(f => f.properties.level, features) .map(f => f.properties.level) .sort(); const levelStyle = levels.reduce( (obj, level, index) => ({ ...obj, [level]: { color: colors[index], fillOpacity: 0, weight: levels.length === 1 ? 1 : weights[index], stroke: true, fill: true } }), {} ); features.forEach(feature => { feature.properties.style = levelStyle[feature.properties.level]; feature.properties.labelStyle = { fontSize: displaySettings.labelFontSize, fontStyle: displaySettings.labelFontStyle, fontColor: displaySettings.labelFontColor, fontWeight: displaySettings.labelFontWeight, paddingTop: feature.geometry.type === 'Point' ? 5 + (radiusLow || 5) + 'px' : '0' }; }); const geoJSonOptions = geoJsonOptions(id, radiusLow, opacity); const geoJsonLayer = L.geoJSON(features, geoJSonOptions); geoJsonLayer.on({ click: boundaryEvents().onClick, mouseover: boundaryEvents().mouseover, mouseout: boundaryEvents().mouseout }); const bounds = geoJsonLayer.getBounds(); const optionsToReturn = { ...options, features, geoJsonLayer }; if (bounds.isValid()) { return { ...optionsToReturn, bounds }; } return optionsToReturn; } export const boundaryEvents = () => { const onClick = evt => { const attr = evt.layer.feature.properties; let content = `