我有一个名为 map.html 的页面,它是一个使用 google maps api 的简单 html:
<head>
<script type="text/javascript"
src="https://maps.googleapis.com/maps/api/js?key=XXXXXXX&sensor=true®ion=IL">
</script>
<script src="map.js" type="text/javascript"></script>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
</head>
<body>
</body>
<template name="map">
<div id="map-canvas"></div>
</template>
我使用 Iron-router 路由到这个页面:
this.route("map");
也使用 pathFor:
<a href="{{pathFor 'map'}}" class="map"><div class="inner">set location</div></a></div>
最后,我的谷歌地图初始化函数位于名为 map.js 的单独文件中:
$(document).ready(function () {
function initialize() {
var TLV = new google.maps.LatLng(32.06461, 34.777222);
var mapOptions = {
zoom: 12,
center: TLV,
panControl: false,
zoomControl: false,
mapTypeControl: true,
scaleControl: false,
streetViewControl: false,
overviewMapControl: true,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);
marker = new google.maps.Marker({
position: TLV,
map: map,
title: 'Hello World!',
draggable: true
});
google.maps.event.addListener(marker, 'dragend', function (evt) {
var pos = [marker.getPosition().lat(), marker.getPosition().lng()];
console.log(pos);
});
}
google.maps.event.addDomListener(window, 'load', initialize);
});
如果您手动路由到 http:localhost/map 一切正常,但是如果您从 localhost 转到该路由的链接以映射其不起作用,现在我知道流星在启动时为所有文件提供服务,问题是如何防止它?或者如何将某个文件提供给特定页面?