2016-10-05 81 views
0

我試過按照說明here進行操作,當我運行流星時我沒有看到地圖。如何使用流星傳單整合傳單和流星?

這裏是所有我採取的步驟:

meteor create map-project 
cd map-project 
meteor add bevanhunt:leaflet 

然後我更改客戶端/ main.html中的內容:

<head> 
    <title>map-project</title> 
</head> 

<body> 
    <div id="map"></div> 
    <h1>Welcome to Meteor!</h1> 

    {{> hello}} 
    {{> info}} 
</body> 

<template name="hello"> 
    <button>Click Me</button> 
    <p>You've pressed the button {{counter}} times.</p> 
</template> 

<template name="info"> 
    <h2>Learn Meteor!</h2> 
    <ul> 
    <li><a href="https://www.meteor.com/try" target="_blank">Do the Tutorial</a></li> 
    <li><a href="http://guide.meteor.com" target="_blank">Follow the Guide</a></li> 
    <li><a href="https://docs.meteor.com" target="_blank">Read the Docs</a></li> 
    <li><a href="https://forums.meteor.com" target="_blank">Discussions</a></li> 
    </ul> 
</template> 

和客戶端/ main.css的到的內容:

#map { 
    min-height: 350px; 
    min-width: 100%; 
    } 

,最後客戶端/ main.js的內容:

import { Template } from 'meteor/templating'; 
import { ReactiveVar } from 'meteor/reactive-var'; 

import './main.html'; 

Template.hello.onCreated(function helloOnCreated() { 
    // counter starts at 0 
    this.counter = new ReactiveVar(0); 
}); 

Template.hello.helpers({ 
    counter() { 
    return Template.instance().counter.get(); 
    }, 
}); 

Template.hello.events({ 
    'click button'(event, instance) { 
    // increment the counter when button is clicked 
    instance.counter.set(instance.counter.get() + 1); 
    }, 
}); 
if (Meteor.isClient) { 
    L.Icon.Default.imagePath = 'packages/bevanhunt_leaflet/images/'; 
    var map = L.map('map'); 
    } 

    if (Meteor.isClient) { 
    L.tileLayer.provider('Thunderforest.Outdoors').addTo(map); 
    } 

然後我做的:

meteor npm install 
meteor 

然後導航到託管的URL,沒有地圖待觀察。

有沒有人成功做過誰可以幫忙?謝謝。

回答

1

的問題是,你還沒有宣佈你的單張地圖變量,如下(從meteor-leaflet documentation):

if (Meteor.isClient) { 
    L.Icon.Default.imagePath = 'packages/bevanhunt_leaflet/images/'; 
    var map = L.map('map'); 
    } 

你需要有一個單張地圖對象(這不只是你的地圖格!)加層,你試圖在下面的代碼行前要做的事:

if (Meteor.isClient) { 
    L.tileLayer.provider('Thunderforest.Outdoors').addTo(map); 
    } 

我建議你一個簡單的實現流星單張讀了這tutorial。 希望有所幫助!

+0

我添加了'if(Meteor.isClient){I0.Icon.Default.imagePath ='packages/bevanhunt_leaflet/images /'; var map = L.map('map'); }'到我的上面的main.js腳本和地圖仍然不顯示 –