맵 페이지에 대한 스크립팅

  • 릴리스 버전: Yokohama
  • 업데이트 날짜 2025년 01월 30일
  • 읽기10분
  • 맵 페이지 양식의 스크립트 필드에서는 속성 또는 사용자 지정 코드를 사용하여 마커 모양, 표시 정보 등과 같은 맵 특성을 정의할 수 있습니다.

    스크립팅 맵 항목 속성

    다음과 같은 속성을 사용할 수 있습니다.
    주:
    맵에 항목을 생성하려면 map.addItem(glideRecord) 메서드를 사용합니다. 유효한 GlideRecord를 에 전달합니다 addItem().
    속성 설명
    이름 식별에 사용되는 이름입니다.
    위도 주소를 정의하는 경우에는 위도가 필요하지 않습니다.
    경도 주소를 정의하는 경우 경도는 필요하지 않습니다.
    아이콘 마커에 표시할 아이콘의 URL입니다. 사용자 지정 아이콘을 지정하지 않으면 기본 Google 마커가 사용됩니다.
    icon_width 아이콘의 너비입니다. 기본값은 32입니다.
    icon_height 아이콘의 높이입니다. 기본값은 32입니다.
    table_name 마커 아이콘을 클릭할 때 기록이 표시되는 테이블입니다. 속성과 sys_id 함께 사용됩니다.
    sys_id 마커 아이콘을 클릭할 때 표시되는 기록의 Sys_id입니다. 속성과 table_name 함께 사용됩니다.
    마커 아이콘을 클릭할 때 대화 상자에 표시되는 양식의 뷰입니다.
    HTML 팝업 창에 대한 임의의 HTML 코드입니다. 이 값을 사용하면 대화 상자가 재정의됩니다.
    marker_label 선택적 마커 아이콘 레이블 텍스트입니다.
    label_offset_left 마커 레이블의 수평 위치를 정의하는 데 사용되는 marker_label 선택적 속성입니다. 기본값은 0입니다.
    label_offset_top 마커 레이블의 수직 위치를 정의하는 데 사용되는 marker_label 선택적 속성입니다. 기본값은 0입니다.

    스마트폰에 대한 사용자 지정 맵 페이지 동작 스크립팅

    스마트폰에서 맵 페이지에 접근하려는 경우 변수를 사용하여 스마트폰 인터페이스 동작을 설정할 수 있습니다 isMobile . 이 isMobile 변수를 사용하여 맵의 스마트폰 뷰에 대한 사용자 지정 동작을 설정할 수 있습니다. 예를 들어, is true인 icon_width 경우 isMobile and icon_height 속성에 대해 다른 값을 설정할 수 있습니다.

    기본 맵 페이지 스크립트

    이 스크립트는 모든 중요 활성 인시던트 위치를 표시합니다.
    //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 맵 페이지 스크립트

    이 스크립트는 스마트폰 사용자를 위한 사용자 지정 설정을 사용하여 모든 중요 활성 인시던트 위치를 표시합니다.
    //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";
     }
    }

    고급 맵 페이지 스크립트

    이 스크립트는 위치별로 오픈 인시던트 수를 표시합니다. 위치에 대한 미해결 인시던트 수에 따라 아이콘의 크기가 달라집니다. 또한 html 매개변수를 사용하면 위치 이름과 인시던트 수 및 관련 인시던트 목록에 대한 링크도 표시됩니다.
    //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";
     }
     }
    }

    맵 페이지 마커 레이블 스크립트

    마커 레이블을 사용하면 마커에 동적 텍스트를 추가할 수 있습니다. 이 예에서는 각 위치의 활성 인시던트 개수를 표시합니다.
    그림 1. 맵 마커 레이블
    //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;
     
     }
    }