mirror of
https://github.com/Viglino/ol-ext.git
synced 2026-01-25 17:36:21 +00:00
194 lines
6.7 KiB
HTML
194 lines
6.7 KiB
HTML
<!DOCTYPE html>
|
|
<!----------------------------------------------------------
|
|
|
|
Copyright (c) 2015 Jean-Marc VIGLINO,
|
|
released under CeCILL-B (french BSD like) licence: http://www.cecill.info/
|
|
|
|
------------------------------------------------------------>
|
|
<html>
|
|
<head>
|
|
<title>OL3-ext: target control</title>
|
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
|
|
|
<meta name="description" content="target control for OL3" />
|
|
<meta name="keywords" content="ol3, control, target, center, canvas" />
|
|
|
|
<link rel="stylesheet" href="style.css" />
|
|
|
|
<link rel="stylesheet" href="http://fontawesome.io/assets/font-awesome/css/font-awesome.css" type="text/css" />
|
|
|
|
<!-- jQuery -->
|
|
<script type="text/javascript" src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
|
|
|
|
<!-- OL3 -->
|
|
<link rel="stylesheet" href="http://openlayers.org/en/master/css/ol.css" />
|
|
<script type="text/javascript" src="http://openlayers.org/en/master/build/ol.js"></script>
|
|
<!-- http://openlayers.org/en/v3.2.0/build/ol.js -->
|
|
<!-- http://openlayers.org/en/v3.2.0/build/ol-debug.js -->
|
|
|
|
<!-- controls -->
|
|
<script type="text/javascript" src="../control/targetcontrol.js"></script>
|
|
|
|
|
|
</head>
|
|
<body >
|
|
<a href="https://github.com/Viglino/ol3-ext"><img style="position: absolute; top: 0; right: 0; border: 0;" src="https://camo.githubusercontent.com/38ef81f8aca64bb9a64448d0d70f1308ef5341ab/68747470733a2f2f73332e616d617a6f6e6177732e636f6d2f6769746875622f726962626f6e732f666f726b6d655f72696768745f6461726b626c75655f3132313632312e706e67" alt="Fork me on GitHub" data-canonical-src="https://s3.amazonaws.com/github/ribbons/forkme_right_darkblue_121621.png"></a>
|
|
|
|
<a href="../index.html">
|
|
<h1>OL3-ext: target controls</h1>
|
|
</a>
|
|
<div class="info">
|
|
Target control draw a target to materialize the center of the map.
|
|
<br/>
|
|
The style define the target to draw
|
|
<ul><li>
|
|
an <i>ol.style.Stroke</i> and a <i>radius</i> will draw a cros on the map
|
|
</li><li>
|
|
an <i>ol.style.Image</i> to draw an image on the map
|
|
</li><li>
|
|
an <i>ol.style.Text</i> to draw text on the map
|
|
</li></ul>
|
|
The <i>composite</i> option performs a composite operation when drawing.
|
|
</div>
|
|
|
|
<!-- Map div -->
|
|
<div id="map" style="width:600px; height:400px;"></div>
|
|
|
|
<div class="options">
|
|
<h2>Options:</h2>
|
|
<ul><li>
|
|
Style: <select id="style" onchange="setTarget()">
|
|
<option value="cross">default</option>
|
|
<option value="circle">circle</option>
|
|
<option value="regular">regular shape</option>
|
|
<option value="icon">icon</option>
|
|
<option value="text">text</option>
|
|
<option value="bullseye">text bullseye (fontawesome)</option>
|
|
<option value="crosshairs">text crosshairs (fontawesome)</option>
|
|
<option value="mixt">mixt</option>
|
|
</select>
|
|
</li><li>
|
|
Color: <select id="color" onchange="setTarget()">
|
|
<option value="black">black</option>
|
|
<option value="red">red</option>
|
|
<option value="green">green</option>
|
|
<option value="blue">blue</option>
|
|
<option value="yellow">yellow</option>
|
|
<option value="white">white</option>
|
|
</select>
|
|
</li><li>
|
|
Composite: <select id="composite" onchange="setTarget()">
|
|
<option value="">default</option>
|
|
<option value="difference">difference</option>
|
|
<option value="multiply">multiply</option>
|
|
<option value="overlay">overlay</option>
|
|
<option value="luminosity">luminosity</option>
|
|
<option value="xor">xor</option>
|
|
</select>
|
|
</li></ul>
|
|
</div>
|
|
|
|
<script type="text/javascript">
|
|
|
|
// Layers
|
|
var layers = [
|
|
new ol.layer.Tile({
|
|
name: "Natural Earth",
|
|
minResolution: 306,
|
|
source0: new ol.source.XYZ(
|
|
{ url: 'http://{a-d}.tiles.mapbox.com/v3/mapbox.natural-earth-hypso-bathy/{z}/{x}/{y}.png',
|
|
attributions: [new ol.Attribution({ html: '© <a href="https://www.mapbox.com/map-feedback/">Mapbox</a> ' })]
|
|
}),
|
|
source: new ol.source.XYZ(
|
|
{ url: 'http://{a-d}.tiles.mapbox.com/v3/mapbox.blue-marble-topo-bathy-jan/{z}/{x}/{y}.png',
|
|
attributions: [new ol.Attribution({ html: '© <a href="https://www.mapbox.com/map-feedback/">Mapbox</a> ' })]
|
|
})
|
|
})
|
|
];
|
|
|
|
// The map
|
|
var map = new ol.Map
|
|
({ target: 'map',
|
|
view: new ol.View
|
|
({ zoom: 5,
|
|
center: [166326, 5992663]
|
|
}),
|
|
layers: layers
|
|
});
|
|
|
|
// Target control
|
|
var img = new Image();
|
|
img.src = "data/target.png";
|
|
var target;
|
|
|
|
function setTarget()
|
|
{
|
|
if (target) map.removeControl(target);
|
|
|
|
var stroke = new ol.style.Stroke({ color:$("#color").val(), width:2 });
|
|
|
|
switch ($("#style").val())
|
|
{ case 'icon':
|
|
style = new ol.style.Style({
|
|
image: new ol.style.Icon( { img: img, imgSize:[img.width,img.height] } )
|
|
});
|
|
break;
|
|
case 'circle':
|
|
style = new ol.style.Style({
|
|
image: new ol.style.Circle({ radius: 10, stroke: stroke }),
|
|
snapToPixel:true
|
|
});
|
|
break;
|
|
case 'regular':
|
|
style = new ol.style.Style({
|
|
image: new ol.style.RegularShape (
|
|
{ radius:20,
|
|
points: 6,
|
|
stroke: stroke
|
|
}),
|
|
snapToPixel:true
|
|
});
|
|
break;
|
|
case 'text':
|
|
style = new ol.style.Style({
|
|
text: new ol.style.Text(
|
|
{ text: 'A',
|
|
font: '30px sherif',
|
|
fill: new ol.style.Fill({ color: $("#color").val() })
|
|
})
|
|
});
|
|
break;
|
|
case 'bullseye':
|
|
case 'crosshairs':
|
|
style = new ol.style.Style({
|
|
text: new ol.style.Text(
|
|
{ text: $("#style").val()=="bullseye" ? '\uf140' : '\uf05b',
|
|
font: '30px Fontawesome',
|
|
fill: new ol.style.Fill({ color: $("#color").val() })
|
|
})
|
|
});
|
|
break;
|
|
case 'mixt':
|
|
style = [ new ol.style.Style({ image: new ol.style.RegularShape ({ points: 4, radius: 11, radius1: 0, radius2: 0, stroke: stroke }), snapToPixel:true }),
|
|
new ol.style.Style({ image: new ol.style.Circle({ radius:10, stroke: stroke }), snapToPixel:true }),
|
|
new ol.style.Style({ image: new ol.style.RegularShape ({ radius:20,points: 6, stroke: stroke}), snapToPixel:true })
|
|
];
|
|
break;
|
|
default:
|
|
style = [ new ol.style.Style({ image: new ol.style.RegularShape ({ points: 4, radius: 11, radius1: 0, radius2: 0, snapToPixel:true, stroke: new ol.style.Stroke({ color: "#fff", width:3 }) }) }),
|
|
new ol.style.Style({ image: new ol.style.RegularShape ({ points: 4, radius: 11, radius1: 0, radius2: 0, snapToPixel:true, stroke: stroke }) })
|
|
];
|
|
break;
|
|
}
|
|
target = new ol.control.Target ({ style: style, composite: $("#composite").val() });
|
|
map.addControl(target);
|
|
|
|
}
|
|
|
|
setTarget()
|
|
|
|
|
|
</script>
|
|
|
|
</body>
|
|
</html> |