Ejemplo n.º 1
0
        private void OnMapViewInfoNeeded(MapViewInfoEventArgs e)
        {
            var handler = MapViewInfoNeeded;

            if (handler != null)
            {
                handler(this, e);
            }
        }
Ejemplo n.º 2
0
        void MapControlOnMapViewInfoNeeded(object sender, MapViewInfoEventArgs mapViewInfoEventArgs)
        {
            var mapView      = ModelMapView;
            var mapViewInfos = new List <MapViewInfo>();

            foreach (var obj in ((IList)MapControl.DataSource))
            {
                var    mapViewInfo = new MapViewInfo();
                string address     = GetMemberValueToString(obj, mapView.AddressMember);
                if (!string.IsNullOrEmpty(address))
                {
                    mapViewInfo.Address = address;
                }

                mapViewInfo.InfoWindowText = GetMemberValueToString(obj, mapView.InfoWindowTextMember);

                mapViewInfo.Latitude  = GetMemberValue <decimal?>(obj, mapView.LatitudeMember);
                mapViewInfo.Longitude = GetMemberValue <decimal?>(obj, mapView.LongitudeMember);
                mapViewInfos.Add(mapViewInfo);
            }
            mapViewInfoEventArgs.MapViewInfos = mapViewInfos;
        }
