diff options
Diffstat (limited to 'ishtar_common/static/js')
| -rw-r--r-- | ishtar_common/static/js/ishtar-map.js | 109 | 
1 files changed, 108 insertions, 1 deletions
| diff --git a/ishtar_common/static/js/ishtar-map.js b/ishtar_common/static/js/ishtar-map.js index a93813e61..b22467668 100644 --- a/ishtar_common/static/js/ishtar-map.js +++ b/ishtar_common/static/js/ishtar-map.js @@ -285,7 +285,9 @@ var enable_clustering = function(map_id){  };  var reinit_clustering = function(map_id){ -    cluster_source[map_id].getSource().clear(); +    if (map_id in cluster_source) { +        cluster_source[map_id].getSource().clear(); +    }      _styleCache = {};  }; @@ -642,3 +644,108 @@ var display_lines_and_polys = function(map_id, lines_and_polys){          map_view[map_id].fit(vector_source[map_id].getExtent());      }  }; + +var disp_geo_items = function(map_id, base_url, slug, pk, display_both) { +    var url = base_url; +    if (slug === "operation") { +        url += "?operation_pk="; +    } +    else { +        url += "?context_record_pk="; +    } +    url += pk; + +    httpRequest = new XMLHttpRequest(); +    if (!httpRequest) { return; } +    httpRequest.onreadystatechange = function() { +        if (httpRequest.readyState === XMLHttpRequest.DONE) { +            if (httpRequest.status === 200) { +                geo_items = to_geo_items(JSON.parse(httpRequest.responseText), slug, display_both) +                for (geo_item of geo_items['base-finds']) { +                    display_associated_polys(map_id, geo_item, 'basefind'); +                } +                for (geo_item of geo_items['context-records']) { +                    display_associated_polys(map_id, geo_item, 'contextrecord'); +                } +            } else { return; } +        } +    }; +    httpRequest.open('GET', url, true); +    httpRequest.send(); +}; + +var to_geo_items = function (obj, slug, display_both) { +    var objects = {'context-records': [], 'base-finds': []}; +    if (slug === "operation") { +        var crs = obj['properties']['context-records']; +        for (cr of crs['features']) { +            if (display_both) { +                objects['base-finds'].push(cr['properties']['base-finds']) +            } +            delete cr['properties']; +        } +        objects['context-records'].push(crs); +    } +    else { +        objects['base-finds'].push(obj['properties']['base-finds']) +    } +    return objects; +} + +var display_associated_polys = function (map_id, polys, slug) { +    _vector_features = geojson_format.readFeatures(polys); +    _vector_source = new ol.source.Vector(); +    _vector_source.addFeatures(_vector_features); +    style = get_associated_base_find_style; +    if (slug === 'contextrecord') { +        style = get_associated_context_record_style; +    } +    _vector_layer = new ol.layer.Vector({ +        source: _vector_source, +        style: style +    }); +    map[map_id].addLayer(_vector_layer); +} + +var get_associated_base_find_style = function (feature) { +    return new ol.style.Style({ +        stroke: new ol.style.Stroke({ +            color: 'rgba(0, 0, 0, 1)', +            width: 2 +        }), +        fill: new ol.style.Fill({ +            color: 'rgba(O, O, O, 0.2)' +        }) +    }); +}; + +var get_associated_context_record_style = function (feature) { +    return new ol.style.Style({ +        stroke: new ol.style.Stroke({ +            color: 'rgba(255, 255, 255, 1)', +            width: 2 +        }), +        fill: new ol.style.Fill({ +            color: 'rgba(255, 255, 255, 0.2)' +        }) +    }); +}; + +var display_associated_points = function (map_id, points, slug) { +    _point_features = geojson_format.readFeatures(points); +    _cluster_source = new ol.source.Cluster({ +        distance: 40, +        source: new ol.source.Vector() +    }); +    style = get_associated_base_find_style; +    if (slug === 'contextrecord') { +        style = get_associated_context_record_style; +    } +    _cluster_layer = new ol.layer.Vector({ +        name: 'Cluster', +        source: _cluster_source, +        style: style +    }); +    map[map_id].addLayer(_cluster_layer); +    _cluster_source.getSource().addFeatures(_point_features); +}
\ No newline at end of file | 
