当前位置: 动力学知识库 > 问答 > 编程问答 >

Adding geoJSON layer to a google map in Meteor.js

问题描述:

I have a plain google map that displays fine, while running in Meteor with bootstrap, and this plugin - https://github.com/dburles/meteor-google-maps I am new to Meteor.js and can't figure how to load in some local trails data from a city open geoJSON file. I've been able to do it in plain javascript using loadGeoJson() but having a hard time incorporating this in meteor.

The template and javascript are below.

if (Meteor.isClient) {

Meteor.startup(function() {

GoogleMaps.load();

});

Template.map.helpers({

exampleMapOptions: function() {

// Make sure the maps API has loaded

if (GoogleMaps.loaded()) {

// Map initialization options

return {

center: new google.maps.LatLng(43.613, -116.211),

zoom: 12

};

}

}

});

Template.map.onCreated(function() {

// We can use the `ready` callback to interact with the map API once the map is ready.

GoogleMaps.ready('exampleMap', function(map) {

// Add a marker to the map once it's ready

var marker = new google.maps.Marker({

position: map.options.center,

map: map.instance

});

});

}

<template name="map"><div class="container-fluid text-center"><div class="map-container">{{> googleMap name="exampleMap" options=exampleMapOptions}}</div></div>

</template>

网友答案:

There are some ways to load a map into meteor, but the meteor way to knows when the map is ready is taking off the $(document).ready(function(){}); and instead use a onRendered function, you don't need a helper at all, the only you need is a init function and a onRender (just to be sure that the <div> with the map is ready.

I made a Demo here is the Source Code on Github, it use a older version of meteor (1.2.1), but the only think that changes its the rendered function

I never use that meteor-gogole-maps for me putting the CDN into the <head> works ;p

Seems you are asking a way to use gmaps on meteor, i think thats all i can do for now, also there is no errors given.

Good Luck

分享给朋友:
您可能感兴趣的文章:
随机阅读: