1

(Asked on stackoverflow, but later found gis@stackexchange, and think it may be a more suitable place)

I am using a L.vectorGrid.protobuf layer (named as pbfLayer) to display vector tiles, and I want to trigger click events by pbfLayer.fileEvent('click', {latlng: <some coordinate>}). But if in this way the event argument e will only have properties latlng, target, and type, while if triggered manually by mouse clicking it will have more properties including layer.

Example: https://jsfiddle.net/ziyuang/dfekwzhd/

Every time a click event is triggered, the console will print the event argument e. A screenshot of console output is as follow, if I first trigger an event manually by clicking and then by programming, using the same coordinate:

demo-points

Is there a way to find and fill other properties of e, so that fireEvent can perfectly mimic a clicking?


(https://jsfiddle.net/ziyuang/dfekwzhd/4/):

I tried prosthetic-hand for mimicking mouse clicking but still not working. The code added is

var crs = L.CRS.EPSG3857;
var rambaut_lake_latlng = L.latLng(40.99842740667731,-74.16458129882814);
var rambaut_lake_point = crs.latLngToPoint(rambaut_lake_latlng , map.getZoom());
var southwest_point = crs.latLngToPoint(map.getBounds()._southWest, map.getZoom());
var x = rambaut_lake_point.x - southwest_point.x;
var y = map.getSize().y - (southwest_point.y - rambaut_lake_point.y);
console.log([x, y])

var hand = new Hand();
var finger = hand.growFinger('mouse');
finger.moveTo(x, y, 0).down().up();

Manually clicking will create a popup of "Rambaut Lake" but I don't see any popup on the page.


I finally get this done by using happen. In my case, I have to

var canvas = document.elementFromPoint(left, top);
$(canvas).happen({type: 'click', clientX: left, clientY: top});

And neither $('#map').happen({type: 'click', clientX: left, clientY: top}) nor using jQuery's trigger on the found canvas works for me.

closed as off-topic by PolyGeo May 19 '17 at 13:01

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This problem cannot or can no longer be reproduced. Changes to the system or to the asker's circumstances may have rendered the question obsolete, or the question does not include a procedure to enable potential answerers to reproduce the same symptoms. Such questions are off-topic as they are unlikely to help future readers, but editing them to include more details can lead to re-opening." – PolyGeo
If this question can be reworded to fit the rules in the help center, please edit the question.