add an example of how to use a WKT string in a vector source
This commit is contained in:
55
examples/wkt.html
Normal file
55
examples/wkt.html
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
<!doctype html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<meta http-equiv="X-UA-Compatible" content="chrome=1">
|
||||||
|
<meta name="viewport" content="initial-scale=1.0, user-scalable=no, width=device-width">
|
||||||
|
<link rel="stylesheet" href="../css/ol.css" type="text/css">
|
||||||
|
<link rel="stylesheet" href="../resources/bootstrap/css/bootstrap.min.css" type="text/css">
|
||||||
|
<link rel="stylesheet" href="../resources/layout.css" type="text/css">
|
||||||
|
<link rel="stylesheet" href="../resources/bootstrap/css/bootstrap-responsive.min.css" type="text/css">
|
||||||
|
<title>WKT example</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
|
||||||
|
<div class="navbar navbar-inverse navbar-fixed-top">
|
||||||
|
<div class="navbar-inner">
|
||||||
|
<div class="container">
|
||||||
|
<a class="brand" href="./"><img src="../resources/logo.png"> OpenLayers 3 Examples</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="container-fluid">
|
||||||
|
|
||||||
|
<div class="row-fluid">
|
||||||
|
<div class="span12">
|
||||||
|
<div id="map" class="map"></div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="row-fluid">
|
||||||
|
|
||||||
|
<div class="span4">
|
||||||
|
<h4 id="title">WKT example</h4>
|
||||||
|
<p id="shortdesc">Example of using the WKT parser.</p>
|
||||||
|
<div id="docs">
|
||||||
|
<p>See the <a href="wkt.js" target="_blank">wkt.js source</a> to see how this is done.</p>
|
||||||
|
</div>
|
||||||
|
<div id="tags">WKT Well Known Text</div>
|
||||||
|
</div>
|
||||||
|
<div class="span4 offset4">
|
||||||
|
<div id="info" class="alert alert-success">
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<script src="jquery.min.js" type="text/javascript"></script>
|
||||||
|
<script src="loader.js?id=wkt" type="text/javascript"></script>
|
||||||
|
<script src="../resources/example-behaviour.js" type="text/javascript"></script>
|
||||||
|
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
33
examples/wkt.js
Normal file
33
examples/wkt.js
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
goog.require('ol.Map');
|
||||||
|
goog.require('ol.RendererHint');
|
||||||
|
goog.require('ol.View2D');
|
||||||
|
goog.require('ol.layer.Tile');
|
||||||
|
goog.require('ol.layer.Vector');
|
||||||
|
goog.require('ol.parser.WKT');
|
||||||
|
goog.require('ol.proj');
|
||||||
|
goog.require('ol.source.OSM');
|
||||||
|
goog.require('ol.source.Vector');
|
||||||
|
|
||||||
|
var raster = new ol.layer.Tile({
|
||||||
|
source: new ol.source.OSM()
|
||||||
|
});
|
||||||
|
|
||||||
|
var vector = new ol.layer.Vector({
|
||||||
|
source: new ol.source.Vector({
|
||||||
|
parser: new ol.parser.WKT(),
|
||||||
|
projection: ol.proj.get('EPSG:4326'),
|
||||||
|
data: 'POLYGON((10.689697265625 -25.0927734375, 34.595947265625 ' +
|
||||||
|
'-20.1708984375, 38.814697265625 -35.6396484375, 13.502197265625 ' +
|
||||||
|
'-39.1552734375, 10.689697265625 -25.0927734375))'
|
||||||
|
})
|
||||||
|
});
|
||||||
|
|
||||||
|
var map = new ol.Map({
|
||||||
|
layers: [raster, vector],
|
||||||
|
renderer: ol.RendererHint.CANVAS,
|
||||||
|
target: 'map',
|
||||||
|
view: new ol.View2D({
|
||||||
|
center: [2952104.019976033, -3277504.823700756],
|
||||||
|
zoom: 4
|
||||||
|
})
|
||||||
|
});
|
||||||
@@ -2,6 +2,7 @@ goog.provide('ol.parser.WKT');
|
|||||||
|
|
||||||
goog.require('goog.array');
|
goog.require('goog.array');
|
||||||
goog.require('goog.string');
|
goog.require('goog.string');
|
||||||
|
goog.require('ol.Feature');
|
||||||
goog.require('ol.geom.Geometry');
|
goog.require('ol.geom.Geometry');
|
||||||
goog.require('ol.geom.GeometryCollection');
|
goog.require('ol.geom.GeometryCollection');
|
||||||
goog.require('ol.geom.LineString');
|
goog.require('ol.geom.LineString');
|
||||||
@@ -11,12 +12,14 @@ goog.require('ol.geom.MultiPolygon');
|
|||||||
goog.require('ol.geom.Point');
|
goog.require('ol.geom.Point');
|
||||||
goog.require('ol.geom.Polygon');
|
goog.require('ol.geom.Polygon');
|
||||||
goog.require('ol.parser.Parser');
|
goog.require('ol.parser.Parser');
|
||||||
|
goog.require('ol.parser.StringFeatureParser');
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @constructor
|
* @constructor
|
||||||
* @extends {ol.parser.Parser}
|
* @extends {ol.parser.Parser}
|
||||||
|
* @implements {ol.parser.StringFeatureParser}
|
||||||
* @todo stability experimental
|
* @todo stability experimental
|
||||||
*/
|
*/
|
||||||
ol.parser.WKT = function() {
|
ol.parser.WKT = function() {
|
||||||
@@ -341,6 +344,24 @@ ol.parser.WKT.prototype.read = function(str) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parse a WKT document provided as a string.
|
||||||
|
* @param {string} str WKT document.
|
||||||
|
* @return {ol.parser.ReadFeaturesResult} Features and metadata.
|
||||||
|
*/
|
||||||
|
ol.parser.WKT.prototype.readFeaturesFromString = function(str) {
|
||||||
|
var geom = this.read(str);
|
||||||
|
var obj = /** @type {ol.parser.ReadFeaturesResult} */
|
||||||
|
({});
|
||||||
|
if (goog.isDef(geom)) {
|
||||||
|
var feature = new ol.Feature();
|
||||||
|
feature.setGeometry(geom);
|
||||||
|
obj.features = [feature];
|
||||||
|
}
|
||||||
|
return obj;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Write out a geometry as a WKT string.
|
* Write out a geometry as a WKT string.
|
||||||
* @param {ol.geom.Geometry} geom The geometry to encode.
|
* @param {ol.geom.Geometry} geom The geometry to encode.
|
||||||
|
|||||||
Reference in New Issue
Block a user