0

Я изо всех сил стараюсь, чтобы Google Maps отображал мне данные, хранящиеся в объекте GeoJSON. Если я использую событие click на полигоне, он работает в первый раз. Нижеприведенный код:Google Maps GeoComplete с GeoJson

// Get the GeoJSON file from the server 
HTTP.get(Meteor.absoluteUrl("/geo.json"), function(err,result) { 
    GoogleMaps.maps.fibreMap.instance.data.loadGeoJson("/geo.json"); 
}); 

// Add style and colouring to the map 
GoogleMaps.maps.fibreMap.instance.data.setStyle(function(feature) { 
    // Get the Fibrehood Status 
    var status = feature.getProperty('status'); 
    // Add colour accoring to status 
    if (status == "live") { 
     opacity = 0.65; 
    } else if (status == "build") { 
     opacity = 0.4; 
    } else if (status == "register_i") { 
     opacity = 0.2; 
    } 
    // Return the correct styling 
    return ({ 
     fillColor: '#ec008c', 
     strokeColor: '#ec008c', 
     strokeOpacity: 0.35, 
     strokeWeight: 0, 
     fillOpacity: opacity 
    }); 
}); 

GoogleMaps.maps.fibreMap.instance.data.addListener('click', function(event) { 
    var hood = event.feature.getProperty('name'); 
    var status = event.feature.getProperty('status'); 
    console.log(hood + " : " + status); 
}); 

Однако при попытке использовать GeoComplete для удаления булавки по адресу он не запускается. Я знаю, что это должно запускаться с каким-то событием, например, сбрасыванием маркера на карте или с изменением Dom Element, но я не могу понять это.

Есть ли у кого-нибудь представление о том, как инициировать события из DOM или бросать маркер на карту? Я немного нуб и очень ценю любую помощь.

Благодаря Майк

+0

существует ли связь между этим 'geo.json' и geocomplete? Я не верю, что вы можете сделать указанные адреса геолокации плагинов, кроме как через Google – amenadiel

ответ

0

Кто-нибудь есть понимание того, как вызвать события из DOM или понижая маркер на карте?

Несомненно, есть. API JS API Google имеет хорошо документированный пример работы с map events и маркерами карт.

В этом примере маркер будет выпадать на карте, где вы нажали кнопку «click event».

// This event listener calls addMarker() when the map is clicked. 
    google.maps.event.addListener(map, 'click', function(event) { 
    addMarker(event.latLng, map); 
    }); 

    // Add a marker at the center of the map. 
    addMarker(bangalore, map); 
} 

// Adds a marker to the map. 
function addMarker(location, map) { 
    // Add the marker at the clicked location, and add the next-available label 
    // from the array of alphabetical characters. 
    var marker = new google.maps.Marker({ 
    position: location, 
    label: labels[labelIndex++ % labels.length], 
    map: map 
    }); 
} 

Полная демо-версия here.

Вот ссылка на образец для прослушивания событий DOM:

https://developers.google.com/maps/documentation/javascript/examples/event-domListener