1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
| <html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link rel="stylesheet" href="style.css" type="text/css">
<script src="http://www.openlayers.org/api/OpenLayers.js"></script>
<script type="text/javascript">
var map;
function init() {
map = new OpenLayers.Map('map',
{allOverlays: true,
center: [91, 15],
zoom: 4,
layers: [new OpenLayers.Layer.Vector()]
});
var featurecollection = {
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"geometry":
{
type: "Polygon",
coordinates:
[[
[110, 20],
[120, 20],
[120, 10],
[110, 10],
[110, 20]],
[[112, 17],
[118, 18],
[118, 16],
[112, 15],
[112, 17]
]]
},
"properties": {"fillColor": "red"}
},
{
"type": "Feature",
"geometry":
{
type: "Polygon",
coordinates:
[[
[60, 20],
[70, 20],
[70, 10],
[60, 10],
[60, 20]],
[[112, 17]
]]
},
"properties": {"fillColor": "blue"}
}
]
};
var myStyles = new OpenLayers.StyleMap({
"default": new OpenLayers.Style({
fillColor: "${fillColor}",
strokeColor: "black",
}),
});
var geojson_format = new OpenLayers.Format.GeoJSON();
var vector_layer = new OpenLayers.Layer.Vector("",{
styleMap: myStyles,
rendererOptions: {zIndexing: true},
});
vector_layer.addFeatures(geojson_format.read(featurecollection));
map.addLayer(vector_layer);
}
</script>
</head>
<body onload="init()">
<div id="map" class="bigmap"></div>
</body>
</html> |
Partager