nansencenter / django-geo-spaas

GeoDjango apps for satellite data management in Geo-Scientific Platform as a Service
GNU General Public License v3.0
20 stars 6 forks source link

Highlight polygon when mouse hovers over table #145

Closed akorosov closed 3 years ago

akorosov commented 3 years ago

that should work:

var footprints_layer_style = {
    "color": "#0000ff",
    "weight": 1,
    "opacity": 0.5,
    "fillOpacity": 0.1,
};

function add_geojson_geometries(map) {
    var geoms = document.getElementsByClassName("geometry_ref");
    for (var i = 0; i < geoms.length; i++) {
        all_geoms.push(new L.GeoJSON.AJAX(
        "https://web.nersc.no" + geoms.item(i).attributes.ajax_url.value,
        {style: footprints_layer_style}).addTo(map));
    };
};

function map_init_callback(e){
    map = e.detail.map;
};

$(window).on('map:init', map_init_callback);

var polygons = {};

$(document).ready(function(){
  $(".geometry_ref").each(function(){
    polygons[$(this).attr("ajax_url")] = new L.GeoJSON.AJAX(
        "https://web.nersc.no" + $(this).attr("ajax_url"),
        {style: footprints_layer_style}).addTo(map);
  });

  $(".geometry_ref").hover(
  function(){
    $(this).css("background-color", "#ffeeee");
    polygons[$(this).attr("ajax_url")].setStyle({color: '#FF0000'});
    polygons[$(this).attr("ajax_url")].options.style.color = '#FF0000';
   },
  function(){
    $(this).css("background-color", "#ffffff");
    polygons[$(this).attr("ajax_url")].setStyle({color: '#0000FF'});
    polygons[$(this).attr("ajax_url")].options.style.color = '#0000FF';
  },
  );
});