[OpenLayers-Commits] r12167 - trunk/openlayers/examples
commits-20090109 at openlayers.org
commits-20090109 at openlayers.org
Tue Jul 12 12:48:40 EDT 2011
Author: tschaub
Date: 2011-07-12 09:48:39 -0700 (Tue, 12 Jul 2011)
New Revision: 12167
Added:
trunk/openlayers/examples/label-scale.html
trunk/openlayers/examples/label-scale.js
Log:
Example demonstrating scale dependent labeling.
Added: trunk/openlayers/examples/label-scale.html
===================================================================
--- trunk/openlayers/examples/label-scale.html (rev 0)
+++ trunk/openlayers/examples/label-scale.html 2011-07-12 16:48:39 UTC (rev 12167)
@@ -0,0 +1,34 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
+ <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
+ <meta name="apple-mobile-web-app-capable" content="yes">
+ <title>OpenLayers Scale Dependent Labels</title>
+ <link rel="stylesheet" href="../theme/default/style.css" type="text/css">
+ <link rel="stylesheet" href="style.css" type="text/css">
+ <script src="../lib/OpenLayers.js"></script>
+ </head>
+ <body>
+ <h1 id="title">Scale Dependent Labels Example</h1>
+ <div id="tags">
+ label, scale, stylemap
+ </div>
+ <p id="shortdesc">
+ Demonstrates how to use a StyleMap for displaying scale dependent labels.
+ </p>
+ <div id="map" class="smallmap"></div>
+ <div id="docs">
+ <p>
+ This example uses rule based styling to change the how features are
+ labeled at different scales. An <code>OpenLayers.Rule</code> object
+ can have <code>minScaleDenominator</code> and
+ <code>maxScaleDenominator</code> properties to control when the
+ provided symbolizer should be used.
+ </p><p>
+ View the <a href="label-scale.js">source</a> to see how this is done.
+ </p>
+ </div>
+ <script src="label-scale.js"></script>
+ </body>
+</html>
Added: trunk/openlayers/examples/label-scale.js
===================================================================
--- trunk/openlayers/examples/label-scale.js (rev 0)
+++ trunk/openlayers/examples/label-scale.js 2011-07-12 16:48:39 UTC (rev 12167)
@@ -0,0 +1,72 @@
+// Create 50 random features, and give them a "type" attribute that
+// will be used for the label text.
+var features = new Array(50);
+for (var i=0; i<features.length; i++) {
+ features[i] = new OpenLayers.Feature.Vector(
+ new OpenLayers.Geometry.Point(
+ (360 * Math.random()) - 180, (180 * Math.random()) - 90
+ ), {
+ type: 5 + parseInt(5 * Math.random())
+ }
+ );
+}
+
+/**
+ * Create a style instance that is a collection of rules with symbolizers.
+ * Use a default symbolizer to extend symoblizers for all rules.
+ */
+var style = new OpenLayers.Style({
+ fillColor: "#ffcc66",
+ strokeColor: "#ff9933",
+ strokeWidth: 2,
+ label: "${type}",
+ fontColor: "#333333",
+ fontFamily: "sans-serif",
+ fontWeight: "bold"
+}, {
+ rules: [
+ new OpenLayers.Rule({
+ minScaleDenominator: 200000000,
+ symbolizer: {
+ pointRadius: 7,
+ fontSize: "9px"
+ }
+ }),
+ new OpenLayers.Rule({
+ maxScaleDenominator: 200000000,
+ minScaleDenominator: 100000000,
+ symbolizer: {
+ pointRadius: 10,
+ fontSize: "12px"
+ }
+ }),
+ new OpenLayers.Rule({
+ maxScaleDenominator: 100000000,
+ symbolizer: {
+ pointRadius: 13,
+ fontSize: "15px"
+ }
+ })
+ ]
+});
+
+// Create a vector layer and give it your style map.
+var points = new OpenLayers.Layer.Vector("Points", {
+ styleMap: new OpenLayers.StyleMap(style)
+});
+points.addFeatures(features);
+
+var map = new OpenLayers.Map({
+ div: "map",
+ layers: [
+ new OpenLayers.Layer.WMS(
+ "OpenLayers WMS",
+ "http://vmap0.tiles.osgeo.org/wms/vmap0",
+ {layers: "basic"}
+ ),
+ points
+ ],
+ center: new OpenLayers.LonLat(0, 0),
+ zoom: 1
+});
+
More information about the Commits
mailing list