How to find the offset value of the Polygon from center on Openlayers

巧了我就是萌 提交于 2019-12-08 07:02:41

问题


i calculated the (x1,Y1) and (x2,Y2) and calculated the difference between them (Blue line ) and gave those pixel values to driver to click but i am not able to click on the polygon (Point). 1.First the mouse will go to center of the map where (x1,y1)=(960,520) according to the window but the driver will consider those values as (0,0). 2. Now i need to calculate the offset values from center to each polygon on the map.(x1,y1)=(960,520) and (x2,y2)=(1000,232)

the difference between the (x1,y1) and (x2,y2) will give me the distance of the point from center.for ex:(x3,y3)

the code below

try {
            driver.get("http://localhost:8090/demo/");
            System.out.println("demo opened");
            Thread.sleep(15000);

            WebElement can = driver.findElements(By.tagName("canvas")).get(0);
            Actions builder = new Actions(driver);
            builder.moveToElement(can,0,0).click().perform();
            Thread.sleep(12000);

            WebElement eler1x = driver
                    .findElement(By.xpath("/html/body/div[2]/div/div/div/div[3]/div/div/div[17]/div"));
            String val1 = eler1x.getText();
            System.out.println(val1);
            WebElement eler1y = driver
                    .findElement(By.xpath("/html/body/div[2]/div/div/div/div[3]/div/div/div[19]/div"));
            String val2 = eler1y.getText();
            System.out.println(val2);
            double x1 = Double.parseDouble(val1);
        //error line    double y1 = Double.parseDouble(val1);
            double y1 = Double.parseDouble(val2);
            int r2x1 = (int) x1;
            int r2y1 = (int) y1;
            builder.moveByOffset(r2x1, r2y1);
            builder.click().build().perform();
            System.out.println("executed");

        } catch (Exception e) {
            System.out.println(e);
        }

i gave the difference between (x3,Y3) as offset value for the driver , the test case passed but no click on the point or polygon .can anyone give example or suggestion how to calculate the offset values on the Openlayers

来源:https://stackoverflow.com/questions/51633480/how-to-find-the-offset-value-of-the-polygon-from-center-on-openlayers

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!