Scifa


I'm having problems when trying to hide / show a layer when i zoom out.

Code Snippet

<html>
<head>
<script src="http://dev.virtualearth.net/mapcontrol/v4/mapcontrol.js"></script>
<script>
var map;

function Destination(){
map.LoadMap(new VELatLong(35, 33 ), 8, 'r', false);
}

function Regions(){
var veLayerSpec = new VELayerSpecification();
veLayerSpec.Type = VELayerType.GeoRSS;
veLayerSpec.ID = 'regions';
veLayerSpec.Method = 'get';
veLayerSpec.LayerSource = 'http://127.0.0.1/phplocator/regions.xml';
map.AddLayer(veLayerSpec);
}

function Resorts(){
var veLayerSpec = new VELayerSpecification();
veLayerSpec.Type = VELayerType.GeoRSS;
veLayerSpec.ID = 'resorts';
veLayerSpec.LayerSource = 'http://127.0.0.1/phplocator/resorts.xml';
veLayerSpec.Method = 'get';
// veLayerSpec.IconUrl = 'hazard.gif';
map.AddLayer(veLayerSpec);
}

function OnPageLoad()
{
map = new VEMap('myMap');
map.LoadMap();

Resorts();

Regions();

Destination();

map.AttachEvent("onendzoom",EndZoomHandler);

}

function EndZoomHandler(e){

var z = map.GetZoomLevel();

}

</script>

<body onload="OnPageLoad();">
<div id="myMap" style="position:relative;width:556px;height:270px;"></div>

</body>
</html>




Re: Hide Layer On Zoom In/Out

Earthware


Hello

are you saying you dont know how to do it or your code is not working I cannot see anything in your code that would hide a layer

Brian Norman

www.earthware.co.uk






Re: Hide Layer On Zoom In/Out

Scifa

It's ok, i didn't know how to do it and it's working now.

Code Snippet

<html>
<head>

<script src="http://dev.virtualearth.net/mapcontrol/mapcontrol.ashx v=5"></script>
<script>

var map;
var regions;
var resorts;
var accoms;


function Destination(){
map.LoadMap(new VELatLong(35, 33 ), 8, 'r', false);
}

function onFeedLoadRegions(layer){
var numShapes = layer.GetShapeCount();
for(var i=0; i < numShapes; ++i){
var s = layer.GetShapeByIndex(i);
s.SetCustomIcon("<img src='region.gif'/>");
}
}

function onFeedLoadResorts(layer){
var numShapes = layer.GetShapeCount();
for(var i=0; i < numShapes; ++i){
var s = layer.GetShapeByIndex(i);
s.SetCustomIcon("<img src='resort.gif'/>");
}
}

function CreateRegions(){

regions = new VEShapeLayer();
var regionsLayerSpec1 = new VEShapeSourceSpecification(VEDataType.GeoRSS, "http://127.0.0.1/phplocator/regions.xml", regions);
map.ImportShapeLayerData(regionsLayerSpec1, onFeedLoadRegions, false);
regions.Show();

}

function CreateResorts(){

resorts = new VEShapeLayer();
var resortsLayerSpec1 = new VEShapeSourceSpecification(VEDataType.GeoRSS, "http://127.0.0.1/phplocator/resorts.xml", resorts);
map.ImportShapeLayerData(resortsLayerSpec1, onFeedLoadResorts, false);
resorts.Hide();
}

function CreateAccom(){

accoms = new VEShapeLayer();
var accomsLayerSpec1 = new VEShapeSourceSpecification(VEDataType.GeoRSS, "http://127.0.0.1/phplocator/resorts.xml", accoms);
map.ImportShapeLayerData(accomsLayerSpec1, onFeedLoadAccoms, false);
accoms.Hide();
}

function OnPageLoad(){

map = new VEMap('myMap');
map.LoadMap(new VELatLong(35, 33 ), 8, 'r', false);

CreateResorts();

CreateRegions();

map.AttachEvent("onendzoom",EndZoomHandler);

}

function EndZoomHandler(e){

var z = map.GetZoomLevel();

if( z >= 9 ){

try{
regions.Hide();
resorts.Show();
} catch (err){
alert(err.source + "\n" + err.name + "\n" + err.number + "\n" + err.message);
}

}else{

regions.Show();
resorts.Hide();
}


}

</script>

<body onload="OnPageLoad();">
<div id="myMap" style="position:relative;width:556px;height:270px;"></div>

</body>
</html>