Zum Hauptinhalt springen

MapEdit Mobile API (Deprecated)

Hinweis

This article refers to MapEdit Mobile Version lower or equal to 20.2.8

This Topics describes the MapEdit Mobile API which can be used for scripting API-Buttons and Scripting-Buttons inside a Form. For a better understanding, we provide examples explaining how to deal with this API. MapEdit Mobile is not based on the Topobase API, but instead on JavaScript and this requires an asynchronous programming style. Therefore, existing Topobase API scripts cannot be used directly, but must be reviewed and adapted, to the MapEdit Mobile API and JavaScript.

In the upper section, you can see the original Topobase API code. In the lower section, you find the MapEdit Mobile API Code. It is hardly recommended to use scripting just for small code pieces. For larger Code you should import your Script per import function. The main reason for this is that, Debugging Mode of the IDE can be conveniently used. Besides this it also offers a lot more benefits, like highlighting.

3.1 Mobile API Basics

This chapter describes the basic knowledge about Scripting with MapEdit Mobile.

You have to use the “mapedit.” Operator (a reference to the current object) to get an access to the methods. In the following paragraph, the basic methods MapEdit Mobile are explained. In the first Table “MapEditJavaScriptApi” can be found all functions to handle values, create Callbacks and display messages on the Screen. An example of its usage described in the next paragraph.

MapEditJavaScript API

Gets the current mouse position as Point.

static void 
clickHandler(com.google.gwt.core.client.JavaScriptObject func)

Create a attribute feature.

static void  
createAttributeFeature(java.lang.String datasourceName, java.lang.String tableName, com.google.gwt.core.client.JavaScriptObject func)

Create a Geometry Point

static de.mum.geo.share d.geometry.Point 
createPoint(double x, double y, double z)

Gets the value of the given column.

static double
dblValue(java.lang.String columnName)

Execute a asnyc SQL Query at the current datasource

static void  
executeQuery com.google.gwt.core.client.JavaScriptObject func,java.lang.String sql)

Find Geometry

static void  
findGeometryfindGeometry(java.lang.String datasourceName, java.lang.String tableName, double x, double y, com.google.gwt.core.client.JavaScriptObject func)

Gets the geometry as a point object.

static com.google.gwt.core.client.JavaScript Object
geomPointValue()

Gets the geometry as a geometry object.

static de.mum.geo.shared.geometry.Geometry
geomValue()

Gets the Center of geometry as a point object.

static de.mum.geo.shared.geometry.Point 
getCenterPoint()

Gets the Center of geometry as a point object in LatLon.

static de.mum.geo.shared.geometry.Point 
getCenterPointLatLon(com.google.gwt.core.client.JavaScriptObject func)

Gets the current feature.

static de.mum.geo.client.util.SimpleFeature
getCurrentFeature()

Gets the current location as point based on the location services if available.

static void   
getCurrentLocation com.google.gwt.core.client.JavaScriptObject
func)

Gets the location in the center of the map if available.

static de.mum.geo.shared.geometry.Point
getMapLocation()

Gets the value of the given column.

static int intValue(java.lang.String columnName)

Checks, if the given column is null.

static boolean isNull(java.lang.String columnName)

Gets the value of the given column.

static long lngValue(java.lang.String columnName)

open form

static void openForm(java.lang.String dialogName, java.lang.String filter,
java.lang.String mode, com.google.gwt.core.client.JavaScriptObject func)

open from for given simplefeature

static void openSimpleFeatureInForm(de.mum.geo.client.util.SimpleFeature sf,
java.lang.String mode, com.google.gwt.core.client.JavaScriptObject func)

Opens a URL in a new window.

static void openUrl(java.lang.String url)

save SimpleFeature

static void saveSimpleFeature(de.mum.geo.client.util.SimpleFeature sf, com.google.gwt.core.client.JavaScriptObject func)

Selects a feature of the given table in the map.

static void selectFeatureFromMap(java.lang.String datasourceName,
java.lang.String tableName, java.lang.String prompt, com.google.gwt.core.client.JavaScriptObject func)

set SimpleFeature value for given colunm

static void setColumnValue(de.mum.geo.client.util.SimpleFeature sf,
java.lang.String columnName, java.lang.String value)

set SimpleFeature value for given colunm

static void setGeom(de.mum.geo.client.util.SimpleFeature sf, de.mum.geo.shared.geometry.Geometry geom)

Set the Geometry of the feature

static void setGeometryPoint(de.mum.geo.client.util.SimpleFeature sf, double x, double y)

setPicture

static void setPicture(de.mum.geo.client.util.SimpleFeature sf,
java.lang.String columnName, java.lang.String dataURL,
java.lang.String url, java.lang.String preName, com.google.gwt.core.client.JavaScriptObject func)

Shows the given error using the AppController, if it is availabe.

static void 
showError(java.lang.Throwable ex)

Shows a message box containing the given message.

static void 
showMessageBox(java.lang.String message)

Gets the value of the given column.

static java.lang.String
strValue(java.lang.String columnName)