Ejemplo n.º 3
0
        protected override string GetStartupScript()
        {
            var sb = new StringBuilder();

            sb.AppendLine("var adjustSizeOverride = " + XpandLayoutManager.GetAdjustSizeScript());
            sb.AppendLine("adjustSizeOverride();");
            sb.AppendFormat("var div = document.getElementById('{0}');", div.ClientID);
            sb.AppendLine("window.ElementToResize = div;");
            sb.AppendLine("var initMap = function() { ");

            sb.AppendFormat(@"{0}
                var parentSplitter = XpandHelper.GetElementParentControl(div);
                if (parentSplitter && !parentSplitter.xpandInitialized) {{
                    window.setTimeout(initMap, 500);
                    return;
                }}
            

            ", XpandLayoutManager.GetXpandHelperScript(), div.ClientID);

            sb.AppendLine("var mapOptions = {");
            sb.AppendLine("zoom: 4,");
            sb.AppendLine("mapTypeId: google.maps.MapTypeId.ROADMAP }");
            sb.AppendFormat(" var map = new google.maps.Map(document.getElementById('{0}'), mapOptions);\r\n",
                            div.ClientID);

            sb.AppendLine("var geocoder = new google.maps.Geocoder();");
            sb.AppendLine(@"var addMarkerClickEvent = function(marker, objectId) {
                                google.maps.event.addListener(marker, 'click', function() {");
            sb.AppendLine(@"if (marker.infoWindow) marker.infoWindow.open(map, marker);");


            sb.AppendLine(@"var markerCallback = function (s,e) {");
            if (PerformCallbackOnMarker)
            {
                sb.Append(@"
                    var up = XpandHelper.GetFirstChildControl(parentSplitter.GetPane(1).GetElement().childNodes[0]);
                    if (up && up.GetMainElement()) {{ 
                        up.PerformCallback(objectId);}}");
            }
            sb.AppendLine("};");

            sb.AppendLine("var arg = 'd1:' + objectId;");
            sb.AppendLine(RenderUtils.GetCallbackEventReference(Page, this, "arg", "markerCallback", "'" + ClientID + "'",
                GetCallBackErrorHandlerName()) + ";");

            sb.AppendLine(" });};");

            sb.AppendLine("var bounds = new google.maps.LatLngBounds ();");
            sb.AppendLine("var createMarker = function(location, objectId, fitBounds, infoWindowContent, infoWindowMaxWidth) {");
            sb.AppendLine(@" 
                           
                              var marker = new google.maps.Marker({
                                  map: map,
                                  position: location
                              
                              });
                              if (infoWindowContent) {
                                marker.infoWindow = new google.maps.InfoWindow({
                                    content: infoWindowContent,
                                    maxWidth: infoWindowMaxWidth
                                });
                              }
        
                              addMarkerClickEvent(marker, objectId);  
                              bounds.extend(location);  
                              if (fitBounds) map.fitBounds(bounds);
                              
                         }");

            sb.AppendLine(@"
                        var geoCodeQueue = new Array();
                        var createMarkersWithGeoCode = function() {
                                if (geoCodeQueue.length == 0) {
                                    console.log('resizing...');
                                    google.maps.event.trigger(map, 'resize');
                                    window.AdjustSize();
                                    map.fitBounds(bounds);
                                    return;
                                }

                                var info = geoCodeQueue.pop();
                                console.log(info.address);
                                geocoder.geocode( { 'address': info.address}, function(results, status) {
                                    if (status == google.maps.GeocoderStatus.OK) {
                                        console.log('geocode: success');
                                        info.onSuccess(results);
                                    } 
                                    else if (status == google.maps.GeocoderStatus.OVER_QUERY_LIMIT) {
                                        geoCodeQueue.push(info);
                                        window.setTimeout(function () { createMarkersWithGeoCode(); }, 1000);
                                        return;
                                    }
                                    else {
                                        console.error('Geocode was not successful for the following reason: ' + status);
                                    }
                                    createMarkersWithGeoCode();   
                                 });
                                
                                
                            }");

            sb.AppendLine("var createMarkerWithGeocode = function(address, objectId, fitBounds, infoWindowContent, infoWindowMaxWidth) {");
            sb.AppendLine(@"geoCodeQueue.push( {'address': address, 'onSuccess': function(results) {
                              console.log('Success ' + address);
                              createMarker(results[0].geometry.location, objectId, fitBounds, infoWindowContent, infoWindowMaxWidth);  
                            }});}");


            bool useGeoCode = false;

            if (DataSource != null)
            {
                var list = DataSource as IList;
                if (list != null)
                {
                    sb.AppendLine("var marker, infoWindow;");
                    var mapViewInfoEventArgs = new MapViewInfoEventArgs();
                    OnMapViewInfoNeeded(mapViewInfoEventArgs);
                    int index = 0;
                    if (mapViewInfoEventArgs.MapViewInfos != null)
                    {
                        foreach (var mapViewInfo in mapViewInfoEventArgs.MapViewInfos)
                        {
                            string infoWindowText = "undefined";
                            if (!string.IsNullOrEmpty(mapViewInfo.InfoWindowText))
                            {
                                infoWindowText = GetInfoWindowText(mapViewInfo);
                            }

                            if (mapViewInfo.Longitude != null && mapViewInfo.Latitude != null)
                            {

                                sb.AppendFormat(CultureInfo.InvariantCulture,
                                           "createMarker(new google.maps.LatLng({0},{1}), '{2}', {3}, '{4}', {5});\r\n",
                                    mapViewInfo.Latitude, mapViewInfo.Longitude, index,
                                    (index == list.Count - 1).ToString(CultureInfo.InvariantCulture).ToLower(),
                                    infoWindowText, InfoWindowWidth);
                            }
                            else if (!string.IsNullOrWhiteSpace(mapViewInfo.Address))
                            {
                                useGeoCode = true;
                                sb.AppendFormat(CultureInfo.InvariantCulture,
                                                "createMarkerWithGeocode('{0}', '{1}', {2}, '{3}', {4});\r\n",
                                                mapViewInfo.Address, index,
                                                (index == list.Count - 1).ToString(CultureInfo.InvariantCulture).ToLower(),
                                                infoWindowText, InfoWindowWidth);
                            }
                            index++;
                        }

                    }
                }
            }


            if (useGeoCode)
            {

                sb.AppendLine("createMarkersWithGeoCode();");
            }
            else
            {
                sb.AppendLine("window.AdjustSize();");
                sb.AppendLine("google.maps.event.trigger(map, 'resize');");
            }

            sb.AppendLine("};");
            sb.AppendLine("window.setTimeout(initMap, 500);");
            return sb.ToString();
        }
Ejemplo n.º 4
0
 private void OnMapViewInfoNeeded(MapViewInfoEventArgs e)
 {
     var handler = MapViewInfoNeeded;
     if (handler != null) handler(this, e);
 }
Ejemplo n.º 5
0
        protected override string GetStartupScript()
        {
            var sb = new StringBuilder();

            sb.AppendLine("var adjustSizeOverride = " + XpandLayoutManager.GetAdjustSizeScript());
            sb.AppendLine("adjustSizeOverride();");
            sb.AppendFormat("var div = document.getElementById('{0}');", div.ClientID);
            sb.AppendLine("window.ElementToResize = div;");
            sb.AppendLine("var initMap = function() { ");

            sb.AppendFormat(@"{0}
                var parentSplitter = XpandHelper.GetElementParentControl(div);
                if (parentSplitter && !parentSplitter.xpandInitialized) {{
                    window.setTimeout(initMap, 500);
                    return;
                }}
            

            ", XpandLayoutManager.GetXpandHelperScript(), div.ClientID);

            sb.AppendLine("var mapOptions = {");
            sb.AppendLine("zoom: 4,");
            sb.AppendLine("mapTypeId: google.maps.MapTypeId.ROADMAP }");
            sb.AppendFormat(" var map = new google.maps.Map(document.getElementById('{0}'), mapOptions);\r\n",
                            div.ClientID);

            sb.AppendLine("var geocoder = new google.maps.Geocoder();");
            sb.AppendLine(@"var addMarkerClickEvent = function(marker, objectId) {
                                google.maps.event.addListener(marker, 'click', function() {");
            sb.AppendLine(@"if (marker.infoWindow) marker.infoWindow.open(map, marker);");


            sb.AppendLine(@"var markerCallback = function (s,e) {");
            if (PerformCallbackOnMarker)
            {
                sb.Append(@"
                    var up = XpandHelper.GetFirstChildControl(parentSplitter.GetPane(1).GetElement().childNodes[0]);
                    if (up && up.GetMainElement()) {{ 
                        up.PerformCallback(objectId);}}");
            }
            sb.AppendLine("};");

            sb.AppendLine("var arg = 'd1:' + objectId;");
            sb.AppendLine(RenderUtils.GetCallbackEventReference(Page, this, "arg", "markerCallback", "'" + ClientID + "'",
                                                                GetCallBackErrorHandlerName()) + ";");

            sb.AppendLine(" });};");

            sb.AppendLine("var bounds = new google.maps.LatLngBounds ();");
            sb.AppendLine("var createMarker = function(location, objectId, fitBounds, infoWindowContent, infoWindowMaxWidth) {");
            sb.AppendLine(@" 
                           
                              var marker = new google.maps.Marker({
                                  map: map,
                                  position: location
                              
                              });
                              if (infoWindowContent) {
                                marker.infoWindow = new google.maps.InfoWindow({
                                    content: infoWindowContent,
                                    maxWidth: infoWindowMaxWidth
                                });
                              }
        
                              addMarkerClickEvent(marker, objectId);  
                              bounds.extend(location);  
                              if (fitBounds) map.fitBounds(bounds);
                              
                         }");

            sb.AppendLine(@"
                        var geoCodeQueue = new Array();
                        var createMarkersWithGeoCode = function() {
                                if (geoCodeQueue.length == 0) {
                                    console.log('resizing...');
                                    google.maps.event.trigger(map, 'resize');
                                    window.AdjustSize();
                                    map.fitBounds(bounds);
                                    return;
                                }

                                var info = geoCodeQueue.pop();
                                console.log(info.address);
                                geocoder.geocode( { 'address': info.address}, function(results, status) {
                                    if (status == google.maps.GeocoderStatus.OK) {
                                        console.log('geocode: success');
                                        info.onSuccess(results);
                                    } 
                                    else if (status == google.maps.GeocoderStatus.OVER_QUERY_LIMIT) {
                                        geoCodeQueue.push(info);
                                        window.setTimeout(function () { createMarkersWithGeoCode(); }, 1000);
                                        return;
                                    }
                                    else {
                                        console.error('Geocode was not successful for the following reason: ' + status);
                                    }
                                    createMarkersWithGeoCode();   
                                 });
                                
                                
                            }");

            sb.AppendLine("var createMarkerWithGeocode = function(address, objectId, fitBounds, infoWindowContent, infoWindowMaxWidth) {");
            sb.AppendLine(@"geoCodeQueue.push( {'address': address, 'onSuccess': function(results) {
                              console.log('Success ' + address);
                              createMarker(results[0].geometry.location, objectId, fitBounds, infoWindowContent, infoWindowMaxWidth);  
                            }});}");


            bool useGeoCode = false;

            if (DataSource != null)
            {
                var list = DataSource as IList;
                if (list != null)
                {
                    sb.AppendLine("var marker, infoWindow;");
                    var mapViewInfoEventArgs = new MapViewInfoEventArgs();
                    OnMapViewInfoNeeded(mapViewInfoEventArgs);
                    int index = 0;
                    if (mapViewInfoEventArgs.MapViewInfos != null)
                    {
                        foreach (var mapViewInfo in mapViewInfoEventArgs.MapViewInfos)
                        {
                            string infoWindowText = "undefined";
                            if (!string.IsNullOrEmpty(mapViewInfo.InfoWindowText))
                            {
                                infoWindowText = GetInfoWindowText(mapViewInfo);
                            }

                            if (mapViewInfo.Longitude != null && mapViewInfo.Latitude != null)
                            {
                                sb.AppendFormat(CultureInfo.InvariantCulture,
                                                "createMarker(new google.maps.LatLng({0},{1}), '{2}', {3}, '{4}', {5});\r\n",
                                                mapViewInfo.Latitude, mapViewInfo.Longitude, index,
                                                (index == list.Count - 1).ToString(CultureInfo.InvariantCulture).ToLower(),
                                                infoWindowText, InfoWindowWidth);
                            }
                            else if (!string.IsNullOrWhiteSpace(mapViewInfo.Address))
                            {
                                useGeoCode = true;
                                sb.AppendFormat(CultureInfo.InvariantCulture,
                                                "createMarkerWithGeocode('{0}', '{1}', {2}, '{3}', {4});\r\n",
                                                mapViewInfo.Address, index,
                                                (index == list.Count - 1).ToString(CultureInfo.InvariantCulture).ToLower(),
                                                infoWindowText, InfoWindowWidth);
                            }
                            index++;
                        }
                    }
                }
            }


            if (useGeoCode)
            {
                sb.AppendLine("createMarkersWithGeoCode();");
            }
            else
            {
                sb.AppendLine("window.AdjustSize();");
                sb.AppendLine("google.maps.event.trigger(map, 'resize');");
            }

            sb.AppendLine("};");
            sb.AppendLine("window.setTimeout(initMap, 500);");
            return(sb.ToString());
        }