【发布时间】:2017-10-31 04:34:03
【问题描述】:
我需要在我的 react 应用程序上使用 KML 层并尝试来自 https://tomchentw.github.io/react-google-maps/#kmllayer (https://developers.google.com/maps/documentation/javascript/examples/layer-kml) 的示例。
const { compose, withProps } = require("recompose");
const {
withScriptjs,
withGoogleMap,
GoogleMap,
KmlLayer,
} = require("../index");
const MapWithAKmlLayer = compose(
withProps({
googleMapURL: "https://maps.googleapis.com/maps/api/js?key=AIzaSyC4R6AN7SmujjPUIGKdyao2Kqitzr1kiRg&v=3.exp&libraries=geometry,drawing,places",
loadingElement: <div style={{ height: `100%` }} />,
containerElement: <div style={{ height: `400px` }} />,
mapElement: <div style={{ height: `100%` }} />,
}),
withScriptjs,
withGoogleMap
)(props =>
<GoogleMap
defaultZoom={9}
defaultCenter={{ lat: 41.9, lng: -87.624 }}
>
<KmlLayer
url="http://googlemaps.github.io/js-v2-samples/ggeoxml/cta.kml"
options={{ preserveViewport: true }}
/>
</GoogleMap>
);
<MapWithAKmlLayer />
app.use(express.static(`${__dirname}/assets`));
例如,如果我输入http://localhost:3000/cta.kml,则文件将直接下载,就像示例中输入http://googlemaps.github.io/js-v2-samples/ggeoxml/cta.kml一样。但是,如果我将“http://localhost:3000/cta.kml”作为 URL 放在 KmlLayer 的 URL 属性上,则谷歌地图无法显示任何线条。我不知道为什么,因为两个文件完全相同。我还尝试了其他示例 URL,并且发生了同样的事情。例如本例给出的KML文件URL(https://developers.google.com/maps/documentation/javascript/kml)
【问题讨论】:
标签: javascript node.js google-maps