【发布时间】:2016-06-05 14:28:27
【问题描述】:
我正在尝试让 react-google-maps 节点模块加载地图样式的 json 文件。控制台日志显示它正在查找 json 文件并加载它,但我从 require() 获得的值是一个空对象,仅加载了 getter 和 setter 函数。
像这样:
var mapStyle = require('./darkMapStyle.json');
// compiles down using webpack
var mapStyle = __webpack_require__(428);
mapStyle = {
__defineGetter__: __defineGetter__()
__defineSetter__: __defineSetter__()
__lookupGetter__: __lookupGetter__()
__lookupSetter__: __lookupSetter__()
constructor: Object()
hasOwnProperty: hasOwnProperty()
isPrototypeOf: isPrototypeOf()
propertyIsEnumerable: propertyIsEnumerable()
toLocaleString: toLocaleString()
toString: toString()
valueOf: valueOf()
get __proto__: get __proto__()
set __proto__: set __proto__()
}
// load my google map in the render()
<GoogleMapLoader
loadingElement={<div>loading</div>}
containerElement={
<div {...this.props} style={{height: "100%",}}/>
}
googleMapElement={
<GoogleMap
defaultZoom={results.mapZoom}
defaultCenter={{lat: 37.400343, lng: -122.110043}}
defaultOptions={{styles: mapStyle}}
onClick={this.handleMapClick}>
</GoogleMap>
}
/>
我使用 require 导入的所有其他模块都按预期运行,但 mapStyle 没有提供我在 json 文件中的 json 数据。
我按照这个例子来做到这一点: http://tomchentw.github.io/react-google-maps/#/basics/styled-map?_k=nd5q0e
感谢任何帮助
【问题讨论】:
标签: javascript json google-maps reactjs