2016-09-30 7 views
-2

私は油ガス業界向けのプログラムを作成しています。このプログラムでは、現場のリモートロジックボードを使用してポンプジャックがオンかオフかを確認したり、 4Gインターネットを介して情報を中継します。私は、ボード上のアラームがトリップしたかどうかによって、マップ上のアイコンが赤または緑になるように構築しようとしています。このファイルのパスは、どちらかGoogleマップのif文を使用してアイコンを変更

http://111.111.111.111/var/rmsdata/alarm1

1または0

の値を与えるどのように私は0または1の値を翻訳します:アラーム用のファイル・パスは、例えばのような静的IPを介して到達することができます値に応じてアイコンを変更するif文に挿入しますか?私は与えられたURLとベース応答のアイコンのための簡単なAjaxリクエストをやってる

 function initialize() { 


     var map_canvas = document.getElementById('map_canvas'); 
     var map_options = { 
      center: new google.maps.LatLng(50.242913, -111.195383), 
      zoom: 14, 
      mapTypeId: google.maps.MapTypeId.TERRAIN 


     } 
     var map = new google.maps.Map(map_canvas, map_options); 

     var point  =  new google.maps.LatLng(47.5, -100); 
     var derrick1 =  new google.maps.Marker ({ 
      position: new google.maps.LatLng(50.244915, -111.198540),  
      map: map, 
      icon: 'on.png', 
      size: new google.maps.Size(20, 32), 
      title: '1' 

     }) 



     google.maps.event.addDomListener(window, 'load', initialize); 
    

答えて

1

は、ここでのアイコンのいずれかのために私のコードです。このコードはテストされておらず、多く改善することができます。しかし、うまくいけば正しい方向に向けることができます。

function initialize() { 
    var url = 'http://111.111.111.111/var/rmsdata/alarm1'; 
    var map_canvas = document.getElementById('map_canvas'); 
    var map_options = { 
     center: new google.maps.LatLng(50.242913, -111.195383), 
     zoom: 14, 
     mapTypeId: google.maps.MapTypeId.TERRAIN 
    }; 
    var map = new google.maps.Map(map_canvas, map_options); 

    // Make an ajax request for the url that you specified above and base your icon on the response. 
    $.get(url, function(response) { 
     var on = true; 

     if (isNaN(response)) { 
      // If the response would contain anything else but a number. 
      console.log('Response is not a number, defaults to "on"'); 
     } else { 
      // Converts the "0" to "false" and anything else to "true". 
      on = !!+response; 
     } 

     var point = new google.maps.LatLng(47.5, -100); 
     var derrick1 = new google.maps.Marker({ 
      position: new google.maps.LatLng(50.244915, -111.198540), 
      map: map, 
      icon: (on) ? 'on.png' : 'off.png', // Shorthand if-statement to determine the icon. Also called Ternary Operator. 
      size: new google.maps.Size(20, 32), 
      title: '1' 

     }) 
    }); 

    google.maps.event.addDomListener(window, 'load', initialize); 
} 
関連する問題