<commit_before>//converts leaflet layer to WKT
//requires Leaflet, Leaflet ArcGIS plugin,
var leaflet_helper = {};

leaflet_helper.styles = {};
leaflet_helper.styles.extentStyle = {"weight": 2, "color": "red", "fill": null, "opacity": 1};
leaflet_helper.styles.completed = {"weight": 2, "color": "green", "fillColor": "green", "fillOpacity": .9, "opacity": 1};
leaflet_helper.styles.in_work = {"weight": 2, "color": "yellow", "fillColor": "orange", "fillOpacity": .9, "opacity": 1};
leaflet_helper.styles.assigned = {"weight": 2, "color": "orange", "fillColor": "orange", "fillOpacity": .9, "opacity": 1};


leaflet_helper.layer_conversion = function (lyr) {

    var options = {
        layers: lyr.layer,
        format: lyr.format,
        transparent: lyr.transparent,
        attribution: lyr.attribution,
        subdomains: lyr.subdomains,
        opacity: lyr.opacity,
        zIndex: lyr.zIndex,
        visibile: lyr.shown
    };
    var layerParams = lyr.layerParams;
    var layerOptions;

    console.log(layerParams);

    var esriPluginInstalled = L.hasOwnProperty('esri');

    if (!esriPluginInstalled) {
        console.log('Esri Leaflet plugin not installed.  Esri layer types disabled.');
    }

    if (lyr.type == 'WMS') {

        layerOptions = _.extend(options, layerParams);

        return new L.tileLayer.wms(lyr.url, layerOptions);
    }

    if (lyr.type == 'ESRI Tiled Map Service' && esriPluginInstalled) {

        layerOptions = options;

        return new L.esri.tiledMapLayer(lyr.url, layerOptions);
    }

    if (lyr.type == 'ESRI Dynamic Map Layer' && esriPluginInstalled) {

        layerOptions = options;

        return new L.esri.dynamicMapLayer(lyr.url, layerOptions);
    }

    if (lyr.type == 'ESRI Feature Layer' && esriPluginInstalled) {

        layerOptions = options;

        return new L.esri.featureLayer(lyr.url, layerOptions);
    }

    if (lyr.type == 'GeoJSON') {
        layerOptions = options;

        function addGeojson(e) {
            return new L.GeoJSON(e, layerOptions);
        }

        var url = lyr.url;
        if (url && url.substr(0,4) == "http") {
            url = "/geoq/proxy/" + url;
        }

        $.ajax({
            type: 'GET',
            url: lyr.url,
            dataType: 'json',
            success: function (result) {
                var isESRIpseudoJSON = false;
                if (result &&
                    result.geometryType && result.geometryType == "esriGeometryPoint" &&
                    result.features && result.features.length &&
                    result.features[0] && result.features[0].attributes) isESRIpseudoJSON = true;

                if (isESRIpseudoJSON) {
                    leaflet_helper.add_dynamic_capimage_data(result);
                } else {
                    addGeojson(result);
                }
            }

        })

    }

};
leaflet_helper.add_dynamic_capimage_data = function (result) {
    var jsonObjects = [];
    $(result.features).each(function () {
        var feature = $(this)[0];
        var json = {
            type: "Feature",
            properties: {
                name: feature.attributes.ID + " - " + feature.attributes.DaysOld + " days old",
                image: feature.attributes.ImageURL,
                thumbnail: feature.attributes.ThumbnailURL,
                popupContent: "<a href='" + feature.attributes.ImageURL + "'><img style='width:256px' src='" + feature.attributes.ThumbnailURL + "' /></a>"
            },
            geometry: {
                type: "Point",
                coordinates: [feature.geometry.x, feature.geometry.y]
            }
        };
        jsonObjects.push(json);
    });

    function onEachFeature(feature, layer) {
        // does this feature have a property named popupContent?
        if (feature.properties && feature.properties.popupContent) {
            layer.bindPopup(feature.properties.popupContent);
        }
    }

    L.geoJson(jsonObjects, {onEachFeature: onEachFeature}).addTo(map);
};

