// Name: Zebra.Mapping.debug.js // Assembly: Zebra.Web.Mapping // Version: 1.0.0.0 // FileVersion: 1.0.0.0 // Zebra.Mapping.debug GeoService = new function GeoService() { function search(address, countryTLD, callback) { var gc = new GClientGeocoder(); if (countryTLD != '') gc.setBaseCountryCode(countryTLD); gc.getLocations(address, callback); } function revSearch(latlng, countryTLD, callback) { var gc = new GClientGeocoder(); if (countryTLD != '') gc.setBaseCountryCode(countryTLD); gc.getLocations(latlng, callback); } this.search = search; this.revSearch = revSearch; } MapFactory = new function MapFactory() { var items = new Object(); function add(canvasId, options) { if (!items[canvasId]) { items[canvasId] = new Map({options:options,canvasId:canvasId}); jQuery(this).trigger('mapCreated', items[canvasId]); } } function get(canvasId) { return items[canvasId]; } this.add = add; this.get = get; } function Map(o) { var hotSpotsTimer = null; var map = null; var tileLayer = null; var defCursor = null; var options = o.options; var canvasId = o.canvasId; var lastRangeResult = null; var lastRangeResultLayer = null; var focusTileLayer = null; var isLoaded = false; var markers = new Array(); var selectedLocation = null; /* public members */ this.load = load; this.addMarker = addMarker; this.getMarker = getMarker; this.focusByAttribute = focusByAttribute; this.getMap = function () { return map; }; this.getOptions = function () { return options; }; this.getSelectedLocation = function () { return selectedLocation; }; this.setSelectedLocation = setSelectedLocation; this.setViewBox = setViewBox; /* end public members */ if (options.onInit) { options.onInit(this); } function load(mapSize) { var gmOptions = {}; if (isLoaded) return; if (mapSize) gmOptions.size = new GSize(mapSize.x, mapSize.y); var lCanvasObject = document.getElementById(canvasId); map = new GMap2(lCanvasObject, gmOptions); if (lCanvasObject) jQuery(lCanvasObject).bind("resize", function() { map.checkResize(); }); if (options.gmInit) options.gmInit(map); jQuery(window).unload(function () { unload(); }); setViewBox(options.north, options.east, options.south, options.west); tileLayer = new TileLayer(this, "all", true); tileLayer.setIcon(options.icon); GEvent.bind(map, "mousemove", this, function (latlng) { if (hotSpotsTimer) window.clearTimeout(hotSpotsTimer); hotSpotsTimer = window.setTimeout(function () { checkHotSpots(latlng) }, 10); } ); GEvent.bind(map, "zoomend", this, function(oldLevel, newLevel) { initHotSpots(); }); if (options.selectLocationEnabled) { selectedLocationData = document.getElementById(options.selectLocationFieldId); var mrkLocation = (selectedLocationData.value == "") ? null : GLatLng.fromUrlValue(selectedLocationData.value); var markerOptions = { draggable: true }; if (mrkLocation == null) { markerOptions.hide = true; mrkLocation = map.getCenter(); } selectedLocation = new GMarker(mrkLocation, markerOptions); selectedLocation.isVisible = !markerOptions.hide; GEvent.addListener(selectedLocation, 'dragend', (function(latlng, triggerChange) { updateSelectedLocationDataField(latlng); if (triggerChange) { jQuery(this).trigger('selectedLocationChanged', latlng); } })); map.addOverlay(selectedLocation); } isLoaded = true; jQuery(this).trigger('loaded'); }; function updateSelectedLocationDataField(location) { var dataField = selectedLocationData; if (dataField) dataField.value = location.toUrlValue(); }; function setSelectedLocation(lat, lng) { var latlng = new GLatLng(lat, lng); selectedLocation.hide(); selectedLocation.setLatLng(latlng); selectedLocation.show(); GEvent.trigger(selectedLocation, 'dragend', latlng, true); updateSelectedLocationDataField(latlng); }; function showViewBox() { }; function focus() { jQuery(this).trigger("onFocus"); }; function getMarker(key) { if (!markers) return null; return markers[key]; } function addMarker(marker) { if (!marker) return; var latlng = new GLatLng(marker.latitude, marker.longitude); var gMarkerOptions = {}; gMarkerOptions.title = marker.options.title; gMarkerOptions.clickable = marker.options.clickable; gMarkerOptions.draggable = marker.options.draggable; if (marker.options.icon != null) { gMarkerOptions.icon = new GIcon(G_DEFAULT_ICON); gMarkerOptions.icon.image = marker.options.icon.image; gMarkerOptions.icon.shadow = marker.options.icon.shadow; if (marker.options.icon.iconSize) gMarkerOptions.icon.iconSize = new GSize(marker.options.icon.iconSize.width, marker.options.icon.iconSize.height); if (marker.options.icon.shadowSize) gMarkerOptions.icon.shadowSize = new GSize(marker.options.icon.shadowSize.width, marker.options.icon.shadowSize.height); } var gMarker = new GMarker(latlng, gMarkerOptions); //attach events if (marker.options.onMouseOver) GEvent.addListener(gMarker, "mouseover", function() { eval(marker.options.onMouseOver) }); if (marker.options.onMouseOut) GEvent.addListener(gMarker, "mouseout", function() { eval(marker.options.onMouseOut) }); if (marker.options.onClick) GEvent.addListener(gMarker, "click", function() { eval(marker.options.onClick) }); markers[marker.key] = gMarker; map.addOverlay(gMarker); if (marker.options.tooltip) { var tooltip = new Infowin(gMarker, marker.options.tooltip); map.addOverlay(tooltip); } } function setViewBox(north, east, south, west) { if (north == -Infinity || east == -Infinity || south == Infinity || west == Infinity) return; var lsw = new GLatLng(south, west); var lne = new GLatLng(north, east); var lBounds = new GLatLngBounds(lsw, lne); var zoom = map.getBoundsZoomLevel(lBounds); zoom = Math.min(zoom, 14); map.setCenter(lBounds.getCenter(), zoom); } function unload() { GUnload(); var lCanvasObject = document.getElementById(canvasId); if (lCanvasObject) jQuery(lCanvasObject).unbind("resize"); hotSpots = null; loadedHotSpots = null; tileLayer = null; options = null; lastRangeResult = null; focusTileLayer = null; } function checkHotSpots(latlng) { var spots; var cursor = 'pointer'; if (focusTileLayer) { spots = focusTileLayer.findHotSpots(latlng); } if (!spots || spots.length == 0) { spots = tileLayer.findHotSpots(latlng); lastRangeResultLayer = tileLayer; } else { lastRangeResultLayer = focusTileLayer; cursor = 'cross'; } lastRangeResult = spots; if (spots.length > 0) { map.getDragObject().setDraggableCursor('pointer'); } else { map.getDragObject().setDraggableCursor('default'); } } function initHotSpots() { tileLayer.hotSpots = null; tileLayer.loadedHotSpots = null; tileLayer.hotSpots = new KDTree.KDTree(2); tileLayer.loadedHotSpots = new KDTree.KDTree(3); if (focusTileLayer) { focusTileLayer.hotSpots = null; focusTileLayer.loadedHotSpots = null; focusTileLayer.hotSpots = new KDTree.KDTree(2); focusTileLayer.loadedHotSpots = new KDTree.KDTree(3); } } function focusByAttribute(attribute, values, icons, adaptView) { load(); var lReqUrl = "/MapHttpHandler.ashx?CacheKey=" + options.cacheKey + "&ht=3&attribute=" + attribute + "&values=" + values.join(",") + "&icons=" + icons.join(",") + "&q=" + new Date().getTime(); jQuery.getJSON(lReqUrl, '', parseResponse); function parseResponse(data, status) { if (status == "success" || status == "notmodified") { var lOptions = data; if (!lOptions) return; if (adaptView) { setViewBox(lOptions.north, lOptions.east, lOptions.south, lOptions.west); } if (!focusTileLayer) focusTileLayer = new TileLayer(this, "focused", true); focusTileLayer.setIcon(lOptions.icon); focusTileLayer.setQuery(new Date().getTime()); focusTileLayer.getOverlay().refresh(); } } } } function TileLayer(mapContext, command, getdata) { var myMap = mapContext; var command = command; var getData = getdata; var overlay = null; var icon = null; var hotSpots = new KDTree.KDTree(2); var loadedHotSpots = new KDTree.KDTree(3); var query = ""; var blMarker = null; var trMarker = null; /* public members */ this.findHotSpots = findHotSpots; this.getIcon = function () { return icon }; this.setIcon = function (o) { icon = o }; this.getQuery = function () { return query }; this.setQuery = function (o) { query = o }; this.getOverlay = function () { return overlay }; this.setOverlay = function (o) { overlay = o }; /* end public members */ function GetTileUrl(point, zoom) { if (getData && !loadedHotSpots.search(new Array(point.x, point.y, zoom))) { //Get hotspots for this tile GetTileData(point, zoom); } return "/MapHttpHandler.ashx?CacheKey=" + myMap.getOptions().cacheKey + "&ht=1&X=" + point.x + "&Y=" + point.y + "&Z=" + zoom + "&c=" + command + "&q=" + query; } function GetTileData(point, zoom) { var lReqUrl = "/MapHttpHandler.ashx?CacheKey=" + myMap.getOptions().cacheKey + "&ht=2&X=" + point.x + "&Y=" + point.y + "&Z=" + zoom + "&c=" + command + "&q=" + query; jQuery.getJSON(lReqUrl, '', function(data, status) { if (status == "success" || status == "notmodified") LoadTileData(point, zoom, data); } ); } function LoadTileData(point, zoom, sData) { loadedHotSpots.insert(new Array(point.x, point.y, zoom), true); var arrData = eval(sData); for (i = 0; i < arrData.length; i++) hotSpots.insert(arrData[i].key, arrData[i].data); } function findHotSpots(latlng) { var xy = myMap.getMap().getCurrentMapType().getProjection().fromLatLngToPixel(latlng, myMap.getMap().getZoom()); var bottomLeft = new GPoint(xy.x - icon.width + icon.offsetX, xy.y - icon.height + icon.offsetY); var topRight = new GPoint(xy.x + icon.offsetX, xy.y + icon.offsetY); var bl = new Array(xy.x - icon.width + icon.offsetX, xy.y - icon.height + icon.offsetY); var tr = new Array(xy.x + icon.offsetX, xy.y + icon.offsetY) return hotSpots.range(bl, tr, 1); } }