Script para páginas de mapa

  • Versão de lançamento: Xanadu
  • Atualizado 1 de ago. de 2024
  • 5 min. de leitura
  • O campo Script no formulário Mapear página permite o uso de atributos ou código personalizado para definir características do mapa, como aparência do marcador, informações de exibição e muito mais.

    Atributos de item do mapa de script

    Os seguintes atributos estão disponíveis.
    Nota:
    Para criar um item no mapa, use o método map.addItem(glideRecord). Passe um GlideRecord válido para addItem().
    Atributo Descrição
    nome Nome usado para identificação.
    latitude Se você definir um endereço, a latitude não será necessária.
    longitude Se você definir um endereço, a longitude não será necessária.
    ícones URL do ícone a ser exibido para o marcador. Se um ícone personalizado não for especificado, o marcador padrão do Google será usado.
    icon_width Largura do ícone. O padrão é 32.
    icon_height Altura do ícone. O padrão é 32.
    table_name Tabela cujos registros são exibidos quando o ícone do marcador é clicado. Usado com o atributo sys_id.
    sys_id Sys_id do registro que é exibido quando o ícone do marcador é clicado. Usado com o atributo table_name.
    exibição Exibição do formulário exibido na caixa de diálogo quando o ícone do marcador é clicado.
    html Código HTML arbitrário para a janela pop-up. Se usado, este valor substitui a caixa de diálogo.
    marcador_rótulo Texto do rótulo do ícone do marcador opcional.
    rótulo_offset_left Atributo opcional que é usado com marker_label para definir a posição horizontal do rótulo do marcador. O padrão é 0.
    rótulo_compensação_topo Atributo opcional que é usado com marker_label para definir a posição vertical do rótulo do marcador. O padrão é 0.

    Script do comportamento da página de mapa personalizado para smartphone

    Se você planeja acessar a página de mapa de um smartphone, convém definir o comportamento personalizado da interface do smartphone usando a variável isMobile. Você pode usar a variável isMobile para definir um comportamento personalizado para a exibição de smartphone do mapa. Por exemplo, você pode definir valores diferentes para os atributos icon_width e icon_height quando isMobile for verdadeiro.

    Script de página de mapa básico

    Este script exibe todos os locais de incidentes críticos ativos.
    //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";
    }

    Script da página do mapa isMobile

    Este script exibe todos os locais de incidentes críticos ativos com configurações personalizadas para usuários de smartphones.
    //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";
     }
    }

    Script de página de mapa avançado

    Este script exibe o número de incidentes em aberto por local. Ele varia o tamanho do ícone com base no número de incidentes abertos para o local. Usando o parâmetro html, ele também exibe o nome do local e o número de incidentes, bem como um link para a lista de incidentes relacionados.
    //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";
     }
     }
    }

    Mapear script de rótulo de marcador de página

    Os rótulos do marcador permitem adicionar texto dinâmico aos marcadores. Este exemplo exibe a contagem de incidentes ativos em cada local.
    Figura 1. Mapear rótulos de marcador
    //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;
     
     }
    }