Google Maps - Trigger a click event on a data layer at a specific point (long/lat) -
i loading google map geojson, , after map loaded , data layers applied, trigger click event @ specific point automatically user. subsequently, can click on map interact it.
so automatic load part, tried this:
var x = new google.maps.latlng(mylongitude, mylatitude); google.maps.event.trigger(map.data, 'click', what_goes_here?);
but can't figure out goes in last part of function. corresponding function clicking this:
map.data.addlistener('click', function (event) { ... code ... }
the event fires, event null of course. need (event) populated feature (that's type expected be) can't seem figure out how feature long/lat.
so load data layers, have long/lat, can't seem retrieve feature long/lat. suggestions on how retrieve this?
a (on)click looks (let's put marker there):
map.addlistener('click', function (event) { var position = {lat: event.latlng.lat(), lng: event.latlng.lng()} //alert(json.stringify(position)); var marker = new google.maps.marker({position: position, map: map}); });
so let's reverse this.
let's heve buttons invoke click on brussels or paris
<input type="button" value="click on brussels" onclick="clickonmap(50.85, 4.35)"> <input type="button" value="click on paris" onclick="clickonmap(48.84, 2.35)"> <script> function clickonmap(lat, lng) { var event = {latlng: {}}; event.latlng.lat = function() { return lat }; event.latlng.lng = function() { return lng }; google.maps.event.trigger(map, 'click', event); } </script>
clicking on button have same effect clicking on map, on same coordinates.
and of course can call function clickonmap automatically.
are helped this?
edit: let's need more properties of event, event.feature.getproperty("name");
try adding this: don't know else expected, can keep adding properties this.
function clickonmap(lat, lng, name) { var event = {latlng: {}, feature: {}}; event.latlng.lat = function() { return lat }; event.latlng.lng = function() { return lng }; event.feature.getproperty = function(property) { return name; }; google.maps.event.trigger(map, 'click', event); }
Comments
Post a Comment