-
FEATURED COMPONENTS
First time here? Check out the FAQ!
Hi all,
with "gmarker.setAttribute" i remember a few parameters. Each of the gmarkers contains an HTML-Link. Is it possible to read the parameters in the controller by clicking on the Link.
Regards Andi
here an example showing several options: https://zkfiddle.org/sample/1flj58q/1-gmaps-gmarker-with-links
key is the gmarker content, can contain listeners in the form of <a onclick="somejscode" ...>
these can be be passed as a string into Gmarker.setContent()
Using ZK's client side API the Gmarker widget can be found via its component id and then widget methods can be called.
zk.$('$marker01').fire('onCustomEvent', data, opts)
you could just do this directly or as in my example, add a dedicated method to the Gmarker widget to handle these clicks doClickContentLink
.
https://www.zkoss.org/javadoc/latest/jsdoc/global/zk.html#Z:Z:D-- https://www.zkoss.org/javadoc/latest/jsdoc/global/zk.html#override-java.lang.Object-global.Map-global.Map- https://www.zkoss.org/javadoc/latest/jsdoc/zk/Widget.html#fire-global.String-zk.Object-global.Map-int-
you do the same as I showed in the example:
<gmarker id="marker01" lat="0" lng="0" open="true">
<attribute name="content"><![CDATA[
some text
<a role="button" href="#" onclick="zk.$('$marker01').doClickContentLink({ info: 'more_info', foo: 'this is a Map at server side', bar: 1234 });">more info</a>
more text
<a role="button" href="#" onclick="zk.$('$marker01').doClickContentLink('just a string');">even more info</a>
]]></attribute>
</gmarker>
the <attribute name="content">
is equivalent to calling
gmarker.setContent("some text<a role=\"button\" href=\"#\" " +
"onclick=\"zk.$('$marker01').doClickContentLink( ... [the same content here]");
can you tell me how to set the gmarker.setcontent in Java to fire the "doClickContentLink"-Event?
With "marker.setContent" i put an info text and a link with "show me more information" to the marker. if the user clicks on the link i would like to intercept it in the controller in order to give him further information in the same controller!
Or is there an option with "marker.setContent" e.g. to set a zk-Toolbarbutton and intercept the event?
In the end i need the possibility to click on something in the marker and to catch this event in the controller.
The instant answer would be: Call gmarker.getAttribute()
on the same marker instance, to read the 'remembered' parameters.
Anyway that sounds too trivial for you to ask.
So I guess your question is how to get the gmarker instance that was clicked on.
<zk>
<gmaps id="map" width="400px" height="300px" lat="0" lng="0">
<gmarker id="marker" lat="0" lng="0" />
</gmaps>
</zk>
set/access the attribute from a composer/listener
marker.setAttribute("test", 123);
map.addEventListener("onMapClick", new EventListener() {
public void onEvent(Event e) {
MapMouseEvent mme = (MapMouseEvent) e;
Gmarker markerFromEvent = mme.getGmarker();
if(markerFromEvent != null) {
Clients.log("attr from marker: test = " + markerFromEvent.getAttribute("test"));
}
}
});
That's how you would access the attribute in a onMapClick listener from the controller.
You also mention a "HTML-Link" without giving a concrete example. Where does the link lead?
Redirecting to a different page? Then your Gmarker component - including its attributes - won't be available there. You could use URL parameters instead to convey information to the other page.
OR
Are you trying to call an event listener inside the same controller that already set the attribute?
Asked: 2020-06-15 02:53:02 +0800
Seen: 20 times
Last updated: Jun 23 '20