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 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239
| var geojson = {
"type": "FeatureCollection",
"crs" : {
"type": "name",
"properties": {
"name": 'EPSG:30731'
}},
"features": []
};
var projection = new ol.proj.Projection({
code: 'EPSG:30731',
units: 'm'
});
var geo;
var resolution = [800,500];
var extent = [218470.985603305,3950936.00068151,297327.00560837,4023055.0106858];
var layer=['mostac'];
var layers = [
new ol.layer.Image({
title: 'a',
type: 'base',
extent: extent,
source: new ol.source.ImageWMS({
url: 'http://localhost/cgi-bin/mapserv.exe?map=C:/ms4w/Apache/htdocs/54/bootstrap-3.3.6-dist/Mosta.map',
params: {
'LAYERS': layer,
'CRS': 'EPSG:30731',
'BBOX': '218470.985603305,3950936.00068151,297327.00560837,4023055.0106858',
'WIDTH': '800',
'HEIGHT': '500',
'FORMAT': 'image/png'
},
serverType: 'mapserver'
})
})
];
var layers2 = [
new ol.layer.Image({
title: 'b',
extent: extent,
source: new ol.source.ImageWMS({
url: 'http://localhost/cgi-bin/mapserv.exe?map=C:/ms4w/Apache/htdocs/54/bootstrap-3.3.6-dist/Mosta.map',
params: {
'LAYERS': ['parcellles'],
'CRS': 'EPSG:30731',
'BBOX': '218470.985603305,3950936.00068151,297327.00560837,4023055.0106858',
'WIDTH': '800',
'HEIGHT': '500',
'FORMAT': 'image/png'
},
serverType: 'mapserver'
})
})
];
var fill = new ol.style.Fill({
color: 'rgba(0,0,0,0.2)'
});
var stroke = new ol.style.Stroke({
color: 'rgba(0,0,0,0.4)'
});
var circle = new ol.style.Circle({
radius: 6,
fill: fill,
stroke: stroke
});
var vectorStyle = new ol.style.Style({
fill: fill,
stroke: stroke,
image: circle
});
var vectorLoader = function(extent, resolution, projection) {
var url = 'http://localhost/cgi-bin/mapserv.exe?map=C:/ms4w/Apache/htdocs/54/bootstrap-3.3.6-dist/m.map?service=WFS&' +
'version=1.1.0&request=GetFeature&typename=com&' +
'outputFormat=text/javascript&format_options=callback:loadFeatures' + '&srsname=EPSG:30731&bbox=' + extent.join(',') + ',EPSG:30731';
$.ajax({
url: url,
dataType: 'jsonp'
});
};
var loadFeatures = function(response) {
var features = vectorSource.readFeatures(response);
vectorSource.addFeatures(features);
};
var vectorSource = new ol.source.Vector({
strategy: ol.loadingstrategy.tile(new ol.tilegrid.createXYZ({maxZoom: 19})),
loader: vectorLoader,
projection: 'EPSG:30731',
});
var serverVector = new ol.layer.Vector({
source: vectorSource,
style: vectorStyle
});
/*var map = new ol.Map({
layers: layers,
target: 'map',
view: new ol.View({
center: [259470,3989000],
zoom: 10,
projection: projection
})
});*/
var gl1 = new ol.layer.Group({
'title': 'Base maps',
layers: layers
});
var gl2 = new ol.layer.Group({
title: 'Overlays',
layers: layers2
});
var gl3 = new ol.layer.Group({
title: 'Ovserlays',
layers: vectorLayer
});
var map = new ol.Map({
target: 'map',
layers: [
gl1,
gl2,
gl3
],
view: new ol.View({
center: [259470,3989000],
zoom: 10,
projection: projection
})
});
var layerSwitcher = new ol.control.LayerSwitcher({
tipLabel: 'Légende' // Optional label for button
});
map.addControl(layerSwitcher);
/*(function() {
window.alert(map.getView().getZoom());
var zoom = map.getView().getZoom();
if (zoom >=10) {
window.alert(1);
gl1.setVisible(false);
}
else if (zoom < 10) {
gl1.setVisible(true);
}
})();*/
map.on('moveend', (function() {
var ghostZoom = map.getView().getZoom();
if (ghostZoom > 10 ) {
gl2.setVisible(true);
console.log('1');
}else if (ghostZoom <= 10)
{
gl2.setVisible(false);
}
}));
/*
map.events.on({
zoomend: function(evt) {
zoom = map.getZoom();
if (zoom >= 10)
{
gl1.setVisible(false);
}
else if (zoom < 10)
{
gl1.setVisible(true);
}
}
});
*/
var fields = ["geom"];
var data = {
table: "parcellles",
fields: fields
};
$('#submit').submit(
$.ajax("get_data.php",{
data: {
email: "email",
pwd: "password"
},
success: function(data){
window.alert("");
}
})
);
$('#submit').submit(
$.ajax("get_geom.php",{
data: data,
success: function(data){
//create geojson container object
//split data into features
var dataArray = data.split(", ;");
dataArray.pop();
//console.log(dataArray);
//build geojson features
dataArray.forEach(function(d){
d = d.split(", "); //split the data up into individual attribute values and the geometry
//feature object container
var feature = {
"type": "Feature",
"properties": {}, //properties object container
"geometry": JSON.parse(d[fields.length]) //parse geometry
};
for (var i=0; i<fields.length; i++){
feature.properties[fields[i]] = d[i];
};
geojson.features.push(feature);
});
}
}));
console.log(geojson);
var vectorSource = new ol.source.Vector({
projection: 'EPSG:30731',
url: geojson,
format: new ol.format.GeoJSON()
});
var vectorLayer = new ol.layer.Vector({
source: vectorSource
}); |
Partager