---
sourceDocument: Now Platform-Anwenderoberfläche von Xanadu
sourceDocumentLink: https://servicenow-prod.fluidtopics.net/r/de-DE/xanadu/platform-user-interface

 Release :

    - xanadu

ft:locale :

    - de-DE

ft:publication_title :

    - Now Platform-Anwenderoberfläche von Xanadu

ft:clusterId :

    - platux

bundleId :

    - platux

workflow :

    - Platform


---

# Skripting für Kartenseiten

# Skripting für Kartenseiten {#ariaid-title1}

* Freigeben Version: Xanadu
* 
* Aktualisiert 1. August 2024
* 
* ![](https://www.servicenow.com/docs/portal-asset/ico-clock) 5 Minuten Lesedauer

Das Feld Skript im Formular „Kartenseite" ermöglicht die Verwendung von Attributen oder anwenderdefiniertem Code zum Definieren von Karteneigenschaften, wie z. B. die Darstellung von Markern, Anzeigeinformationen und mehr.

## Skripting-Zuordnungselementattribute

Die folgenden Attribute sind verfügbar.  
Hinweis:  
Um ein Element auf der Karte zu erstellen, verwenden Sie die Methode map.addItem(glideRecord). Übergeben Sie einen gültigen GlideRecord an addItem().
{#scripting-for-map-pages__table_a3s_kr5_cr__entry__2}

| Attribut | Beschreibung |
|-|-|
| Name | Zur Identifizierung verwendeter Name. |
| latitude | Wenn Sie eine Adresse definieren, ist der Breitengrad nicht erforderlich. |
| longitude | Wenn Sie eine Adresse definieren, ist der Längengrad nicht erforderlich. |
| icon | URL des Symbols, das für den Marker angezeigt werden soll. Wenn kein anwenderdefiniertes Symbol angegeben ist, wird der Standardmarker von Google verwendet. |
| icon_width | Breite des Symbols. Der Standardwert ist 32. |
| icon_height | Höhe des Symbols. Der Standardwert ist 32. |
| table_name | Tabelle, deren Datensätze angezeigt werden, wenn auf das Markersymbol geklickt wird. Wird mit dem Attribut sys_id verwendet. |
| sys_id | Sys_id des Datensatzes, der angezeigt wird, wenn auf das Markersymbol geklickt wird. Wird mit dem Attribut table_name verwendet. |
| Ansicht | Ansicht des Formulars, das im Dialogfeld angezeigt wird, wenn Sie auf das Markersymbol klicken. |
| html | Beliebiger HTML-Code für das Popup-Fenster. Bei Verwendung überschreibt dieser Wert das Dialogfeld. |
| Marker_Bezeichnung | Optionaler Beschriftungstext des Markersymbols. |
| label_offset_left | Optionales Attribut, das mit marker_label verwendet wird, um die horizontale Position der Markerbezeichnung zu definieren. Der Standardwert ist 0. |
| label_offset_top | Optionales Attribut, das mit marker_label verwendet wird, um die vertikale Position der Markerbezeichnung zu definieren. Der Standardwert ist 0. |
[ ]

{#scripting-for-map-pages__table_a3s_kr5_cr}

## Erstellen eines Skripts für das Verhalten der anwenderdefinierten Kartenseite für Smartphones {#scripting-for-map-pages__section_sx4_jtw_j1b}

Wenn Sie von einem Smartphone aus auf die Kartenseite zugreifen möchten, können Sie mit der Variablen isMobile ein anwenderdefiniertes Verhalten der Smartphone-Schnittstelle festlegen. Mit der Variablen isMobile können Sie anwenderdefiniertes Verhalten für die Smartphone-Ansicht der Zuordnung festlegen. Beispielsweise können Sie unterschiedliche Werte für die Attribute icon_width und icon_height festlegen, wenn isMobile auf „wahr" festgelegt ist.

## Skript für einfache Kartenseite {#scripting-for-map-pages__section_q5n_ytw_j1b}

Dieses Skript zeigt alle aktiven Standorte kritischer Incidents an.

    //setup new GlideRecord query on the incident table
    var now_GR = new GlideRecord("incident");
    //add condition for priority 1
    gr.addQuery('priority', '1');
    //add condition for active incidents
    gr.addActiveQuery();
    //execute the query
    gr.query();
     
    //loop through the list of incidents returned by the query
    while (gr.next()) {
     
     //create a new map item to display - linked to the current incident record
     var item = map.addItem(now_GR);
     //add the latitude value from the incident's location
     item.latitude = gr.location.latitude;
     //add the longitude value from the incident's location
     item.longitude = gr.location.longitude;
     //link to the icon image
     item.icon = "http://maps.google.com/mapfiles/kml/pal3/icon51.png";
     //set the icon size
     item.icon_width = "16";
     item.icon_height = "16";
    }

## isMobile-Kartenseitenskript {#scripting-for-map-pages__section_ldd_v5w_j1b}

Dieses Skript zeigt alle aktiven, kritischen Incident-Standorte mit anwenderdefinierten Einstellungen für Smartphone-Benutzer an.

    //setup new GlideRecord query on the incident table
    var now_GR = new GlideRecord("incident");
    //add condition for priority 1
    gr.addQuery('priority', '1');
    //add condition for active incidents
    gr.addActiveQuery();
    //execute the query
    gr.query();
     
    //loop through the list of incidents returned by the query
    while (gr.next()) {
     
     //create a new map item to display - linked to the current incident record
     var item = map.addItem(now_GR);
     //add the latitude value from the incident's location
     item.latitude = gr.location.latitude;
     //add the longitude value from the incident's location
     item.longitude = gr.location.longitude;
     //link to the icon image
     item.icon = "http://maps.google.com/mapfiles/kml/pal3/icon51.png";
     
     //set the icon size (use smaller icons for smartphone users)
     if (isMobile) {
       item.icon_width = "12";
       item.icon_height = "12";
     }
     else { 
       item.icon_width = "16";
       item.icon_height = "16";
     }
    }

## Erweitertes Skript für Kartenseite {#scripting-for-map-pages__section_blc_bvw_j1b}

Dieses Skript zeigt die Anzahl der offenen Incidents nach Standort an. Sie variiert die Größe des Symbols basierend auf der Anzahl der offenen Incidents für den Standort. Bei Verwendung des HTML-Parameters werden auch der Standortname und die Anzahl der Incidents sowie ein Link zur Liste der zugehörigen Incidents angezeigt.

    //get the instances url so we can link back to it
    var uri = gs.getProperty("glide.servlet.uri");
    //create an aggregate query on the incident table
    var count = new GlideAggregate('incident');
    //set condition for active incidents
    count.addQuery('active', 'true');
    //set aggregate field to location to get count by location
    count.addAggregate('COUNT', 'location');
    //execute the query
    count.query();
     
    //loop through the results
    while (count.next()) {
     
     //get the current record's location
     var loc = count.location;
     //get the count of incidents for this location
     var locCount = count.getAggregate('COUNT', 'location');
     //only display location is there are active incidents
     if (locCount > 0) {
     //create new new map item for this location
     var item = map.addItem(count);
     //set lat/long from the location record
     item.latitude = loc.latitude;
     item.longitude = loc.longitude;
     //build the link to the list of incidents for the location
     var link = 'href=' + uri + 'incident_list.do?sysparm_query=active%3Dtrue^location%3D' + loc;
     //build the html value to be displayed when you click the map icon
     item.html='<a ' + link + '>' + loc.getDisplayValue() + ' (' + locCount + ')</a>';
     //link to the icon image
     item.icon = "http://maps.google.com/mapfiles/kml/pal3/icon51.png";
     //set the size of the icon based on the number of active incidents
     if (locCount < 5) {
     item.icon_width = "12";
     item.icon_height = "12";
     }
     else if (locCount < 15) {
     item.icon_width = "16";
     item.icon_height = "16";
     }
     else {
     item.icon_width = "32";
     item.icon_height = "32";
     }
     }
    }

## Skript für Markerbeschriftung für Kartenseite {#scripting-for-map-pages__section_nyt_mvw_j1b}

Mit Markerbezeichnungen können Sie Markern dynamischen Text hinzufügen. In diesem Beispiel wird die Anzahl der aktiven Incidents an jedem -Standort angezeigt. Abbildung : 1. Kartenmarkerbezeichnungen

    //get the instances url so we can link back to it
    var uri = gs.getProperty("glide.servlet.uri");
    //create an aggregate query on the incident table
    var count = new GlideAggregate('incident');
    //set condition for active incidents
    count.addQuery('active', 'true');
    //set aggregate field to location to get count by location
    count.addAggregate('COUNT', 'location');
    //execute the query
    count.query();
     
    //loop through the results
    while (count.next()) {
     
     //get the current record's location
     var loc = count.location;
     //get the count of incidents for this location
     var locCount = count.getAggregate('COUNT', 'location');
     //only display location is there are active incidents
     if (locCount > 0) {
     //create new new map item for this location
     var item = map.addItem(count);
     //set lat/long from the location record
     item.latitude = loc.latitude;
     item.longitude = loc.longitude; 
     
     //create a marker label with the count
     item.marker_label = locCount;
     //define label offset for proper position
     item.label_offset_left = -4;
     item.label_offset_top = -20;
     
     //option to define table and record for label hyperlink
     //setting table and sys_id will override the use of html parameter
     //item.table = 'cmn_location';
     //item.sys_id = loc;
     
     //build the link to the list of incidents for the location
     var link = 'href=' + uri + 'incident_list.do?sysparm_query=active%3Dtrue^location%3D' + loc;
     //build the html value to be displayed when you click the map icon
     item.html='<a ' + link + '>' + loc.getDisplayValue() + ' (' + locCount + ')</a>';
     
     //link to the icon image
     item.icon = "images/red_marker.png";
     //set the size of the icon based on the number of active incidents
     item.icon_width = 24;
     item.icon_height = 24;
     
     }
    }

**Zugehörige Tasks**   

* [Google Maps API einrichten](https://servicenow-prod.fluidtopics.net/1untn54IHL859VLbWQYd4A "Sie aktivieren die Positionsbestimmungsfunktion mithilfe der entsprechenden Einträge aus einer Google Maps API for Business-Lizenz oder einem Google Maps-JavaScript-API-Schlüssel.")
* [Erstellen Sie eine Kartenseite](https://servicenow-prod.fluidtopics.net/aQ30msQtLZlB0NoZvTDeJQ "Ihre Instanz ServiceNow stellt mehrere Standardkartenseiten bereit. Sie können auch anwenderdefinierte Kartenseiten mit den auf dieser Seite beschriebenen Skriptbeispielen erstellen.")
* [Erstellen Sie ein Kartenseitenmodul](https://servicenow-prod.fluidtopics.net/LwooBdbRgBiuX4oCJtaq6w "Sie können ein neues Anwendungsmodul für Desktop- oder Smartphone-Benutzer erstellen, um eine Google -Kartenseite anzuzeigen.")
* [Erstellt eine erweiterte Kartenseite](https://servicenow-prod.fluidtopics.net/jVOZhl7bT2QrbDy7U7sX9g "Verwenden Sie die erweiterte Konfiguration, um Kartenseiten ohne Skripterstellung einzurichten.")
* [Legen Sie den Zuordnungs-Anwendungsbereich fest](https://servicenow-prod.fluidtopics.net/l1oRk5pKyDtxwNzXxbFjdQ "Aktivieren Sie den Anwendungsbereich zuordnen, um anzugeben, welche Anwendung die Konfiguration der Kartenseite ändern kann.")
* [Erstellt ein Seitenmodul für Smartphones](https://servicenow-prod.fluidtopics.net/5_bsTZUH0N5ZuwayyEzFig "Sie können ein anwenderdefiniertes Smartphone-Modul erstellen, das direkt mit einer Kartenseite verknüpft ist.")

