예제 #1
0
    private void DisplayLayersSelector(ref WMSTexture wmsTexture, WMSInfo wmsInfo, out bool layerChanged)
    {
        layerChanged = false;

        EditorGUILayout.BeginVertical(EditorStyles.helpBox);
        EditorGUILayout.LabelField("Layers");

        WMSLayer[] layers = wmsInfo.layers;
        for (int i = 0; i < layers.Length; i++)
        {
            if (layers[i].name != "")
            {
                bool newToggleValue =
                    EditorGUILayout.ToggleLeft(layers[i].title, (wmsTexture.LayerSelected(layers[i].name)));

                layerChanged |= (newToggleValue != wmsTexture.LayerSelected(layers[i].name));
                wmsTexture.SetLayerSelected(layers[i].name, newToggleValue);
            }
        }

        if (wmsTexture.SelectedLayersNumber() == 0)
        {
            EditorGUILayout.HelpBox("No layers selected", MessageType.Warning);
        }

        EditorGUILayout.EndVertical();
    }
예제 #2
0
    public void OnEnable()
    {
        WMSTexture wmsTexture = (WMSTexture)target;

        if (!Application.isPlaying && (wmsTexture.wmsRequestID == "" || !wmsInfoRequester.ExistsTransaction(wmsTexture.wmsRequestID)))
        {
            RequestWMSInfo(ref wmsTexture);
        }
    }
예제 #3
0
    public void Refresh()
    {
        WMSTexture wmsTexture = (WMSTexture)target;

        if (wmsInfoRequester.Update(wmsTexture.wmsRequestID) != RequestStatus.DOWNLOADING)
        {
            // Stop refreshing when server download stops.
            EditorApplication.update -= Refresh;
            Repaint();
        }
    }
예제 #4
0
    protected override void InnerCopyTo(OnlineTexture copy)
    {
        WMSTexture target = (WMSTexture)copy;

        target.serverURL             = serverURL;
        target.wmsRequestID          = wmsRequestID;
        target.keepBoundingBoxRatio  = keepBoundingBoxRatio;
        target.bottomLeftCoordinates = bottomLeftCoordinates;
        target.topRightCoordinates   = topRightCoordinates;
        target.selectedLayers        = selectedLayers;
        target.wmsVersion            = wmsVersion;
        target.SRS = SRS;
    }
예제 #5
0
    private void DisplayServerPopup(ref WMSTexture wmsTexture, ref bool serverChanged)
    {
        string[] serverTitles = bookmarks.ServerTitles();

        int newServerIndex = EditorGUILayout.Popup("Bookmarked servers", 0, serverTitles);

        serverChanged = (newServerIndex != 0 && bookmarks.GetServerURL(serverTitles[newServerIndex]) != wmsTexture.serverURL);

        if (serverChanged)
        {
            wmsTexture.serverURL = bookmarks.GetServerURL(serverTitles[newServerIndex]);
        }
    }
예제 #6
0
    private void DisplayBoundingBoxSelector(ref WMSTexture wmsTexture, WMSInfo wmsInfo, out bool boundingBoxChanged)
    {
        boundingBoxChanged = false;

        List <string> boundingBoxesNames = wmsInfo.GetBoundingBoxesNames(wmsTexture.selectedLayers).ToList();

        boundingBoxesNames.Insert(0, "Select bounding box from server");

        if (boundingBoxesNames.Count > 1)
        {
            int newBoundingBoxIndex =
                EditorGUILayout.Popup(
                    "BBs from server",
                    0,
                    boundingBoxesNames.ToArray()
                    ) - 1;

            boundingBoxChanged = (newBoundingBoxIndex != -1);

            if (boundingBoxChanged)
            {
                wmsTexture.SRS = wmsInfo.GetBoundingBox(wmsTexture.selectedLayers, newBoundingBoxIndex).SRS;
                WMSBoundingBox currentBoundingBox = wmsInfo.GetBoundingBox(wmsTexture.selectedLayers, newBoundingBoxIndex);

                wmsTexture.bottomLeftCoordinates = currentBoundingBox.bottomLeftCoordinates;
                wmsTexture.topRightCoordinates   = currentBoundingBox.topRightCoordinates;

                wmsTexture.RequestTexturePreview();
            }
            else
            {
                if (wmsTexture.selectedLayers.Count == 1)
                {
                    // If we have one layer selected, use the SRS of its first bounding box.
                    wmsTexture.SRS = wmsInfo.GetBoundingBox(wmsTexture.selectedLayers, 0).SRS;
                }
            }
        }
    }
