Here I give a simple demo how to write map class.
-
MapOptions
-
Map
1. MapOptions
A JSON object in JavaScript, but in GWT you must write a class extend BaseJavaScriptObject for it. Because it is a simple JSON, so result in the createNew method as following. In this JSON, "resolutions" and "controls" are JavaScript Array, so I must convert Object[] to JavaScript Array then can setProperty.
package org.gwtopenmaps.openlayers.client;
import org.gwtopenmaps.openlayers.client.common.BaseJavaScriptObject;
import org.gwtopenmaps.openlayers.client.common.JavaScriptObjectHelper;
import org.gwtopenmaps.openlayers.client.control.Control;
import com.google.gwt.core.client.JavaScriptObject;
public class MapOptions extends BaseJavaScriptObject {
protected MapOptions() {}
public static MapOptions createNew() {
return (MapOptions) JavaScriptObject.createObject();
}
public final void setProjection(String projection) {
setProperty("projection", projection);
}
public final void setResolutions(Double... resolutions) {
JavaScriptObject javaScriptArray = JavaScriptObjectHelper.toJavaScriptArray((Object[]) resolutions);
setProperty("resolutions", javaScriptArray);
}
public final void setPanRatio(int panRatio) {
setProperty("panRatio", panRatio);
}
public final void setPanDuration(int panDuration) {
setProperty("panDuration", panDuration);
}
public final void setControls(Control... controls) {
JavaScriptObject javaScriptArray = JavaScriptObjectHelper.toJavaScriptArray((Object[]) controls);
setProperty("controls", javaScriptArray);
}
}
2. Map
Because this is a small demo, so just see the code following...
package org.gwtopenmaps.openlayers.client;
import org.gwtopenmaps.openlayers.client.common.BaseJavaScriptObject;
import org.gwtopenmaps.openlayers.client.control.Control;
import org.gwtopenmaps.openlayers.client.layer.Layer;
public class Map extends BaseJavaScriptObject {
protected Map() {
}
public static native Map createNew(String divId, MapOptions mapOptions) /*-{
return new $wnd.OpenLayers.Map(divId, mapOptions);
}-*/;
public final void addLayer(Layer layer) {
invokeMethodReturnJavaScriptObject("addLayer", layer);
}
public final void setCenter(LonLat lonLat, int zoom) {
invokeMethodReturnJavaScriptObject("setCenter", lonLat, zoom);
}
public final Control getControl(String id) {
return (Control) invokeMethodReturnJavaScriptObject("getControl", id);
}
public final int getZoom() {
return invokeMethodReturnInt("getZoom");
}
}
to be continued...
分享到:
相关推荐
第3章:走进Openlayers.rar
openlayers.js库及入门事例; OpenLayers是一个开源的js框架,用于在您的浏览器中实现地图浏览的效果和基本的zoom,pan等功能。OpenLayers支持的地图来源包括了WMS,GoogleMap,KaMap,MSVirtualEarth等等,您也可以...
openlayer ol.js ol.css
Packt.OpenLayers.3.x.Cookbook.2nd.Edition.2016.3.pdf
在使用 OpenLayers 时,需要实例化一个地图类 OpenLayers.Map,加载 WMS 和 GML 文件,添加控件 OpenLayers.Control 等。 OpenLayers 的优点包括: * 灵活的数据格式支持 * 丰富的地图数据资源 * 无浏览器依赖性 *...
var map = new OpenLayers.Map('map'); var layer = new OpenLayers.Layer.WMS('myLayer', 'http://example.com/wms', {layers: 'myLayer'}); map.addLayer(layer); map.zoomToExtent(new OpenLayers.Bounds(-180, -...
OpenLayers.mobile.debug.js
OpenLayers.2.10.Beginners.Guide (英文版) 非常好的OpenLayers的入门及工具书,强烈推荐
openlayer 需引入ol.css ,ol.js,就和Arcgis 引入 Arcgis JS API 一样的道理
OpenLayers网站构建实用程序使用main的更新来更新站点要求您已安装和 。 当前,构建网站还需要所有openlayers。 # only once: clonegit clone -b build ... 这将从openlayers存储库的main分支中更新站点文档和示例。...
OpenLayers.debug.js
OpenLayers.2.10.Beginners.Guide原书pdf和书中所有代码
Packt.OpenLayers.2.10.Beginner's.Guide英文pdf電子檔
map = new OpenLayers.Map( $('map') , options); ``` 在这个示例中,我们配置了缩放级别的各种参数,包括比例尺、解析度、最大最小比例尺、最大最小解析度、最大最小范围等。这些参数可以根据实际情况进行调整,以...
position: new OpenLayers.Pixel(2, 15) })); ``` 添加鼠标坐标拾取控件 使用以下代码添加鼠标坐标拾取控件: ```javascript map.addControl(new OpenLayers.Control.MousePosition()); ``` 其他控件 OpenLayers ...
link rel =" stylesheet " href =" https://cdn.jsdelivr.net/gh/openlayers/openlayers.github.io@master/en/v6.3.1/css/ol.css " type =" text/css " > < style > . map { height : 400 px ; width ...
openlayers 加载蓝黑色天地图颜色工具类,openlayers 加载蓝黑色底图。 使用介绍: 直接 import 然后使用 TileSourceColor.getSource (图层对象,类型) 即可。 let layer = new LayerTile({ name: "天地图矢量...
OpenLayers最新源码,包含v6.2.1和v6.2.1-dist。Github下载太慢,放到这里,需要的朋友可以下载。
openlayers.zip