Take a picture and get the dataUrl.

static void 
takeAPicture(com.google.gwt.core.client.JavaScriptObject func)

Test function.

static void 
test()

Transforms the given geometry from latitude/longitude WGS-84 coordinates (in degrees) into local coordinates.

de.mum.geo.shared.geometry.Geometry>void
transformLatLonToLocalXY(T geom, com.google.gwt.core.client.JavaScriptObject func)

Transforms the given geometry from latitude/longitude WGS-84 coordinates (in degrees)

static <T extends de.mum.geo.shared.geometry.Geometry>void
transformLocalXYToLatLon(T geom, com.google.gwt.core.client.JavaScriptObject func)

To get an detailed summary of all function please check out this File:
MapEditJavaScriptApi.html

3.2 Mobile API Code Samples

This chapter shows some Samples for coding with JavaScript and the MapEdit Mobile API

3.2.1 Get the Content of a specified field of the current record

In this simple Example you can see how to get the value from a field. In the first line we get the FID as String. The second one show a message Box with includes the FID. JavaScript: get the content of a specified field

var fid=mapedit.strValue("FID"); //get the fid as String
mapedit.showMessageBox(fid); //show the MessageBox

3.2.2 Open a URL

In this Sample we open GoogleMaps at the center point of the Element. Of course you can also access all other Websites or control WebApplication over URL. (Hint: Checkout the Google Maps API Terms of Service License Restrictions before using it commercial) Javascript: Open Google Maps at Element Position

var point = mapedit.getCenterPointLatLon(); //get the center of current geometry as lat/lon
var url = "https://www.google.de/maps/@" + point.y + "," + point.x + ",12z";
mapedit.openUrl(url); // open googlemaps static Url

3.2.3 SQL-Query

An important thing needed to be known is everything we want to get from the server has to be done asynchronously. In this example we execute a dummy SQL and show the result in a message box. The callback Function “show(result)” create a Table and display the result in a message box. In this Example we should just see two Lines.

JavaScript: SQL-Query

function show(result) {
var tableString = "";
var columnName = result.columnName;
var valuetype = result.valuetype; //is not used in this example
//create table header
for (i = 0; i < columnName.length; i++) {
tableString = tableString + " " + columnName[i].toString();
}
tableString = tableString + "\n";
//create data
var record = result.record;
for (i = 0; i < record.length; i++) {
var row = record[i];
for (j = 0; j < row.length; j++) {
var value = row[j];
if (value != null) {
tableString = tableString + " " + value.toString();
} else {
tableString = tableString + " - ";
}
}
tableString = tableString + "\n";
}
mapedit.showMessageBox(tableString); //show Table
}
mapedit.executeQuery(show, "select * from dual"); //query with dummy sql

3.2.4 Open Google Maps Routing

In this example show how to create a routing from our position to the position of the element. At First we get our element position and our own position. Therefore we have to us a callback Function. At the end we add these items as values in the URL and open a new window. JavaScript: open googlemaps routing to element

var posFeature;
function CurrentLocationCallback(posMy) //callback Function
{
if(posMy!=null)
{
var google="https://www.google.de/maps/dir/";
var url=google+posMy.y+","+posMy.x+"/"+posFeature.y+","+posFeature.x;
mapedit.openUrl(url);
}
}
function centerPointCallback(centerPos) //callback Function
{
if(centerPos!=null)
{
posFeature=centerPos;
mapedit.getCurrentLocation(CurrentLocationCallback);
}
}
mapedit.getCenterPointLatLon(centerPointCallback);

3.2.5 Transformation

This Sample shows how to transform a Point to local Coordinates JavaScript: Transformation

var posFeature;
function CurrentLocationCallback(posMy)
{
if (posMy != null)
{
mapedit.transformLatLonToLocalXY(mapedit.createPoint(posMy.x, posMy.y, posMy.z), trans);
}
}
function trans(geom)
{
mapedit.showMessageBox(geom.toString());
}
mapedit.getCurrentLocation(CurrentLocationCallback);

3.2.6 Open a form

This Sample shows how to open a Form in View Mode. The Forms name is STMORITZ_EW.EL_LIGHT. To filter the result we use the NAME_NUMBER=500.510 Condition. JavaScript: open a form

mapedit.openForm("STMORITZ_EW.EL_LIGHT","NAME_NUMBER=500.510","VIEW",openForm)
function openForm()
{
//do something afterwoards
}

3.2.7 Take a picture

In this Sample you can see how to Take picture and save the picture server side. Before you can do this, you have to configure two things: At First, you have to configure a Virtual Directory inside your IIS or Apache. The Second step is to insert the physical and Alias into your TN_GN_DIRECTORY_ALIAS table. JavaScript: Take a picture

mapedit.takeAPicture(pic);
function pic(url)
{
mapedit.setPicture(simpleFeature,"FOTO",url,"https://gisdemo2.mum.de/MapEdit- upload/","test",callbackSetPicture);
}
function callbackSetPicture()
{
//doSomthingElse
}