예제 #7
0
    public void DisplayBoundingBoxPanel(ref WMSTexture wmsTexture, ref WMSInfo wmsInfo, out bool boundingBoxChanged)
    {
        EditorGUILayout.BeginVertical(EditorStyles.helpBox);

        EditorGUILayout.LabelField("Bounding Box");

        DisplayBoundingBoxSelector(ref wmsTexture, wmsInfo, out boundingBoxChanged);

        EditorGUILayout.LabelField("SRS", wmsTexture.SRS);

        wmsTexture.keepBoundingBoxRatio =
            EditorGUILayout.Toggle("Keep ratio", wmsTexture.keepBoundingBoxRatio);

        Vector2 newBottomLeftCoordinates =
            EditorGUILayout.Vector2Field(
                "Bottom left coords.",
                wmsTexture.bottomLeftCoordinates
                );

        Vector2 newTopRightCoordinates =
            EditorGUILayout.Vector2Field(
                "Top right coords.",
                wmsTexture.topRightCoordinates
                );

        UpdateBoundingBox(
            ref wmsTexture.bottomLeftCoordinates,
            ref wmsTexture.topRightCoordinates,
            newBottomLeftCoordinates,
            newTopRightCoordinates,
            wmsTexture.keepBoundingBoxRatio);

        if (GUILayout.Button("Update bounding box preview (may take a while)"))
        {
            wmsTexture.RequestTexturePreview();
        }

        EditorGUILayout.EndVertical();
    }
예제 #8
0
    private void DisplayServerSelector(ref WMSTexture wmsTexture, out bool serverChanged)
    {
        serverChanged = false;

        DisplayServerPopup(ref wmsTexture, ref serverChanged);

        string newServerURL = EditorGUILayout.TextField("Server URL:", wmsTexture.serverURL);

        serverChanged       |= (newServerURL != wmsTexture.serverURL);
        wmsTexture.serverURL = newServerURL;

        if ((wmsTexture.wmsRequestID != "") && (wmsInfoRequester.GetRequestStatus(wmsTexture.wmsRequestID) == RequestStatus.OK))
        {
            WMSInfo wmsInfo =
                wmsInfoRequester.GetResponse(wmsTexture.wmsRequestID);

            if (!bookmarks.ServerIsBookmarked(wmsInfo.serverTitle))
            {
                DisplayServerBookmarkButton(wmsInfo.serverTitle, wmsTexture.serverURL);
                //} else {
                //	RemoveServerFromBookmarksButton (requestStatus.response.serverTitle);
            }
        }
    }
예제 #9
0
    public override void OnInspectorGUI()
    {
        if (Application.isPlaying)
        {
            EditorGUILayout.LabelField("Currently play mode editting is not allowed");
            return;
        }

        WMSTexture wmsTexture = (WMSTexture)target;

        bool serverChanged      = false;
        bool layerChanged       = false;
        bool boundingBoxChanged = false;

        EditorGUILayout.BeginVertical(EditorStyles.helpBox);
        EditorGUILayout.LabelField("Server");
        DisplayServerSelector(ref wmsTexture, out serverChanged);

        if (serverChanged)
        {
            wmsTexture.selectedLayers.Clear();
            RequestWMSInfo(ref wmsTexture);
        }

        RequestStatus requestStatus =
            wmsInfoRequester.GetRequestStatus(wmsTexture.wmsRequestID);

        if (requestStatus != RequestStatus.OK)
        {
            if (requestStatus == RequestStatus.DOWNLOADING)
            {
                EditorGUILayout.HelpBox("Downloading WMS info ...", MessageType.Info);
            }
            else if (requestStatus == RequestStatus.ERROR)
            {
                string errorLog = wmsInfoRequester.GetErrorLog(wmsTexture.wmsRequestID);
                EditorGUILayout.HelpBox("ERROR downloading WMS info: \n" + errorLog, MessageType.Error);
            }

            if (GUI.changed)
            {
                EditorUtility.SetDirty(wmsTexture);
                EditorSceneManager.MarkSceneDirty(EditorSceneManager.GetActiveScene());
            }
            EditorGUILayout.EndVertical();
            return;
        }

        WMSInfo wmsInfo = wmsInfoRequester.GetResponse(wmsTexture.wmsRequestID);

        EditorGUILayout.LabelField("Server title: " + wmsInfo.serverTitle);
        EditorGUILayout.LabelField("Server abstract: " + wmsInfo.serverAbstract);
        EditorGUILayout.EndVertical();

        if (wmsInfo.GetLayerTitles().Length > 0)
        {
            DisplayLayersSelector(ref wmsTexture, wmsInfo, out layerChanged);

            if (layerChanged)
            {
                wmsTexture.RequestTexturePreview();
            }

            if (wmsTexture.SelectedLayersNumber() > 0)
            {
                DisplayBoundingBoxPanel(ref wmsTexture, ref wmsInfo, out boundingBoxChanged);
            }
        }
        else
        {
            EditorGUILayout.HelpBox("No layers returned by server", MessageType.Warning);
        }


        if (wmsTexture.IsDownloading())
        {
            EditorGUILayout.HelpBox("Downloading texture from server...", MessageType.Info);
        }


        // Mark the target assert as changed ("dirty") so Unity save it to disk.
        if (GUI.changed)
        {
            EditorUtility.SetDirty(wmsTexture);
            EditorSceneManager.MarkSceneDirty(EditorSceneManager.GetActiveScene());
        }
    }
예제 #10
0
 private void RequestWMSInfo(ref WMSTexture wmsTexture)
 {
     wmsTexture.wmsRequestID = wmsInfoRequester.RequestServerInfo(wmsTexture.serverURL);
     wmsTexture.RequestTexturePreview();
     EditorApplication.update += Refresh;
 }