Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New to the CF scene
    Join Date
    Feb 2012
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    a mystery for me...

    hi all
    i am a beginner in java script. sorry due to this question
    well i am studying jsmap.js javascript from koders web site and i can nof find out what is going on
    in the jsmap.ja there is the source code like this:

    var = new jsmap(...)

    first question
    can java script instantiate an object?

    some days later i found that opengts opensource project is using jsmap.js. i also foind that inside that project there is some java files one of them defines the class jsmap

    second question
    can javascript instqtiate java objects?

    if not which technollgy is beeing used in the opengts project that allows javascript to instatiate java classes?

    thanks a lot

    alex tilt

  • #2
    New Coder
    Join Date
    Sep 2011
    Location
    United Kingdom
    Posts
    74
    Thanks
    2
    Thanked 3 Times in 3 Posts

    Question

    Can you explain what instantiate means and in which context in related to coding it usually used. This is the first time I heard about jsmap(). It is obviously a JavaScript object, which enables you to display some form of pop up and maps.

    with
    Code:
    var = new jsmap()
    The "var" variable becomes an jsmap object. Now you have to find which methods and pramenter this jsmap() object has to do something with it.

    What means opengts, instqtiate, and intantialte ?

  • #3
    New to the CF scene
    Join Date
    Feb 2012
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    sorry i am using android to write messages

    if you access www.opengts.org you can see in source code a javascript called jsmap.js instantiating an object of type jsmap...
    as far as i know we can not call java methods from javascript but in that opensource product we can see it

    my question is
    how can they do that?

    may be they are using ajax or something? i dont know nothibg about ajax

    i would like to reuse the jsmap.js and all java class files in order to show openstreet maps in my html page

    any comments?

    thanks a lot

    alex

  • #4
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,021
    Thanks
    75
    Thanked 4,323 Times in 4,289 Posts
    JavaScript *CAN* call Java methods if the Java is in an applet (that is, loaded into the user's browser). It can't call server-side Java (e.g., JSP) without using AJAX, though.

    Here:
    http://www.lmgtfy.com/?q=calling+jav...avascript+code
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #5
    New to the CF scene
    Join Date
    Feb 2012
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    It does not seems to be an applet:

    Here the details copied from opengts project:

    Firstly the jsmap.js javascript:


    jsmap.js

    ...

    function jsMapInit()
    {
    if (jsmap == null) {
    jsmapElem = document.getElementById(MAP_ID);
    if (jsmapElem != null) {
    try {
    jsmap = new JSMap(jsmapElem);
    jsmap.JSDrawPushpins(null, RECENTER_ZOOM, 0);
    } catch (e) {
    alert("Error [jsMapInit]:\n" + e);
    }
    } else {
    alert("Error [jsMapInit]:\nDiv '" + MAP_ID + "' not found");
    }
    }
    };

    ...


    Look to the instruction:
    jsmap = new JSMap(jsmapElem);


    Now the java file of the same project:


    JSMap.java

    ...

    // Required funtions defined by 'jsmap.js':
    // new JSMap(String mapID)
    // JSClearLayers()
    // JSDrawPushpins(JSMapPushpin pushPins[], recenter)
    // JSDrawRoute(JSMapPoint points[])
    // JSDrawGeozone(int type, boolean editable, double radius, JSMapPoint points[], int primaryIndex)
    // JSShowPushpin(JSMapPushpin pushPin)
    // JSUnload()

    import java.util.*;
    import java.io.*;

    import javax.servlet.*;
    import javax.servlet.http.*;

    //import org.opengts.util.*;


    public class JSMap extends MapProviderAdapter
    {

    // ------------------------------------------------------------------------

    public static final String DEFAULT_MAP_ID = "jsmap";

    private static final int DEFAULT_ZOOM = 14; // when no points are displayed
    private static final int PUSHPIN_ZOOM = 8; // when points are displayed

    private static final String PROP_MAP_ID = "jsmap.mapID";
    private static final String PROP_MAP_LOADING = "jsmap.showMapLoading";
    private static final String PROP_MAP_LOADING_IMAGE = "jsmap.showMapLoading.image";

    // ------------------------------------------------------------------------
    // ------------------------------------------------------------------------

    /* JSMap instance */
    public JSMap(String name, String key)
    {
    super(name, key);
    }

    // ------------------------------------------------------------------------

    /* get map element ID */
    public String getMapID()
    {
    RTProperties rtp = this.getProperties();
    return rtp.getString(PROP_MAP_ID, DEFAULT_MAP_ID);
    }


    MapProviderAdapter:

    import java.util.*;
    import java.io.*;

    import javax.servlet.*;
    import javax.servlet.http.*;

    import javax.xml.parsers.*;
    import org.w3c.dom.*;
    import org.xml.sax.*;

    public abstract class MapProviderAdapter
    implements MapProvider
    {
    ...


    MapProvider:

    import java.util.*;
    import java.io.*;

    import javax.servlet.*;
    import javax.servlet.http.*;


    public interface MapProvider
    {

    // ------------------------------------------------------------------------

    /* these attributes are used during runtime only, they are not cached */
    public static final long FEATURE_GEOZONES = 0x00000001L;
    public static final long FEATURE_LATLON_DISPLAY = 0x00000002L;
    public static final long FEATURE_DISTANCE_RULER = 0x00000004L;
    public static final long FEATURE_DETAIL_REPORT = 0x00000008L;
    public static final long FEATURE_DETAIL_INFO_BOX = 0x00000010L;



    Ok, I can see that all this is produced using servlets, that is, the client issues a request and the servlet returns a web page with embedded javascript .

    But i cant understand how the javascript returned by the servelet (which is in the beginning of this email) can then create an instance of JSMap at client side in order to show a map to the user and allow him to make zoom, etc.



    Any help?

    Alex

  • #6
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,021
    Thanks
    75
    Thanked 4,323 Times in 4,289 Posts
    Are you talking about *THIS* jsmap: http://drupal.org/project/jsmap
    ??
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •