コード例 #1
0
ファイル: Page.cs プロジェクト: fugaku/scriptsharp
        static Page() {
            if (Document.Body.GetAttribute("data-app") == null) {
                return;
            }

            string flickrKey = (string)Document.Body.GetAttribute("data-flickr-key");
            Debug.Assert(String.IsNullOrEmpty(flickrKey) == false);

            string bingMapsKey = (string)Document.Body.GetAttribute("data-bingmaps-key");
            Debug.Assert(String.IsNullOrEmpty(bingMapsKey) == false);

            _tileUrlFormat = (string)Document.Body.GetAttribute("data-tile-url");
            Debug.Assert(String.IsNullOrEmpty(_tileUrlFormat) == false);

            _model = new PageModel(new FlickrService(flickrKey), new HtmlStorageService());
            _model.PropertyChanged += delegate(object sender, PropertyChangedEventArgs e) {
                if (e.PropertyName == "Searching") {
                    Element progressElement = Utility.GetElement("searchProgress");
                    if (_model.Searching) {
                        progressElement.ClassName = "active";
                    }
                    else {
                        progressElement.ClassName = "";
                    }
                }
                else if (e.PropertyName == "Photos") {
                    if (_model.SelectedPhoto != null) {
                        ShowPhoto(null);
                    }

                    UpdatePhotos(/* newPhotos */ true);
                }
            };

            MapOptions mapOptions = new MapOptions();
            mapOptions.Credentials = bingMapsKey;
            mapOptions.ShowMapTypeSelector = false;
            mapOptions.ShowDashboard = false;
            mapOptions.ShowScalebar = false;
            mapOptions.ShowCopyright = false;
            mapOptions.ShowLogo = false;
            mapOptions.MapType = MapType.Custom;
            mapOptions.Zoom = 2;
            mapOptions.BackgroundColor = new MapColor(255, 255, 255, 255);
            _map = new Map(Utility.GetElement("mapContainer"), mapOptions);

            MapTileSourceOptions sourceOptions = new MapTileSourceOptions();
            sourceOptions.UriGenerator = CreateTileUrl;

            MapTileLayerOptions layerOptions = new MapTileLayerOptions();
            layerOptions.Mercator = new MapTileSource(sourceOptions);
            _map.Entities.Push(new MapTileLayer(layerOptions));

            MapEvents.AddHandler(_map, "viewchangestart", delegate(MapEventArgs e) {
                _viewChanging = true;
                _zoomLevel = _map.GetZoom();
            });
            MapEvents.AddThrottledHandler(_map, "viewchangeend", delegate(MapEventArgs e) {
                _viewChanging = false;

                if (_zoomLevel != _map.GetZoom()) {
                    UpdatePhotos(/* newPhotos */ false);
                }
            }, 250);
            MapEvents.AddHandler(_map, "mousedown", delegate(MapEventArgs e) {
                _oldMode = Document.Body.ClassName;
                Document.Body.ClassName = MapModeClassName;
            });
            MapEvents.AddHandler(_map, "mouseup", delegate(MapEventArgs e) {
                Document.Body.ClassName = _oldMode;
            });

            Utility.SubscribeKey("searchBox", delegate(ElementEvent e) {
                Window.SetTimeout(delegate() {
                    Document.GetElementById("searchButton").ClassName =
                        String.IsNullOrEmpty(Utility.GetElement("searchBox").As<InputElement>().Value) ? "reset" : "";
                }, 0);
            });
            Utility.SubscribeBlur("searchBox", delegate(ElementEvent e) {
                Window.SetTimeout(delegate() {
                    Document.GetElementById("searchButton").ClassName = "";
                }, 0);
            });
            Utility.SubscribeClick("searchButton", delegate(ElementEvent e) {
                Search(Utility.GetElement("searchBox").As<InputElement>().Value);
                Document.ActiveElement.Blur();
            });
            Utility.SubscribeClick("locateMeButton", delegate(ElementEvent e) {
                ShowLocation();
            });
            Utility.SubscribeClick("favButton", delegate(ElementEvent e) {
                ShowFavorites();
            });

            Utility.SubscribeClick("photoAroundButton", delegate(ElementEvent e) {
                SearchSimilar();
            });
            Utility.SubscribeClick("photoCloseButton", delegate(ElementEvent e) {
                HidePhoto();
            });
            Utility.SubscribeClick("photoSaveButton", delegate(ElementEvent e) {
                FavoritePhoto();
            });
            Utility.SubscribeClick("photoShareButton", delegate(ElementEvent e) {
                SharePhoto();
            });
            Utility.SubscribeClick("photoSourceButton", delegate(ElementEvent e) {
                ShowPhotoFlickrPage();
            });

            ShowLocation();
        }
コード例 #2
0
        static Page()
        {
            string flickrKey = (string)Document.Body.GetAttribute("data-flickr-key");

            Debug.Assert(String.IsNullOrEmpty(flickrKey) == false);

            string bingMapsKey = (string)Document.Body.GetAttribute("data-bingmaps-key");

            Debug.Assert(String.IsNullOrEmpty(bingMapsKey) == false);

            _tileUrlFormat = (string)Document.Body.GetAttribute("data-tile-url");
            Debug.Assert(String.IsNullOrEmpty(_tileUrlFormat) == false);

            _model = new PageModel(new FlickrService(flickrKey), new HtmlStorageService());
            _model.PropertyChanged += delegate(object sender, PropertyChangedEventArgs e) {
                if (e.PropertyName == "Searching")
                {
                    Element progressElement = Utility.GetElement("searchProgress");
                    if (_model.Searching)
                    {
                        progressElement.ClassName = "active";
                    }
                    else
                    {
                        progressElement.ClassName = "";
                    }
                }
                else if (e.PropertyName == "Photos")
                {
                    if (_model.SelectedPhoto != null)
                    {
                        ShowPhoto(null);
                    }

                    UpdatePhotos(/* newPhotos */ true);
                }
            };

            MapOptions mapOptions = new MapOptions();

            mapOptions.Credentials         = bingMapsKey;
            mapOptions.ShowMapTypeSelector = false;
            mapOptions.ShowDashboard       = false;
            mapOptions.ShowScalebar        = false;
            mapOptions.ShowCopyright       = false;
            mapOptions.ShowLogo            = false;
            mapOptions.MapType             = MapType.Custom;
            mapOptions.Zoom            = 2;
            mapOptions.BackgroundColor = new MapColor(255, 255, 255, 255);
            _map = new Map(Utility.GetElement("mapContainer"), mapOptions);

            MapTileSourceOptions sourceOptions = new MapTileSourceOptions();

            sourceOptions.UriGenerator = CreateTileUrl;

            MapTileLayerOptions layerOptions = new MapTileLayerOptions();

            layerOptions.Mercator = new MapTileSource(sourceOptions);
            _map.Entities.Push(new MapTileLayer(layerOptions));

            MapEvents.AddHandler(_map, "viewchangestart", delegate(MapEventArgs e) {
                _viewChanging = true;
                _zoomLevel    = _map.GetZoom();
            });
            MapEvents.AddThrottledHandler(_map, "viewchangeend", delegate(MapEventArgs e) {
                _viewChanging = false;

                if (_zoomLevel != _map.GetZoom())
                {
                    UpdatePhotos(/* newPhotos */ false);
                }
            }, 250);
            MapEvents.AddHandler(_map, "mousedown", delegate(MapEventArgs e) {
                _oldMode = Document.Body.ClassName;
                Document.Body.ClassName = MapModeClassName;
            });
            MapEvents.AddHandler(_map, "mouseup", delegate(MapEventArgs e) {
                Document.Body.ClassName = _oldMode;
            });

            Utility.SubscribeKey("searchBox", delegate(ElementEvent e) {
                Window.SetTimeout(delegate() {
                    Document.GetElementById("searchButton").ClassName =
                        String.IsNullOrEmpty(Utility.GetElement("searchBox").As <InputElement>().Value) ? "reset" : "";
                }, 0);
            });
            Utility.SubscribeBlur("searchBox", delegate(ElementEvent e) {
                Window.SetTimeout(delegate() {
                    Document.GetElementById("searchButton").ClassName = "";
                }, 0);
            });
            Utility.SubscribeClick("searchButton", delegate(ElementEvent e) {
                Search(Utility.GetElement("searchBox").As <InputElement>().Value);
                Document.ActiveElement.Blur();
            });
            Utility.SubscribeClick("locateMeButton", delegate(ElementEvent e) {
                ShowLocation();
            });
            Utility.SubscribeClick("favButton", delegate(ElementEvent e) {
                ShowFavorites();
            });

            Utility.SubscribeClick("photoAroundButton", delegate(ElementEvent e) {
                SearchSimilar();
            });
            Utility.SubscribeClick("photoCloseButton", delegate(ElementEvent e) {
                HidePhoto();
            });
            Utility.SubscribeClick("photoSaveButton", delegate(ElementEvent e) {
                FavoritePhoto();
            });
            Utility.SubscribeClick("photoShareButton", delegate(ElementEvent e) {
                SharePhoto();
            });
            Utility.SubscribeClick("photoSourceButton", delegate(ElementEvent e) {
                ShowPhotoFlickrPage();
            });

            ShowLocation();
        }