Jelajahi Sumber

地图暴露静态只读map对象

HuangKai 1 Minggu lalu
induk
melakukan
c3df7e2a4b
1 mengubah file dengan 7 tambahan dan 2 penghapusan
  1. 7 2
      src/view/Map.js

+ 7 - 2
src/view/Map.js

@@ -106,7 +106,6 @@ L.Hash.prototype.update = function() {
  * Map component handles the whole map and associated widgets.
  */
 class MyMap extends Component {
-	static map;
 	constructor() {
 		super();
 
@@ -473,7 +472,13 @@ class MyMap extends Component {
 
 		window.mapUUID = this.props.uuid;
 
-		MyMap.map = this.elem.leafletElement;
+		//静态只读map
+		Object.defineProperty(MyMap, 'map', {
+			value: this.elem.leafletElement,
+			writable: false,
+			enumerable: false,
+			configurable: false
+		});
 
 		// URL hash for map
 		this._mapHash = new L.Hash(this.elem.leafletElement);