1
votes

UPDATE: The basic question is, if my GeoJSON delivered by the REST interface (Json data is visible at end of question) is a valid GeoJSON for the vector layer, because as soon as i add this as source for the vector layer, the layer is broken.

Currently there is no REST Interface to upload shapes, so i just took some valid coordinates from current shapes and created a static JSON on serverside

I try to make it possible that users can draw shapes (Polygons, Lines) on a vector layer and the i store the geometric data on a server and the next time the map is loaded it should be displayed again. But it seems somehow when i define my REST interface as source for the vector layer, that there is some problem as painting and adding objects into the vector layer does not work anymore.

Here the code i put together from OpenLayers Examples. First an image how it should look like:

Shapes how they should be displayed I extracted the coordinates on the map with drawend event and built a REST interface where i could load the geometric data, this is the response i get for the vector layer source:

{
   "type":"FeatureCollection",
   "crs":{
      "type":"name",
      "properties":{
         "name":"EPSG:2000"
      }
   },
   "features":[
      {
         "type":"Feature",
         "id":"1",
         "properties":{
            "name":"TEST1"
         },
         "geometry":{
            "type":"LineString",
            "coordinates":[
               [
                  -5920506.46285661,
                  1533632.5355137766
               ],
               [
                  -1882185.384494179,
                  234814.55089206155
               ]
            ]
         }
      }
   ]
}

But if i load this, nothing will be displayed and its not possible to draw on the layer anymore (if i remove the "source" attribute from the vector layer source it works again)

Here the complete code on pastebin: Example Code

1
Please, simplify your question to a single issue. Put on a jsFiddle what is exactly not working.Jonatas Walker
Sorry for the late answer. Bascially all i ask is, if my defined source for the vector layer in Lines 52-56 of my pastebin, deliver a syntactic correct json for initializing the vector layer and draw a line. If i only change the source from my specified json source to a default vector source, or even if just my js link is invalid, it works. I would like to add a JS Fiddle, but as all important parts are delivered by http sources, it would be a meaningless example, cause jsfiddle blocks away mixed content. I hope you can help me though, i tried to clarify the questionRayden78
Which projection is this coordinate [-5920506.46285661, 1533632.5355137766]? Isn't it EPSG:3857? Why are you using EPSG:2000?Jonatas Walker
I wanted to display a quadratic map from an own XYZ source and it wasn't displayed right with EPSG:3857 .. i was just playing around and with EPSG:2000 it worked. That would maybe a topic for another question what projection to use for that purpose.Rayden78
I don't think that (projection) is another question. If [-5920506.46285661, 1533632.5355137766] is EPSG:3857 than you should use EPSG:3857.Jonatas Walker

1 Answers

-1
votes

I fixed the problem meanwhile, i was trying to load GeoJSON into my vector layer but the vector layer was always broken afterwards. As i was pretty new to open layers, i didn't notice my mistake, but i had syntax errors in my GeoJSON and the coordinates i supplied were also wrong.

After correcting the syntax and the coordinates everything is working as intended and as mentioned above EPSG:3857 was also the right thing to use. Sorry for my first messy experiences with open layers, but thanks for the friendly help ;)