- 浏览: 13825 次
- 性别:
- 来自: 上海
最近访客 更多访客>>
文章分类
最新评论
-
纯情小火鸡:
不行啊,为什么我按住鼠标在图片上拖动是可以的,当我按住不放一直 ...
用GWT处理用鼠标拖动图片的问题 -
纯情小火鸡:
现在我可以实现拖动了 但是我在拖的过程中有延迟 这些图片的延迟 ...
用GWT处理用鼠标拖动图片的问题 -
7thbyte:
在mousedown时绑定mousemove事件在mouseu ...
用GWT处理用鼠标拖动图片的问题 -
纯情小火鸡:
多谢楼上的 就是现在我的地图是用GRID那种方式加载的 就 ...
用GWT做地图 -
aibozeng:
GWT里,使用 Grid (就是Html的Table)划分很多 ...
用GWT做地图
<div class="quote_title">sheva.wen 写道</div><div class="quote_div"><p>下面要写的东西是一个使用GWT编写的在有限区域内通过拖动查看整个地图的简单实现。</p><p> <strong>一些细节:</strong></p><ol style="margin-right: 0px"><li>为什么能拖? <p><span style="font-family: Arial"><a href="http://code.google.com/webtoolkit/documentation/com.google.gwt.user.client.ui.MouseListener.html">com.google.gwt.user.client.ui.MouseListener</a> 通过实现这个接口,可以实现UI对象对鼠标的Enter,Down,Leave,Move,Up动作的支持。</span></p><p><span style="font-family: Arial"><span style="font-family: Arial"><a href="http://code.google.com/webtoolkit/documentation/com.google.gwt.user.client.ui.FocusPanel.html">com.google.gwt.user.client.ui.FocusPanel</a> 并不是每个UI对象都能够实现MouseListener接口的,可以通过添加到FocusPanel来实现。</span></span></p><span style="font-family: Arial"></span></li><li>怎么才能显示地图的局部,或者说怎么把其他部分藏起来? </li></ol><blockquote dir="ltr" style="margin-right: 0px"><p dir="ltr">通过样式:</p><div class="code_title">java 代码</div><div class="dp-highlighter"><ol class="dp-j"><li class="alt"><span><span>DOM.setStyleAttribute(viewPortArea.getElement(), </span><span class="string">"overflow"</span><span>, </span><span class="string">"hidden"</span><span>); </span></span> </li><li><span> </span> </li><li class="alt"><span>DOM.setStyleAttribute(viewPortArea.getElement(), </span><span class="string">"position"</span><span>,</span><span class="string">"relative"</span><span>); </span> </li></ol></div><p>设置显示区域的"overflow"属性为"hidden"及"position"属性为"relative",图片可以实现局部显示显示框内。</p></blockquote><p dir="ltr"><strong>代码:</strong></p><blockquote dir="ltr" style="margin-right: 0px"><div class="code_title">java 代码</div><div class="dp-highlighter"><ol class="dp-j"><li class="alt"><span><span class="keyword">package</span><span> cn.gov.imwb.client; </span></span> </li><li><span> </span> </li><li class="alt"><span class="keyword">import</span><span> com.google.gwt.user.client.DOM; </span> </li><li><span class="keyword">import</span><span> com.google.gwt.user.client.Event; </span> </li><li class="alt"><span class="keyword">import</span><span> com.google.gwt.user.client.ui.AbsolutePanel; </span> </li><li><span class="keyword">import</span><span> com.google.gwt.user.client.ui.Composite; </span> </li><li class="alt"><span class="keyword">import</span><span> com.google.gwt.user.client.ui.FocusPanel; </span> </li><li><span class="keyword">import</span><span> com.google.gwt.user.client.ui.Image; </span> </li><li class="alt"><span class="keyword">import</span><span> com.google.gwt.user.client.ui.MouseListener; </span> </li><li><span class="keyword">import</span><span> com.google.gwt.user.client.ui.Widget; </span> </li><li class="alt"><span> </span> </li><li><span class="comment">/** </span> </li><li class="alt"><span><span class="comment"> * @author sheva.wen </span> </span> </li><li><span><span class="comment"> * </span> </span> </li><li class="alt"><span><span class="comment"> */</span><span> </span></span> </li><li><span class="keyword">public</span><span> </span><span class="keyword">class</span><span> MapViewerPanel </span><span class="keyword">extends</span><span> Composite { </span> </li><li class="alt"><span> </span><span class="keyword">public</span><span> </span><span class="keyword">int</span><span> areaHeight; </span> </li><li><span> </span> </li><li class="alt"><span> </span><span class="keyword">public</span><span> </span><span class="keyword">int</span><span> areaWidth; </span> </li><li><span> </span> </li><li class="alt"><span> </span><span class="keyword">public</span><span> </span><span class="keyword">int</span><span> centerLeft; </span> </li><li><span> </span> </li><li class="alt"><span> </span><span class="keyword">public</span><span> </span><span class="keyword">int</span><span> centerTop; </span> </li><li><span> </span> </li><li class="alt"><span> </span><span class="keyword">public</span><span> </span><span class="keyword">int</span><span> imageHeight; </span> </li><li><span> </span> </li><li class="alt"><span> </span><span class="keyword">public</span><span> String imageUrl; </span> </li><li><span> </span> </li><li class="alt"><span> </span><span class="keyword">public</span><span> </span><span class="keyword">int</span><span> imageWidth; </span> </li><li><span> </span> </li><li class="alt"><span> </span><span class="keyword">public</span><span> </span><span class="keyword">int</span><span> maxLeft; </span> </li><li><span> </span> </li><li class="alt"><span> </span><span class="keyword">public</span><span> </span><span class="keyword">int</span><span> maxTop; </span> </li><li><span> </span> </li><li class="alt"><span> </span><span class="keyword">public</span><span> </span><span class="keyword">int</span><span> minLeft; </span> </li><li><span> </span> </li><li class="alt"><span> </span><span class="keyword">public</span><span> </span><span class="keyword">int</span><span> minTop; </span> </li><li><span> </span> </li><li class="alt"><span> </span><span class="keyword">private</span><span> Image image; </span> </li><li><span> </span> </li><li class="alt"><span> </span><span class="keyword">private</span><span> FocusPanel mouseListenerContainer; </span> </li><li><span> </span> </li><li class="alt"><span> </span><span class="keyword">public</span><span> </span><span class="keyword">double</span><span> showPositionLeftRatio; </span> </li><li><span> </span> </li><li class="alt"><span> </span><span class="keyword">public</span><span> </span><span class="keyword">double</span><span> showPositionTopRatio; </span> </li><li><span> </span> </li><li class="alt"><span> </span><span class="keyword">private</span><span> </span><span class="keyword">int</span><span> startLeft; </span> </li><li><span> </span> </li><li class="alt"><span> </span><span class="keyword">private</span><span> </span><span class="keyword">int</span><span> startTop; </span> </li><li><span> </span> </li><li class="alt"><span> </span><span class="keyword">private</span><span> </span><span class="keyword">int</span><span> startX; </span> </li><li><span> </span> </li><li class="alt"><span> </span><span class="keyword">private</span><span> </span><span class="keyword">int</span><span> startY; </span> </li><li><span> </span> </li><li class="alt"><span> </span><span class="keyword">private</span><span> </span><span class="keyword">int</span><span> state = </span><span class="number">0</span><span>;</span><span class="comment">//用于判断当前用户的鼠标动作 </span><span> </span> </li><li><span> </span> </li><li class="alt"><span> </span><span class="keyword">private</span><span> AbsolutePanel viewArea; </span> </li><li><span> </span> </li><li class="alt"><span> </span><span class="keyword">private</span><span> AbsolutePanel viewPortArea = </span><span class="keyword">new</span><span> AbsolutePanel(); </span> </li><li><span> </span> </li><li class="alt"><span> </span><span class="comment">/** </span> </li><li><span><span class="comment"> * </span> </span> </li><li class="alt"><span><span class="comment"> * @param areaWidth 显示区域的宽 </span> </span> </li><li><span><span class="comment"> * @param areaHeight 显示区域的高 </span> </span> </li><li class="alt"><span><span class="comment"> * @param imageUrl 地图的链接 </span> </span> </li><li><span><span class="comment"> * @param imageWidth 地图的宽 </span> </span> </li><li class="alt"><span><span class="comment"> * @param imageHeight 地图的高 </span> </span> </li><li><span><span class="comment"> * @param showPositionLeftRatio 地图初始显示的位置 最左占宽度的比例 </span> </span> </li><li class="alt"><span><span class="comment"> * @param showPositionTopRatio 地图初始显示的位置 最上占宽度的比例 </span> </span> </li><li><span><span class="comment"> */</span><span> </span></span> </li><li class="alt"><span> </span><span class="keyword">public</span><span> MapViewerPanel(</span><span class="keyword">int</span><span> areaWidth, </span><span class="keyword">int</span><span> areaHeight, String imageUrl, </span> </li><li><span> </span><span class="keyword">int</span><span> imageWidth, </span><span class="keyword">int</span><span> imageHeight, </span><span class="keyword">double</span><span> showPositionLeftRatio, </span> </li><li class="alt"><span> </span><span class="keyword">double</span><span> showPositionTopRatio) { </span> </li><li><span> mouseListenerContainer = </span><span class="keyword">new</span><span> FocusPanel(viewPortArea); </span> </li><li class="alt"><span> viewArea = </span><span class="keyword">new</span><span> AbsolutePanel(); </span> </li><li><span> </span><span class="comment">/** </span> </li><li class="alt"><span><span class="comment"> * 将地图(图片)上的默认浏览器行为除去。 </span> </span> </li><li><span><span class="comment"> */</span><span> </span></span> </li><li class="alt"><span> image = </span><span class="keyword">new</span><span> Image(){ </span> </li><li><span> </span><span class="comment">/** </span> </li><li class="alt"><span><span class="comment"> * 这个部分必须紧跟在实例化过程的后面,不然就不起作用,没有在官方文档里找到原因。 </span> </span> </li><li><span><span class="comment"> */</span><span> </span></span> </li><li class="alt"><span> </span><span class="keyword">public</span><span> </span><span class="keyword">void</span><span> onBrowserEvent (Event event) </span> </li><li><span> { </span> </li><li class="alt"><span> DOM.eventPreventDefault(event); </span> </li><li><span> </span><span class="keyword">super</span><span>.onBrowserEvent(event); </span> </li><li class="alt"><span> } </span> </li><li><span> </span> </li><li class="alt"><span> }; </span> </li><li><span> viewArea.add(image); </span> </li><li class="alt"><span> image.setPixelSize(imageWidth, imageHeight); </span> </li><li><span> image.setUrl(imageUrl); </span> </li><li class="alt"><span> </span> </li><li><span> viewPortArea.setPixelSize(areaWidth, areaHeight); </span> </li><li class="alt"><span> viewPortArea.addStyleName(</span><span class="string">"viewportViewer"</span><span>); </span> </li><li><span> DOM.setStyleAttribute(viewPortArea.getElement(), </span><span class="string">"overflow"</span><span>, </span><span class="string">"hidden"</span><span>); </span> </li><li class="alt"><span> </span> </li><li><span> DOM.setStyleAttribute(viewPortArea.getElement(), </span><span class="string">"position"</span><span>, </span> </li><li class="alt"><span> </span><span class="string">"relative"</span><span>); </span> </li><li><span> initWidget(mouseListenerContainer); </span> </li><li class="alt"><span> </span> </li><li><span> </span> </li><li class="alt"><span> </span> </li><li><span> </span><span class="keyword">this</span><span>.showPositionLeftRatio = showPositionLeftRatio; </span> </li><li class="alt"><span> </span><span class="keyword">this</span><span>.showPositionTopRatio = showPositionTopRatio; </span> </li><li><span> </span><span class="keyword">this</span><span>.areaWidth = areaWidth; </span> </li><li class="alt"><span> </span><span class="keyword">this</span><span>.areaHeight = areaHeight; </span> </li><li><span> </span><span class="keyword">this</span><span>.imageUrl = imageUrl; </span> </li><li class="alt"><span> </span><span class="keyword">this</span><span>.imageWidth = imageWidth; </span> </li><li><span> </span><span class="keyword">this</span><span>.imageHeight = imageHeight; </span> </li><li class="alt"><span> </span> </li><li><span> </span><span class="comment">/** </span> </li><li class="alt"><span><span class="comment"> * 设置图片可被拖放的极限,防止图片被拖出边界 </span> </span> </li><li><span><span class="comment"> */</span><span> </span></span> </li><li class="alt"><span> </span> </li><li><span> maxLeft = imageWidth - areaWidth; </span> </li><li class="alt"><span> maxTop = imageHeight - areaHeight; </span> </li><li><span> minLeft = -(imageWidth - areaWidth); </span> </li><li class="alt"><span> minTop = -(imageHeight - areaHeight); </span> </li><li><span> </span> </li><li class="alt"><span> </span><span class="comment">/** </span> </li><li><span><span class="comment"> * 地图初始应该在的位置 </span> </span> </li><li class="alt"><span><span class="comment"> */</span><span> </span></span> </li><li><span> centerLeft = (</span><span class="keyword">int</span><span>) ((areaWidth - imageWidth) * showPositionLeftRatio); </span> </li><li class="alt"><span> centerTop = (</span><span class="keyword">int</span><span>) ((areaHeight - imageHeight) * showPositionTopRatio); </span> </li><li><span> </span> </li><li class="alt"><span> viewPortArea.add(viewArea, centerLeft, centerTop); </span> </li><li><span> </span><span class="comment">/** </span> </li><li class="alt"><span><span class="comment"> * 鼠标拖放的行为 </span> </span> </li><li><span><span class="comment"> */</span><span> </span></span> </li><li class="alt"><span> MouseListener listener = </span><span class="keyword">new</span><span> MouseListener(){ </span> </li><li><span> </span> </li><li class="alt"><span> </span><span class="keyword">public</span><span> </span><span class="keyword">void</span><span> onMouseDown(Widget sender, </span><span class="keyword">int</span><span> x, </span><span class="keyword">int</span><span> y) { </span> </li><li><span> state = </span><span class="number">1</span><span>; </span> </li><li class="alt"><span> startX = x; </span> </li><li><span> startY = y; </span> </li><li class="alt"><span> startLeft = viewPortArea.getWidgetLeft(viewArea); </span> </li><li><span> startTop = viewPortArea.getWidgetTop(viewArea); </span> </li><li class="alt"><span> </span> </li><li><span> } </span> </li><li class="alt"><span> </span> </li><li><span> </span><span class="keyword">public</span><span> </span><span class="keyword">void</span><span> onMouseEnter(Widget sender) { </span> </li><li class="alt"><span> </span> </li><li><span> } </span> </li><li class="alt"><span> </span> </li><li><span> </span><span class="keyword">public</span><span> </span><span class="keyword">void</span><span> onMouseLeave(Widget sender) { </span> </li><li class="alt"><span> state = </span><span class="number">0</span><span>; </span> </li><li><span> DOM.setStyleAttribute(mouseListenerContainer.getElement(), </span><span class="string">"cursor"</span><span>, </span><span class="string">"default"</span><span>); </span> </li><li class="alt"><span> } </span> </li><li><span> </span> </li><li class="alt"><span> </span><span class="keyword">public</span><span> </span><span class="keyword">void</span><span> onMouseMove(Widget sender, </span><span class="keyword">int</span><span> x, </span><span class="keyword">int</span><span> y) { </span> </li><li><span> </span><span class="keyword">if</span><span>(state == </span><span class="number">1</span><span>){ </span> </li><li class="alt"><span> DOM.setStyleAttribute(mouseListenerContainer.getElement(), </span><span class="string">"cursor"</span><span>, </span><span class="string">"move"</span><span>); </span> </li><li><span> </span><span class="keyword">if</span><span>(viewPortArea.getWidgetLeft(viewArea) >= minLeft </span> </li><li class="alt"><span> && viewPortArea.getWidgetLeft(viewArea) <= maxLeft </span> </li><li><span> && viewPortArea.getWidgetTop(viewArea) >= minTop </span> </li><li class="alt"><span> && viewPortArea.getWidgetTop(viewArea) <= maxTop){ </span> </li><li><span> viewPortArea.setWidgetPosition(viewArea,startLeft + (x - startX), startTop + (y - startY)); </span> </li><li class="alt"><span> } </span> </li><li><span> } </span> </li><li class="alt"><span> } </span> </li><li><span> </span> </li><li class="alt"><span> </span><span class="keyword">public</span><span> </span><span class="keyword">void</span><span> onMouseUp(Widget sender, </span><span class="keyword">int</span><span> x, </span><span class="keyword">int</span><span> y) { </span> </li><li><span> </span><span class="comment">// TODO 缺报当拖放结束时,地图还在显示框内 </span><span> </span> </li><li class="alt"><span> </span><span class="keyword">if</span><span>(viewPortArea.getWidgetLeft(viewArea) < minLeft){ </span> </li><li><span> viewPortArea.setWidgetPosition(viewArea, minLeft, viewPortArea.getWidgetTop(viewArea)); </span> </li><li class="alt"><span> } </span> </li><li><span> </span><span class="keyword">if</span><span>(viewPortArea.getWidgetTop(viewArea) < minTop){ </span> </li><li class="alt"><span> viewPortArea.setWidgetPosition(viewArea, viewPortArea.getWidgetLeft(viewArea), minTop); </span> </li><li><span> } </span> </li><li class="alt"><span> </span><span class="keyword">if</span><span>(viewPortArea.getWidgetLeft(viewArea) > </span><span class="number">0</span><span>){ </span> </li><li><span> viewPortArea.setWidgetPosition(viewArea, </span><span class="number">0</span><span>, viewPortArea.getWidgetTop(viewArea)); </span> </li><li class="alt"><span> } </span> </li><li><span> </span><span class="keyword">if</span><span>(viewPortArea.getWidgetTop(viewArea) > </span><span class="number">0</span><span>){ </span> </li><li class="alt"><span> viewPortArea.setWidgetPosition(viewArea, viewPortArea.getWidgetLeft(viewArea), </span><span class="number">0</span><span>); </span> </li><li><span> } </span> </li><li class="alt"><span> state = </span><span class="number">0</span><span>; </span> </li><li><span> DOM.setStyleAttribute(mouseListenerContainer.getElement(), </span><span class="string">"cursor"</span><span>, </span><span class="string">"default"</span><span>); </span> </li><li class="alt"><span> } </span> </li><li><span> </span> </li><li class="alt"><span> }; </span> </li><li><span> mouseListenerContainer.addMouseListener(listener); </span> </li><li class="alt"><span> </span> </li><li><span> } </span> </li><li class="alt"><span> </span> </li><li><span>} </span> </li></ol></div><p>代码很容易理解,这只是一个很简易的实现,至少还有以下需要完善:</p><ol><li>地图分块载入 </li><li>支持鼠标滚轮的缩放 </li><li>“鹰眼”功能。 </li></ol><p>感兴趣的跟进一下:)</p></blockquote></div>
相关推荐
MapViewer 是一款强大的地图可视化工具,它允许用户创建、编辑和展示地理信息数据。"mvdemo" 可能是 MapViewer 提供的一个演示或样本数据集,用于帮助用户了解如何使用该软件以及其功能。这个压缩包 "mvdemo11R1" 很...
在IT领域,尤其是在商业智能(BI)与地理信息系统(GIS)的交集上,Oracle Business Intelligence Enterprise Edition (OBIEE)与MapViewer的集成提供了一种强大的方式来展示和分析带有地理位置信息的数据。...
Mapviewer7.3 压缩包第三部分,全部上传完毕。
根据提供的文件信息,我们可以总结出以下关于Oracle MapViewer的相关知识点: ### 一、产品概述 **Oracle MapViewer** 是一款地图渲染工具,用于显示不同类型的地理空间数据。它作为Oracle Fusion Middleware的一...
Golden software 出品的一款酷软,用于地图的处理,功能强大,使用方便。
MapViewer与BIEE集成 之一MapViewer的安装和设置 MapViewer与BIEE集成 之二通过网页集成 MapViewer与BIEE集成 之三新地图文件向Oracle spatial数据库导入 MapViewer与BIEE集成 之四MapBuilder教程 MapViewer与BIEE...
### Oracle Spatial 与 MapViewer 新特性详解 #### 一、Oracle Spatial 11g 新特性概览 **Oracle Spatial 11g** 是 Oracle 数据库 11g 的一个重要组成部分,它引入了一系列重要的新特性,并对现有的特性和 API ...
知识点:Oracle MapViewer详解 一、Oracle MapViewer概述: Oracle MapViewer是Oracle Fusion Middleware套件中的一个关键组件,主要用于地理信息系统(GIS)和空间数据的可视化处理。它为用户提供了一个强大的平台...
MapViewer是一款强大的地理信息系统(GIS)软件,专用于地图制作、数据分析和可视化。在油田管理中,绘制开采现状图是至关重要的,它可以帮助我们理解油田的分布、开采进度以及资源利用情况。本教程将详细解释如何...
MapViewer与BIEE集成是将Oracle的GIS(地理信息系统)工具MapViewer与Business Intelligence Enterprise Edition(BIEE)相结合,以提供具有空间可视化能力的商业智能解决方案。Oracle Spatial是Oracle数据库的一个...
通过这个控件,我们可以加载Google Maps的网页,并在本地环境中展示地图。 **Google Map API的使用** Google Maps API是一组用于在网页和应用程序中嵌入地图、获取地理位置信息、绘制路线等功能的JavaScript库。在...
### 基于MapViewer的LBS系统设计与实现 #### MapViewer介绍及技术特性 MapViewer作为Oracle应用服务器10g的一个重要组件,主要用于可视化由Oracle Locator或Oracle Spatial管理的地理空间数据。该工具通过简化空间...
Oracle MapViewer 是 Oracle 11g 中的一个组件,主要用于创建、管理和展示地理空间数据。MapViewer 提供了一个直观的Web界面,使得用户可以方便地查看地图、地理信息以及相关的属性数据。这个“oracle11g配套...
【图形学MapViewer】是一个专注于地图可视化应用的项目,它允许用户通过图形界面来查看地图,并支持地图的拖动操作以实现平移查看。虽然开发者自谦表示功能并不完善,但这一工具对于学习和理解图形学原理,以及地图...
### OBIEE MapViewer 地图数据管理及GIS展示详解 #### OBIEE MapViewer概述 Oracle Business Intelligence Enterprise Edition (OBIEE) 提供了一系列强大的工具和服务,旨在帮助企业更好地理解和利用其业务数据。...
Mapviewer7.3 压缩包第二部分,一共三个压缩包;
地图浏览器Mapviewer是的抽象,可以使用配置创建常见的GIS应用程序。 Mapviewer需要npm install leaflet d3 d3-scale-chromatic mapviewer color npm install leaflet d3 d3-scale-chromatic mapviewer 。 < link...
MapViewer是一款专业的地形制作软件,广泛应用于地理信息系统(GIS)行业和教育领域。这款软件的主要功能是帮助用户创建、编辑和分析地图数据,特别是在地形建模方面表现出色。MapViewer 8.4.406是该软件的一个特定...
### ArcGIS.Engine.Demo.MapViewer知识点详解 #### 一、项目概述 **ArcGIS.Engine.Demo.MapViewer** 是一个基于ArcGIS Engine开发平台的应用程序示例。该项目主要目的是展示如何利用ArcGIS Engine的各种控件来构建...
【ArcGIS Engine Demo MapViewer】是一个面向初学者的ArcGIS二次开发示例,它通过MapViewer应用程序演示了如何使用ArcGIS Engine进行地图显示和交互的基本操作。ArcGIS Engine是Esri公司提供的一款强大的GIS开发工具...