Instructions
This example shows how to add multiple hand-drawn redlines.
Source code
The JavaScript code for this demo is listed below.
var mapview;
var redlineIns=new Array();
var rlflag=true;
var ordflag=false;
var mapMoveFlag=false;
function init()
{
document.getElementById("redLineOrdFlag").checked = false;
showMap();
}
function showMap()
{
var baseURL = "http://"+document.location.host+"/mapviewer";
var mapCenterLon = -122.45;
var mapCenterLat = 37.6706;
var mapZoom = 4;
var centerPoint = MVSdoGeometry.createPoint(mapCenterLon,mapCenterLat,8307);
mapview = new MVMapView(document.getElementById("map"), baseURL);
mapview.addMapTileLayer(new MVMapTileLayer("mvdemo.demo_map"));
mapview.setCenter(centerPoint);
mapview.setZoomLevel(mapZoom);
mapview.attachEventListener(MVEvent.RECENTER,checkMapMove);
mapview.attachEventListener(MVEvent.MOUSE_CLICK,getRedLineOrd);
mapview.display();
}
//create a redline tool
function redLine()
{
var redline = new MVRedlineTool("mvdemo.L.FERRY", "mvdemo.C.RED");
mapview.addRedLineTool(redline);
redlineIns.push(redline);
refreshRedlineList();
}
//initialize a redline tool
function initRedLine()
{
var redlineList=document.getElementById("redlineList");
if((redlineList.selectedIndex)<0)
{
alert("Please choose redline tool instance from the list above to initialize! ");
return;
}
redlineIns[redlineList.selectedIndex].init();
setRLFlag(true);
}
function generateRedLine()
{
var redlineList=document.getElementById("redlineList");
if((redlineList.selectedIndex)<0)
{
alert("Please choose redline tool instance from the list above to generate the polygon! ");
return;
}
redlineIns[redlineList.selectedIndex].generateArea();
setRLFlag(false);
}
//clear a red line tool
function clearRedLine()
{
var redlineList=document.getElementById("redlineList");
if((redlineList.selectedIndex)<0)
{
alert("Please choose redline tool instance from the list above to clear! ");
return;
}
redlineIns[redlineList.selectedIndex].clear();
}
function refreshRedlineList()
{
var redlineList=document.getElementById("redlineList");
redlineList.options.length=0;
for(var i=0; i
//show coordinates of the redline tool
function getRedLineOrd()
{
if(mapMoveFlag)
{
mapMoveFlag = false;
return;
}
var redlineList=document.getElementById("redlineList");
if((redlineList.selectedIndex)<0)
{
return;
}
if (rlflag && ordflag)
alert("Redline coordinates:"+ redlineIns[redlineList.selectedIndex].getOrdinates()+" ");
}
function showRedLineOrd(item)
{
ordflag=item.checked;
}
function setRLFlag(flag)
{
rlflag=flag;
}