You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
1343 lines
71 KiB
HTML
1343 lines
71 KiB
HTML
2 weeks ago
|
<!DOCTYPE html>
|
||
|
<html lang="en-US">
|
||
|
<head>
|
||
|
<meta charset="UTF-8">
|
||
|
<meta http-equiv="X-UA-Compatible" content="IE=Edge">
|
||
|
<meta name="viewport" content="initial-scale=1.0, user-scalable=no, width=device-width">
|
||
|
<script>
|
||
|
var gaProperty = 'UA-2577926-1';
|
||
|
// Disable tracking if the opt-out cookie exists.
|
||
|
var disableStr = 'ga-disable-' + gaProperty;
|
||
|
if (document.cookie.indexOf(disableStr + '=true') > -1) {
|
||
|
window[disableStr] = true;
|
||
|
}
|
||
|
function gaOptout() {
|
||
|
document.cookie = disableStr + '=true; expires=Thu, 31 Dec 2099 23:59:59 UTC; path=/';
|
||
|
window[disableStr] = true;
|
||
|
}
|
||
|
function gaOptoutRevoke() {
|
||
|
document.cookie = disableStr + '=false; expires=Thu, 31 Dec 2099 23:59:59 UTC; path=/';
|
||
|
window[disableStr] = false;
|
||
|
}
|
||
|
</script>
|
||
|
<!-- Global site tag (gtag.js) - Google Analytics -->
|
||
|
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-2577926-1"></script>
|
||
|
<script>
|
||
|
window.dataLayer = window.dataLayer || [];
|
||
|
function gtag(){dataLayer.push(arguments);}
|
||
|
gtag('js', new Date());
|
||
|
gtag('config', 'UA-2577926-1', { 'anonymize_ip': true });
|
||
|
</script>
|
||
|
<link rel="stylesheet" type="text/css" href="//cdnjs.cloudflare.com/ajax/libs/cookieconsent2/3.1.0/cookieconsent.min.css" />
|
||
|
<script src="//cdnjs.cloudflare.com/ajax/libs/cookieconsent2/3.1.0/cookieconsent.min.js"></script>
|
||
|
<script src="https://unpkg.com/lz-string@1.4.4/libs/lz-string.min.js"></script>
|
||
|
<script>
|
||
|
window.addEventListener("load", function() {
|
||
|
window.cookieconsent.initialise({
|
||
|
'palette': {
|
||
|
'popup': {
|
||
|
'background': '#eaf7f7',
|
||
|
'text': '#5c7291'
|
||
|
},
|
||
|
'button': {
|
||
|
'background': '#56cbdb',
|
||
|
'text': '#ffffff'
|
||
|
}
|
||
|
},
|
||
|
'theme': 'edgeless',
|
||
|
'type': 'opt-out',
|
||
|
'onInitialise': function (status) {
|
||
|
if (!this.hasConsented()) {
|
||
|
gaOptout()
|
||
|
}
|
||
|
},
|
||
|
'onStatusChange': function(status, chosenBefore) {
|
||
|
if (!this.hasConsented()) {
|
||
|
gaOptout()
|
||
|
}
|
||
|
},
|
||
|
'onRevokeChoice': function() {
|
||
|
gaOptoutRevoke()
|
||
|
}
|
||
|
})
|
||
|
});
|
||
|
</script>
|
||
|
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" type="text/css">
|
||
|
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css" type="text/css">
|
||
|
<link rel="stylesheet" href="./resources/prism/prism-1.20.0.css" type="text/css">
|
||
|
<link rel="stylesheet" href="./css/ol.css" type="text/css">
|
||
|
<link rel="stylesheet" href="./resources/layout.css" type="text/css">
|
||
|
<script src="https://unpkg.com/elm-pep"></script>
|
||
|
<script src="https://cdn.polyfill.io/v3/polyfill.min.js?features=fetch,requestAnimationFrame,Element.prototype.classList,URL,TextDecoder"></script>
|
||
|
|
||
|
<link rel="stylesheet" href="vector-labels.css">
|
||
|
<title>Vector Labels</title>
|
||
|
</head>
|
||
|
<body>
|
||
|
|
||
|
<header class="navbar navbar-expand-sm navbar-dark mb-3 py-0" role="navigation">
|
||
|
<a class="navbar-brand" href="https://openlayers.org/"><img src="./resources/logo-70x70.png" alt=""> OpenLayers</a>
|
||
|
|
||
|
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#olmenu" aria-controls="olmenu" aria-expanded="false" aria-label="Toggle navigation">
|
||
|
<span class="navbar-toggler-icon"></span>
|
||
|
</button>
|
||
|
|
||
|
<!-- menu items that get hidden below 768px width -->
|
||
|
<nav class="collapse navbar-collapse" id="olmenu">
|
||
|
<ul class="nav navbar-nav ml-auto">
|
||
|
<li class="nav-item dropdown">
|
||
|
<a class="nav-link dropdown-toggle" href="#" id="docdropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Docs</a>
|
||
|
<div class="dropdown-menu dropdown-menu-right mb-3" aria-labelledby="docdropdown">
|
||
|
<a class="dropdown-item" href="../doc/">Docs</a>
|
||
|
<div class="dropdown-divider"></div>
|
||
|
<a class="dropdown-item" href="../doc/quickstart.html"><i class="fa fa-check fa-fw mr-2 fa-lg"></i>Quick Start</a>
|
||
|
<a class="dropdown-item" href="../doc/faq.html"><i class="fa fa-question fa-fw mr-2 fa-lg"></i>FAQ</a>
|
||
|
<a class="dropdown-item" href="../doc/tutorials/"><i class="fa fa-book fa-fw mr-2 fa-lg"></i>Tutorials</a>
|
||
|
<a class="dropdown-item" href="/workshop/"><i class="fa fa-graduation-cap fa-fw mr-2 fa-lg"></i>Workshop</a>
|
||
|
<div class="dropdown-divider"></div>
|
||
|
<a class="dropdown-item" href="https://stackoverflow.com/questions/tagged/openlayers"><i class="fa fa-stack-overflow fa-fw mr-2"></i>Ask a Question</a>
|
||
|
</div>
|
||
|
</li>
|
||
|
<li class="nav-item active"><a class="nav-link" href="../examples/">Examples</a></li>
|
||
|
<li class="nav-item"><a class="nav-link" href="../apidoc/"><i class="fa fa-sitemap mr-1"></i>API</a></li>
|
||
|
<li class="nav-item dropdown">
|
||
|
<a class="nav-link dropdown-toggle" href="#" id="codedropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Code</a>
|
||
|
<div class="dropdown-menu dropdown-menu-right mb-3" aria-labelledby="codedropdown">
|
||
|
<a class="dropdown-item" href="https://github.com/openlayers/openlayers"><i class="fa fa-github fa-fw mr-2 fa-lg"></i>Repository</a>
|
||
|
<a class="dropdown-item" href="/download/"><i class="fa fa-download fa-fw mr-2 fa-lg"></i>Download</a>
|
||
|
</div>
|
||
|
</li>
|
||
|
</ul>
|
||
|
</nav>
|
||
|
</header>
|
||
|
|
||
|
<div class="container-fluid line-numbers">
|
||
|
|
||
|
<div id="latest-check" class="alert alert-warning alert-dismissible" role="alert" style="display:none">
|
||
|
<button id="latest-dismiss" type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button>
|
||
|
This example uses OpenLayers v<span>6.5.0</span>. The <a id="latest-link" href="#" class="alert-link">latest</a> is v<span id="latest-version"></span>.
|
||
|
</div>
|
||
|
|
||
|
|
||
|
<div class="row-fluid">
|
||
|
<a href="#" id="codepen-button" class="btn btn-link float-right">
|
||
|
<i class="fa fa-codepen fa-lg"></i> Edit
|
||
|
</a>
|
||
|
<div class="span12">
|
||
|
<h4 id="title">Vector Labels</h4>
|
||
|
<p class="tags">
|
||
|
<span class="badge-group">
|
||
|
<a
|
||
|
href="./index.html?q=geojson" class="badge badge-info">geojson</a
|
||
|
><a
|
||
|
class="badge badge-info tag-modal-toggle text-white"
|
||
|
data-toggle="modal"
|
||
|
data-target="#tag-example-list"
|
||
|
data-title="geojson"
|
||
|
data-content="
|
||
|
<a class="list-group-item list-group-item-action" href="./drag-and-drop.html">Drag-and-Drop</a>
|
||
|
<a class="list-group-item list-group-item-action" href="./drag-and-drop-image-vector.html">Drag-and-Drop Image Vector</a>
|
||
|
<a class="list-group-item list-group-item-action" href="./geojson.html">GeoJSON</a>
|
||
|
<a class="list-group-item list-group-item-action" href="./geojson-vt.html">geojson-vt integration</a>
|
||
|
<a class="list-group-item list-group-item-action" href="./style-renderer.html">Style renderer</a>
|
||
|
<a class="list-group-item list-group-item-action active" href="./vector-labels.html">Vector Labels</a>
|
||
|
<a class="list-group-item list-group-item-action" href="./vector-layer.html">Vector Layer</a>
|
||
|
<a class="list-group-item list-group-item-action" href="./hitdetect-vector.html">Vector Layer Hit Detection</a>"
|
||
|
tabindex="0"
|
||
|
>8</a>
|
||
|
</span>
|
||
|
<span class="badge-group">
|
||
|
<a
|
||
|
href="./index.html?q=vector" class="badge badge-info">vector</a
|
||
|
><a
|
||
|
class="badge badge-info tag-modal-toggle text-white"
|
||
|
data-toggle="modal"
|
||
|
data-target="#tag-example-list"
|
||
|
data-title="vector"
|
||
|
data-content="
|
||
|
<a class="list-group-item list-group-item-action" href="./mapbox-vector-tiles-advanced.html">Advanced Mapbox Vector Tiles</a>
|
||
|
<a class="list-group-item list-group-item-action" href="./animated-gif.html">Animated GIF</a>
|
||
|
<a class="list-group-item list-group-item-action" href="./vector-esri.html">ArcGIS REST Feature Service</a>
|
||
|
<a class="list-group-item list-group-item-action" href="./cluster.html">Clustered Features</a>
|
||
|
<a class="list-group-item list-group-item-action" href="./feature-animation.html">Custom Animation</a>
|
||
|
<a class="list-group-item list-group-item-action" href="./custom-circle-render.html">Custom Circle Render</a>
|
||
|
<a class="list-group-item list-group-item-action" href="./custom-interactions.html">Custom Interactions</a>
|
||
|
<a class="list-group-item list-group-item-action" href="./polygon-styles.html">Custom Polygon Styles</a>
|
||
|
<a class="list-group-item list-group-item-action" href="./drag-and-drop-image-vector.html">Drag-and-Drop Image Vector</a>
|
||
|
<a class="list-group-item list-group-item-action" href="./draw-and-modify-features.html">Draw and Modify Features</a>
|
||
|
<a class="list-group-item list-group-item-action" href="./draw-features.html">Draw Features</a>
|
||
|
<a class="list-group-item list-group-item-action" href="./draw-shapes.html">Draw Shapes</a>
|
||
|
<a class="list-group-item list-group-item-action" href="./earthquake-clusters.html">Earthquake Clusters</a>
|
||
|
<a class="list-group-item list-group-item-action" href="./heatmap-earthquakes.html">Earthquakes Heatmap</a>
|
||
|
<a class="list-group-item list-group-item-action" href="./kml-earthquakes.html">Earthquakes in KML</a>
|
||
|
<a class="list-group-item list-group-item-action" href="./earthquake-custom-symbol.html">Earthquakes with custom symbols</a>
|
||
|
<a class="list-group-item list-group-item-action" href="./vector-esri-edit.html">Editable ArcGIS REST Feature Service</a>
|
||
|
<a class="list-group-item list-group-item-action" href="./flight-animation.html">Flight Animation</a>
|
||
|
<a class="list-group-item list-group-item-action" href="./fractal.html">Fractal Rendering</a>
|
||
|
<a class="list-group-item list-group-item-action" href="./draw-freehand.html">Freehand Drawing</a>
|
||
|
<a class="list-group-item list-group-item-action" href="./geojson.html">GeoJSON</a>
|
||
|
<a class="list-group-item list-group-item-action" href="./geojson-vt.html">geojson-vt integration</a>
|
||
|
<a class="list-group-item list-group-item-action" href="./icon-color.html">Icon Colors</a>
|
||
|
<a class="list-group-item list-group-item-action" href="./modify-icon.html">Icon modification</a>
|
||
|
<a class="list-group-item list-group-item-action" href="./icon-negative.html">Icon Pixel Operations</a>
|
||
|
<a class="list-group-item list-group-item-action" href="./icon-scale.html">Icon Scale</a>
|
||
|
<a class="list-group-item list-group-item-action" href="./icon.html">Icon Symbolizer</a>
|
||
|
<a class="list-group-item list-group-item-action" href="./jsts.html">JSTS Integration</a>
|
||
|
<a class="list-group-item list-group-item-action" href="./line-arrows.html">LineString Arrows</a>
|
||
|
<a class="list-group-item list-group-item-action" href="./mapbox-vector-layer.html">Mapbox Vector Layer</a>
|
||
|
<a class="list-group-item list-group-item-action" href="./mapbox-vector-tiles.html">Mapbox Vector Tiles</a>
|
||
|
<a class="list-group-item list-group-item-action" href="./mapbox-layer.html">Mapbox-gl Layer</a>
|
||
|
<a class="list-group-item list-group-item-action" href="./measure.html">Measure</a>
|
||
|
<a class="list-group-item list-group-item-action" href="./modify-features.html">Modify Features</a>
|
||
|
<a class="list-group-item list-group-item-action" href="./modify-test.html">Modify Features Test</a>
|
||
|
<a class="list-group-item list-group-item-action" href="./osm-vector-tiles.html">OSM Vector Tiles</a>
|
||
|
<a class="list-group-item list-group-item-action" href="./vector-osm.html">OSM XML</a>
|
||
|
<a class="list-group-item list-group-item-action" href="./regularshape.html">Regular Shapes</a>
|
||
|
<a class="list-group-item list-group-item-action" href="./select-features.html">Select Features</a>
|
||
|
<a class="list-group-item list-group-item-action" href="./select-hover-features.html">Select Features by Hover</a>
|
||
|
<a class="list-group-item list-group-item-action" href="./select-multiple-features.html">Select multiple Features</a>
|
||
|
<a class="list-group-item list-group-item-action" href="./snap.html">Snap Interaction</a>
|
||
|
<a class="list-group-item list-group-item-action" href="./street-labels.html">Street Labels</a>
|
||
|
<a class="list-group-item list-group-item-action" href="./style-renderer.html">Style renderer</a>
|
||
|
<a class="list-group-item list-group-item-action" href="./synthetic-lines.html">Synthetic Lines</a>
|
||
|
<a class="list-group-item list-group-item-action" href="./synthetic-points.html">Synthetic Points</a>
|
||
|
<a class="list-group-item list-group-item-action" href="./kml-timezones.html">Timezones in KML</a>
|
||
|
<a class="list-group-item list-group-item-action" href="./topojson.html">TopoJSON</a>
|
||
|
<a class="list-group-item list-group-item-action" href="./topolis.html">topolis integration</a>
|
||
|
<a class="list-group-item list-group-item-action" href="./tracing.html">Tracing around a polygon</a>
|
||
|
<a class="list-group-item list-group-item-action" href="./translate-features.html">Translate Features</a>
|
||
|
<a class="list-group-item list-group-item-action" href="./turf.html">turf.js</a>
|
||
|
<a class="list-group-item list-group-item-action" href="./layer-clipping-vector.html">Vector Clipping Layer</a>
|
||
|
<a class="list-group-item list-group-item-action" href="./image-vector-layer.html">Vector Image Layer</a>
|
||
|
<a class="list-group-item list-group-item-action" href="./vector-label-decluttering.html">Vector Label Decluttering</a>
|
||
|
<a class="list-group-item list-group-item-action active" href="./vector-labels.html">Vector Labels</a>
|
||
|
<a class="list-group-item list-group-item-action" href="./vector-layer.html">Vector Layer</a>
|
||
|
<a class="list-group-item list-group-item-action" href="./hitdetect-vector.html">Vector Layer Hit Detection</a>
|
||
|
<a class="list-group-item list-group-item-action" href="./vector-wfs.html">WFS</a>
|
||
|
<a class="list-group-item list-group-item-action" href="./vector-wfs-getfeature.html">WFS - GetFeature</a>"
|
||
|
tabindex="0"
|
||
|
>60</a>
|
||
|
</span>
|
||
|
<span class="badge-group">
|
||
|
<a
|
||
|
href="./index.html?q=openstreetmap" class="badge badge-info">openstreetmap</a
|
||
|
><a
|
||
|
class="badge badge-info tag-modal-toggle text-white"
|
||
|
data-toggle="modal"
|
||
|
data-target="#tag-example-list"
|
||
|
data-title="openstreetmap"
|
||
|
data-content="
|
||
|
<a class="list-group-item list-group-item-action" href="./center.html">Advanced View Positioning</a>
|
||
|
<a class="list-group-item list-group-item-action" href="./attributions.html">Attributions</a>
|
||
|
<a class="list-group-item list-group-item-action" href="./canvas-tiles.html">Canvas Tiles</a>
|
||
|
<a class="list-group-item list-group-item-action" href="./cartodb.html">CartoDB source example</a>
|
||
|
<a class="list-group-item list-group-item-action" href="./export-pdf.html">Export PDF example</a>
|
||
|
<a class="list-group-item list-group-item-action" href="./geojson.html">GeoJSON</a>
|
||
|
<a class="list-group-item list-group-item-action" href="./geolocation.html">Geolocation</a>
|
||
|
<a class="list-group-item list-group-item-action" href="./hit-tolerance-priority.html">Hit tolerance priority</a>
|
||
|
<a class="list-group-item list-group-item-action" href="./layer-clipping.html">Layer Clipping</a>
|
||
|
<a class="list-group-item list-group-item-action" href="./layer-swipe.html">Layer Swipe</a>
|
||
|
<a class="list-group-item list-group-item-action" href="./localized-openstreetmap.html">Localized OpenStreetMap</a>
|
||
|
<a class="list-group-item list-group-item-action" href="./export-map.html">Map Export</a>
|
||
|
<a class="list-group-item list-group-item-action" href="./mouse-position.html">Mouse Position</a>
|
||
|
<a class="list-group-item list-group-item-action" href="./reprojection-wgs84.html">OpenStreetMap Reprojection</a>
|
||
|
<a class="list-group-item list-group-item-action" href="./scaleline-indiana-east.html">OpenStreetMap Reprojection with ScaleLine Control</a>
|
||
|
<a class="list-group-item list-group-item-action" href="./permalink.html">Permalink</a>
|
||
|
<a class="list-group-item list-group-item-action" href="./scale-line.html">Scale Line</a>
|
||
|
<a class="list-group-item list-group-item-action" href="./simple.html">Simple Map</a>
|
||
|
<a class="list-group-item list-group-item-action" href="./teleport.html">Teleporting Maps</a>
|
||
|
<a class="list-group-item list-group-item-action" href="./layer-clipping-vector.html">Vector Clipping Layer</a>
|
||
|
<a class="list-group-item list-group-item-action active" href="./vector-labels.html">Vector Labels</a>
|
||
|
<a class="list-group-item list-group-item-action" href="./rotation.html">View Rotation</a>"
|
||
|
tabindex="0"
|
||
|
>22</a>
|
||
|
</span>
|
||
|
<span class="badge-group">
|
||
|
<a
|
||
|
href="./index.html?q=label" class="badge badge-info">label</a
|
||
|
><a
|
||
|
class="badge badge-info tag-modal-toggle text-white"
|
||
|
data-toggle="modal"
|
||
|
data-target="#tag-example-list"
|
||
|
data-title="label"
|
||
|
data-content="
|
||
|
<a class="list-group-item list-group-item-action" href="./icon-scale.html">Icon Scale</a>
|
||
|
<a class="list-group-item list-group-item-action" href="./street-labels.html">Street Labels</a>
|
||
|
<a class="list-group-item list-group-item-action active" href="./vector-labels.html">Vector Labels</a>"
|
||
|
tabindex="0"
|
||
|
>3</a>
|
||
|
</span>
|
||
|
</p>
|
||
|
<div class="modal modal-tag-example" id="tag-example-list" tabindex="-1" role="dialog" aria-labelledby="tag-example-title" aria-hidden="true">
|
||
|
<div class="modal-dialog modal-dialog-scrollable" role="document">
|
||
|
<div class="modal-content">
|
||
|
<div class="modal-header">
|
||
|
<h5 class="modal-title" id="tag-example-title"></h5>
|
||
|
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
|
||
|
<span aria-hidden="true">×</span>
|
||
|
</button>
|
||
|
</div>
|
||
|
<div class="modal-body">
|
||
|
<div class="list-group"></div>
|
||
|
</div>
|
||
|
</div>
|
||
|
</div>
|
||
|
</div>
|
||
|
<div id="map" class="map"></div>
|
||
|
|
||
|
<div class="edit-form">
|
||
|
<input id="refresh-points" type="button" value="Refresh" />
|
||
|
<h2>Points</h2>
|
||
|
<div class="edit-form-elem">
|
||
|
<label for="points-text">Text: </label>
|
||
|
<select id="points-text">
|
||
|
<option value="hide">Hide</option>
|
||
|
<option value="normal">Normal</option>
|
||
|
<option value="shorten" selected="selected">Shorten</option>
|
||
|
<option value="wrap">Wrap</option>
|
||
|
</select>
|
||
|
<br />
|
||
|
<label for="points-maxreso" title="Max Resolution Denominator">MaxReso.: </label>
|
||
|
<select id="points-maxreso">
|
||
|
<option value="38400">38,400</option>
|
||
|
<option value="19200">19,200</option>
|
||
|
<option value="9600">9,600</option>
|
||
|
<option value="4800">4,800</option>
|
||
|
<option value="2400">2,400</option>
|
||
|
<option value="1200" selected="selected">1,200</option>
|
||
|
<option value="600">600</option>
|
||
|
<option value="300">300</option>
|
||
|
<option value="150">150</option>
|
||
|
<option value="75">75</option>
|
||
|
<option value="32">32</option>
|
||
|
<option value="16">16</option>
|
||
|
<option value="8">8</option>
|
||
|
</select>
|
||
|
<br />
|
||
|
<label for="points-align">Align: </label>
|
||
|
<select id="points-align">
|
||
|
<option value="center" selected="selected">Center</option>
|
||
|
<option value="end">End</option>
|
||
|
<option value="left">Left</option>
|
||
|
<option value="right">Right</option>
|
||
|
<option value="start">Start</option>
|
||
|
</select>
|
||
|
<br />
|
||
|
<label for="points-baseline">Baseline: </label>
|
||
|
<select id="points-baseline">
|
||
|
<option value="alphabetic">Alphabetic</option>
|
||
|
<option value="bottom">Bottom</option>
|
||
|
<option value="hanging">Hanging</option>
|
||
|
<option value="ideographic">Ideographic</option>
|
||
|
<option value="middle" selected="selected">Middle</option>
|
||
|
<option value="top">Top</option>
|
||
|
</select>
|
||
|
<br />
|
||
|
<label for="points-rotation">Rotation: </label>
|
||
|
<select id="points-rotation">
|
||
|
<option value="0">0°</option>
|
||
|
<option value="0.785398164">45°</option>
|
||
|
<option value="1.570796327">90°</option>
|
||
|
</select>
|
||
|
<br />
|
||
|
<label for="points-font">Font: </label>
|
||
|
<select id="points-font">
|
||
|
<option value="Arial" selected="selected">Arial</option>
|
||
|
<option value="'Courier New'">Courier New</option>
|
||
|
<option value="'Open Sans'">Open Sans</option>
|
||
|
<option value="Verdana">Verdana</option>
|
||
|
</select>
|
||
|
<br />
|
||
|
<label for="points-weight">Weight: </label>
|
||
|
<select id="points-weight">
|
||
|
<option value="bold">Bold</option>
|
||
|
<option value="normal" selected="selected">Normal</option>
|
||
|
</select>
|
||
|
<br />
|
||
|
<label for="points-placement">Placement: </label>
|
||
|
<select disabled id="points-placement">
|
||
|
<option value="line">Line</option>
|
||
|
<option value="point" selected="selected">Point</option>
|
||
|
</select>
|
||
|
<br />
|
||
|
<label for="points-maxangle">Max Angle: </label>
|
||
|
<select disabled id="points-maxangle">
|
||
|
<option value="0.7853981633974483" selected="selected">45°</option>
|
||
|
<option value="2.0943951023931953">120°</option>
|
||
|
<option value="6.283185307179586">360°</option>
|
||
|
</select>
|
||
|
<br />
|
||
|
<label for="points-overflow">Exceed Len: </label>
|
||
|
<select disabled id="points-overflow">
|
||
|
<option value="true">True</option>
|
||
|
<option value="false" selected="selected">False</option>
|
||
|
</select>
|
||
|
<br />
|
||
|
<label for="points-size">Size: </label>
|
||
|
<input type="text" value="12px" id="points-size" />
|
||
|
<br />
|
||
|
<label for="points-height">Line height: </label>
|
||
|
<input type="text" value="1" id="points-height" />
|
||
|
<br />
|
||
|
<label for="points-offset-x">Offset X: </label>
|
||
|
<input type="text" value="0" id="points-offset-x" />
|
||
|
<br />
|
||
|
<label for="points-offset-y">Offset Y: </label>
|
||
|
<input type="text" value="0" id="points-offset-y" />
|
||
|
<br />
|
||
|
<label for="points-color">Color: </label>
|
||
|
<input type="text" value="#aa3300" id="points-color" />
|
||
|
<br />
|
||
|
<label for="points-outline" title="Outline Color">O. Color: </label>
|
||
|
<input type="text" value="#ffffff" id="points-outline" />
|
||
|
<br />
|
||
|
<label for="points-outline-width" title="Outline Width">O. Width: </label>
|
||
|
<input type="text" value="3" id="points-outline-width" />
|
||
|
</div>
|
||
|
</div>
|
||
|
|
||
|
<div class="edit-form">
|
||
|
<input id="refresh-lines" type="button" value="Refresh" />
|
||
|
<h2>Lines</h2>
|
||
|
<div class="edit-form-elem">
|
||
|
<label for="lines-text">Text: </label>
|
||
|
<select id="lines-text">
|
||
|
<option value="hide">Hide</option>
|
||
|
<option value="normal">Normal</option>
|
||
|
<option value="shorten">Shorten</option>
|
||
|
<option value="wrap" selected="selected">Wrap</option>
|
||
|
</select>
|
||
|
<br />
|
||
|
<label for="lines-maxreso" title="Max Resolution Denominator">MaxReso.: </label>
|
||
|
<select id="lines-maxreso">
|
||
|
<option value="38400">38,400</option>
|
||
|
<option value="19200">19,200</option>
|
||
|
<option value="9600">9,600</option>
|
||
|
<option value="4800">4,800</option>
|
||
|
<option value="2400">2,400</option>
|
||
|
<option value="1200" selected="selected">1,200</option>
|
||
|
<option value="600">600</option>
|
||
|
<option value="300">300</option>
|
||
|
<option value="150">150</option>
|
||
|
<option value="75">75</option>
|
||
|
<option value="32">32</option>
|
||
|
<option value="16">16</option>
|
||
|
<option value="8">8</option>
|
||
|
</select>
|
||
|
<br />
|
||
|
<label for="lines-align">Align: </label>
|
||
|
<select id="lines-align">
|
||
|
<option value="" selected="selected"></option>
|
||
|
<option value="center">Center</option>
|
||
|
<option value="end">End</option>
|
||
|
<option value="left">Left</option>
|
||
|
<option value="right">Right</option>
|
||
|
<option value="start">Start</option>
|
||
|
</select>
|
||
|
<br />
|
||
|
<label for="lines-baseline">Baseline: </label>
|
||
|
<select id="lines-baseline">
|
||
|
<option value="alphabetic">Alphabetic</option>
|
||
|
<option value="bottom">Bottom</option>
|
||
|
<option value="hanging">Hanging</option>
|
||
|
<option value="ideographic">Ideographic</option>
|
||
|
<option value="middle" selected="selected">Middle</option>
|
||
|
<option value="top">Top</option>
|
||
|
</select>
|
||
|
<br />
|
||
|
<label for="lines-rotation">Rotation: </label>
|
||
|
<select id="lines-rotation">
|
||
|
<option value="0">0°</option>
|
||
|
<option value="0.785398164">45°</option>
|
||
|
<option value="1.570796327">90°</option>
|
||
|
</select>
|
||
|
<br />
|
||
|
<label for="lines-font">Font: </label>
|
||
|
<select id="lines-font">
|
||
|
<option value="Arial">Arial</option>
|
||
|
<option value="'Courier New'" selected="selected">Courier New</option>
|
||
|
<option value="'Open Sans'">Open Sans</option>
|
||
|
<option value="Verdana">Verdana</option>
|
||
|
</select>
|
||
|
<br />
|
||
|
<label for="lines-weight">Weight: </label>
|
||
|
<select id="lines-weight">
|
||
|
<option value="bold" selected="selected">Bold</option>
|
||
|
<option value="normal">Normal</option>
|
||
|
</select>
|
||
|
<br />
|
||
|
<label for="lines-placement">Placement: </label>
|
||
|
<select id="lines-placement">
|
||
|
<option value="line">Line</option>
|
||
|
<option value="point" selected="selected">Point</option>
|
||
|
</select>
|
||
|
<br />
|
||
|
<label for="lines-maxangle">Max Angle: </label>
|
||
|
<select id="lines-maxangle">
|
||
|
<option value="0.7853981633974483" selected="selected">45°</option>
|
||
|
<option value="2.0943951023931953">120°</option>
|
||
|
<option value="6.283185307179586">360°</option>
|
||
|
</select>
|
||
|
<br />
|
||
|
<label for="lines-overflow">Exceed Len: </label>
|
||
|
<select id="lines-overflow">
|
||
|
<option value="true">True</option>
|
||
|
<option value="false" selected="selected">False</option>
|
||
|
</select>
|
||
|
<br />
|
||
|
<label for="lines-size">Size: </label>
|
||
|
<input type="text" value="12px" id="lines-size" />
|
||
|
<br />
|
||
|
<label for="lines-height">Line height: </label>
|
||
|
<input type="text" value="1.2" id="lines-height" />
|
||
|
<br />
|
||
|
<label for="lines-offset-x">Offset X: </label>
|
||
|
<input type="text" value="0" id="lines-offset-x" />
|
||
|
<br />
|
||
|
<label for="lines-offset-y">Offset Y: </label>
|
||
|
<input type="text" value="0" id="lines-offset-y" />
|
||
|
<br />
|
||
|
<label for="lines-color">Color: </label>
|
||
|
<input type="text" value="green" id="lines-color" />
|
||
|
<br />
|
||
|
<label for="lines-outline" title="Outline Color">O. Color: </label>
|
||
|
<input type="text" value="#ffffff" id="lines-outline" />
|
||
|
<br />
|
||
|
<label for="lines-outline-width" title="Outline Width">O. Width: </label>
|
||
|
<input type="text" value="3" id="lines-outline-width" />
|
||
|
</div>
|
||
|
</div>
|
||
|
|
||
|
<div class="edit-form">
|
||
|
<input id="refresh-polygons" type="button" value="Refresh" />
|
||
|
<h2>Polygons</h2>
|
||
|
<div class="edit-form-elem">
|
||
|
<label for="polygons-text">Text: </label>
|
||
|
<select id="polygons-text">
|
||
|
<option value="hide">Hide</option>
|
||
|
<option value="normal" selected="selected">Normal</option>
|
||
|
<option value="shorten">Shorten</option>
|
||
|
<option value="wrap">Wrap</option>
|
||
|
</select>
|
||
|
<br />
|
||
|
<label for="polygons-maxreso" title="Max Resolution Denominator">MaxReso.: </label>
|
||
|
<select id="polygons-maxreso">
|
||
|
<option value="38400">38,400</option>
|
||
|
<option value="19200">19,200</option>
|
||
|
<option value="9600">9,600</option>
|
||
|
<option value="4800">4,800</option>
|
||
|
<option value="2400">2,400</option>
|
||
|
<option value="1200" selected="selected">1,200</option>
|
||
|
<option value="600">600</option>
|
||
|
<option value="300">300</option>
|
||
|
<option value="150">150</option>
|
||
|
<option value="75">75</option>
|
||
|
<option value="32">32</option>
|
||
|
<option value="16">16</option>
|
||
|
<option value="8">8</option>
|
||
|
</select>
|
||
|
<br />
|
||
|
<label for="polygons-align">Align: </label>
|
||
|
<select id="polygons-align">
|
||
|
<option value="" selected="selected"></option>
|
||
|
<option value="center">Center</option>
|
||
|
<option value="end">End</option>
|
||
|
<option value="left">Left</option>
|
||
|
<option value="right">Right</option>
|
||
|
<option value="start">Start</option>
|
||
|
</select>
|
||
|
<br />
|
||
|
<label for="polygons-baseline">Baseline: </label>
|
||
|
<select id="polygons-baseline">
|
||
|
<option value="alphabetic">Alphabetic</option>
|
||
|
<option value="bottom">Bottom</option>
|
||
|
<option value="hanging">Hanging</option>
|
||
|
<option value="ideographic">Ideographic</option>
|
||
|
<option value="middle" selected="selected">Middle</option>
|
||
|
<option value="top">Top</option>
|
||
|
</select>
|
||
|
<br />
|
||
|
<label for="polygons-rotation">Rotation: </label>
|
||
|
<select id="polygons-rotation">
|
||
|
<option value="0">0°</option>
|
||
|
<option value="0.785398164">45°</option>
|
||
|
<option value="1.570796327">90°</option>
|
||
|
</select>
|
||
|
<br />
|
||
|
<label for="polygons-font">Font: </label>
|
||
|
<select id="polygons-font">
|
||
|
<option value="Arial">Arial</option>
|
||
|
<option value="'Courier New'">Courier New</option>
|
||
|
<option value="'Open Sans'">Open Sans</option>
|
||
|
<option value="Verdana" selected="selected">Verdana</option>
|
||
|
</select>
|
||
|
<br />
|
||
|
<label for="polygons-weight">Weight: </label>
|
||
|
<select id="polygons-weight">
|
||
|
<option value="bold" selected="selected">Bold</option>
|
||
|
<option value="normal">Normal</option>
|
||
|
</select>
|
||
|
<br />
|
||
|
<label for="polygons-placement">Placement: </label>
|
||
|
<select id="polygons-placement">
|
||
|
<option value="line">Line</option>
|
||
|
<option value="point" selected="selected">Point</option>
|
||
|
</select>
|
||
|
<br />
|
||
|
<label for="polygons-maxangle">Max Angle: </label>
|
||
|
<select id="polygons-maxangle">
|
||
|
<option value="0.7853981633974483" selected="selected">45°</option>
|
||
|
<option value="2.0943951023931953">120°</option>
|
||
|
<option value="6.283185307179586">360°</option>
|
||
|
</select>
|
||
|
<br />
|
||
|
<label for="polygons-overflow">Exceed Len: </label>
|
||
|
<select id="polygons-overflow">
|
||
|
<option value="true">True</option>
|
||
|
<option value="false" selected="selected">False</option>
|
||
|
</select>
|
||
|
<br />
|
||
|
<label for="polygons-size">Size: </label>
|
||
|
<input type="text" value="10px" id="polygons-size" />
|
||
|
<br />
|
||
|
<label for="polygons-height">Line height: </label>
|
||
|
<input type="text" value="1" id="polygons-height" />
|
||
|
<br />
|
||
|
<label for="polygons-offset-x">Offset X: </label>
|
||
|
<input type="text" value="0" id="polygons-offset-x" />
|
||
|
<br />
|
||
|
<label for="polygons-offset-y">Offset Y: </label>
|
||
|
<input type="text" value="0" id="polygons-offset-y" />
|
||
|
<br />
|
||
|
<label for="polygons-color">Color: </label>
|
||
|
<input type="text" value="blue" id="polygons-color" />
|
||
|
<br />
|
||
|
<label for="polygons-outline" title="Outline Color">O. Color: </label>
|
||
|
<input type="text" value="#ffffff" id="polygons-outline" />
|
||
|
<br />
|
||
|
<label for="polygons-outline-width" title="Outline Width">O. Width: </label>
|
||
|
<input type="text" value="3" id="polygons-outline-width" />
|
||
|
</div>
|
||
|
</div>
|
||
|
|
||
|
</div>
|
||
|
<form method="POST" id="codepen-form" target="_blank" action="https://codesandbox.io/api/v1/sandboxes/define">
|
||
|
<input id="codesandbox-params" type="hidden" name="parameters">
|
||
|
</form>
|
||
|
</div>
|
||
|
|
||
|
<div class="row-fluid">
|
||
|
<div class="span12">
|
||
|
<p id="shortdesc">Example of GeoJSON features with labels.</p>
|
||
|
<div id="docs"><p>This example showcases a number of options that can be set on text styles. When "Text/Wrap" is chosen (for example for the line features), the label is wrapped by inserting the character <code>\n</code>, which will create a multi-line label. The "Open Sans" web font will be loaded on demand, to show dynamic font loading.</p>
|
||
|
</div>
|
||
|
</div>
|
||
|
</div>
|
||
|
|
||
|
<div class="row-fluid">
|
||
|
<h5 class="source-heading">main.js</h5>
|
||
|
<pre><code id="example-js-source" class="language-js">import 'ol/ol.css';
|
||
|
import GeoJSON from 'ol/format/GeoJSON';
|
||
|
import Map from 'ol/Map';
|
||
|
import View from 'ol/View';
|
||
|
import {
|
||
|
Circle as CircleStyle,
|
||
|
Fill,
|
||
|
Stroke,
|
||
|
Style,
|
||
|
Text,
|
||
|
} from 'ol/style';
|
||
|
import {OSM, Vector as VectorSource} from 'ol/source';
|
||
|
import {Tile as TileLayer, Vector as VectorLayer} from 'ol/layer';
|
||
|
|
||
|
var openSansAdded = false;
|
||
|
|
||
|
var myDom = {
|
||
|
points: {
|
||
|
text: document.getElementById('points-text'),
|
||
|
align: document.getElementById('points-align'),
|
||
|
baseline: document.getElementById('points-baseline'),
|
||
|
rotation: document.getElementById('points-rotation'),
|
||
|
font: document.getElementById('points-font'),
|
||
|
weight: document.getElementById('points-weight'),
|
||
|
size: document.getElementById('points-size'),
|
||
|
height: document.getElementById('points-height'),
|
||
|
offsetX: document.getElementById('points-offset-x'),
|
||
|
offsetY: document.getElementById('points-offset-y'),
|
||
|
color: document.getElementById('points-color'),
|
||
|
outline: document.getElementById('points-outline'),
|
||
|
outlineWidth: document.getElementById('points-outline-width'),
|
||
|
maxreso: document.getElementById('points-maxreso'),
|
||
|
},
|
||
|
lines: {
|
||
|
text: document.getElementById('lines-text'),
|
||
|
align: document.getElementById('lines-align'),
|
||
|
baseline: document.getElementById('lines-baseline'),
|
||
|
rotation: document.getElementById('lines-rotation'),
|
||
|
font: document.getElementById('lines-font'),
|
||
|
weight: document.getElementById('lines-weight'),
|
||
|
placement: document.getElementById('lines-placement'),
|
||
|
maxangle: document.getElementById('lines-maxangle'),
|
||
|
overflow: document.getElementById('lines-overflow'),
|
||
|
size: document.getElementById('lines-size'),
|
||
|
height: document.getElementById('lines-height'),
|
||
|
offsetX: document.getElementById('lines-offset-x'),
|
||
|
offsetY: document.getElementById('lines-offset-y'),
|
||
|
color: document.getElementById('lines-color'),
|
||
|
outline: document.getElementById('lines-outline'),
|
||
|
outlineWidth: document.getElementById('lines-outline-width'),
|
||
|
maxreso: document.getElementById('lines-maxreso'),
|
||
|
},
|
||
|
polygons: {
|
||
|
text: document.getElementById('polygons-text'),
|
||
|
align: document.getElementById('polygons-align'),
|
||
|
baseline: document.getElementById('polygons-baseline'),
|
||
|
rotation: document.getElementById('polygons-rotation'),
|
||
|
font: document.getElementById('polygons-font'),
|
||
|
weight: document.getElementById('polygons-weight'),
|
||
|
placement: document.getElementById('polygons-placement'),
|
||
|
maxangle: document.getElementById('polygons-maxangle'),
|
||
|
overflow: document.getElementById('polygons-overflow'),
|
||
|
size: document.getElementById('polygons-size'),
|
||
|
height: document.getElementById('polygons-height'),
|
||
|
offsetX: document.getElementById('polygons-offset-x'),
|
||
|
offsetY: document.getElementById('polygons-offset-y'),
|
||
|
color: document.getElementById('polygons-color'),
|
||
|
outline: document.getElementById('polygons-outline'),
|
||
|
outlineWidth: document.getElementById('polygons-outline-width'),
|
||
|
maxreso: document.getElementById('polygons-maxreso'),
|
||
|
},
|
||
|
};
|
||
|
|
||
|
var getText = function (feature, resolution, dom) {
|
||
|
var type = dom.text.value;
|
||
|
var maxResolution = dom.maxreso.value;
|
||
|
var text = feature.get('name');
|
||
|
|
||
|
if (resolution > maxResolution) {
|
||
|
text = '';
|
||
|
} else if (type == 'hide') {
|
||
|
text = '';
|
||
|
} else if (type == 'shorten') {
|
||
|
text = text.trunc(12);
|
||
|
} else if (
|
||
|
type == 'wrap' &&
|
||
|
(!dom.placement || dom.placement.value != 'line')
|
||
|
) {
|
||
|
text = stringDivider(text, 16, '\n');
|
||
|
}
|
||
|
|
||
|
return text;
|
||
|
};
|
||
|
|
||
|
var createTextStyle = function (feature, resolution, dom) {
|
||
|
var align = dom.align.value;
|
||
|
var baseline = dom.baseline.value;
|
||
|
var size = dom.size.value;
|
||
|
var height = dom.height.value;
|
||
|
var offsetX = parseInt(dom.offsetX.value, 10);
|
||
|
var offsetY = parseInt(dom.offsetY.value, 10);
|
||
|
var weight = dom.weight.value;
|
||
|
var placement = dom.placement ? dom.placement.value : undefined;
|
||
|
var maxAngle = dom.maxangle ? parseFloat(dom.maxangle.value) : undefined;
|
||
|
var overflow = dom.overflow ? dom.overflow.value == 'true' : undefined;
|
||
|
var rotation = parseFloat(dom.rotation.value);
|
||
|
if (dom.font.value == "'Open Sans'" && !openSansAdded) {
|
||
|
var openSans = document.createElement('link');
|
||
|
openSans.href = 'https://fonts.googleapis.com/css?family=Open+Sans';
|
||
|
openSans.rel = 'stylesheet';
|
||
|
document.getElementsByTagName('head')[0].appendChild(openSans);
|
||
|
openSansAdded = true;
|
||
|
}
|
||
|
var font = weight + ' ' + size + '/' + height + ' ' + dom.font.value;
|
||
|
var fillColor = dom.color.value;
|
||
|
var outlineColor = dom.outline.value;
|
||
|
var outlineWidth = parseInt(dom.outlineWidth.value, 10);
|
||
|
|
||
|
return new Text({
|
||
|
textAlign: align == '' ? undefined : align,
|
||
|
textBaseline: baseline,
|
||
|
font: font,
|
||
|
text: getText(feature, resolution, dom),
|
||
|
fill: new Fill({color: fillColor}),
|
||
|
stroke: new Stroke({color: outlineColor, width: outlineWidth}),
|
||
|
offsetX: offsetX,
|
||
|
offsetY: offsetY,
|
||
|
placement: placement,
|
||
|
maxAngle: maxAngle,
|
||
|
overflow: overflow,
|
||
|
rotation: rotation,
|
||
|
});
|
||
|
};
|
||
|
|
||
|
// Polygons
|
||
|
function polygonStyleFunction(feature, resolution) {
|
||
|
return new Style({
|
||
|
stroke: new Stroke({
|
||
|
color: 'blue',
|
||
|
width: 1,
|
||
|
}),
|
||
|
fill: new Fill({
|
||
|
color: 'rgba(0, 0, 255, 0.1)',
|
||
|
}),
|
||
|
text: createTextStyle(feature, resolution, myDom.polygons),
|
||
|
});
|
||
|
}
|
||
|
|
||
|
var vectorPolygons = new VectorLayer({
|
||
|
source: new VectorSource({
|
||
|
url: 'data/geojson/polygon-samples.geojson',
|
||
|
format: new GeoJSON(),
|
||
|
}),
|
||
|
style: polygonStyleFunction,
|
||
|
});
|
||
|
|
||
|
// Lines
|
||
|
function lineStyleFunction(feature, resolution) {
|
||
|
return new Style({
|
||
|
stroke: new Stroke({
|
||
|
color: 'green',
|
||
|
width: 2,
|
||
|
}),
|
||
|
text: createTextStyle(feature, resolution, myDom.lines),
|
||
|
});
|
||
|
}
|
||
|
|
||
|
var vectorLines = new VectorLayer({
|
||
|
source: new VectorSource({
|
||
|
url: 'data/geojson/line-samples.geojson',
|
||
|
format: new GeoJSON(),
|
||
|
}),
|
||
|
style: lineStyleFunction,
|
||
|
});
|
||
|
|
||
|
// Points
|
||
|
function pointStyleFunction(feature, resolution) {
|
||
|
return new Style({
|
||
|
image: new CircleStyle({
|
||
|
radius: 10,
|
||
|
fill: new Fill({color: 'rgba(255, 0, 0, 0.1)'}),
|
||
|
stroke: new Stroke({color: 'red', width: 1}),
|
||
|
}),
|
||
|
text: createTextStyle(feature, resolution, myDom.points),
|
||
|
});
|
||
|
}
|
||
|
|
||
|
var vectorPoints = new VectorLayer({
|
||
|
source: new VectorSource({
|
||
|
url: 'data/geojson/point-samples.geojson',
|
||
|
format: new GeoJSON(),
|
||
|
}),
|
||
|
style: pointStyleFunction,
|
||
|
});
|
||
|
|
||
|
var map = new Map({
|
||
|
layers: [
|
||
|
new TileLayer({
|
||
|
source: new OSM(),
|
||
|
}),
|
||
|
vectorPolygons,
|
||
|
vectorLines,
|
||
|
vectorPoints ],
|
||
|
target: 'map',
|
||
|
view: new View({
|
||
|
center: [-8161939, 6095025],
|
||
|
zoom: 8,
|
||
|
}),
|
||
|
});
|
||
|
|
||
|
document
|
||
|
.getElementById('refresh-points')
|
||
|
.addEventListener('click', function () {
|
||
|
vectorPoints.setStyle(pointStyleFunction);
|
||
|
});
|
||
|
|
||
|
document.getElementById('refresh-lines').addEventListener('click', function () {
|
||
|
vectorLines.setStyle(lineStyleFunction);
|
||
|
});
|
||
|
|
||
|
document
|
||
|
.getElementById('refresh-polygons')
|
||
|
.addEventListener('click', function () {
|
||
|
vectorPolygons.setStyle(polygonStyleFunction);
|
||
|
});
|
||
|
|
||
|
/**
|
||
|
* @param {number} n The max number of characters to keep.
|
||
|
* @return {string} Truncated string.
|
||
|
*/
|
||
|
String.prototype.trunc =
|
||
|
String.prototype.trunc ||
|
||
|
function (n) {
|
||
|
return this.length > n ? this.substr(0, n - 1) + '...' : this.substr(0);
|
||
|
};
|
||
|
|
||
|
// http://stackoverflow.com/questions/14484787/wrap-text-in-javascript
|
||
|
function stringDivider(str, width, spaceReplacer) {
|
||
|
if (str.length > width) {
|
||
|
var p = width;
|
||
|
while (p > 0 && str[p] != ' ' && str[p] != '-') {
|
||
|
p--;
|
||
|
}
|
||
|
if (p > 0) {
|
||
|
var left;
|
||
|
if (str.substring(p, p + 1) == '-') {
|
||
|
left = str.substring(0, p + 1);
|
||
|
} else {
|
||
|
left = str.substring(0, p);
|
||
|
}
|
||
|
var right = str.substring(p + 1);
|
||
|
return left + spaceReplacer + stringDivider(right, width, spaceReplacer);
|
||
|
}
|
||
|
}
|
||
|
return str;
|
||
|
}
|
||
|
</code></pre>
|
||
|
</div>
|
||
|
|
||
|
<div class="row-fluid">
|
||
|
<h5 class="source-heading">index.html</h5>
|
||
|
<pre><code id="example-html-source" class="language-markup"><!DOCTYPE html>
|
||
|
<html lang="en">
|
||
|
<head>
|
||
|
<meta charset="UTF-8">
|
||
|
<title>Vector Labels</title>
|
||
|
<!-- Pointer events polyfill for old browsers, see https://caniuse.com/#feat=pointer -->
|
||
|
<script src="https://unpkg.com/elm-pep"></script>
|
||
|
<style>
|
||
|
.map {
|
||
|
width: 100%;
|
||
|
height:400px;
|
||
|
}
|
||
|
.edit-form {
|
||
|
display: inline-block;
|
||
|
margin: 5px;
|
||
|
padding: 10px;
|
||
|
border: 1px solid black;
|
||
|
white-space: nowrap;
|
||
|
}
|
||
|
|
||
|
.edit-form h2 {
|
||
|
font-size: 1.5em;
|
||
|
}
|
||
|
|
||
|
.edit-form input[type="button"] {
|
||
|
float: right;
|
||
|
}
|
||
|
|
||
|
.edit-form-elem label {
|
||
|
display: inline-block;
|
||
|
width: 85px;
|
||
|
}
|
||
|
|
||
|
.edit-form-elem input[type="text"],
|
||
|
.edit-form-elem select {
|
||
|
width: 130px;
|
||
|
}
|
||
|
</style>
|
||
|
</head>
|
||
|
<body>
|
||
|
<div id="map" class="map"></div>
|
||
|
|
||
|
<div class="edit-form">
|
||
|
<input id="refresh-points" type="button" value="Refresh" />
|
||
|
<h2>Points</h2>
|
||
|
<div class="edit-form-elem">
|
||
|
<label for="points-text">Text: </label>
|
||
|
<select id="points-text">
|
||
|
<option value="hide">Hide</option>
|
||
|
<option value="normal">Normal</option>
|
||
|
<option value="shorten" selected="selected">Shorten</option>
|
||
|
<option value="wrap">Wrap</option>
|
||
|
</select>
|
||
|
<br />
|
||
|
<label for="points-maxreso" title="Max Resolution Denominator">MaxReso.: </label>
|
||
|
<select id="points-maxreso">
|
||
|
<option value="38400">38,400</option>
|
||
|
<option value="19200">19,200</option>
|
||
|
<option value="9600">9,600</option>
|
||
|
<option value="4800">4,800</option>
|
||
|
<option value="2400">2,400</option>
|
||
|
<option value="1200" selected="selected">1,200</option>
|
||
|
<option value="600">600</option>
|
||
|
<option value="300">300</option>
|
||
|
<option value="150">150</option>
|
||
|
<option value="75">75</option>
|
||
|
<option value="32">32</option>
|
||
|
<option value="16">16</option>
|
||
|
<option value="8">8</option>
|
||
|
</select>
|
||
|
<br />
|
||
|
<label for="points-align">Align: </label>
|
||
|
<select id="points-align">
|
||
|
<option value="center" selected="selected">Center</option>
|
||
|
<option value="end">End</option>
|
||
|
<option value="left">Left</option>
|
||
|
<option value="right">Right</option>
|
||
|
<option value="start">Start</option>
|
||
|
</select>
|
||
|
<br />
|
||
|
<label for="points-baseline">Baseline: </label>
|
||
|
<select id="points-baseline">
|
||
|
<option value="alphabetic">Alphabetic</option>
|
||
|
<option value="bottom">Bottom</option>
|
||
|
<option value="hanging">Hanging</option>
|
||
|
<option value="ideographic">Ideographic</option>
|
||
|
<option value="middle" selected="selected">Middle</option>
|
||
|
<option value="top">Top</option>
|
||
|
</select>
|
||
|
<br />
|
||
|
<label for="points-rotation">Rotation: </label>
|
||
|
<select id="points-rotation">
|
||
|
<option value="0">0°</option>
|
||
|
<option value="0.785398164">45°</option>
|
||
|
<option value="1.570796327">90°</option>
|
||
|
</select>
|
||
|
<br />
|
||
|
<label for="points-font">Font: </label>
|
||
|
<select id="points-font">
|
||
|
<option value="Arial" selected="selected">Arial</option>
|
||
|
<option value="'Courier New'">Courier New</option>
|
||
|
<option value="'Open Sans'">Open Sans</option>
|
||
|
<option value="Verdana">Verdana</option>
|
||
|
</select>
|
||
|
<br />
|
||
|
<label for="points-weight">Weight: </label>
|
||
|
<select id="points-weight">
|
||
|
<option value="bold">Bold</option>
|
||
|
<option value="normal" selected="selected">Normal</option>
|
||
|
</select>
|
||
|
<br />
|
||
|
<label for="points-placement">Placement: </label>
|
||
|
<select disabled id="points-placement">
|
||
|
<option value="line">Line</option>
|
||
|
<option value="point" selected="selected">Point</option>
|
||
|
</select>
|
||
|
<br />
|
||
|
<label for="points-maxangle">Max Angle: </label>
|
||
|
<select disabled id="points-maxangle">
|
||
|
<option value="0.7853981633974483" selected="selected">45°</option>
|
||
|
<option value="2.0943951023931953">120°</option>
|
||
|
<option value="6.283185307179586">360°</option>
|
||
|
</select>
|
||
|
<br />
|
||
|
<label for="points-overflow">Exceed Len: </label>
|
||
|
<select disabled id="points-overflow">
|
||
|
<option value="true">True</option>
|
||
|
<option value="false" selected="selected">False</option>
|
||
|
</select>
|
||
|
<br />
|
||
|
<label for="points-size">Size: </label>
|
||
|
<input type="text" value="12px" id="points-size" />
|
||
|
<br />
|
||
|
<label for="points-height">Line height: </label>
|
||
|
<input type="text" value="1" id="points-height" />
|
||
|
<br />
|
||
|
<label for="points-offset-x">Offset X: </label>
|
||
|
<input type="text" value="0" id="points-offset-x" />
|
||
|
<br />
|
||
|
<label for="points-offset-y">Offset Y: </label>
|
||
|
<input type="text" value="0" id="points-offset-y" />
|
||
|
<br />
|
||
|
<label for="points-color">Color: </label>
|
||
|
<input type="text" value="#aa3300" id="points-color" />
|
||
|
<br />
|
||
|
<label for="points-outline" title="Outline Color">O. Color: </label>
|
||
|
<input type="text" value="#ffffff" id="points-outline" />
|
||
|
<br />
|
||
|
<label for="points-outline-width" title="Outline Width">O. Width: </label>
|
||
|
<input type="text" value="3" id="points-outline-width" />
|
||
|
</div>
|
||
|
</div>
|
||
|
|
||
|
<div class="edit-form">
|
||
|
<input id="refresh-lines" type="button" value="Refresh" />
|
||
|
<h2>Lines</h2>
|
||
|
<div class="edit-form-elem">
|
||
|
<label for="lines-text">Text: </label>
|
||
|
<select id="lines-text">
|
||
|
<option value="hide">Hide</option>
|
||
|
<option value="normal">Normal</option>
|
||
|
<option value="shorten">Shorten</option>
|
||
|
<option value="wrap" selected="selected">Wrap</option>
|
||
|
</select>
|
||
|
<br />
|
||
|
<label for="lines-maxreso" title="Max Resolution Denominator">MaxReso.: </label>
|
||
|
<select id="lines-maxreso">
|
||
|
<option value="38400">38,400</option>
|
||
|
<option value="19200">19,200</option>
|
||
|
<option value="9600">9,600</option>
|
||
|
<option value="4800">4,800</option>
|
||
|
<option value="2400">2,400</option>
|
||
|
<option value="1200" selected="selected">1,200</option>
|
||
|
<option value="600">600</option>
|
||
|
<option value="300">300</option>
|
||
|
<option value="150">150</option>
|
||
|
<option value="75">75</option>
|
||
|
<option value="32">32</option>
|
||
|
<option value="16">16</option>
|
||
|
<option value="8">8</option>
|
||
|
</select>
|
||
|
<br />
|
||
|
<label for="lines-align">Align: </label>
|
||
|
<select id="lines-align">
|
||
|
<option value="" selected="selected"></option>
|
||
|
<option value="center">Center</option>
|
||
|
<option value="end">End</option>
|
||
|
<option value="left">Left</option>
|
||
|
<option value="right">Right</option>
|
||
|
<option value="start">Start</option>
|
||
|
</select>
|
||
|
<br />
|
||
|
<label for="lines-baseline">Baseline: </label>
|
||
|
<select id="lines-baseline">
|
||
|
<option value="alphabetic">Alphabetic</option>
|
||
|
<option value="bottom">Bottom</option>
|
||
|
<option value="hanging">Hanging</option>
|
||
|
<option value="ideographic">Ideographic</option>
|
||
|
<option value="middle" selected="selected">Middle</option>
|
||
|
<option value="top">Top</option>
|
||
|
</select>
|
||
|
<br />
|
||
|
<label for="lines-rotation">Rotation: </label>
|
||
|
<select id="lines-rotation">
|
||
|
<option value="0">0°</option>
|
||
|
<option value="0.785398164">45°</option>
|
||
|
<option value="1.570796327">90°</option>
|
||
|
</select>
|
||
|
<br />
|
||
|
<label for="lines-font">Font: </label>
|
||
|
<select id="lines-font">
|
||
|
<option value="Arial">Arial</option>
|
||
|
<option value="'Courier New'" selected="selected">Courier New</option>
|
||
|
<option value="'Open Sans'">Open Sans</option>
|
||
|
<option value="Verdana">Verdana</option>
|
||
|
</select>
|
||
|
<br />
|
||
|
<label for="lines-weight">Weight: </label>
|
||
|
<select id="lines-weight">
|
||
|
<option value="bold" selected="selected">Bold</option>
|
||
|
<option value="normal">Normal</option>
|
||
|
</select>
|
||
|
<br />
|
||
|
<label for="lines-placement">Placement: </label>
|
||
|
<select id="lines-placement">
|
||
|
<option value="line">Line</option>
|
||
|
<option value="point" selected="selected">Point</option>
|
||
|
</select>
|
||
|
<br />
|
||
|
<label for="lines-maxangle">Max Angle: </label>
|
||
|
<select id="lines-maxangle">
|
||
|
<option value="0.7853981633974483" selected="selected">45°</option>
|
||
|
<option value="2.0943951023931953">120°</option>
|
||
|
<option value="6.283185307179586">360°</option>
|
||
|
</select>
|
||
|
<br />
|
||
|
<label for="lines-overflow">Exceed Len: </label>
|
||
|
<select id="lines-overflow">
|
||
|
<option value="true">True</option>
|
||
|
<option value="false" selected="selected">False</option>
|
||
|
</select>
|
||
|
<br />
|
||
|
<label for="lines-size">Size: </label>
|
||
|
<input type="text" value="12px" id="lines-size" />
|
||
|
<br />
|
||
|
<label for="lines-height">Line height: </label>
|
||
|
<input type="text" value="1.2" id="lines-height" />
|
||
|
<br />
|
||
|
<label for="lines-offset-x">Offset X: </label>
|
||
|
<input type="text" value="0" id="lines-offset-x" />
|
||
|
<br />
|
||
|
<label for="lines-offset-y">Offset Y: </label>
|
||
|
<input type="text" value="0" id="lines-offset-y" />
|
||
|
<br />
|
||
|
<label for="lines-color">Color: </label>
|
||
|
<input type="text" value="green" id="lines-color" />
|
||
|
<br />
|
||
|
<label for="lines-outline" title="Outline Color">O. Color: </label>
|
||
|
<input type="text" value="#ffffff" id="lines-outline" />
|
||
|
<br />
|
||
|
<label for="lines-outline-width" title="Outline Width">O. Width: </label>
|
||
|
<input type="text" value="3" id="lines-outline-width" />
|
||
|
</div>
|
||
|
</div>
|
||
|
|
||
|
<div class="edit-form">
|
||
|
<input id="refresh-polygons" type="button" value="Refresh" />
|
||
|
<h2>Polygons</h2>
|
||
|
<div class="edit-form-elem">
|
||
|
<label for="polygons-text">Text: </label>
|
||
|
<select id="polygons-text">
|
||
|
<option value="hide">Hide</option>
|
||
|
<option value="normal" selected="selected">Normal</option>
|
||
|
<option value="shorten">Shorten</option>
|
||
|
<option value="wrap">Wrap</option>
|
||
|
</select>
|
||
|
<br />
|
||
|
<label for="polygons-maxreso" title="Max Resolution Denominator">MaxReso.: </label>
|
||
|
<select id="polygons-maxreso">
|
||
|
<option value="38400">38,400</option>
|
||
|
<option value="19200">19,200</option>
|
||
|
<option value="9600">9,600</option>
|
||
|
<option value="4800">4,800</option>
|
||
|
<option value="2400">2,400</option>
|
||
|
<option value="1200" selected="selected">1,200</option>
|
||
|
<option value="600">600</option>
|
||
|
<option value="300">300</option>
|
||
|
<option value="150">150</option>
|
||
|
<option value="75">75</option>
|
||
|
<option value="32">32</option>
|
||
|
<option value="16">16</option>
|
||
|
<option value="8">8</option>
|
||
|
</select>
|
||
|
<br />
|
||
|
<label for="polygons-align">Align: </label>
|
||
|
<select id="polygons-align">
|
||
|
<option value="" selected="selected"></option>
|
||
|
<option value="center">Center</option>
|
||
|
<option value="end">End</option>
|
||
|
<option value="left">Left</option>
|
||
|
<option value="right">Right</option>
|
||
|
<option value="start">Start</option>
|
||
|
</select>
|
||
|
<br />
|
||
|
<label for="polygons-baseline">Baseline: </label>
|
||
|
<select id="polygons-baseline">
|
||
|
<option value="alphabetic">Alphabetic</option>
|
||
|
<option value="bottom">Bottom</option>
|
||
|
<option value="hanging">Hanging</option>
|
||
|
<option value="ideographic">Ideographic</option>
|
||
|
<option value="middle" selected="selected">Middle</option>
|
||
|
<option value="top">Top</option>
|
||
|
</select>
|
||
|
<br />
|
||
|
<label for="polygons-rotation">Rotation: </label>
|
||
|
<select id="polygons-rotation">
|
||
|
<option value="0">0°</option>
|
||
|
<option value="0.785398164">45°</option>
|
||
|
<option value="1.570796327">90°</option>
|
||
|
</select>
|
||
|
<br />
|
||
|
<label for="polygons-font">Font: </label>
|
||
|
<select id="polygons-font">
|
||
|
<option value="Arial">Arial</option>
|
||
|
<option value="'Courier New'">Courier New</option>
|
||
|
<option value="'Open Sans'">Open Sans</option>
|
||
|
<option value="Verdana" selected="selected">Verdana</option>
|
||
|
</select>
|
||
|
<br />
|
||
|
<label for="polygons-weight">Weight: </label>
|
||
|
<select id="polygons-weight">
|
||
|
<option value="bold" selected="selected">Bold</option>
|
||
|
<option value="normal">Normal</option>
|
||
|
</select>
|
||
|
<br />
|
||
|
<label for="polygons-placement">Placement: </label>
|
||
|
<select id="polygons-placement">
|
||
|
<option value="line">Line</option>
|
||
|
<option value="point" selected="selected">Point</option>
|
||
|
</select>
|
||
|
<br />
|
||
|
<label for="polygons-maxangle">Max Angle: </label>
|
||
|
<select id="polygons-maxangle">
|
||
|
<option value="0.7853981633974483" selected="selected">45°</option>
|
||
|
<option value="2.0943951023931953">120°</option>
|
||
|
<option value="6.283185307179586">360°</option>
|
||
|
</select>
|
||
|
<br />
|
||
|
<label for="polygons-overflow">Exceed Len: </label>
|
||
|
<select id="polygons-overflow">
|
||
|
<option value="true">True</option>
|
||
|
<option value="false" selected="selected">False</option>
|
||
|
</select>
|
||
|
<br />
|
||
|
<label for="polygons-size">Size: </label>
|
||
|
<input type="text" value="10px" id="polygons-size" />
|
||
|
<br />
|
||
|
<label for="polygons-height">Line height: </label>
|
||
|
<input type="text" value="1" id="polygons-height" />
|
||
|
<br />
|
||
|
<label for="polygons-offset-x">Offset X: </label>
|
||
|
<input type="text" value="0" id="polygons-offset-x" />
|
||
|
<br />
|
||
|
<label for="polygons-offset-y">Offset Y: </label>
|
||
|
<input type="text" value="0" id="polygons-offset-y" />
|
||
|
<br />
|
||
|
<label for="polygons-color">Color: </label>
|
||
|
<input type="text" value="blue" id="polygons-color" />
|
||
|
<br />
|
||
|
<label for="polygons-outline" title="Outline Color">O. Color: </label>
|
||
|
<input type="text" value="#ffffff" id="polygons-outline" />
|
||
|
<br />
|
||
|
<label for="polygons-outline-width" title="Outline Width">O. Width: </label>
|
||
|
<input type="text" value="3" id="polygons-outline-width" />
|
||
|
</div>
|
||
|
</div>
|
||
|
<script src="main.js"></script>
|
||
|
</body>
|
||
|
</html></code></pre>
|
||
|
</div>
|
||
|
|
||
|
|
||
|
<div class="row-fluid">
|
||
|
<h5 class="source-heading">package.json</h5>
|
||
|
<pre><code id="example-pkg-source" class="language-json">{
|
||
|
"name": "vector-labels",
|
||
|
"dependencies": {
|
||
|
"ol": "6.5.0"
|
||
|
},
|
||
|
"devDependencies": {
|
||
|
"parcel": "^2.0.0-beta.1"
|
||
|
},
|
||
|
"scripts": {
|
||
|
"start": "parcel index.html",
|
||
|
"build": "parcel build --public-url . index.html"
|
||
|
}
|
||
|
}</code></pre>
|
||
|
</div>
|
||
|
</div>
|
||
|
|
||
|
<script src="https://code.jquery.com/jquery-3.5.1.min.js"></script>
|
||
|
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.0/js/bootstrap.bundle.min.js"></script>
|
||
|
<script src="./resources/prism/prism-1.20.0.min.js"></script>
|
||
|
<script src="./resources/common.js"></script>
|
||
|
<script src="common.js"></script>
|
||
|
<script src="vector-labels.js"></script>
|
||
|
<script>
|
||
|
$('#tag-example-list').on('show.bs.modal', function (event) {
|
||
|
const button = $(event.relatedTarget); // Button that triggered the modal
|
||
|
const title = button.data('title');
|
||
|
const content = button.data('content');
|
||
|
const modal = $(this)
|
||
|
modal.find('.modal-title').text(title);
|
||
|
modal.find('.modal-body').html(content);
|
||
|
});
|
||
|
|
||
|
var packageUrl = 'https://raw.githubusercontent.com/openlayers/openlayers.github.io/build/package.json';
|
||
|
fetch(packageUrl).then(function(response) {
|
||
|
return response.json();
|
||
|
}).then(function(json) {
|
||
|
var latestVersion = json.version;
|
||
|
document.getElementById('latest-version').innerHTML = latestVersion;
|
||
|
var url = window.location.href;
|
||
|
var branchSearch = url.match(/\/([^\/]*)\/examples\//);
|
||
|
var cookieText = 'dismissed=-' + latestVersion + '-';
|
||
|
var dismissed = document.cookie.indexOf(cookieText) != -1;
|
||
|
if (branchSearch && !dismissed && /^v[0-9\.]*$/.test(branchSearch[1]) && '6.5.0' != latestVersion) {
|
||
|
var link = url.replace(branchSearch[0], '/latest/examples/');
|
||
|
fetch(link, {method: 'head'}).then(function(response) {
|
||
|
var a = document.getElementById('latest-link');
|
||
|
a.href = response.status == 200 ? link : '../../latest/examples/';
|
||
|
});
|
||
|
var latestCheck = document.getElementById('latest-check');
|
||
|
latestCheck.style.display = '';
|
||
|
document.getElementById('latest-dismiss').onclick = function() {
|
||
|
latestCheck.style.display = 'none';
|
||
|
document.cookie = cookieText;
|
||
|
}
|
||
|
}
|
||
|
});
|
||
|
</script>
|
||
|
</body>
|
||
|
</html>
|