简体   繁体   English

我想在我的Openlayer地图上有一些坐标

[英]I want to have some coordinates on my openlayer map

i am trying to get some Dots on my Map with Openlayer. 我正在尝试使用Openlayer在我的地图上获得一些点。 The Maps works fine. 地图工作正常。 I got a JSON file with longitude and latitude and i want them to appear on my map. 我有一个具有经度和纬度的JSON文件,我希望它们出现在我的地图上。 But it is not working. 但这是行不通的。 the parsing wont work somehow. 该解析将无法正常工作。

Error 1: 错误1:
错误1

Error 2: 错误2:
错误2

JSON file: https://github.com/CodeforChemnitz/Haltestellen/blob/gh-pages/haltestellen.json JSON文件: https//github.com/CodeforChemnitz/Haltestellen/blob/gh-pages/haltestellen.json

My Code: 我的代码:

 <div class="main-container-cvag">

        <div id="map" class="map"></div>
        <script src="https://openlayersbook.github.io/openlayers_book_samples/assets/ol3/js/ol.js"></script>
        <script>

            // Declare a Tile layer with an openstreetmap
            var osmLayer = new ol.layer.Tile({
                source: new ol.source.OSM()
            });
            // latitude and longitude to Chemnitz projection
            var chemnitz = ol.proj.transform([12.9213697, 50.827845], 'EPSG:4326', 'EPSG:3857');

            // Create a View, set it center and zoom level
            var view = new ol.View({
                center: chemnitz,
                zoom: 13
            });

            //source
            var chemnitzStationSource = new ol.source.Vector();

            //dot style
            function dotstyle(feature) {
                var style = new ol.style.Style({
                    image: new ol.style.Circle({
                        radius: 6,
                        stroke: new ol.style.Stroke({
                            color: 'white',
                            width: 2
                        }),
                        fill: new ol.style.Fill({
                            color: 'green'
                        })
                    })
                });
                return [style];
            }

            //new layer
            var chemnitzStations = new ol.layer.Vector({

                source: chemnitzStationSource,
                style: dotstyle
            })

            //new Map
            var map = new ol.Map({
                target: 'map',
                layers: [osmLayer, chemnitzStations],
                view: view
            });

            $.ajax({

                url: "haltestellen.json",
                dataType: "jsonp",
                crossDomain: true,
                success: function(data) {

                    var transform = ol.proj.getTransform('EPSG:4326', 'EPSG:3857');

                    data.items.forEach(function (item) {

                        var feature = new ol.Feature(item);
                        feature.set('url', item.stations);
                        var coordinate = transform([parseFloat(item.longitude), parseFloat(item.latitude)]);
                        var geometry = new ol.geom.Point(coordinate);
                        feature.setGeometry(geometry);
                        chemnitzStationSource.addFeature(feature);
                        console.log(parseFloat(item.longitude));

                    });

                }

            });

            map.addLayer(osmLayer);
            // Set the view for the map
            map.setView(view);


        </script>

    </div>

Can someone help me what to do? 有人可以帮我怎么办吗? :) :)

You are loading JSON, but have dataType: "jsonp" . 您正在加载JSON,但具有dataType: "jsonp"
Change it to dataType: "json", . 将其更改为dataType: "json",

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我想在Openlayer地图上点击鼠标添加这些圆圈 - I want add these circles onClick of mouse on Openlayer map 我必须在jquery中阅读childs div的坐标,我想按x坐标进行排序,我的代码如下 - I have to read Coordinates of childs div in jquery and i want to sort out by x coordinates my code is below 我的 function 有问题,我不想用现有坐标创建节点 - I have a problem about my function, I don't want to create a node with existing coordinates 如何使我的OpenLayer 3贴图AutoPan与动画一起显示? - How do I make my OpenLayer 3 map AutoPan together with my animation? 如何使用Openlayer和geoJson文件更改地图中图标的样式 - How can I change the style of the icons in a map with openlayer and a geoJson file 我的 javascript、html 和 css 也没有做我想做的事。 我可以请我的待办事项列表应用程序的一些帮助 - my javascript, html and css is not doing what i want it too. can i please have some assistance with my todo list app 我在片段中有一个复选框,我希望它在单击注册按钮时发布一些数据,这个按钮在我的主要活动中吗? - I have a checkbox inside a fragment and i want it to post some data on click of a register button this button is inside my main activity? 我创建了一个只使用 JavaScript 的包含一些记录的表,我想将我的数组与对象设置为本地存储 - I have created a table with some records using with JavaScript only, I want to set my array with objects to local Storage 我有一个数据,想将所有元素映射到其他元素 - I have a data and want to map all the elements to other elements 将事件绑定到openlayer3映射 - Binding event to a openlayer3 map
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM