Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I have a json file with large geometries(MultiLineString), here I got a Point among the json layer(baseLayer). I would like to search for a Point's LineString in the layer, from which MultiLineString that Point been selected. And how to read a json file in OpenLayers/JavaScript

I can project the json file in OpenLayers, but when I click the map I am getting the Point, from that Point I would like to search for its base geometry(LineString/MultiLineString)

Thank you

share|improve this question
    
Please provide your code in JS Fiddle –  Sunil Jan 2 '13 at 9:29

2 Answers 2

you can read json file in openlayers with OpenLayers.Format.GeoJSON().

  jsLayer = new OpenLayers.Layer.Vector("MyLayer", {
        strategies: [new OpenLayers.Strategy.Fixed()],
        projection: map.displayProjection,
        protocol: new OpenLayers.Protocol.HTTP({
            url: "jsons/roads.json",
            format: new OpenLayers.Format.GeoJSON()
        })
    });

UPDATE:

Searching point from another layer:

  layer.events.on({
        "featureselected": function(e) {    
             var mlFeat = multiLayer.features // Another Layer Features
             for(var a=0; a<mlFeat.length; a++){
                   var mlGeom = mlFeat[a].geometry;
                   if(e.geometry.x == mlGeom.x || e.geometry.y == mlGeom.y){
                      alert('Your Features')
                       }
                          }             
        }
      }); 

i hope it helps you...

share|improve this answer
    
Perfect answer : ) –  Sunil Jan 2 '13 at 9:26
    
I can project the json file OpenLayers, but when I click the map I am getting the Point from the Point I would like to search for its base geometry(LineString/MultiLineString) –  SriRamaChandra.G Jan 2 '13 at 9:28
    
thanks, let me try –  SriRamaChandra.G Jan 2 '13 at 9:42

Well if you want to select/find a feature you clicked can use the built in OpenLayers.Control.SelectFeature.

var selectfeature = new OpenLayers.Control.SelectFeature(    
  <OpenLayers.Layer.Vector>
 ,{ 
    multiple: false 
   ,onSelect: function( feature )
    {
      //feature already identified to you, do not need do point run
    }
  } 
);
share|improve this answer
    
thanks let me try –  SriRamaChandra.G Jan 7 '13 at 7:23

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.