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.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電子檔
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最新源码,包含v6.2.1和v6.2.1-dist。Github下载太慢,放到这里,需要的朋友可以下载。
openlayers 加载蓝黑色天地图颜色工具类,openlayers 加载蓝黑色底图。 使用介绍: 直接 import 然后使用 TileSourceColor.getSource (图层对象,类型) 即可。 let layer = new LayerTile({ name: "天地图矢量...
openlayers.zip
ngx-openlayers 安装 要安装此库,请运行: npm install ngx-openlayers --save 例子 这是一个“最小”地图示例,该示例从OpenStreetMap获取图块并将地图居中于Meylan(法国): 在app.module.ts : ... import {...
开放层测试 测试 Openlayers.js
openlayers-map openlayers-map openlayers-map openlayers-map
作为实战中vue+openlayers+geoserver文章的资源文件