You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
1 line
18 KiB
1 line
18 KiB
2 years ago
|
{"ast":null,"code":"function ownKeys(object, enumerableOnly) {\n var keys = Object.keys(object);\n\n if (Object.getOwnPropertySymbols) {\n var symbols = Object.getOwnPropertySymbols(object);\n enumerableOnly && (symbols = symbols.filter(function (sym) {\n return Object.getOwnPropertyDescriptor(object, sym).enumerable;\n })), keys.push.apply(keys, symbols);\n }\n\n return keys;\n}\n\nfunction _objectSpread(target) {\n for (var i = 1; i < arguments.length; i++) {\n var source = null != arguments[i] ? arguments[i] : {};\n i % 2 ? ownKeys(Object(source), !0).forEach(function (key) {\n _defineProperty(target, key, source[key]);\n }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) {\n Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));\n });\n }\n\n return target;\n}\n\nfunction _defineProperty(obj, key, value) {\n if (key in obj) {\n Object.defineProperty(obj, key, {\n value: value,\n enumerable: true,\n configurable: true,\n writable: true\n });\n } else {\n obj[key] = value;\n }\n\n return obj;\n}\n\nimport { PropTypes } from 'prop-types';\nimport Draw from 'leaflet-draw'; // eslint-disable-line\n\nimport isEqual from 'fast-deep-equal';\nimport React, { useRef } from 'react';\nimport { useLeafletContext } from '@react-leaflet/core';\nimport leaflet, { Map, Control } from 'leaflet';\nvar eventHandlers = {\n onEdited: 'draw:edited',\n onDrawStart: 'draw:drawstart',\n onDrawStop: 'draw:drawstop',\n onDrawVertex: 'draw:drawvertex',\n onEditStart: 'draw:editstart',\n onEditMove: 'draw:editmove',\n onEditResize: 'draw:editresize',\n onEditVertex: 'draw:editvertex',\n onEditStop: 'draw:editstop',\n onDeleted: 'draw:deleted',\n onDeleteStart: 'draw:deletestart',\n onDeleteStop: 'draw:deletestop'\n};\n\nfunction EditControl(props) {\n var context = useLeafletContext();\n var drawRef = useRef();\n var propsRef = useRef(props);\n\n var onDrawCreate = function onDrawCreate(e) {\n var onCreated = props.onCreated;\n var container = context.layerContainer || context.map;\n container.addLayer(e.layer);\n onCreated && onCreated(e);\n };\n\n React.useEffect(function () {\n var map = context.map;\n var onMounted = props.onMounted;\n\n for (var key in eventHandlers) {\n map.on(eventHandlers[key], function (evt) {\n var handlers = Object.keys(eventHandlers).filter(function (handler) {\n return eventHandlers[handler] === evt.type;\n });\n\n if (handlers.length === 1) {\n var handler = handlers[0];\n props[handler] && props[handler](evt);\n }\n });\n }\n\n map.on(leaflet.Draw.Event.CREATED, onDrawCreate);\n drawRef.current = createDrawElement(props, context);\n map.addControl(drawRef.current);\n onMounted && onMounted(drawRef.current);\n return function () {\n map.off(leaflet.Draw.Event.CREATED, onDrawCreate);\n\n for (var _key in eventHandlers) {\n if (props[_key]) {\n map.off(eventHandlers[_key], props[_key]);\n }\n }\n };\n }, []);\n React.useEffect(function () {\n if (isEqual(props.draw, propsRef.current.draw) && isEqual(props.edit, propsRef.current.edit) && props.position === propsRef.current.position) {\n return;\n }\n\n var map = context.map;\n drawRef.current.remove(map);\n drawRef.current = createDrawElement(props, context);\n drawRef.current.addTo(map);\n var onMounted = props.onMounted;\n onMounted && onMounted(drawRef.current);\n }, [props.draw, props.edit, props.position]);\n return null;\n}\n\nfunction createDrawElement(props, context) {\n var layerContainer = context.layerContainer;\n var draw = props.draw,\n edit = props.edit,\n position = props.position;\n var options = {\n edit: _objectSpread(_objectSpread({}, edit), {}, {\n featureGroup: layerContainer\n })\n };\n\n if (draw) {\n options.draw
|