{"size": 1509, "ext": "js", "max_stars_repo_path": "resources/js/mapDragAndDropKml.js", "max_stars_repo_name": "abhisanGhimire/corona_map", "max_stars_repo_stars_event_min_datetime": "2021-05-25T08:47:13.000Z", "max_stars_repo_stars_event_max_datetime": "2021-05-25T08:47:13.000Z", "max_issues_repo_path": "resources/js/mapDragAndDropKml.js", "max_issues_repo_name": "abhisanGhimire/corona_map", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "resources/js/mapDragAndDropKml.js", "max_forks_repo_name": "abhisanGhimire/corona_map", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 1, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 32.1063829787, "max_line_length": 76, "alphanum_fraction": 0.6560636183}
import * as mapConstants from "./mapConstants";
import * as mapMain from "./mapMain";
import { Vector as VectorLayer } from "ol/layer";
import { Vector as VectorSource } from "ol/source";
import * as mapOverlay from "./mapOverlay";
import * as mapInteractionAndControls from "./mapInteractionAndControls";

//DragAndDrop Feature for KML
mapInteractionAndControls.dragAndDropInteraction.on("addfeatures", function(
    event
) {
    var vectorSourceDragAndDrop = new VectorSource({
        features: event.features
    });
    mapMain.map.addLayer(
        new VectorLayer({
            source: vectorSourceDragAndDrop
        })
    );
    mapMain.map.getView().fit(vectorSourceDragAndDrop.getExtent());
});

//Trigger
mapConstants.kml_pointer.addEventListener("click", function(evt) {
    mapMain.map.on("click", function(evt) {
        displayFeatureInfo(evt.pixel, evt.coordinate);
    });
});
var displayFeatureInfo = function(pixel, coordinate) {
    var features = [];
    mapMain.map.forEachFeatureAtPixel(pixel, function(feature) {
        features.push(feature);
        console.log(features);
    });
    if (features.length > 0) {
        var info = [];
        if (typeof features[0].get("description") != "undefined") {
            info.push(features[0].get("description"));
        } else {
            info.push("<p>No description available</p>");
        }
        console.log(info);
        mapOverlay.kmlOverlay.setPosition(coordinate);
        mapOverlay.content.innerHTML = info;
    }
};
