{"version":3,"sources":["jsdelivr-header.js","/npm/ymaps-polygonmap@1.1.0/src/Polygonmap.js"],"names":[],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA,OCNO,qBAAsB,kCACtB,kBAAmB,+BACnB,kBAAmB,+BACnB,wBAAyB,qCACzB,wBAAyB,qCACzB,0BAA2B,uCAC3B,mBAAoB,gCACpB,WAAY,wBACZ,aAAc,0BACd,gBAAiB,sBASxB,MAAM,QAAQ,OAAO,aAAc,CAC/B,OACA,iBACA,kBACD,CAAC,EAAS,EAAM,EAAe,KA+Z9B,EApXA,MACI,WAAA,CAAY,EAAM,EAAU,CAAC,GACzB,MAAM,EAAiB,IAAI,EAAc,CACrC,OAAQ,cACR,OAAQ,SACR,iBAAkB,SAClB,iBAAkB,SAClB,mBAAoB,EACpB,YAAa,EACb,YAAa,CACT,UACA,UACA,UACA,WAEJ,YAAa,GACb,sBAAuB,UACvB,YAAa,OACb,YAAa,EACb,YAAY,EACZ,eAAgB,YAAY,gBAC5B,eAAgB,CACZ,IAAK,GACL,MAAO,IAIX,YAAQ,EACR,qBAAqB,EACrB,aAAc,oBACd,aAAc,oBACd,QAAS,eACT,eAAgB,sBAChB,oBAAgB,EAChB,iBAAkB,GAClB,iBAAkB,OAClB,iBAAkB,EAClB,qBAAiB,EACjB,kBAAmB,GACnB,kBAAmB,OACnB,kBAAmB,EACnB,eAAe,IAGnB,KAAK,aAAa,EAAS,GAC3B,KAAK,QAAQ,EACjB,CAQA,OAAA,GACI,OAAO,KAAK,OAAS,IACzB,CAWA,OAAA,CAAQ,GAYJ,OAXA,KAAK,MAAQ,EAET,IACA,KAAK,MAAQ,CACT,OAAQ,CAAC,KAAM,oBAAqB,SAAU,IAC9C,SAAU,CAAC,KAAM,oBAAqB,SAAU,KAEpD,KAAK,SAAS,GACd,KAAK,sBAGF,IACX,CAQA,MAAA,GACI,OAAO,KAAK,IAChB,CASA,MAAA,CAAO,GASH,OARI,KAAK,OAAS,IACd,KAAK,KAAO,EA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AAY,EAAS,CAAC,WAE3B,EAAI,KAAK,IAGN,GAGX,KAAK,MAAM,SAAS,SAAW,KAAK,MAAM,SAAS,SAAS,OAAO,EAAS,GAChF,CAEA,IACI,KAAK,SAAW,IAAI,SACO,QAAvB,EACI,EAAe,KAAK,oBAAsB,KAAK,mBAC/C,EACJ,EAAe,KAAK,oBAAsB,KAAK,mBAC/C,CACI,YAAa,KAAK,QAAQ,IAAI,eAC9B,YAAa,KAAK,QAAQ,IAAI,gBAG1C,CAAE,MAAO,GACL,QAAQ,MAAM,EAClB,CAgBA,KAAK,MAAM,SAAS,SAAW,KAAK,MAAM,SAAS,SAAS,QAd5C,CAAC,EAAK,KACS,QAAvB,GAAiC,IAAU,EAAO,KAC9C,EACA,EAAI,KAAK,EAAO,IAEhB,EAAI,KAAK,GAGb,KAAK,YAAY,EAAS,CAAC,YAGxB,IAGiE,IAE5E,KAAK,cAAgB,IAAI,EACzB,KAAK,cAAc,IAAI,KAAK,MAAM,SACtC,CAOA,kBAAA,GACI,KAAK,cAAgB,KACrB,KAAK,QAAU,IAAI,MAAM,QAAQ,KAAK,MAEtC,MAAM,EAAe,KAAK,QAAQ,IAAI,gBAChC,EAAe,KAAK,QAAQ,IAAI,gBAChC,EAAU,KAAK,QAAQ,IAAI,WAEjC,KAAK,cAAc,OAAO,IAAI,aAAc,GAE5C,KAAK,cAAc,OAAO,IAAI,aAAc,GAE5C,KAAK,QAAQ,QAAQ,UAAU,KAAK,KAAK,SAEzC,KAAK,cAAc,OAAO,IAAI,QAAS,EAC3C,GAGe","file":"/npm/ymaps-polygonmap@1.1.0/src/Polygonmap.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/ymaps-polygonmap@1.1.0/src/Polygonmap.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","import normalizeFeature from './utils/normalizeFeature';\nimport defaultMapper from './utils/defaultMapper';\nimport defaultFilter from './utils/defaultFilter';\nimport defaultOnMouseEnter from './utils/defaultOnMouseEnter';\nimport defaultOnMouseLeave from './utils/defaultOnMouseLeave';\nimport defaultBalloonContent from './utils/defaultBalloonContent';\nimport defaultOnClick from './utils/defaultOnClick';\nimport inside from './utils/inside';\nimport Colorize from './utils/colorize';\nimport colorLegend from './utils/colorLegend';\n\n/**\n * Polygonmap module.\n *\n * @module Polygonmap\n * @requires option.Manager\n * @requires ObjectManager\n */\nymaps.modules.define('Polygonmap', [\n    'meta',\n    'option.Manager',\n    'ObjectManager'\n], (provide, meta, OptionManager, ObjectManager) => {\n    /**\n     * @param {Object} [data] Polygons and points.\n     * @param {Object} data.polygons GeoJSON FeatureCollections.\n     * @param {Object} data.points GeoJSON FeatureCollections.\n     * @param {Object} [options] Options for customization.\n     * @param {function} [options.mapper=defaultMapper] Function of iterative transformation of features.\n     * @param {string} [options.fillBy=points] Calculate the color by points | weight.\n     * @param {string} [options.fillByWeightProp=weight] Prop name in data object, for weight value.\n     * If fillBy is \"weight\".\n     * @param {string} [options.fillByWeightType=middle] Type of calculate color by weight. Can be middle | maximum\n     * @param {number|array} [options.colorRanges=4] Count of ranges or array of custom ranges.\n     * @param {string|array} [options.colorScheme=['#e66a54', '#ce4356', '#ab2960', '#571756']]\n     * Preset for colorize or array of custom colors.\n     * @param {number} [options.fillOpacity=0.8] Opacity of polygon.\n     * @param {string} [options.fillColorEmptyPolygon=#f4f6f8] Color of polygon\n     * where points count equal 0.\n     * @param {string} [options.strokeColor=#fff] Color of polygon stroke.\n     * @param {number} [options.strokeWidth=1] Width of polygon stroke.\n     * @param {boolean} [options.showLegend=true] Flag to show color legend.\n     * @param {function} [options.legendTemplate=colorLegend.defaultTemplate] Receives object {color: value}\n     * returns html legend template.\n     * @param {object} [options.legendPosition=top: 10, right: 10] Position of legend,\n     * you can only change the top or bottom and right or left.\n     * @param {function} [options.filter=undefined] Function for custom filter polygons with points.\n     * @param {boolean} [options.filterEmptyPolygons=false] Flag for show polygon with count of points equal 0.\n     * @param {function} [options.onMouseEnter=defaultOnMouseEnter] Handler for mouseEnter event.\n     * @param {function} [options.onMouseLeave=defaultOnMouseLeave] Handler for mouseLeave event.\n     * @param {function} [options.onClick=defaultOnClick] Handler for click event.\n     * @param {function} [options.balloonContent=defaultBalloonContent] Function for render content of baloon.\n     * Recieves object with properties of polygon.\n     * @param {string} [options.fillColorHover] Color of polygon on polygon hover.\n     * @param {number} [options.fillOpacityHover=0.9] Number of opacity on polygon hover.\n     * @param {string} [options.strokeColorHover] Color of polygon stroke on polygon hover.\n     * @param {number} [options.strokeWidthHover=2] Number of stroke width on polygon hover.\n     * @param {string} [options.fillColorActive] Color of polygon on polygon active.\n     * @param {number} [options.fillOpacityActive=0.9] Number of opacity on polygon active.\n     * @param {string} [options.strokeColorActive] Color of polygon stroke on polygon active.\n     * @param {number} [options.strokeWidthActive=2] Number of stroke width on polygon active.\n     * @param {boolean} [options.interactivity=true] Flag for enable interactivity.\n     *\n     * @alias module:Polygonmap\n     */\n    class Polygonmap {\n        constructor(data, options = {}) {\n            const defaultOptions = new OptionManager({\n                mapper: defaultMapper,\n                fillBy: 'points',\n                fillByWeightProp: 'weight',\n                fillByWeightType: 'middle',\n                colorRangesMinimum: 0,\n                colorRanges: 4,\n                colorScheme: [\n                    '#e66a54',\n                    '#ce4356',\n                    '#ab2960',\n                    '#571756'\n                ],\n                fillOpacity: 0.8,\n                fillColorEmptyPolygon: '#f4f6f8',\n                strokeColor: '#fff',\n                strokeWidth: 1,\n                showLegend: true,\n                legendTemplate: colorLegend.defaultTemplate,\n                legendPosition: {\n                    top: 10,\n                    right: 10\n                },\n                // Since the default filter for empty polygons is disabled by default,\n                // this option will be undefined.\n                filter: undefined,\n                filterEmptyPolygons: false,\n                onMouseEnter: defaultOnMouseEnter,\n                onMouseLeave: defaultOnMouseLeave,\n                onClick: defaultOnClick,\n                balloonContent: defaultBalloonContent,\n                fillColorHover: undefined,\n                fillOpacityHover: 0.9,\n                strokeColorHover: '#fff',\n                strokeWidthHover: 2,\n                fillColorActive: undefined,\n                fillOpacityActive: 0.9,\n                strokeColorActive: '#fff',\n                strokeWidthActive: 2,\n                interactivity: true\n            });\n\n            this._initOptions(options, defaultOptions);\n            this.setData(data);\n        }\n\n        /**\n         * Get the data, polygons and points.\n         *\n         * @public\n         * @returns {Object} Polygons and points.\n         */\n        getData() {\n            return this._data || null;\n        }\n\n        /**\n         * Set the data, polygons and points.\n         *\n         * @public\n         * @param {Object} data Polygons and points.\n         * @param {Object} data.polygons GeoJSON FeatureCollections.\n         * @param {Object} data.points GeoJSON FeatureCollections.\n         * @returns {Polygonmap} Self-reference.\n         */\n        setData(data) {\n            this._data = data;\n\n            if (data) {\n                this._data = {\n                    points: {type: 'FeatureCollection', features: []},\n                    polygons: {type: 'FeatureCollection', features: []}\n                };\n                this._prepare(data);\n                this._initObjectManager();\n            }\n\n            return this;\n        }\n\n        /**\n         * Get the Map instance.\n         *\n         * @public\n         * @returns {Map} Reference to Map instance.\n         */\n        getMap() {\n            return this._map;\n        }\n\n        /**\n         * Set Map instance to render Polygonmap object.\n         *\n         * @public\n         * @param {Map} map Map instance.\n         * @returns {Polygonmap} Self-reference.\n         */\n        setMap(map) {\n            if (this._map !== map) {\n                this._map = map;\n\n                if (map && this._data) {\n                    this._render();\n                }\n            }\n\n            return this;\n        }\n\n        /**\n         * Destructs Polygonmap instance.\n         *\n         * @public\n         */\n        destroy() {\n            this.setData(null);\n            this.objectManager.removeAll();\n            this._legendControl.setParent(null);\n            this.balloon.close();\n            this.setMap(null);\n        }\n\n        /**\n         * Prepare for render Polygonmap.\n         *\n         * @private\n         * @param {Object} data Polygons and points.\n         * @param {Object} data.polygons GeoJSON FeatureCollections.\n         * @param {Object} data.points GeoJSON FeatureCollections.\n         * @returns {undefined}\n         */\n        _prepare(data) {\n            if (\n                data.polygons.type === 'FeatureCollection' &&\n                data.points.type === 'FeatureCollection'\n            ) {\n                const polygonFeatures = data.polygons.features;\n\n                const fillBy = this.options.get('fillBy');\n                const fillByWeightType = this.options.get('fillByWeightType');\n                const fillByWeightProp = this.options.get('fillByWeightProp');\n\n                let pointFeatures = data.points.features;\n\n                for (let i = 0; i < polygonFeatures.length; i++) {\n                    const restPointFeatures = [];\n                    const polygonFeature = normalizeFeature(polygonFeatures[i], meta, {id: i});\n\n                    let pointsCount = 0;\n                    let pointsWeight = 0;\n\n                    for (let j = 0; j < pointFeatures.length; j++) {\n                        let pointFeature;\n\n                        if (i === 0) {\n                            pointFeature = normalizeFeature(pointFeatures[j], meta, {id: j});\n                            this._data.points.features.push(pointFeature);\n                        } else {\n                            pointFeature = pointFeatures[j];\n                        }\n\n                        if (inside(polygonFeature.geometry, pointFeature.geometry)) {\n                            pointsCount++;\n                            pointsWeight += pointFeature.properties[fillByWeightProp];\n                        } else {\n                            restPointFeatures.push(pointFeature);\n                        }\n                    }\n\n                    pointFeatures = restPointFeatures;\n\n                    if (fillBy === 'weight') {\n                        pointsWeight = fillByWeightType === 'middle' ?\n                            pointsWeight === 0 && pointsCount === 0 ?\n                                0 :\n                                pointsWeight / pointsCount :\n                            pointsWeight;\n                    }\n\n                    polygonFeature.properties = polygonFeature.properties || {};\n                    polygonFeature.properties.pointsCount = pointsCount;\n                    polygonFeature.properties.pointsWeight = pointsWeight;\n\n                    this._calculator(polygonFeature, {fillBy});\n\n                    this._data.polygons.features.push(polygonFeature);\n                }\n            }\n        }\n\n        /**\n         * Calculator for feture values.\n         *\n         * @param {Object} feature GeoJSON FeatureCollection.\n         * @param {Object} options Options for calculating.\n         * @private\n         */\n        _calculator(feature, options) {\n            const {pointsCount} = feature.properties;\n            const {pointsWeight} = feature.properties;\n            const {fillBy} = options;\n\n            if (\n                typeof this.pointsCountMinimum === 'undefined' ||\n                pointsCount <= this.pointsCountMinimum\n            ) {\n                this.pointsCountMinimum = pointsCount;\n            }\n\n            if (\n                typeof this.pointsCountMaximum === 'undefined' ||\n                pointsCount >= this.pointsCountMaximum\n            ) {\n                this.pointsCountMaximum = pointsCount;\n            }\n\n            if (fillBy === 'weight') {\n                if (\n                    typeof this.pointsWeightMinimum === 'undefined' ||\n                    pointsWeight <= this.pointsWeightMinimum\n                ) {\n                    this.pointsWeightMinimum = pointsWeight;\n                }\n\n                if (\n                    typeof this.pointsWeightMaximum === 'undefined' ||\n                    pointsWeight >= this.pointsWeightMaximum\n                ) {\n                    this.pointsWeightMaximum = pointsWeight;\n                }\n            }\n        }\n\n        /**\n         * Render ObjectManager.\n         *\n         * @private\n         */\n        _render() {\n            if (this.options.get('interactivity')) {\n                this._initInteractivity();\n            }\n\n            this._map.geoObjects.add(this.objectManager);\n            colorLegend.init(this);\n        }\n\n        /**\n         * Init Options.\n         *\n         * @param {Object} options Options.\n         * @param {Object} defaultOptions Default options.\n         * @private\n         */\n        _initOptions(options, defaultOptions) {\n            this.options = new OptionManager(options, defaultOptions);\n\n            const mapper = this.options.get('mapper');\n            const filterEmptyPolygons = this.options.get('filterEmptyPolygons');\n            const colorScheme = this.options.get('colorScheme');\n            const colorRanges = this.options.get('colorRanges');\n            const onMouseEnter = this.options.get('onMouseEnter');\n            const onMouseLeave = this.options.get('onMouseLeave');\n            const onClick = this.options.get('onClick');\n\n            this.options.set('mapper', mapper.bind(this));\n\n            if (filterEmptyPolygons) {\n                this.options.set('filter', defaultFilter.bind(this));\n            }\n\n            if (\n                typeof options.colorRanges === 'undefined' &&\n                colorRanges !== colorScheme.length\n            ) {\n                this.options.set('colorRanges', colorScheme.length);\n            }\n\n            this.options.set('onMouseEnter', onMouseEnter.bind(this));\n            this.options.set('onMouseLeave', onMouseLeave.bind(this));\n            this.options.set('onClick', onClick.bind(this));\n        }\n\n        /**\n         * Init ObjectManager.\n         *\n         * @private\n         */\n        _initObjectManager() {\n            const mapper = this.options.get('mapper');\n            const filter = this.options.get('filter');\n            const fillBy = this.options.get('fillBy');\n            const fillByWeight = fillBy === 'weight';\n            const colorRangesMinimum = this.options.get('colorRangesMinimum');\n\n            if (colorRangesMinimum === 'min') {\n                delete this.pointsCountMinimum;\n                delete this.pointsWeightMinimum;\n\n                const reducer = (acc, feature) => {\n                    if (!filter || filter(feature)) {\n                        this._calculator(feature, {fillBy});\n\n                        acc.push(feature);\n                    }\n\n                    return acc;\n                };\n\n                this._data.polygons.features = this._data.polygons.features.reduce(reducer, []);\n            }\n\n            try {\n                this.colorize = new Colorize(\n                    colorRangesMinimum === 'min' ?\n                        fillByWeight ? this.pointsWeightMinimum : this.pointsCountMinimum :\n                        colorRangesMinimum,\n                    fillByWeight ? this.pointsWeightMaximum : this.pointsCountMaximum,\n                    {\n                        colorScheme: this.options.get('colorScheme'),\n                        colorRanges: this.options.get('colorRanges')\n                    }\n                );\n            } catch (error) {\n                console.error(error);\n            }\n\n            const reducer = (acc, feature) => {\n                if (colorRangesMinimum !== 'min' || !filter || filter(feature)) {\n                    if (mapper) {\n                        acc.push(mapper(feature));\n                    } else {\n                        acc.push(feature);\n                    }\n\n                    this._calculator(feature, {fillBy});\n                }\n\n                return acc;\n            };\n\n            this._data.polygons.features = this._data.polygons.features.reduce(reducer, []);\n\n            this.objectManager = new ObjectManager();\n            this.objectManager.add(this._data.polygons);\n        }\n\n        /**\n         * Init interactivity.\n         *\n         * @private\n         */\n        _initInteractivity() {\n            this._prevObjectId = null;\n            this.balloon = new ymaps.Balloon(this._map);\n\n            const onMouseEnter = this.options.get('onMouseEnter');\n            const onMouseLeave = this.options.get('onMouseLeave');\n            const onClick = this.options.get('onClick');\n\n            this.objectManager.events.add('mouseenter', onMouseEnter);\n\n            this.objectManager.events.add('mouseleave', onMouseLeave);\n\n            this.balloon.options.setParent(this._map.options);\n\n            this.objectManager.events.add('click', onClick);\n        }\n    }\n\n    provide(Polygonmap);\n});\n"]}