📄 zoomtobookmarktask.java
字号:
package com.esri.solutions.jitk.web.tasks.navigation.bookmark;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import org.apache.log4j.Logger;
import com.esri.adf.web.data.WebContext;
import com.esri.adf.web.data.WebMap;
import com.esri.adf.web.data.geometry.WebExtent;
import com.esri.adf.web.data.geometry.WebSpatialReference;
import com.esri.adf.web.data.tasks.ADFTaskException;
import com.esri.adf.web.data.tasks.TaskInfo;
import com.esri.adf.web.faces.event.TaskEvent;
import com.esri.solutions.jitk.common.personalization.IPersonalizable;
import com.esri.solutions.jitk.common.personalization.IPersonalizationContext;
import com.esri.solutions.jitk.personalization.PersonalizationException;
import com.esri.solutions.jitk.personalization.data.IBookmark;
import com.esri.solutions.jitk.personalization.data.beans.v1.BookmarkType;
import com.esri.solutions.jitk.personalization.data.beans.v1.SpatialReferenceType;
import com.esri.solutions.jitk.web.tasks.RenderControlledTask;
import com.esri.solutions.jitk.web.tasks.mapcomp.IADFToBeanConverter;
public class ZoomToBookmarkTask extends RenderControlledTask implements IFormBookmarkData, IPersonalizable {
private static final long serialVersionUID = -8789210675841768615L;
private static final Logger _logger = Logger.getLogger(ZoomToBookmarkTask.class.getName());
protected ZoomToBookmarkTaskInfo _taskInfo;
protected Map<String, Bookmark> _bookmarks;
protected Map<String, IBookmark> _bookmarkIds;
protected Map<String, String> _bookmarkIdss;
protected String _selectedBookmark;
protected String _bookmarkId;
protected String _bookmarkIdStr;
protected String _newBookmark;
protected String _description;
private String _tab1 = null;
private String _tab2 = null;
private String _footerNoteTab1 = null;
private String _footerNoteTab2 = null;
protected String errormessage;
protected IBookmarkPersister _bookmarkPersister;
protected IPersonalizationContext _PersonalizationContext;
protected IADFToBeanConverter _adfToBeanConverter;
public ZoomToBookmarkTask() {
super();
try {
setTaskInfo(new ZoomToBookmarkTaskInfo(
ZoomToBookmarkTask.class, "ZoomToBookmarkTask"));
}
catch (Throwable ex) {
_logger.error("Unable to load resource", ex);
}
}
public TaskInfo getTaskInfo() {
if (this.getContext() == null) {
_taskInfo.getTaskDescriptor().setDisabled(true);
_logger.warn("WebContext not set, disabling");
}
return this._taskInfo;
}
public void setTaskInfo(TaskInfo taskInfo) {
this._taskInfo = (ZoomToBookmarkTaskInfo) taskInfo;
super.setTaskInfo(this._taskInfo);
}
public void setPersistenceBeanConverter (IADFToBeanConverter converter) {
if (converter == null) {
throw new NullPointerException();
}
_adfToBeanConverter = converter;
}
public void setPersonalizationContext(IPersonalizationContext ctx) {
if (ctx == null) {
_logger.error("Personalization context passed as null");
throw new NullPointerException();
}
_PersonalizationContext = ctx;
try {
List<IBookmark> bookmarks = _PersonalizationContext.getData().getBookmarks();
setBookmarkIdStrs(bookmarks);
}
catch (PersonalizationException e) {
_logger.error("Unable to setBookmarkIds.", e);
}
}
public void setBookmarkPersister (IBookmarkPersister bookmarkPersister) {
_bookmarkPersister = bookmarkPersister;
}
/**
* The set of Bookmark instances to which the user can choose to zoom.
* @return a map of key/value pairs.
*/
public Map<String, Bookmark> getBookmarks() {
return _bookmarks;
}
/**
* Simple setter of the mapping of key/value pairs
* @param bookmarks
*/
public void setBookmarks(Map<String, Bookmark> bookmarks) throws PersonalizationException {
this._bookmarks = bookmarks;
}
public void deleteBookmark(TaskEvent event) throws ADFTaskException {
_logger.info("Deleting bookmark");
super.requestTaskRender();
IBookmark bookmark = null;
String chosenBookmarkId = getBookmarkIdStr();
try {
bookmark = _PersonalizationContext.getData().getBookmark(UUID.fromString(chosenBookmarkId));
if (bookmark != null) {
bookmark.remove();
setBookmarkIdStrs(_PersonalizationContext.getData().getBookmarks());
renderResourceMessage("jitk.task.zoomToBookmark.ui.msg.deleteSuccess", messageType.SUCCESS);
} else {
renderResourceMessage("jitk.task.zoomToBookmark.ui.msg.notFound", messageType.ERROR);
_logger.warn("Bookmark not found in personalization data");
}
} catch (PersonalizationException e) {
renderResourceMessage("jitk.task.zoomToBookmark.ui.msg.errorDeleting", messageType.ERROR);
_logger.error("Could not delete bookmark", e);
}
}
/**
* The create bookmark action button is wired up to call this when fired. It results in the
* creating new Bookmark and adding to the current Bookmark list.
*/
public void createBookmark(TaskEvent event) {
_logger.info("Creating bookmark");
super.requestTaskRender();
try {
IBookmark bookmark = _PersonalizationContext.getData().createBookmark();
BookmarkType bean = bookmark.getBookmark();
bean.setName(this.getName());
bean.setDescription(this.getDescription());
bean.setEnvelope(_adfToBeanConverter.createEnvelope(event.getWebContext().getWebMap().getCurrentExtent()));
bookmark.save();
_PersonalizationContext.setAttribute("CURRENT_BOOKMARK_KEY", bookmark);
//this._bookmarkPersister.save(this);
setBookmarkIdStrs(_PersonalizationContext.getData().getBookmarks());
renderResourceMessage("jitk.task.zoomToBookmark.ui.msg.saveSuccess", messageType.SUCCESS);
} catch (Exception ex) {
renderResourceMessage("jitk.task.zoomToBookmark.ui.msg.errorSaving", messageType.ERROR);
_logger.error("Could not create bookmark", ex);
}
}
/**
* The zoom action button is wired up to call this when fired. It results in the
* extent changing to whatever the currently-selected Bookmark indicates.
*/
public void zoomToBookmark(TaskEvent event) throws ADFTaskException {
_logger.info("Zooming to bookmark");
super.requestTaskRender();
try {
IBookmark bookmarkRef = null;
WebExtent extent = null;
String chosenBookmarkId = getBookmarkIdStr();
bookmarkRef = _PersonalizationContext.getData().getBookmark(UUID.fromString(chosenBookmarkId));
if (bookmarkRef != null) {
WebContext webContext = super._context;
WebMap webMap = webContext.getWebMap();
WebSpatialReference mapSref = webContext.getSpatialReference();
BookmarkType bookmark = bookmarkRef.getBookmark();
WebExtentBuilder webExtBuilder = new WebExtentBuilder();
extent = webExtBuilder.toWebExtent(bookmark);
if (mapSref == null) {
//TODO: Report error to MVS error reporting framework
//renderMessage("Map Reference is Null");
_logger.error("WebSpatialReference has null spatial reference, aborting");
return;
}
if (bookmark.getEnvelope().getSpatialReference() == null) {
//TODO: Report error to MVS error reporting framework
_logger.error("Bookmark '" + chosenBookmarkId + "' lacks a spatial reference.");
return;
}
if (!isSameProjection(bookmark, webContext)) {
_logger.info("Bookmark in differnet spatail reference than map, attempting to project");
//TODO: Implement this
extent= projectBookmark(bookmark, webContext);
}
webContext.getWebMap().setCurrentExtent(extent);
webContext.refresh(webMap);
}
else {
//TODO: Report error to MVS error reporting framework
_logger.error("Chosen bookmark '" +chosenBookmarkId+ "' could not be aquired from personalization");
}
}
catch (PersonalizationException e) {
//TODO: Report error to MVS error reporting framework
_logger.error("Could not zoom To bookmark.", e);
}
}
protected boolean isSameProjection(BookmarkType bookmark, WebContext webContext) {
SpatialReferenceType bookmarkSpatRef = bookmark.getEnvelope().getSpatialReference();
WebSpatialReference bookmarkWebSpatRef = WebSpatialReference.getWebSpatialReference(bookmarkSpatRef.getWKT());
String bookmarkSpatRefStr = bookmarkWebSpatRef.getDefinitionString();
String webContextSpatRefStr = webContext.getSpatialReference().getDefinitionString();
return bookmarkSpatRefStr.equals(webContextSpatRefStr);
}
protected WebExtent projectBookmark(BookmarkType bookmark, WebContext webContext) {
//TODO: Impliment this
SpatialReferenceType bookmarkSpatRef = bookmark.getEnvelope().getSpatialReference();
WebSpatialReference mapSref = webContext.getSpatialReference();
WebSpatialReference bookmarkWebSpatRef = WebSpatialReference.getWebSpatialReference(bookmarkSpatRef.getWKT());
WebExtent bookmarkExtent=null;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -