Skip to content

Commit

Permalink
修改GeoJsonReader为GeoJsonFormat,将读取要素和字段分开,编写geojson.html示例。
Browse files Browse the repository at this point in the history
  • Loading branch information
fanzia committed Sep 22, 2016
1 parent 932d710 commit 568d638
Show file tree
Hide file tree
Showing 5 changed files with 799 additions and 391 deletions.
187 changes: 187 additions & 0 deletions example/all/Format/geoJson.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,187 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<link rel="stylesheet" type="text/css" href="../../../lib/css/Map5.min.css">

<script type="text/javascript" src="../../../src/depends/jquery-1.11.1.js"></script>
<script type="text/javascript" src="../../../src/depends/bootstrap.min.js"></script>

<!--Base-->
<script type="text/javascript" src="../../../src/GeoBeans.js"></script>
<script type="text/javascript" src="../../../src/GeoBeans/BaseTypes/Class.js"></script>
<script type="text/javascript" src="../../../src/GeoBeans/BaseTypes/Color.js"></script>
<script type="text/javascript" src="../../../src/GeoBeans/BaseTypes/Envelope.js"></script>
<script type="text/javascript" src="../../../src/GeoBeans/Utility/Utility.js"></script>

<!--View-->
<script type="text/javascript" src="../../../src/GeoBeans/Render/Viewer.js"></script>
<script type="text/javascript" src="../../../src/GeoBeans/Renderer.js"></script>
<!--Geometry-->
<script type="text/javascript" src="../../../src/GeoBeans/Geometry.js"></script>
<script type="text/javascript" src="../../../src/GeoBeans/Geometry/Point.js"></script>
<script type="text/javascript" src="../../../src/GeoBeans/Geometry/LineString.js"></script>
<script type="text/javascript" src="../../../src/GeoBeans/Geometry/Line/LinearRing.js"></script>
<script type="text/javascript" src="../../../src/GeoBeans/Geometry/Polygon.js"></script>
<script type="text/javascript" src="../../../src/GeoBeans/Geometry/MultiPoint.js"></script>
<script type="text/javascript" src="../../../src/GeoBeans/Geometry/MultiLineString.js"></script>
<script type="text/javascript" src="../../../src/GeoBeans/Geometry/MultiPolygon.js"></script>
<script type="text/javascript" src="../../../src/GeoBeans/Geometry/Circle.js"></script>
<!--Stype-->
<script type="text/javascript" src="../../../src/GeoBeans/Style.js"></script>
<script type="text/javascript" src="../../../src/GeoBeans/Symbolizer.js"></script>
<script type="text/javascript" src="../../../src/GeoBeans/Style/Font.js"></script>
<script type="text/javascript" src="../../../src/GeoBeans/Style/Fill.js"></script>
<script type="text/javascript" src="../../../src/GeoBeans/Style/Stroke.js"></script>
<script type="text/javascript" src="../../../src/GeoBeans/Style/PointSymbolizer.js"></script>
<script type="text/javascript" src="../../../src/GeoBeans/Style/LineSymbolizer.js"></script>
<script type="text/javascript" src="../../../src/GeoBeans/Style/PolygonSymbolizer.js"></script>
<script type="text/javascript" src="../../../src/GeoBeans/Style/FeatureStyle.js"></script>
<script type="text/javascript" src="../../../src/GeoBeans/Style/Rule.js"></script>
<!--Control-->
<script type="text/javascript" src="../../../src/GeoBeans/Control.js"></script>
<script type="text/javascript" src="../../../src/GeoBeans/Control/DragMapControl.js"></script>
<script type="text/javascript" src="../../../src/GeoBeans/Control/ScrollMapControl.js"></script>
<script type="text/javascript" src="../../../src/GeoBeans/Control/TrackControl.js"></script>
<script type="text/javascript" src="../../../src/GeoBeans/Control/TrackControl/TrackOverlayControl.js"></script>
<script type="text/javascript" src="../../../src/GeoBeans/Control/ZoomControl.js"></script>
<script type="text/javascript" src="../../../src/GeoBeans/Control/MapNavControl.js"></script>
<!--Format-->
<script type="text/javascript" src="../../../src/GeoBeans/Format/GML.js"></script>
<!--Filter-->
<script type="text/javascript" src="../../../src/GeoBeans/Filter.js"></script>
<script type="text/javascript" src="../../../src/GeoBeans/Filter/SpatialFilter.js"></script>
<script type="text/javascript" src="../../../src/GeoBeans/Filter/SpatialFilter/BBoxFilter.js"></script>
<script type="text/javascript" src="../../../src/GeoBeans/Filter/FilterWriter.js"></script>
<script type="text/javascript" src="../../../src/GeoBeans/Filter/OrderBy.js"></script>
<script type="text/javascript" src="../../../src/GeoBeans/Query.js"></script>