//TODO: Add MULTIPOLYGON support and commit back to https://gist.github.com/bmcbride/4248238
leaflet_helper.toWKT = function (layer) {
    var lng, lat, coords = [];
    if (layer instanceof L.Polygon || layer instanceof L.Polyline) {
        var latlngs = layer.getLatLngs();
        for (var i = 0; i < latlngs.length; i++) {
            latlngs[i]<commit_msg>Fixed loading of GeoJSON items<commit_after>//converts leaflet layer to WKT
//requires Leaflet, Leaflet ArcGIS plugin,
var leaflet_helper = {};

leaflet_helper.styles = {};
leaflet_helper.styles.extentStyle = {"weight": 2, "color": "red", "fill": null, "opacity": 1};
leaflet_helper.styles.completed = {"weight": 2, "color": "green", "fillColor": "green", "fillOpacity": .9, "opacity": 1};
leaflet_helper.styles.in_work = {"weight": 2, "color": "yellow", "fillColor": "orange", "fillOpacity": .9, "opacity": 1};
leaflet_helper.styles.assigned = {"weight": 2, "color": "orange", "fillColor": "orange", "fillOpacity": .9, "opacity": 1};


leaflet_helper.layer_conversion = function (lyr) {

    var options = {
        layers: lyr.layer,
        format: lyr.format,
        transparent: lyr.transparent,
        attribution: lyr.attribution,
        subdomains: lyr.subdomains,
        opacity: lyr.opacity,
        zIndex: lyr.zIndex,
        visibile: lyr.shown
    };
    var layerParams = lyr.layerParams;
    var layerOptions;

    console.log(layerParams);

    var esriPluginInstalled = L.hasOwnProperty('esri');

    if (!esriPluginInstalled) {
        console.log('Esri Leaflet plugin not installed.  Esri layer types disabled.');
    }

    if (lyr.type == 'WMS') {

        layerOptions = _.extend(options, layerParams);

        return new L.tileLayer.wms(lyr.url, layerOptions);
    }

    if (lyr.type == 'ESRI Tiled Map Service' && esriPluginInstalled) {

        layerOptions = options;

        return new L.esri.tiledMapLayer(lyr.url, layerOptions);
    }

    if (lyr.type == 'ESRI Dynamic Map Layer' && esriPluginInstalled) {

        layerOptions = options;

        return new L.esri.dynamicMapLayer(lyr.url, layerOptions);
    }

    if (lyr.type == 'ESRI Feature Layer' && esriPluginInstalled) {

        layerOptions = options;

        return new L.esri.featureLayer(lyr.url, layerOptions);
    }

    if (lyr.type == 'GeoJSON') {
        layerOptions = options;

        function addGeojson(e) {
            return new L.GeoJSON(e, layerOptions);
        }

        var url = lyr.url;
        if (url && url.substr(0,4) == "http") {
            url = "/geoq/proxy/" + url;
        }

        $.ajax({
            type: 'GET',
            url: url,
            dataType: 'json',
            success: function (result) {
                var isESRIpseudoJSON = false;
                if (result &&
                    result.geometryType && result.geometryType == "esriGeometryPoint" &&
                    result.features && result.features.length &&
                    result.features[0] && result.features[0].attributes) isESRIpseudoJSON = true;

                if (isESRIpseudoJSON) {
                    leaflet_helper.add_dynamic_capimage_data(result);
                } else {
                    addGeojson(result);
                }
            }

        })

    }

};
leaflet_helper.add_dynamic_capimage_data = function (result) {
    var jsonObjects = [];
    $(result.features).each(function () {
        var feature = $(this)[0];
        var json = {
            type: "Feature",
            properties: {
                name: feature.attributes.ID + " - " + feature.attributes.DaysOld + " days old",
                image: feature.attributes.ImageURL,
                thumbnail: feature.attributes.ThumbnailURL,
                popupContent: "<a href='" + feature.attributes.ImageURL + "'><img style='width:256px' src='" + feature.attributes.ThumbnailURL + "' /></a>"
            },
            geometry: {
                type: "Point",
                coordinates: [feature.geometry.x, feature.geometry.y]
            }
        };
        jsonObjects.push(json);
    });

    function onEachFeature(feature, layer) {
        // does this feature have a property named popupContent?
        if (feature.properties && feature.properties.popupContent) {
            layer.bindPopup(feature.properties.popupContent);
        }
    }

    L.geoJson(jsonObjects, {onEachFeature: onEachFeature}).addTo(aoi_feature_edit.map);
//    return new L.geoJson(jsonObjects, {onEachFeature: onEachFeature});
};

//TODO: Add MULTIPOLYGON support and commit back to https://gist.github.com/bmcbride/4248238
leaflet_helper.toWKT = function (layer) {
    var lng, lat, coords = [];
    if (layer instanceof L.Polygon || layer instanceof L.Polyline) {
        var latlngs = layer.getLatLngs();
        for (var i = 0; i < latlngs.length; i++) {
            latlngs[i]
{'fraction_non_alphanumeric': 0.13279224439183857, 'fraction_numerical': 0.00608725059181603, 'mean_word_length': 2.2486268766019775, 'pattern_counts': {'":': 38, '<': 11, '<?xml version=': 0, '>': 9, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4880712', 'n_tokens_mistral': 2794, 'n_tokens_neox': 2640, 'n_words': 578}