0

gmaps: gmarker and HTML-Link

asked 2020-06-15 02:53:02 +0800

andij62 gravatar image andij62
307 1 7

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

delete flag offensive retag edit

5 Answers

Sort by ยป oldest newest most voted
1

answered 2020-06-22 16:05:38 +0800

cor3000 gravatar image cor3000
5250 2 7
ZK Team

updated 2020-06-22 16:11:54 +0800

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-

link publish delete flag offensive edit
1

answered 2020-06-23 12:21:48 +0800

cor3000 gravatar image cor3000
5250 2 7
ZK Team

updated 2020-06-23 12:29:32 +0800

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]");
link publish delete flag offensive edit
0

answered 2020-06-15 14:47:25 +0800

cor3000 gravatar image cor3000
5250 2 7
ZK Team

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?

link publish delete flag offensive edit
0

answered 2020-06-19 17:43:38 +0800

andij62 gravatar image andij62
307 1 7

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.

link publish delete flag offensive edit

Comments

for this you'll have to add some JS into the content, e.g. to trigger a custom event. Since it's already end-of-business today I'll try to get back with an example on monday

cor3000 ( 2020-06-19 18:57:55 +0800 )edit

Thank you! I'm looking forward to the example

andij62 ( 2020-06-20 20:41:23 +0800 )edit
0

answered 2020-06-22 23:03:54 +0800

andij62 gravatar image andij62
307 1 7

updated 2020-06-22 23:05:26 +0800

can you tell me how to set the gmarker.setcontent in Java to fire the "doClickContentLink"-Event?

link publish delete flag offensive edit
Your answer
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow
1 follower

RSS

Stats

Asked: 2020-06-15 02:53:02 +0800

Seen: 18 times

Last updated: Jun 23

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More