<!--Workspace-->
<script type="text/javascript" src="../../../src/GeoBeans/Field.js"></script>
<script type="text/javascript" src="../../../src/GeoBeans/Feature.js"></script>
<script type="text/javascript" src="../../../src/GeoBeans/FeatureType.js"></script>
<script type="text/javascript" src="../../../src/GeoBeans/Workspace.js"></script>
<script type="text/javascript" src="../../../src/GeoBeans/Source/Workspace/WFS/WFSWorkspace.js"></script>
<!--Layer-->
<script type="text/javascript" src="../../../src/GeoBeans/Layer.js"></script>
<script type="text/javascript" src="../../../src/GeoBeans/Layer/FeatureLayer.js"></script>
<script type="text/javascript" src="../../../src/GeoBeans/Layer/OverlayLayer.js"></script>
<script type="text/javascript" src="../../../src/GeoBeans/Layer/QueryLayer.js"></script>
<script type="text/javascript" src="../../../src/GeoBeans/Layer/PanoramaLayer.js"></script>
<script type="text/javascript" src="../../../src/GeoBeans/Layer/ImageLayer.js"></script>
<script type="text/javascript" src="../../../src/GeoBeans/Layer/Tile.js"></script>
<script type="text/javascript" src="../../../src/GeoBeans/Layer/TileCache.js"></script>
<script type="text/javascript" src="../../../src/GeoBeans/Layer/TileLayer.js"></script>
<script type="text/javascript" src="../../../src/GeoBeans/Layer/TileLayer/QSLayer.js"></script>
<script type="text/javascript" src="../../../src/GeoBeans/Layer/ChartLayer.js"></script>
<script type="text/javascript" src="../../../src/GeoBeans/Layer/ThematicLayer/RippleLayer.js"></script>
<script type="text/javascript" src="../../../src/GeoBeans/Layer/FeatureLayer/WFSLayer.js"></script>
<!--Interaction-->
<script type="text/javascript" src="../../../src/GeoBeans/Interaction.js"></script>
<script type="text/javascript" src="../../../src/GeoBeans/Interaction/Draw.js"></script>
<script type="text/javascript" src="../../../src/GeoBeans/Interaction/Select.js"></script>
<script type="text/javascript" src="../../../src/GeoBeans/Interaction/Rotate.js"></script>
<!--Events-->
<script type="text/javascript" src="../../../src/GeoBeans/Events.js"></script>
<!--Render-->
<script type="text/javascript" src="../../../src/GeoBeans/Render/Label/Maplex.js"></script>
<!--Widget-->
<script type="text/javascript" src="../../../src/GeoBeans/Widget.js"></script>
<script type="text/javascript" src="../../../src/GeoBeans/Widget/CopyRightWidget.js"></script>
<script type="text/javascript" src="../../../src/GeoBeans/Widget/InfoWindowWidget.js"></script>
<script type="text/javascript" src="../../../src/GeoBeans/Widget/LegendWidget.js"></script>

<!-- format -->
<script type="text/javascript" src="../../../src/GeoBeans/Format/GeoJsonFormat.js"></script>
<!--Map-->
<script type="text/javascript" src="../../../src/GeoBeans/Map.js"></script>

<script type="text/javascript" src="../js/initMap.js"></script>

<style type="text/css">
body{
margin: 0px;
}
</style>
<script type="text/javascript">
// 地图变量
var mapObj = null;
function init(){

loadTileMap();
}

function getGeoJson(){
var url = "../data/geojson/point-samples.geojson";
// var url = "../data/geojson/line-samples.geojson";
// var url = "../data/geojson/polygon-samples.geojson";
// var url = "../data/geojson/countries.geojson";
$.ajax({
url : url,
dataType: "json",
async : false,
beforeSend: function(XMLHttpRequest){
},
success : function(json, textStatus){
readJson(json);
},
complete: function(XMLHttpRequest, textStatus){
},
error : function(){
}
});
}


function readJson(geoJson){
if(geoJson == null){
return;
}
var geoJsonFormat = new GeoBeans.GeoJsonFormat();
var fields = geoJsonFormat.readFields(geoJson);

var features = geoJsonFormat.read(geoJson,fields);

var featureType = new GeoBeans.FeatureType();
featureType.fields = fields;
featureType.geomFieldName = "geometry";

var featureLayer = new GeoBeans.Layer.FeatureLayer("point");
featureLayer.featureType = featureType;

featureLayer.addFeatures(features);

mapObj.addLayer(featureLayer);

// var style = createStyle();
// featureLayer.setStyle(style);

var zoom = 8;
var center = new GeoBeans.Geometry.Point(-72.6,47.7);
var viewer = mapObj.getViewer();
viewer.setZoomCenter(zoom,center);

mapObj.refresh();
}

function createStyle(){
var style = new GeoBeans.Style.FeatureStyle();
var rule = new GeoBeans.Rule();
var symbolizer = new GeoBeans.Symbolizer.PointSymbolizer();
symbolizer.size = 6;
symbolizer.fill.color.set(255, 0, 0,1);
symbolizer.stroke.color.set(0,255, 0,1);
rule.symbolizer = symbolizer;
style.addRule(rule);
return style;
}
</script>
<title>格式:GeoJson</title>
<body onload="init()">
<!-- mapDiv 为初始化地图的容器,给定高度和宽度,并指定定位方式为绝对定位 -->
<div id="mapDiv" style="height:800px;width:100%;position:absolute;top:80px;">
</div>
<button onclick="getGeoJson()">转换</button>
</body>

2 changes: 1 addition & 1 deletion example/all/js/catalog.js
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,7 @@ var g_catalog = [
"link" : "format_gmal.html"
},{
"name" : "(*)GeoJSON<-->Geometry",
"link" : "format_gmal.html"
"link" : "Format/geoJson.html"
}
]
},{
Expand Down
Loading

0 comments on commit 568d638

Please sign in to comment.