<commit_before>/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */


function PathEditor(opt_options) {
    var options = opt_options || {};
    this.setValues(options);    
    this.polylines = new Array();
    this.earthRadius = 6370986;

    this.generalStyle = {strokeColor : "#0000ff", strokeOpacity: 0.5, zIndex: 10};
    this.selectedStyle = {strokeColor : "#ff0000", strokeOpacity : 0.7, zIndex: 10};

    this.drawingManager = new google.maps.drawing.DrawingManager({
	drawingMode: google.maps.drawing.OverlayType.POLYLINE,
	drawingControl: true,
	drawingControlOptions: {
	    position: google.maps.ControlPosition.TOP_CENTER,
	    drawingModes: [google.maps.drawing.OverlayType.POLYLINE]
	},
	polylineOptions: this.selectedStyle
    });
    this.drawingManager.setDrawingMode(null);
    this.drawingManager.setMap(this.map);
    
   
//    this.set('selection', null);
    this.set('length', 0);
    this.set('prevSelection', null);
    var self = this;
    
    google.maps.event.addListener(this.drawingManager, 'polylinecomplete', function(polyline) {
	self.addPolyline(polyline);
	self.set('selection', polyline);
	self.drawingManager.setDrawingMode(null);
    });
   
    
}

PathEditor.prototype = new google.maps.MVCObject();

PathEditor.prototype.toggleEditable = function (){
    if(this.selection != null){
	var editable  = this.selection.getEditable();
        this.selection.setEditable(!editable);
    }
};

PathEditor.prototype.deletePath = function (){
    if(this.selection != null){
        this.selection.setMap(null);
        this.set('selection', null);
    }
    var newPolylines = [];
    for (var i = 0; i < this.polylines.length; i++) {
        var pl = this.polylines[i];
        if(pl.getMap()) newPolylines.push(pl);
    }        
    this.polylines = newPolylines;    
    
}

PathEditor.prototype.deleteAll = function () {
    this.set('selection', null);
    for (var i = 0; i < this.polylines.length; i++) {
        var pl = this.polylines[i];
        pl.setMap(null);
    }
    this.polylines = [];     
}


PathEditor.prototype.showPath = function (str, select) {
//    clearPath();
//    var pl = Walkrr.wkt2GMap(str);
    var pl = new google.maps.Polyline({});
    pl.setPath(google.maps.geometry.encoding.decodePath(str));

    this.addPolyline(pl);
    if(select && pl.getPath().getLength() > 0) {
        this.set('selection', pl);
        var xmin, xmax, ymin, ymax;
        pl.getPath().forEach(function (elem, i){
           if (i == 0) {
               xmin = xmax = elem.lng();
               ymin = ymax = elem.lat();
           }
           else {
               if (xmin > elem.lng()) xmin = elem.lng();
               if (xmax < elem.lng()) xmax = elem.lng();
               if (ymin > elem.lat()) ymin = elem.lat();
               if (ymax < elem.lat()) ymax = elem.lat();
           }
        });
        var center = new google.maps.LatLng((ymin+ymax)/2, (xmin+xmax)/2);
        this.map.panTo(center);
    }
}

PathEditor.prototype.addPolyline = function (pl){

    pl.setOptions(this.generalStyle);
    pl.setMap(this.map);
    this.polylines.push(pl);
    var self = this;

    google.maps.event.addListener(pl, 'click', function () {
        self.set('selection', pl);
    });
}
PathEditor.prototype.selection_changed = function (){
    var prevSelection = this.get('prevSelection');
    if (prevSelection){
        prevSelection.setOptions(this.generalStyle);
	prevSelection.setEditable(false);
    }
    var selection = this.get('selection');
    this.set('prevSelection', selection);

    if (selection) {
        selection.setOptions(this.selectedStyle);
        var path = this.selection.getPath();

        var len = path.getLength();
    }

    this.clearLocalStorage();
    this.set('length', this.getSelectionLength());
}

<commit_msg>delete a vertex in polyline by rightclick.<commit_after>/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */


function PathEditor(opt_options) {
    var options = opt_options || {};
    this.setValues(options);    
    this.polylines = new Array();
    this.earthRadius = 6370986;

    this.generalStyle = {strokeColor : "#0000ff", strokeOpacity: 0.5, zIndex: 10};
    this.selectedStyle = {strokeColor : "#ff0000", strokeOpacity : 0.7, zIndex: 10};

    this.drawingManager = new google.maps.drawing.DrawingManager({
	drawingMode: google.maps.drawing.OverlayType.POLYLINE,
	drawingControl: true,
	drawingControlOptions: {
	    position: google.maps.ControlPosition.TOP_CENTER,
	    drawingModes: [google.maps.drawing.OverlayType.POLYLINE]
	},
	polylineOptions: this.selectedStyle
    });
    this.drawingManager.setDrawingMode(null);
    this.drawingManager.setMap(this.map);
    
   
//    this.set('selection', null);
    this.set('length', 0);
    this.set('prevSelection', null);
    var self = this;
    
    google.maps.event.addListener(this.drawingManager, 'polylinecomplete', function(polyline) {
	self.addPolyline(polyline);
	self.set('selection', polyline);
	self.drawingManager.setDrawingMode(null);
    });
   
    
}

PathEditor.prototype = new google.maps.MVCObject();

PathEditor.prototype.toggleEditable = function (){
    if(this.selection != null){
	var editable  = this.selection.getEditable();
        this.selection.setEditable(!editable);
    }
};

PathEditor.prototype.deletePath = function (){
    if(this.selection != null){
        this.selection.setMap(null);
        this.set('selection', null);
    }
    var newPolylines = [];
    for (var i = 0; i < this.polylines.length; i++) {
        var pl = this.polylines[i];
        if(pl.getMap()) newPolylines.push(pl);
    }        
    this.polylines = newPolylines;    
    
}

PathEditor.prototype.deleteAll = function () {
    this.set('selection', null);
    for (var i = 0; i < this.polylines.length; i++) {
        var pl = this.polylines[i];
        pl.setMap(null);
    }
    this.polylines = [];     
}


PathEditor.prototype.showPath = function (str, select) {
//    clearPath();
//    var pl = Walkrr.wkt2GMap(str);
    var pl = new google.maps.Polyline({});
    pl.setPath(google.maps.geometry.encoding.decodePath(str));

    this.addPolyline(pl);
    if(select && pl.getPath().getLength() > 0) {
        this.set('selection', pl);
        var xmin, xmax, ymin, ymax;
        pl.getPath().forEach(function (elem, i){
           if (i == 0) {
               xmin = xmax = elem.lng();
               ymin = ymax = elem.lat();
           }
           else {
               if (xmin > elem.lng()) xmin = elem.lng();
               if (xmax < elem.lng()) xmax = elem.lng();
               if (ymin > elem.lat()) ymin = elem.lat();
               if (ymax < elem.lat()) ymax = elem.lat();
           }
        });
        var center = new google.maps.LatLng((ymin+ymax)/2, (xmin+xmax)/2);
        this.map.panTo(center);
    }
}

PathEditor.prototype.addPolyline = function (pl){

    pl.setOptions(this.generalStyle);
    pl.setMap(this.map);
    this.polylines.push(pl);
    var self = this;

    google.maps.event.addListener(pl, 'click', function () {
        self.set('selection', pl);
    });
    var deleteNode = function(mev) {
	if (mev.vertex != null) {
	    pl.getPath().removeAt(mev.vertex);
	}
    }
    google.maps.event.addListener(pl, 'rightclick', deleteNode);
}
PathEditor.prototype.selection_changed = function (){
    var prevSelection = this.get('prevSelection');
    if (prevSelection){
        prevSelection.setOptions(this.generalStyle);
	prevSelection.setEditable(false);
    }
    var selection = this.get('selection');
    this.set('prevSelection', selection);

    if (selection) {
        selection.setOptions(this.selectedStyle);
        var path = this.selection.getPath();

        var len = path.getLength();
    }

    this.clearLocalStorage();
    this.set('length', this.getSelectionLength());
}


{'fraction_non_alphanumeric': 0.15032184778492996, 'fraction_numerical': 0.00782531869241449, 'mean_word_length': 2.7518939393939394, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 9, 'https://': 0, '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': '6322879', 'n_tokens_mistral': 2623, 'n_tokens_neox': 2556, 'n_words': 466}