Restoring text box objects from their GeoJSON objects saved in local storage
Closed this issue · 1 comments
I have tried to load text box objects saved as GeoJSON in local storage in following code.
Although I could redraw text boxes, their backgrounds are not transparent.
Any idea to improve this?
//load saved text box objects
var stored = JSON.parse(localStorage.getItem('field_work.memoItems'));// load objects saved in local storage
if(stored == null) return;
if(stored.features.length > 0)
drawnItems.clearLayers();
if (stored != null && stored.length != 0){
for(var i in stored.features){
var item = stored.features[i];
//check properties including annotation text
if(item.properties['textContent'] != null){
var coords = item.geometry.coordinates; // get coordinates
var center = L.latLng(coords[1], coords[0]); //get center point
var width = item.properties.style.width; //get width
var height = item.properties.style.height; //get height
var rotation = item.properties.style.rotation; //get rotation angle
var textOptions = {//set text options
borderColor: '#4387fd',
borderWidth: 2
}
var textbox = new L.Illustrate.Textbox(center, textOptions).setSize(new L.Point(width, height)); // create text box
drawnItems.addLayer(textbox); // add text box
textbox.getTextarea().value= item.properties['textContent']; // set text
//textbox.getTextarea().focus();//not effect
//textbox.setOpacity(0);// just vanished all
textbox.fire('textedit', { textContent: textbox.getContent() });//not effect
textbox._text_edited = false;//not effect
}
}
}
I could fix this program in following code.
textbox.setContent( item.properties['textContent']);
L.DomUtil.removeClass(textbox.getTextarea(), 'leaflet-illustrate-textbox-empty');// adding this for set style
textbox.setRotation(rotation);