簡體   English   中英

在特定坐標中顯示圖標(OpenLayers)

[英]Show an icon in certain coordinates (OpenLayers)

我正在使用 OpenLayers 開發 map,但無論我輸入哪個坐標,圖標始終顯示在非洲海岸(坐標 0,0)。 不幸的是,openlayers web 中的所有示例都在坐標 0,0 中。

這是我到目前為止所嘗試的:

var iconFeature = new ol.Feature({
            geometry: new ol.geom.Point([126.95, 37.5333]),  <--- HERE I INPUT MY COORDINATES
            name: 'Null',
        });

        var iconStyle = new ol.style.Style({
        image: new ol.style.Icon({
            anchor: [0.5, 46],
            anchorXUnits: 'fraction',
            anchorYUnits: 'pixels',
            src: 'https://image.flaticon.com/icons/svg/1673/1673221.svg',
            scale: 0.0625
        })
        });

        iconFeature.setStyle(iconStyle);

        var vectorSource = new ol.source.Vector({
        features: [iconFeature]
        });

        var vectorLayer = new ol.layer.Vector({
        source: vectorSource
        });

        var map = new ol.Map({
            target: 'gmap',
            layers: [
                new ol.layer.Tile({
                    source: new ol.source.OSM()
                }), vectorLayer
            ],
            view: new ol.View({
                // center: ol.proj.fromLonLat([126.95, 37.5333]),
                center: ol.proj.fromLonLat([IvreWebUiService.currentHost.infos.coordinates[1], IvreWebUiService.currentHost.infos.coordinates[0]]),
                zoom: 13
            })
        });

我也在使用 Openlayers 的經度要求,然后是圖標坐標的緯度。 歡迎任何可能的解決方案。 謝謝。

地理坐標必須轉換為投影平面,例如:

geometry: new ol.geom.Point(ol.proj.transform([126.95, 37.5333], "EPSG:4326", "EPSG:3857"))

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM