function LiveMap(id, mapId) { this.id = id; this.mapId = mapId; //mode = selected, polylineDefined, pushpointDefined this.mode = 'selected'; this.selectedMode = 'PostBack'; this.editPolyLine = null; this.notEditPolyLine = new Array(); this.pushpins = new Array(); this.polylineWidth = 3; this.editablePolylineColor = new VEColor(255, 153, 0, 1.0); this.editablePolylineFillColor = new VEColor(255, 153, 0, 0.5); this.notEditablePolylineColor = new VEColor(128, 128, 128, 1.0); this.notEditablePolylineFillColor = new VEColor(128, 128, 128, 0.5); this.polylineMode = "None"; this.map = new VEMap(mapId); this.globals = new Globals("__mapVariable_"+mapId); this.pushPinSelectedLatLong = null; //this.polyLineRender = PolyLineRender; LiveMap._this = this; } LiveMap.prototype.SetPolylineMode = function(mode) { this.polylineMode = mode; } LiveMap.prototype.SetEditablePolyline = function(polyLine) { ///vymazat minuly - nemelo by se stat // this.map.AddPolyline(polyLine); this.editPolyLine = polyLine; } LiveMap.prototype.AddNotEditablePolyline = function(polyLine) { //this.map.AddPolyline(polyLine); this.notEditPolyLine.push(polyLine); } LiveMap.prototype.AddPushpin = function(pushpin) { //this.map.AddPushpin(pushpin); this.pushpins.push(pushpin); } LiveMap.prototype.ShowDashboard = function() { this.map.ShowDashboard(); } LiveMap.prototype.HideDashboard = function() { this.map.HideDashboard(); } LiveMap.prototype.ShowFindControl = function() { this.map.ShowFindControl(); } LiveMap.prototype.HideFindControl = function() { this.map.HideFindControl(); } //mode = selected, polylineDefined, pushpointDefined LiveMap.prototype.SetMapMode = function(mode) { this.mode = mode; } LiveMap.prototype.SetSelectMode = function(mode) { this.selectedMode = mode; } LiveMap.prototype.SetScaleBarDistanceUnit = function(distanceUnit) { this.map.SetScaleBarDistanceUnit(distanceUnit); } LiveMap.prototype.SetPolylineWidth = function (width) { this.polylineWidth = width; } LiveMap.prototype.SetEditablePolylineColor = function(color) { this.editablePolylineColor = color; } LiveMap.prototype.SetNotEditablePolylineColor = function(color) { this.notEditablePolylineColor = color; } LiveMap.prototype.SetEditablePolylineFillColor = function(color) { this.editablePolylineFillColor = color; } LiveMap.prototype.SetNotEditablePolylineFillColor = function(color) { this.notEditablePolylineFillColor = color; } LiveMap.prototype.LoadMap = function(latLong, zoom, mapStyle, fixed) { // If the browser is Firefox get the version number var ffv = 0; var ffn = "Firefox/" var ffp = navigator.userAgent.indexOf(ffn); if (ffp != -1) ffv = parseFloat(navigator.userAgent.substring(ffp + ffn.length)); // If we're using Firefox 1.5 or above override the Virtual Earth drawing functions to use SVG if (ffv >= 1.5) { Msn.Drawing.Graphic.CreateGraphic=function(f,b) { return new Msn.Drawing.SVGGraphic(f,b) } } try{ this.map.LoadMap(latLong, zoom, mapStyle, fixed); } catch(err) { //debugger //alert(err.message); } } LiveMap.prototype.DataBind = function() { //debugger //if (this.mode == 'PolylineDefined' || this.mode == 'PushpinDefined') { this.map.AttachEvent("onchangeview", this.onChangeView); } if (this.mode == 'PolylineDefined' && this.polylineMode != 'None') { this.map.AttachEvent('onclick', this.polylineDefinedHandler); this.notEditablePolyLinesRender(); if (this.editPolyLine != null) { this.editablePolyLinesRender(); } } else if (this.mode == 'PushpinDefined') { this.map.AttachEvent('onclick', this.pushpinDefinedHandler); if (this.pushpins != null && this.pushpins.length != 0) { this.pushPinRender(this.pushpins[0]); } } else if (this.mode == 'Selected') { this.map.AttachEvent('onclick', this.selectedHandler); if (this.polylineMode != "None") { this.notEditablePolyLinesRender(); } this.pushPinsRender(); var div = this.globals.dom.getById(this.mapId); if (div != null) { if(navigator.userAgent.indexOf("IE")>=0) { this.globals.dom.attachEvent(div, 'mouseover', this.polylineMouseOverHandler); this.globals.dom.attachEvent(div, 'mousemove', this.polylineMouseOverHandler); this.globals.dom.attachEvent(div, 'mouseout', VEPolyline.Hide); } else { this.globals.dom.attachEvent(div, 'mouseover', this.polylineMouseOverNotIEHandler); this.globals.dom.attachEvent(div, 'mousemove', this.polylineMouseOverNotIEHandler); this.globals.dom.attachEvent(div, 'mouseout', VEPolyline.Hide); } } } else { if (this.editPolyLine != null) { this.editablePolyLinesRender(); } this.notEditablePolyLinesRender(); this.pushPinsRender(); } this.OnSaveMap(); } LiveMap.prototype.polylineMouseOverHandler = function(e) { ve = LiveMap._this.map.PixelToLatLong(e.x, e.y); // LiveMap._this.View(e.x, e.y); LiveMap._this.OnMouseOverPolyLine(e, ve); } LiveMap.prototype.polylineMouseOverNotIEHandler = function(e) { ve = LiveMap._this.map.PixelToLatLong(e.layerX, e.layerY); // LiveMap._this.View(e.layerX, e.layerY); LiveMap._this.OnMouseOverPolyLine(e, ve); } LiveMap.prototype.OnMouseOverPolyLine = function(e, latLong) { var polyline = null; for(var i = 0; i < this.notEditPolyLine.length; i++) { if (this.IsPointInPolyline(this.notEditPolyLine[i], latLong)) { polyline = this.notEditPolyLine[i]; break; } } if (polyline != null) { var div = this.globals.dom.getById(this.mapId); polyline.Show(this.map, div, e.srcElement, latLong); } } VEPolyline.Show=function(map,id, latLong, mainElement, element, title, details,g,f) { var posunDoprava = 20; if(window.ero==null||window.ero=="undefined")window.ero=ERO.getInstance(); if(VEPolyline.ShowDetailOnMouseOver) { window.ero.setBoundingArea(new Microsoft.Web.Geometry.Point(0,0),new Microsoft.Web.Geometry.Point(document.body.clientWidth, document.body.clientHeight)); var b="

"; if(title != null && title.length>0) b+='

'+unescape(title)+"
"; if(details != null && details.length>0) b+='
'+unescape(details)+"
"; if(!document.all&&(details.length==0||title.length==0)) b+="

"; b+="

"; window.ero.setContent(b); var pixel = map.LatLongToPixel(latLong); if(navigator.userAgent.indexOf("IE")>=0) { window.ero.dockToElement(element); } else { var point = Microsoft.Web.Geometry.Functions.getElementPosition(mainElement); window.ero.dockToPoint(new Microsoft.Web.Geometry.Point(point.x + pixel.x + posunDoprava, point.y + pixel.y), null, element) } } if(VEPolyline.OnMouseOverCallback!=null) VEPolyline.OnMouseOverCallback(pixel.x, pixel.y, d, unescape(c)) } VEPolyline.Hide=function(a) { if(window.ero!=null) { if(a=="undefined"||a==null)a=false; window.ero.hide(a) } } VEPolyline.prototype.Show = function(map, mainElement, element, latLong) { //debugger if (typeof VEPolyline.ShowDetailOnMouseOver == "undefined") { VEPolyline.ShowDetailOnMouseOver = true; } if (this.TitleStyle == null || this.TitleStyle.length == 0) { this.TitleStyle = "VE_Pushpin_Popup_Title"; } if (this.DetailsStyle == null || this.DetailsStyle.length == 0) { this.DetailsStyle = "VE_Pushpin_Popup_Body"; } VEPolyline.Show(map, this.ID, latLong, mainElement, element, escape(this.Title), escape(this.Details), this.TitleStyle, this.DetailsStyle) } LiveMap.prototype.selectedHandler = function(e) { // debugger var isRedirect = LiveMap._this.OnSelectedPushPin(e.view.LatLong); if (isRedirect == false) { LiveMap._this.OnSelectedPolyLine(e.view.LatLong); } } LiveMap.prototype.OnSelectedPushPin = function(latLong) { var clickPixel = this.map.LatLongToPixel(latLong); if(this.pushpins != null) { var push = null; for(var i = 0; i < this.pushpins.length; i++) { var iconUrl = this.pushpins[i].Iconurl; var icon = new Image(); icon.src = iconUrl; ///podle ikonky vypocitam rozsahy kliku. Odecitam nekolik pixelu abych zbytecne nepresahoval var defX = icon.width / 2 - 2; var defY1 = icon.height / 3 - 1; var defY2 = icon.height * 2 / 3 - 4; var pushpinsPixel = this.map.LatLongToPixel(this.pushpins[i].LatLong); if (clickPixel.x >= pushpinsPixel.x-defX && clickPixel.x <= pushpinsPixel.x+defX && clickPixel.y <= pushpinsPixel.y+defY2 && clickPixel.y >= pushpinsPixel.y-defY1) { push = this.pushpins[i]; break; } } if (push != null) { this.OnSelectedChoice(this.pushpins[i], 'pushPinSel_'); return true; } } return false; } LiveMap.prototype.GenerovaniImageMapy = function(imageName) { //var mapa =""; var mapa = ""; for(var i = 0; i < this.pushpins.length; i++) { var pushpinsPixel = this.map.LatLongToPixel(this.pushpins[i].LatLong); } for(var i = 0; i < this.notEditPolyLine.length; i++) { var location = ""; var poly = this.notEditPolyLine[i]; for(var j = 0; j < poly.LatLongs.length; j++) { var pixel = this.map.LatLongToPixel(poly.LatLongs[j]); location += pixel.x+","+pixel.y; if (j != poly.LatLongs.length-1) { location += "," } } mapa +=""+poly.ID+""; } //mapa +=""; this.AddMapElement(imageName, mapa); } LiveMap.prototype.AddMapElement = function(imageName, innerHtml) { var map = this.globals.dom.createElement('map'); map.name = imageName; map.innerHtml = innerHtml; var e = this.globals.dom.getByTagName(("body")); if (e != null && e.length > 0) { this.globals.dom.appendChild(e[0], map); } } LiveMap.prototype.View = function(x, y) { var hiddenArray = this.globals.dom.getById("viewDiv"); if (hiddenArray == null) { hiddenArray = this.globals.dom.createElement('Div'); hiddenArray.style.position = 'absolute'; hiddenArray.style.top = '200px'; hiddenArray.style.left = '950px'; hiddenArray.style.width = '300px'; hiddenArray.style.height = '300px'; hiddenArray.id = "viewDiv"; var e = this.globals.dom.getByTagName(("body")); if (e != null && e.length > 0) { this.globals.dom.appendChild(e[0], hiddenArray); } } hiddenArray.innerText = ""; hiddenArray.innerText += "over x:"+x; hiddenArray.innerText += "\n
"; hiddenArray.innerText += "over y:"+y; hiddenArray.innerText += "
"; /*hiddenArray.innerText += "click x:"+click.x; hiddenArray.innerText += "
"; hiddenArray.innerText += "click x:"+click.y; hiddenArray.innerText += "
"; */ } LiveMap.prototype.OnSelectedPolyLine = function(latLong) { var polyline = null; for(var i = 0; i < this.notEditPolyLine.length; i++) { if (this.IsPointInPolyline(this.notEditPolyLine[i], latLong)) { polyline = this.notEditPolyLine[i]; break; } } if (polyline != null) { this.OnSelectedChoice(polyline, 'polySel_'); } } LiveMap.prototype.OnSelectedChoice = function(polyline, commandArgument) { if (polyline != null) { if (this.selectedMode == 'Link') { this.OnSelectedLink(polyline); } else { this.OnSelectedPostBack(polyline, commandArgument); } } } LiveMap.prototype.OnSelectedPostBack = function(polyline, commandArgument) { this.DoPostBack(commandArgument+polyline.ID); document.close(); } LiveMap.prototype.OnSelectedLink = function(polyline) { if (polyline.navigateUrl != null && polyline.navigateUrl.length > 0) { this.map.DeleteAllPushpins(); window.location.href = polyline.navigateUrl; document.close(); } } LiveMap.prototype.IsPointInPolyline = function(polyline, latLong) { ///viz http://local.wasp.uwa.edu.au/~pbourke/geometry/insidepoly/ var counter = 0; var i; var xinters; var N = polyline.LatLongs.length; var p1 = polyline.LatLongs[0]; var p = latLong; var p2; for (i=1;i<=N;i++) { p2 = polyline.LatLongs[i % N]; if (p.Longitude > Math.min(p1.Longitude,p2.Longitude)) { if (p.Longitude <= Math.max(p1.Longitude,p2.Longitude)) { if (p.Latitude <= Math.max(p1.Latitude,p2.Latitude)) { if (p1.Longitude != p2.Longitude) { xinters = (p.Longitude-p1.Longitude)*(p2.Latitude-p1.Latitude)/(p2.Longitude-p1.Longitude)+p1.Latitude; if (p1.Latitude == p2.Latitude || p.Latitude <= xinters) counter++; } } } } p1 = p2; } if (counter % 2 == 0) return(false); else return(true); } LiveMap.prototype.pushpinDefinedHandler = function(e) { // debugger if (LiveMap._this.pushpins == null || LiveMap._this.pushpins.length == 0) { var pushPin = new VEPushpin("-1", e.view.LatLong); LiveMap._this.pushpins.push(pushPin); LiveMap._this.OnSaveMap(); LiveMap._this.pushPinRender(LiveMap._this.pushpins[0]); LiveMap._this.DoPostBack('cp'); } } LiveMap.prototype.DoPostBack = function(param) { try{ __doPostBack(this.id, param); document.close(); } catch(err){ alert(err); } } LiveMap.prototype.polylineDefinedHandler = function(e) { if (LiveMap._this.editPolyLine == null) { LiveMap._this.editPolyLine = new VEPolyline("-1", [e.view.LatLong]); } else { LiveMap._this.editPolyLine.LatLongs.push(e.view.LatLong); LiveMap._this.OnSaveMap(); LiveMap._this.editablePolyLinesRender(); } } LiveMap.prototype.editablePolyLinesRender = function() { if (this.polylineMode == "Polyline") { this.polyLineRender(this.editPolyLine, this.editablePolylineColor); } else if (this.polylineMode == "Polygon") { this.polygonRender(this.editPolyLine, this.editablePolylineColor, this.editablePolylineFillColor); } } LiveMap.prototype.notEditablePolyLinesRender = function() { for(var i = 0; i < this.notEditPolyLine.length; i++) { if (this.polylineMode == "Polyline") { this.polyLineRender(this.notEditPolyLine[i], this.notEditablePolylineColor); } else if (this.polylineMode == "Polygon") { this.polygonRender(this.notEditPolyLine[i], this.notEditablePolylineColor, this.notEditablePolylineFillColor); } } } LiveMap.prototype.pushPinsRender = function() { if (this.pushpins != null && this.pushpins.length != 0) { for(var i = 0; i < this.pushpins.length; i++) { this.pushPinRender(this.pushpins[i]); } } } LiveMap.prototype.pushPinRender = function(pushPoint) { this.map.AddPushpin(pushPoint); } LiveMap.prototype.polyLineRender = function(polyLine, color) { if (this.polylineMode == "None") { return; } ///na zacatku neni jeste polyline vlozen - vyhodi vyjimku try { this.map.DeletePolyline(polyLine.ID) } catch (err) { } polyLine.SetWidth(this.polylineWidth); polyLine.SetColor(color); this.map.AddPolyline(polyLine); } LiveMap.prototype.polygonRender = function(polyLine, color, fillColor) { if (this.polylineMode == "None") { return; } ///na zacatku neni jeste polyline vlozen - vyhodi vyjimku try { this.map.DeletePolygon(polyLine.ID) } catch (err) { } var poly = new VEPolygon(polyLine.ID,polyLine.LatLongs); poly.SetOutlineWidth(this.polylineWidth); poly.SetOutlineColor(color); poly.SetFillColor(fillColor); this.map.AddPolygon(poly); } ///mazani polygonu LiveMap.prototype.ClearEditablePolyLine = function() { try { if (this.polylineMode == "Polyline") { this.map.DeletePolyline(this.editPolyLine.ID); } else { this.map.DeletePolygon(this.editPolyLine.ID); } } catch(err) { } ///smazat jen edit polygon while(this.editPolyLine.LatLongs.length > 0) { this.editPolyLine.LatLongs.pop(); } this.editPolyLine = null; LiveMap._this.OnSaveMap(); } ///vzit edit polygon a ten upravit LiveMap.prototype.UndoEditablePolyline = function() { if (this.editPolyLine.LatLongs.length > 0) { this.editPolyLine.LatLongs.pop(); LiveMap._this.OnSaveMap(); //this.polyLineRender(this.editPolyLine); this.editablePolyLinesRender(); } } LiveMap.prototype.onChangeView = function (e) { LiveMap._this.OnSaveMap(); } LiveMap.prototype.OnSaveMap = function () { this.globals.setVar('area_x', this.map.GetCenter().Latitude); this.globals.setVar('area_y', this.map.GetCenter().Longitude); this.globals.setVar('area_zoom', this.map.GetZoomLevel()); if (this.editPolyLine != null) { this.SetEditablePolylineVar(); } if (this.pushpins != null && this.pushpins.length != 0) { var sb = new StringBuilder(); sb.Append(this.pushpins[0].ID); sb.Append(","); sb.Append(this.pushpins[0].LatLong.Latitude); sb.Append("_"); sb.Append(this.pushpins[0].LatLong.Longitude); this.globals.setVar("editPushPin", sb.toString()); } return true; } LiveMap.prototype.SetEditablePolylineVar = function () { var sb = new StringBuilder(); if (this.editPolyLine == null) { return; } sb.Append(this.editPolyLine.ID); sb.Append(","); for(var i = 0; i < this.editPolyLine.LatLongs.length; i++) { sb.Append(this.editPolyLine.LatLongs[i].Latitude); sb.Append("_"); sb.Append(this.editPolyLine.LatLongs[i].Longitude); sb.Append(","); } this.globals.setVar("editPolyLine", sb.toString()); } LiveMap.prototype.SaveColorToString = function(color) { var vars = new StringBuilder(); if (color == null || color == 'undefined') { return ""; } vars.Append(color.R); vars.Append("_"); vars.Append(color.G); vars.Append("_"); vars.Append(color.B); vars.Append("_"); vars.Append(color.A); return vars.toString(); } function GetInfo() { alert('The top edge of the map on the Web page is at pixel: '+map.GetTop()); alert('The left edge of the map on the Web page is at pixel: '+map.GetLeft()); alert('The latitude,longitude at the center of the map is: '+map.GetCenter()); alert('The current zoom level of the map is: '+map.GetZoomLevel()); alert('The map control version is: '+VEMap.GetVersion()); }