';
var divMargin = '3px 5px 3px 0px';
var divToolMargin = '2px 0px 2px 0px';
var your = __("Your");
var remove = __("Remove");
var removeTooltip = "";
var divWidth = 210;
if (this.el !== undefined) {
//divWidth = this.getWidth() - 30;
divWidth = this.getInnerWidth() - 50;
}
var contexts = this.hropts;
if (typeof(contexts) !== "undefined") {
for (var i = 0; i < contexts.length; i++) {
// write link with panel id and context id
if (contexts[i].id.substr(0, 11) == "hr_bookmark") {
//This is a user bookmark
//Positioning of link and tool floating.
if (firstUserContext) {
htmllines += '
';
htmllines += '
';
htmllines += '';
firstUserContext = false;
removeTooltip = remove + " " + this.bookmarkTerm;
}
if (this.isValidBookmark(contexts[i])) {
htmllines += '
';
}
else {
//If the bookmark is not valid, show in color gray
htmllines += '
';
}
htmllines += '
';
}
else {
//This is a project bookmark
if (firstProjectContext) {
htmllines += '';
firstProjectContext = false;
}
htmllines += '
';
}
}
}
htmllines += '
';
return htmllines
},
updateHtml: function () {
this.update(this.getHtml());
},
onAddBookmark: function () {
if (this.supportsHtml5Storage()) {
this.AddBookmarkWindow.show();
}
else {
alert(__('Your browser does not support local storage for user-defined bookmarks'));
}
},
addBookmark: function () {
var strBookmarkMaxNr = localStorage.getItem("hr_bookmarkMax");
if (strBookmarkMaxNr) {
var bookmarkmaxNr = Number(strBookmarkMaxNr);
if (bookmarkmaxNr !== NaN) {
bookmarkmaxNr += 1;
}
else {
bookmarkmaxNr = 1;
}
}
else {
bookmarkmaxNr = 1;
}
this.scId = 'hr_bookmark' + bookmarkmaxNr;
this.scName = this.edName.getValue();
this.scDesc = this.edDesc.getValue();
// Just to be defensive
if (!this.scName || this.scName.length == 0) {
Ext.Msg.alert(__('Warning'), __('Bookmark name cannot be empty'));
return false;
}
this.getMapContent();
var newbookmark = {
id: this.scId,
version: this.version,
type: 'bookmark',
name: this.scName,
desc: this.scDesc,
layers: this.scvisibleLayers,
x: this.scX,
y: this.scY,
zoom: this.scZoom,
units: this.scUnits,
projection: this.scProjection
};
//Encode the new bookmark to JSON
var newbookmarkJSON = Ext.encode(newbookmark);
//Add the Heron-bookmark to localStorage
localStorage.setItem(this.scId, newbookmarkJSON);
//Increase number of Heron-bookmarks
localStorage.setItem("hr_bookmarkMax", bookmarkmaxNr);
//Add the Heron-bookmark to hropts
this.hropts.push(newbookmark);
this.updateHtml();
return true;
},
removeBookmark: function (id) {
//Remove the bookmark from localStorage
localStorage.removeItem(id);
//If this is the last bookmark, decrease max. number of Heron-bookmarks
var strBookmarkMaxNr = localStorage.getItem("hr_bookmarkMax")
var bookmarkmaxNr = Number(strBookmarkMaxNr)
if (bookmarkmaxNr == Number(id.substr(4))) {
bookmarkmaxNr -= 1
localStorage.setItem("hr_bookmarkMax", bookmarkmaxNr)
}
//Remove the bookmark from hropts.
var contexts = this.hropts;
var newcontexts = new Array();
for (var i = 0; i < contexts.length; i++) {
if (contexts[i].id !== id) {
newcontexts.push(contexts[i]);
}
}
this.hropts = newcontexts;
//Refresh the panel
this.updateHtml();
},
getlocalStorageBookmarks: function () {
if (!this.supportsHtml5Storage()) {
return null;
}
var bookmarkmaxNr = localStorage.getItem("hr_bookmarkMax");
if (bookmarkmaxNr) {
var bookmarks = new Array();
for (var index = 1; index <= bookmarkmaxNr; index++) {
var bookmarkJSON = localStorage.getItem("hr_bookmark" + index);
if (bookmarkJSON) {
try {
//Decode from JSON to bookmark
var bookmark = Ext.decode(bookmarkJSON)
bookmarks.push(bookmark);
} catch(err) {
// ignore the bookmark, it's not valid
}
}
}
return bookmarks;
}
return null;
},
isValidBookmark: function (context) {
var map = Heron.App.getMap();
//Check for presents of contextlayers in map
if (context.layers) {
var mapLayers = map.layers;
var ctxLayers = context.layers;
for (var m = 0; m < ctxLayers.length; m++) {
var layerPresent = false;
for (var n = 0; n < mapLayers.length; n++) {
if (mapLayers[n].name == ctxLayers[m]) {
layerPresent = true;
break;
}
}
if (!layerPresent) {
return false;
}
}
}
//Check for valid mapcenter
//First check projection and mapunits
if (context.projection !== map.projection) {
return false;
}
if (context.units !== map.units) {
return false;
}
//Then check if mapCenter is within maxExtent
var maxExtent = map.maxExtent; //left, bottom, right, top
//Is x between left and right of maxExtent?
if (context.x < maxExtent.left && context.x > maxExtent.right) {
return false;
}
//Is y between bottom and top of maxExtent?
if (context.y < maxExtent.bottom && context.y > maxExtent.top) {
return false;
}
//Check for valid zoomlevel
if (context.zoom > map.numZoomLevels) {
return false;
}
//Everything is alright. Valid bookmark
return true;
},
getMapContent: function () {
var map = Heron.App.getMap();
var mapCenter = map.getCenter();
this.scUnits = map.units;
this.scProjection = map.projection;
this.scX = mapCenter.lon;
this.scY = mapCenter.lat;
this.scZoom = map.getZoom();
var mapLayers = map.layers;
this.scvisibleLayers = new Array();
for (var n = 0; n < mapLayers.length; n++) {
if (mapLayers[n].getVisibility()) {
this.scvisibleLayers.push(mapLayers[n].name);
}
}
},
createAddBookmarkWindow: function () {
// Maak een formpanel.
var labelWidth = 65;
var fieldWidth = 300;
var formPanel = new Ext.form.FormPanel({
title: "",
baseCls: 'x-plain',
autoHeight: true,
defaultType: "textfield",
labelWidth: labelWidth,
anchor: "100%",
items: [
{
id: "ed_name",
fieldLabel: __("Name"),
displayField: "Name",
width: fieldWidth,
enableKeyEvents: true,
listeners: {
keyup: function (textfield, ev) {
this.onNameKeyUp(textfield, ev);
},
scope: this
}
},
{
id: "ed_desc",
fieldLabel: __("Description"),
displayField: "Decription",
width: fieldWidth
}
]
});
// Maak het formulier.
this.AddBookmarkWindow = new Ext.Window({
title: __("Add a bookmark"),
width: 400,
autoHeight: true,
plain: true,
statefull: true,
stateId: "ZoomToWindow",
bodyStyle: "padding: 5px;",
buttonAlign: "center",
resizable: false,
closeAction: "hide", // klik op X geeft hide.
items: [formPanel],
listeners: {
show: function () {
this.onShowWindow();
},
scope: this
},
buttons: [
{
id: "btn_add",
text: "Add",
disabled: true,
handler: function () {
if (this.addBookmark()) {
this.AddBookmarkWindow.hide();
}
},
scope: this
},
{
name: "btn_cancel",
text: "Cancel",
handler: function () {
this.AddBookmarkWindow.hide();
},
scope: this
}
]
});
this.edName = Ext.getCmp("ed_name");
this.edDesc = Ext.getCmp("ed_desc");
this.btnAdd = Ext.getCmp("btn_add");
},
onNameKeyUp: function (textfield, ev) {
var value = this.edName.getValue();
if (value && OpenLayers.String.trim(value).length > 0) {
this.btnAdd.enable();
}
else {
this.btnAdd.disable();
}
},
onShowWindow: function () {
this.edName.setValue('');
this.edDesc.setValue('');
this.edName.focus(false, 200);
},
supportsHtml5Storage: function () {
try {
return 'localStorage' in window && window['localStorage'] !== null;
} catch (e) {
return false;
}
}
});
/** api: xtype = hr_bookmarkspanel */
Ext.reg('hr_bookmarkspanel', Heron.widgets.BookmarksPanel);
// For compatibility with pre v0.73. Heron.widgets.ContextBrowserPanel was renamed to Heron.widgets.BookmarksPanel
Ext.reg('hr_contextbrowserpanel', Heron.widgets.BookmarksPanel);